]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/commitdiff
Fixes for 6.5
authorSasha Levin <sashal@kernel.org>
Sat, 4 Nov 2023 21:00:57 +0000 (17:00 -0400)
committerSasha Levin <sashal@kernel.org>
Sat, 4 Nov 2023 21:00:57 +0000 (17:00 -0400)
Signed-off-by: Sasha Levin <sashal@kernel.org>
queue-6.5/drm-amd-display-don-t-use-fsleep-for-psr-exit-waits.patch [new file with mode: 0644]
queue-6.5/perf-evlist-avoid-frequency-mode-for-the-dummy-event.patch [new file with mode: 0644]
queue-6.5/power-supply-core-use-blocking_notifier_call_chain-t.patch [new file with mode: 0644]
queue-6.5/rust-make-unsafecell-the-outer-type-in-opaque.patch [new file with mode: 0644]
queue-6.5/rust-types-make-opaque-be-unpin.patch [new file with mode: 0644]
queue-6.5/series

diff --git a/queue-6.5/drm-amd-display-don-t-use-fsleep-for-psr-exit-waits.patch b/queue-6.5/drm-amd-display-don-t-use-fsleep-for-psr-exit-waits.patch
new file mode 100644 (file)
index 0000000..f6f685c
--- /dev/null
@@ -0,0 +1,58 @@
+From dbad77a4bde800ff79148edd16910f09122f562e Mon Sep 17 00:00:00 2001
+From: Sasha Levin <sashal@kernel.org>
+Date: Wed, 27 Sep 2023 15:06:41 -0400
+Subject: drm/amd/display: Don't use fsleep for PSR exit waits
+
+From: Nicholas Kazlauskas <nicholas.kazlauskas@amd.com>
+
+[ Upstream commit 79df45dc4bfb13d9bd3a75338b9d9dab948be3d6 ]
+
+[Why]
+These functions can be called from high IRQ levels and the OS will hang
+if it tries to use a usleep_highres or a msleep.
+
+[How]
+Replace the fsleep with a udelay.
+
+Reviewed-by: Aric Cyr <aric.cyr@amd.com>
+Acked-by: Tom Chung <chiahsuan.chung@amd.com>
+Signed-off-by: Nicholas Kazlauskas <nicholas.kazlauskas@amd.com>
+Tested-by: Daniel Wheeler <daniel.wheeler@amd.com>
+Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
+Signed-off-by: Sasha Levin <sashal@kernel.org>
+---
+ drivers/gpu/drm/amd/display/dc/dce/dce_dmcu.c | 3 ++-
+ drivers/gpu/drm/amd/display/dc/dce/dmub_psr.c | 3 ++-
+ 2 files changed, 4 insertions(+), 2 deletions(-)
+
+diff --git a/drivers/gpu/drm/amd/display/dc/dce/dce_dmcu.c b/drivers/gpu/drm/amd/display/dc/dce/dce_dmcu.c
+index 63009db8b5a72..d156eeef466f9 100644
+--- a/drivers/gpu/drm/amd/display/dc/dce/dce_dmcu.c
++++ b/drivers/gpu/drm/amd/display/dc/dce/dce_dmcu.c
+@@ -586,7 +586,8 @@ static void dcn10_dmcu_set_psr_enable(struct dmcu *dmcu, bool enable, bool wait)
+                               if (state == PSR_STATE0)
+                                       break;
+                       }
+-                      fsleep(500);
++                      /* must *not* be fsleep - this can be called from high irq levels */
++                      udelay(500);
+               }
+               /* assert if max retry hit */
+diff --git a/drivers/gpu/drm/amd/display/dc/dce/dmub_psr.c b/drivers/gpu/drm/amd/display/dc/dce/dmub_psr.c
+index 0f24b6fbd2201..4704c9c85ee6f 100644
+--- a/drivers/gpu/drm/amd/display/dc/dce/dmub_psr.c
++++ b/drivers/gpu/drm/amd/display/dc/dce/dmub_psr.c
+@@ -216,7 +216,8 @@ static void dmub_psr_enable(struct dmub_psr *dmub, bool enable, bool wait, uint8
+                                       break;
+                       }
+-                      fsleep(500);
++                      /* must *not* be fsleep - this can be called from high irq levels */
++                      udelay(500);
+               }
+               /* assert if max retry hit */
+-- 
+2.42.0
+
diff --git a/queue-6.5/perf-evlist-avoid-frequency-mode-for-the-dummy-event.patch b/queue-6.5/perf-evlist-avoid-frequency-mode-for-the-dummy-event.patch
new file mode 100644 (file)
index 0000000..a624987
--- /dev/null
@@ -0,0 +1,86 @@
+From 34e9e42223b418a577afda629d6b2d059be15c3a 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 7ef43f72098e0..c779b9f2e6220 100644
+--- a/tools/perf/util/evlist.c
++++ b/tools/perf/util/evlist.c
+@@ -251,6 +251,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);
+@@ -277,8 +280,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
+
diff --git a/queue-6.5/power-supply-core-use-blocking_notifier_call_chain-t.patch b/queue-6.5/power-supply-core-use-blocking_notifier_call_chain-t.patch
new file mode 100644 (file)
index 0000000..4411f14
--- /dev/null
@@ -0,0 +1,160 @@
+From c9d233d7576d5446f134ca7b331d1c2efcd0b8f1 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 3791aec69ddc6..0d2e72a966c9b 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);
+@@ -1262,13 +1262,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 a427f13c757f4..85b86768c0b91 100644
+--- a/include/linux/power_supply.h
++++ b/include/linux/power_supply.h
+@@ -767,7 +767,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
+
diff --git a/queue-6.5/rust-make-unsafecell-the-outer-type-in-opaque.patch b/queue-6.5/rust-make-unsafecell-the-outer-type-in-opaque.patch
new file mode 100644 (file)
index 0000000..683a930
--- /dev/null
@@ -0,0 +1,77 @@
+From 8454e37da13e2e16b631683e9dbca6148aa5c5ee Mon Sep 17 00:00:00 2001
+From: Sasha Levin <sashal@kernel.org>
+Date: Wed, 14 Jun 2023 11:53:28 +0000
+Subject: rust: make `UnsafeCell` the outer type in `Opaque`
+
+From: Alice Ryhl <aliceryhl@google.com>
+
+[ Upstream commit 35cad617df2eeef8440a38e82bb2d81ae32ca50d ]
+
+When combining `UnsafeCell` with `MaybeUninit`, it is idiomatic to use
+`UnsafeCell` as the outer type. Intuitively, this is because a
+`MaybeUninit<T>` might not contain a `T`, but we always want the effect
+of the `UnsafeCell`, even if the inner value is uninitialized.
+
+Now, strictly speaking, this doesn't really make a difference. The
+compiler will always apply the `UnsafeCell` effect even if the inner
+value is uninitialized. But I think we should follow the convention
+here.
+
+Signed-off-by: Alice Ryhl <aliceryhl@google.com>
+Reviewed-by: Benno Lossin <benno.lossin@proton.me>
+Reviewed-by: Gary Guo <gary@garyguo.net>
+Reviewed-by: Martin Rodriguez Reboredo <yakoyoku@gmail.com>
+Link: https://lore.kernel.org/r/20230614115328.2825961-1-aliceryhl@google.com
+Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
+Stable-dep-of: 0b4e3b6f6b79 ("rust: types: make `Opaque` be `!Unpin`")
+Signed-off-by: Sasha Levin <sashal@kernel.org>
+---
+ rust/kernel/types.rs | 10 +++++-----
+ 1 file changed, 5 insertions(+), 5 deletions(-)
+
+diff --git a/rust/kernel/types.rs b/rust/kernel/types.rs
+index d479f8da8f381..c0b8bb1a75393 100644
+--- a/rust/kernel/types.rs
++++ b/rust/kernel/types.rs
+@@ -206,17 +206,17 @@ fn drop(&mut self) {
+ ///
+ /// This is meant to be used with FFI objects that are never interpreted by Rust code.
+ #[repr(transparent)]
+-pub struct Opaque<T>(MaybeUninit<UnsafeCell<T>>);
++pub struct Opaque<T>(UnsafeCell<MaybeUninit<T>>);
+ impl<T> Opaque<T> {
+     /// Creates a new opaque value.
+     pub const fn new(value: T) -> Self {
+-        Self(MaybeUninit::new(UnsafeCell::new(value)))
++        Self(UnsafeCell::new(MaybeUninit::new(value)))
+     }
+     /// Creates an uninitialised value.
+     pub const fn uninit() -> Self {
+-        Self(MaybeUninit::uninit())
++        Self(UnsafeCell::new(MaybeUninit::uninit()))
+     }
+     /// Creates a pin-initializer from the given initializer closure.
+@@ -240,7 +240,7 @@ pub fn ffi_init(init_func: impl FnOnce(*mut T)) -> impl PinInit<Self> {
+     /// Returns a raw pointer to the opaque data.
+     pub fn get(&self) -> *mut T {
+-        UnsafeCell::raw_get(self.0.as_ptr())
++        UnsafeCell::get(&self.0).cast::<T>()
+     }
+     /// Gets the value behind `this`.
+@@ -248,7 +248,7 @@ pub fn get(&self) -> *mut T {
+     /// This function is useful to get access to the value without creating intermediate
+     /// references.
+     pub const fn raw_get(this: *const Self) -> *mut T {
+-        UnsafeCell::raw_get(this.cast::<UnsafeCell<T>>())
++        UnsafeCell::raw_get(this.cast::<UnsafeCell<MaybeUninit<T>>>()).cast::<T>()
+     }
+ }
+-- 
+2.42.0
+
diff --git a/queue-6.5/rust-types-make-opaque-be-unpin.patch b/queue-6.5/rust-types-make-opaque-be-unpin.patch
new file mode 100644 (file)
index 0000000..6d2cca4
--- /dev/null
@@ -0,0 +1,82 @@
+From f87ce940559e9da9e39f3fd1388362e2ecd7971f Mon Sep 17 00:00:00 2001
+From: Sasha Levin <sashal@kernel.org>
+Date: Fri, 30 Jun 2023 15:03:23 +0000
+Subject: rust: types: make `Opaque` be `!Unpin`
+
+From: Benno Lossin <benno.lossin@proton.me>
+
+[ Upstream commit 0b4e3b6f6b79b1add04008a6ceaaf661107e8902 ]
+
+Adds a `PhantomPinned` field to `Opaque<T>`. This removes the last Rust
+guarantee: the assumption that the type `T` can be freely moved. This is
+not the case for many types from the C side (e.g. if they contain a
+`struct list_head`). This change removes the need to add a
+`PhantomPinned` field manually to Rust structs that contain C structs
+which must not be moved.
+
+Signed-off-by: Benno Lossin <benno.lossin@proton.me>
+Reviewed-by: Gary Guo <gary@garyguo.net>
+Reviewed-by: Alice Ryhl <aliceryhl@google.com>
+Reviewed-by: Andreas Hindborg <a.hindborg@samsung.com>
+Link: https://lore.kernel.org/r/20230630150216.109789-1-benno.lossin@proton.me
+Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
+Signed-off-by: Sasha Levin <sashal@kernel.org>
+---
+ rust/kernel/types.rs | 19 ++++++++++++++-----
+ 1 file changed, 14 insertions(+), 5 deletions(-)
+
+diff --git a/rust/kernel/types.rs b/rust/kernel/types.rs
+index c0b8bb1a75393..50cbd767ea9dd 100644
+--- a/rust/kernel/types.rs
++++ b/rust/kernel/types.rs
+@@ -6,7 +6,7 @@
+ use alloc::boxed::Box;
+ use core::{
+     cell::UnsafeCell,
+-    marker::PhantomData,
++    marker::{PhantomData, PhantomPinned},
+     mem::MaybeUninit,
+     ops::{Deref, DerefMut},
+     ptr::NonNull,
+@@ -206,17 +206,26 @@ fn drop(&mut self) {
+ ///
+ /// This is meant to be used with FFI objects that are never interpreted by Rust code.
+ #[repr(transparent)]
+-pub struct Opaque<T>(UnsafeCell<MaybeUninit<T>>);
++pub struct Opaque<T> {
++    value: UnsafeCell<MaybeUninit<T>>,
++    _pin: PhantomPinned,
++}
+ impl<T> Opaque<T> {
+     /// Creates a new opaque value.
+     pub const fn new(value: T) -> Self {
+-        Self(UnsafeCell::new(MaybeUninit::new(value)))
++        Self {
++            value: UnsafeCell::new(MaybeUninit::new(value)),
++            _pin: PhantomPinned,
++        }
+     }
+     /// Creates an uninitialised value.
+     pub const fn uninit() -> Self {
+-        Self(UnsafeCell::new(MaybeUninit::uninit()))
++        Self {
++            value: UnsafeCell::new(MaybeUninit::uninit()),
++            _pin: PhantomPinned,
++        }
+     }
+     /// Creates a pin-initializer from the given initializer closure.
+@@ -240,7 +249,7 @@ pub fn ffi_init(init_func: impl FnOnce(*mut T)) -> impl PinInit<Self> {
+     /// Returns a raw pointer to the opaque data.
+     pub fn get(&self) -> *mut T {
+-        UnsafeCell::get(&self.0).cast::<T>()
++        UnsafeCell::get(&self.value).cast::<T>()
+     }
+     /// Gets the value behind `this`.
+-- 
+2.42.0
+
index 3daef848495a00b7e8bef4a827188dbcf8eca2e4..fbfe0a81057b002ac9525823566b61d9088ca1ed 100644 (file)
@@ -58,3 +58,8 @@ r8152-rename-rtl8152_unplug-to-rtl8152_inaccessible.patch
 powerpc-mm-fix-boot-crash-with-flatmem.patch
 io_uring-kiocb_done-should-not-trust-ki_pos-if-read-.patch
 ceph_wait_on_conflict_unlink-grab-reference-before-d.patch
+drm-amd-display-don-t-use-fsleep-for-psr-exit-waits.patch
+rust-make-unsafecell-the-outer-type-in-opaque.patch
+rust-types-make-opaque-be-unpin.patch
+power-supply-core-use-blocking_notifier_call_chain-t.patch
+perf-evlist-avoid-frequency-mode-for-the-dummy-event.patch