--- /dev/null
+From 59399ffb6cd4ddc3b756cecd3afb401dd0e259af Mon Sep 17 00:00:00 2001
+From: Sasha Levin <sashal@kernel.org>
+Date: Fri, 15 Sep 2023 20:56:40 -0700
+Subject: perf evlist: Avoid frequency mode for the dummy event
+
+From: Ian Rogers <irogers@google.com>
+
+[ Upstream commit f9cdeb58a9cf46c09b56f5f661ea8da24b6458c3 ]
+
+Dummy events are created with an attribute where the period and freq
+are zero. evsel__config will then see the uninitialized values and
+initialize them in evsel__default_freq_period. As fequency mode is
+used by default the dummy event would be set to use frequency
+mode. However, this has no effect on the dummy event but does cause
+unnecessary timers/interrupts. Avoid this overhead by setting the
+period to 1 for dummy events.
+
+evlist__add_aux_dummy calls evlist__add_dummy then sets freq=0 and
+period=1. This isn't necessary after this change and so the setting is
+removed.
+
+From Stephane:
+
+The dummy event is not counting anything. It is used to collect mmap
+records and avoid a race condition during the synthesize mmap phase of
+perf record. As such, it should not cause any overhead during active
+profiling. Yet, it did. Because of a bug the dummy event was
+programmed as a sampling event in frequency mode. Events in that mode
+incur more kernel overheads because on timer tick, the kernel has to
+look at the number of samples for each event and potentially adjust
+the sampling period to achieve the desired frequency. The dummy event
+was therefore adding a frequency event to task and ctx contexts we may
+otherwise not have any, e.g.,
+
+ perf record -a -e cpu/event=0x3c,period=10000000/.
+
+On each timer tick the perf_adjust_freq_unthr_context() is invoked and
+if ctx->nr_freq is non-zero, then the kernel will loop over ALL the
+events of the context looking for frequency mode ones. In doing, so it
+locks the context, and enable/disable the PMU of each hw event. If all
+the events of the context are in period mode, the kernel will have to
+traverse the list for nothing incurring overhead. The overhead is
+multiplied by a very large factor when this happens in a guest kernel.
+There is no need for the dummy event to be in frequency mode, it does
+not count anything and therefore should not cause extra overhead for
+no reason.
+
+Fixes: 5bae0250237f ("perf evlist: Introduce perf_evlist__new_dummy constructor")
+Reported-by: Stephane Eranian <eranian@google.com>
+Signed-off-by: Ian Rogers <irogers@google.com>
+Acked-by: Adrian Hunter <adrian.hunter@intel.com>
+Cc: Yang Jihong <yangjihong1@huawei.com>
+Cc: Kan Liang <kan.liang@linux.intel.com>
+Link: https://lore.kernel.org/r/20230916035640.1074422-1-irogers@google.com
+Signed-off-by: Namhyung Kim <namhyung@kernel.org>
+Signed-off-by: Sasha Levin <sashal@kernel.org>
+---
+ tools/perf/util/evlist.c | 5 +++--
+ 1 file changed, 3 insertions(+), 2 deletions(-)
+
+diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
+index 6612b00949e70..ca08e6dc8b232 100644
+--- a/tools/perf/util/evlist.c
++++ b/tools/perf/util/evlist.c
+@@ -252,6 +252,9 @@ static struct evsel *evlist__dummy_event(struct evlist *evlist)
+ .type = PERF_TYPE_SOFTWARE,
+ .config = PERF_COUNT_SW_DUMMY,
+ .size = sizeof(attr), /* to capture ABI version */
++ /* Avoid frequency mode for dummy events to avoid associated timers. */
++ .freq = 0,
++ .sample_period = 1,
+ };
+
+ return evsel__new_idx(&attr, evlist->core.nr_entries);
+@@ -278,8 +281,6 @@ struct evsel *evlist__add_aux_dummy(struct evlist *evlist, bool system_wide)
+ evsel->core.attr.exclude_kernel = 1;
+ evsel->core.attr.exclude_guest = 1;
+ evsel->core.attr.exclude_hv = 1;
+- evsel->core.attr.freq = 0;
+- evsel->core.attr.sample_period = 1;
+ evsel->core.system_wide = system_wide;
+ evsel->no_aux_samples = true;
+ evsel->name = strdup("dummy:u");
+--
+2.42.0
+
--- /dev/null
+From c3a82422b8bb2f20814a2ba45546c2ebb9619d5a Mon Sep 17 00:00:00 2001
+From: Sasha Levin <sashal@kernel.org>
+Date: Wed, 13 Sep 2023 11:32:33 +0800
+Subject: power: supply: core: Use blocking_notifier_call_chain to avoid RCU
+ complaint
+
+From: Kai-Heng Feng <kai.heng.feng@canonical.com>
+
+[ Upstream commit bbaa6ffa5b6c9609d3b3c431c389b407eea5441f ]
+
+AMD PMF driver can cause the following warning:
+[ 196.159546] ------------[ cut here ]------------
+[ 196.159556] Voluntary context switch within RCU read-side critical section!
+[ 196.159571] WARNING: CPU: 0 PID: 9 at kernel/rcu/tree_plugin.h:320 rcu_note_context_switch+0x43d/0x560
+[ 196.159604] Modules linked in: nvme_fabrics ccm rfcomm snd_hda_scodec_cs35l41_spi cmac algif_hash algif_skcipher af_alg bnep joydev btusb btrtl uvcvideo btintel btbcm videobuf2_vmalloc intel_rapl_msr btmtk videobuf2_memops uvc videobuf2_v4l2 intel_rapl_common binfmt_misc hid_sensor_als snd_sof_amd_vangogh hid_sensor_trigger bluetooth industrialio_triggered_buffer videodev snd_sof_amd_rembrandt hid_sensor_iio_common amdgpu ecdh_generic kfifo_buf videobuf2_common hp_wmi kvm_amd sparse_keymap snd_sof_amd_renoir wmi_bmof industrialio ecc mc nls_iso8859_1 kvm snd_sof_amd_acp irqbypass snd_sof_xtensa_dsp crct10dif_pclmul crc32_pclmul mt7921e snd_sof_pci snd_ctl_led polyval_clmulni mt7921_common polyval_generic snd_sof ghash_clmulni_intel mt792x_lib mt76_connac_lib sha512_ssse3 snd_sof_utils aesni_intel snd_hda_codec_realtek crypto_simd mt76 snd_hda_codec_generic cryptd snd_soc_core snd_hda_codec_hdmi rapl ledtrig_audio input_leds snd_compress i2c_algo_bit drm_ttm_helper mac80211 snd_pci_ps hid_multitouch ttm drm_exec
+[ 196.159970] drm_suballoc_helper snd_rpl_pci_acp6x amdxcp drm_buddy snd_hda_intel snd_acp_pci snd_hda_scodec_cs35l41_i2c serio_raw gpu_sched snd_hda_scodec_cs35l41 snd_acp_legacy_common snd_intel_dspcfg snd_hda_cs_dsp_ctls snd_hda_codec libarc4 drm_display_helper snd_pci_acp6x cs_dsp snd_hwdep snd_soc_cs35l41_lib video k10temp snd_pci_acp5x thunderbolt snd_hda_core drm_kms_helper cfg80211 snd_seq snd_rn_pci_acp3x snd_pcm snd_acp_config cec snd_soc_acpi snd_seq_device rc_core ccp snd_pci_acp3x snd_timer snd soundcore wmi amd_pmf platform_profile amd_pmc mac_hid serial_multi_instantiate wireless_hotkey hid_sensor_hub sch_fq_codel msr parport_pc ppdev lp parport efi_pstore ip_tables x_tables autofs4 btrfs blake2b_generic raid10 raid456 async_raid6_recov async_memcpy async_pq async_xor async_tx libcrc32c xor raid6_pq raid1 raid0 multipath linear dm_mirror dm_region_hash dm_log cdc_ether usbnet r8152 mii hid_generic nvme i2c_hid_acpi i2c_hid nvme_core i2c_piix4 xhci_pci amd_sfh drm xhci_pci_renesas nvme_common hid
+[ 196.160382] CPU: 0 PID: 9 Comm: kworker/0:1 Not tainted 6.6.0-rc1 #4
+[ 196.160397] Hardware name: HP HP EliteBook 845 14 inch G10 Notebook PC/8B6E, BIOS V82 Ver. 01.02.00 08/24/2023
+[ 196.160405] Workqueue: events power_supply_changed_work
+[ 196.160426] RIP: 0010:rcu_note_context_switch+0x43d/0x560
+[ 196.160440] Code: 00 48 89 be 40 08 00 00 48 89 86 48 08 00 00 48 89 10 e9 63 fe ff ff 48 c7 c7 10 e7 b0 9e c6 05 e8 d8 20 02 01 e8 13 0f f3 ff <0f> 0b e9 27 fc ff ff a9 ff ff ff 7f 0f 84 cf fc ff ff 65 48 8b 3c
+[ 196.160450] RSP: 0018:ffffc900001878f0 EFLAGS: 00010046
+[ 196.160462] RAX: 0000000000000000 RBX: ffff88885e834040 RCX: 0000000000000000
+[ 196.160470] RDX: 0000000000000000 RSI: 0000000000000000 RDI: 0000000000000000
+[ 196.160476] RBP: ffffc90000187910 R08: 0000000000000000 R09: 0000000000000000
+[ 196.160482] R10: 0000000000000000 R11: 0000000000000000 R12: 0000000000000000
+[ 196.160488] R13: 0000000000000000 R14: ffff888100990000 R15: ffff888100990000
+[ 196.160495] FS: 0000000000000000(0000) GS:ffff88885e800000(0000) knlGS:0000000000000000
+[ 196.160504] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
+[ 196.160512] CR2: 000055cb053c8246 CR3: 000000013443a000 CR4: 0000000000750ef0
+[ 196.160520] PKRU: 55555554
+[ 196.160526] Call Trace:
+[ 196.160532] <TASK>
+[ 196.160548] ? show_regs+0x72/0x90
+[ 196.160570] ? rcu_note_context_switch+0x43d/0x560
+[ 196.160580] ? __warn+0x8d/0x160
+[ 196.160600] ? rcu_note_context_switch+0x43d/0x560
+[ 196.160613] ? report_bug+0x1bb/0x1d0
+[ 196.160637] ? handle_bug+0x46/0x90
+[ 196.160658] ? exc_invalid_op+0x19/0x80
+[ 196.160675] ? asm_exc_invalid_op+0x1b/0x20
+[ 196.160709] ? rcu_note_context_switch+0x43d/0x560
+[ 196.160727] __schedule+0xb9/0x15f0
+[ 196.160746] ? srso_alias_return_thunk+0x5/0x7f
+[ 196.160765] ? srso_alias_return_thunk+0x5/0x7f
+[ 196.160778] ? acpi_ns_search_one_scope+0xbe/0x270
+[ 196.160806] schedule+0x68/0x110
+[ 196.160820] schedule_timeout+0x151/0x160
+[ 196.160829] ? srso_alias_return_thunk+0x5/0x7f
+[ 196.160842] ? srso_alias_return_thunk+0x5/0x7f
+[ 196.160855] ? acpi_ns_lookup+0x3c5/0xa90
+[ 196.160878] __down_common+0xff/0x220
+[ 196.160905] __down_timeout+0x16/0x30
+[ 196.160920] down_timeout+0x64/0x70
+[ 196.160938] acpi_os_wait_semaphore+0x85/0x200
+[ 196.160959] acpi_ut_acquire_mutex+0x9e/0x280
+[ 196.160979] acpi_ex_enter_interpreter+0x2d/0xb0
+[ 196.160992] acpi_ns_evaluate+0x2f0/0x5f0
+[ 196.161005] acpi_evaluate_object+0x172/0x490
+[ 196.161018] ? acpi_os_signal_semaphore+0x8a/0xd0
+[ 196.161038] acpi_evaluate_integer+0x52/0xe0
+[ 196.161055] ? kfree+0x79/0x120
+[ 196.161071] ? srso_alias_return_thunk+0x5/0x7f
+[ 196.161089] acpi_ac_get_state.part.0+0x27/0x80
+[ 196.161110] get_ac_property+0x5c/0x70
+[ 196.161127] ? __pfx___power_supply_is_system_supplied+0x10/0x10
+[ 196.161146] __power_supply_is_system_supplied+0x44/0xb0
+[ 196.161166] class_for_each_device+0x124/0x160
+[ 196.161184] ? acpi_ac_get_state.part.0+0x27/0x80
+[ 196.161203] ? srso_alias_return_thunk+0x5/0x7f
+[ 196.161223] power_supply_is_system_supplied+0x3c/0x70
+[ 196.161243] amd_pmf_get_power_source+0xe/0x20 [amd_pmf]
+[ 196.161276] amd_pmf_power_slider_update_event+0x49/0x90 [amd_pmf]
+[ 196.161310] amd_pmf_pwr_src_notify_call+0xe7/0x100 [amd_pmf]
+[ 196.161340] notifier_call_chain+0x5f/0xe0
+[ 196.161362] atomic_notifier_call_chain+0x33/0x60
+[ 196.161378] power_supply_changed_work+0x84/0x110
+[ 196.161394] process_one_work+0x178/0x360
+[ 196.161412] ? __pfx_worker_thread+0x10/0x10
+[ 196.161424] worker_thread+0x307/0x430
+[ 196.161440] ? __pfx_worker_thread+0x10/0x10
+[ 196.161451] kthread+0xf4/0x130
+[ 196.161467] ? __pfx_kthread+0x10/0x10
+[ 196.161486] ret_from_fork+0x43/0x70
+[ 196.161502] ? __pfx_kthread+0x10/0x10
+[ 196.161518] ret_from_fork_asm+0x1b/0x30
+[ 196.161558] </TASK>
+[ 196.161562] ---[ end trace 0000000000000000 ]---
+
+Since there's no guarantee that all the callbacks can work in atomic
+context, switch to use blocking_notifier_call_chain to relax the
+constraint.
+
+Signed-off-by: Kai-Heng Feng <kai.heng.feng@canonical.com>
+Reported-by: Allen Zhong <allen@atr.me>
+Fixes: 4c71ae414474 ("platform/x86/amd/pmf: Add support SPS PMF feature")
+Closes: https://bugzilla.kernel.org/show_bug.cgi?id=217571
+Reviewed-by: Mario Limonciello <mario.limonciello@amd.com>
+Link: https://lore.kernel.org/r/20230913033233.602986-1-kai.heng.feng@canonical.com
+Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
+Signed-off-by: Sasha Levin <sashal@kernel.org>
+---
+ drivers/power/supply/power_supply_core.c | 8 ++++----
+ include/linux/power_supply.h | 2 +-
+ 2 files changed, 5 insertions(+), 5 deletions(-)
+
+diff --git a/drivers/power/supply/power_supply_core.c b/drivers/power/supply/power_supply_core.c
+index 7871ab5e979c0..ac88c9636b663 100644
+--- a/drivers/power/supply/power_supply_core.c
++++ b/drivers/power/supply/power_supply_core.c
+@@ -29,7 +29,7 @@
+ struct class *power_supply_class;
+ EXPORT_SYMBOL_GPL(power_supply_class);
+
+-ATOMIC_NOTIFIER_HEAD(power_supply_notifier);
++BLOCKING_NOTIFIER_HEAD(power_supply_notifier);
+ EXPORT_SYMBOL_GPL(power_supply_notifier);
+
+ static struct device_type power_supply_dev_type;
+@@ -97,7 +97,7 @@ static void power_supply_changed_work(struct work_struct *work)
+ class_for_each_device(power_supply_class, NULL, psy,
+ __power_supply_changed_work);
+ power_supply_update_leds(psy);
+- atomic_notifier_call_chain(&power_supply_notifier,
++ blocking_notifier_call_chain(&power_supply_notifier,
+ PSY_EVENT_PROP_CHANGED, psy);
+ kobject_uevent(&psy->dev.kobj, KOBJ_CHANGE);
+ spin_lock_irqsave(&psy->changed_lock, flags);
+@@ -1112,13 +1112,13 @@ static void power_supply_dev_release(struct device *dev)
+
+ int power_supply_reg_notifier(struct notifier_block *nb)
+ {
+- return atomic_notifier_chain_register(&power_supply_notifier, nb);
++ return blocking_notifier_chain_register(&power_supply_notifier, nb);
+ }
+ EXPORT_SYMBOL_GPL(power_supply_reg_notifier);
+
+ void power_supply_unreg_notifier(struct notifier_block *nb)
+ {
+- atomic_notifier_chain_unregister(&power_supply_notifier, nb);
++ blocking_notifier_chain_unregister(&power_supply_notifier, nb);
+ }
+ EXPORT_SYMBOL_GPL(power_supply_unreg_notifier);
+
+diff --git a/include/linux/power_supply.h b/include/linux/power_supply.h
+index aa2c4a7c4826d..a10428884e6a5 100644
+--- a/include/linux/power_supply.h
++++ b/include/linux/power_supply.h
+@@ -766,7 +766,7 @@ struct power_supply_battery_info {
+ int bti_resistance_tolerance;
+ };
+
+-extern struct atomic_notifier_head power_supply_notifier;
++extern struct blocking_notifier_head power_supply_notifier;
+ extern int power_supply_reg_notifier(struct notifier_block *nb);
+ extern void power_supply_unreg_notifier(struct notifier_block *nb);
+ #if IS_ENABLED(CONFIG_POWER_SUPPLY)
+--
+2.42.0
+