From bd2f13f85be8f42e670b4d362df9bf4b522061a8 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Mon, 13 May 2024 15:09:41 +0200 Subject: [PATCH] 6.1-stable patches added patches: btf-scripts-rust-drop-is_rust_module.sh.patch rust-error-rename-to_kernel_errno-to_errno.patch rust-fix-regexp-in-scripts-is_rust_module.sh.patch rust-macros-fix-soundness-issue-in-module-macro.patch rust-module-place-generated-init_module-function-in-.init.text.patch usb-typec-ucsi-check-for-notifications-after-init.patch usb-typec-ucsi-fix-connector-check-on-init.patch --- ...-scripts-rust-drop-is_rust_module.sh.patch | 84 ++++++ ...rror-rename-to_kernel_errno-to_errno.patch | 45 +++ ...-regexp-in-scripts-is_rust_module.sh.patch | 58 ++++ ...-fix-soundness-issue-in-module-macro.patch | 261 ++++++++++++++++++ ...d-init_module-function-in-.init.text.patch | 68 +++++ queue-6.1/series | 7 + ...i-check-for-notifications-after-init.patch | 64 +++++ ...pec-ucsi-fix-connector-check-on-init.patch | 42 +++ 8 files changed, 629 insertions(+) create mode 100644 queue-6.1/btf-scripts-rust-drop-is_rust_module.sh.patch create mode 100644 queue-6.1/rust-error-rename-to_kernel_errno-to_errno.patch create mode 100644 queue-6.1/rust-fix-regexp-in-scripts-is_rust_module.sh.patch create mode 100644 queue-6.1/rust-macros-fix-soundness-issue-in-module-macro.patch create mode 100644 queue-6.1/rust-module-place-generated-init_module-function-in-.init.text.patch create mode 100644 queue-6.1/usb-typec-ucsi-check-for-notifications-after-init.patch create mode 100644 queue-6.1/usb-typec-ucsi-fix-connector-check-on-init.patch diff --git a/queue-6.1/btf-scripts-rust-drop-is_rust_module.sh.patch b/queue-6.1/btf-scripts-rust-drop-is_rust_module.sh.patch new file mode 100644 index 00000000000..897f6b759a9 --- /dev/null +++ b/queue-6.1/btf-scripts-rust-drop-is_rust_module.sh.patch @@ -0,0 +1,84 @@ +From 41bdc6decda074afc4d8f8ba44c69b08d0e9aff6 Mon Sep 17 00:00:00 2001 +From: Andrea Righi +Date: Tue, 4 Jul 2023 07:21:36 +0200 +Subject: btf, scripts: rust: drop is_rust_module.sh + +From: Andrea Righi + +commit 41bdc6decda074afc4d8f8ba44c69b08d0e9aff6 upstream. + +With commit c1177979af9c ("btf, scripts: Exclude Rust CUs with pahole") +we are now able to use pahole directly to identify Rust compilation +units (CUs) and exclude them from generating BTF debugging information +(when DEBUG_INFO_BTF is enabled). + +And if pahole doesn't support the --lang-exclude flag, we can't enable +both RUST and DEBUG_INFO_BTF at the same time. + +So, in any case, the script is_rust_module.sh is just redundant and we +can drop it. + +NOTE: we may also be able to drop the "Rust loadable module" mark +inside Rust modules, but it seems safer to keep it for now to make sure +we are not breaking any external tool that may potentially rely on it. + +Signed-off-by: Andrea Righi +Reviewed-by: Nathan Chancellor +Tested-by: Eric Curtin +Reviewed-by: Eric Curtin +Reviewed-by: Neal Gompa +Reviewed-by: Masahiro Yamada +Reviewed-by: Martin Rodriguez Reboredo +Acked-by: Daniel Xu +Link: https://lore.kernel.org/r/20230704052136.155445-1-andrea.righi@canonical.com +[ Picked the `Reviewed-by`s from the old patch too. ] +Signed-off-by: Miguel Ojeda +Signed-off-by: Greg Kroah-Hartman +--- + rust/macros/module.rs | 2 +- + scripts/Makefile.modfinal | 2 -- + scripts/is_rust_module.sh | 16 ---------------- + 3 files changed, 1 insertion(+), 19 deletions(-) + delete mode 100755 scripts/is_rust_module.sh + +--- a/rust/macros/module.rs ++++ b/rust/macros/module.rs +@@ -179,7 +179,7 @@ pub(crate) fn module(ts: TokenStream) -> + /// Used by the printing macros, e.g. [`info!`]. + const __LOG_PREFIX: &[u8] = b\"{name}\\0\"; + +- /// The \"Rust loadable module\" mark, for `scripts/is_rust_module.sh`. ++ /// The \"Rust loadable module\" mark. + // + // This may be best done another way later on, e.g. as a new modinfo + // key or a new section. For the moment, keep it simple. +--- a/scripts/Makefile.modfinal ++++ b/scripts/Makefile.modfinal +@@ -41,8 +41,6 @@ quiet_cmd_btf_ko = BTF [M] $@ + cmd_btf_ko = \ + if [ ! -f vmlinux ]; then \ + printf "Skipping BTF generation for %s due to unavailability of vmlinux\n" $@ 1>&2; \ +- elif [ -n "$(CONFIG_RUST)" ] && $(srctree)/scripts/is_rust_module.sh $@; then \ +- printf "Skipping BTF generation for %s because it's a Rust module\n" $@ 1>&2; \ + else \ + LLVM_OBJCOPY="$(OBJCOPY)" $(PAHOLE) -J $(PAHOLE_FLAGS) --btf_base vmlinux $@; \ + $(RESOLVE_BTFIDS) -b vmlinux $@; \ +--- a/scripts/is_rust_module.sh ++++ /dev/null +@@ -1,16 +0,0 @@ +-#!/bin/sh +-# SPDX-License-Identifier: GPL-2.0 +-# +-# is_rust_module.sh module.ko +-# +-# Returns `0` if `module.ko` is a Rust module, `1` otherwise. +- +-set -e +- +-# Using the `16_` prefix ensures other symbols with the same substring +-# are not picked up (even if it would be unlikely). The last part is +-# used just in case LLVM decides to use the `.` suffix. +-# +-# In the future, checking for the `.comment` section may be another +-# option, see https://github.com/rust-lang/rust/pull/97550. +-${NM} "$*" | grep -qE '^[0-9a-fA-F]+ [Rr] _R[^[:space:]]+16___IS_RUST_MODULE[^[:space:]]*$' diff --git a/queue-6.1/rust-error-rename-to_kernel_errno-to_errno.patch b/queue-6.1/rust-error-rename-to_kernel_errno-to_errno.patch new file mode 100644 index 00000000000..d0ec98edc41 --- /dev/null +++ b/queue-6.1/rust-error-rename-to_kernel_errno-to_errno.patch @@ -0,0 +1,45 @@ +From 46384d0990bf99ed8b597e8794ea581e2a647710 Mon Sep 17 00:00:00 2001 +From: Asahi Lina +Date: Mon, 3 Apr 2023 18:48:10 +0900 +Subject: rust: error: Rename to_kernel_errno() -> to_errno() + +From: Asahi Lina + +commit 46384d0990bf99ed8b597e8794ea581e2a647710 upstream. + +This is kernel code, so specifying "kernel" is redundant. Let's simplify +things and just call it to_errno(). + +Reviewed-by: Gary Guo +Reviewed-by: Martin Rodriguez Reboredo +Signed-off-by: Asahi Lina +Link: https://lore.kernel.org/r/20230224-rust-error-v3-1-03779bddc02b@asahilina.net +Signed-off-by: Miguel Ojeda +Signed-off-by: Greg Kroah-Hartman +--- + rust/kernel/error.rs | 2 +- + rust/macros/module.rs | 2 +- + 2 files changed, 2 insertions(+), 2 deletions(-) + +--- a/rust/kernel/error.rs ++++ b/rust/kernel/error.rs +@@ -25,7 +25,7 @@ pub struct Error(core::ffi::c_int); + + impl Error { + /// Returns the kernel error code. +- pub fn to_kernel_errno(self) -> core::ffi::c_int { ++ pub fn to_errno(self) -> core::ffi::c_int { + self.0 + } + } +--- a/rust/macros/module.rs ++++ b/rust/macros/module.rs +@@ -258,7 +258,7 @@ pub(crate) fn module(ts: TokenStream) -> + return 0; + }} + Err(e) => {{ +- return e.to_kernel_errno(); ++ return e.to_errno(); + }} + }} + }} diff --git a/queue-6.1/rust-fix-regexp-in-scripts-is_rust_module.sh.patch b/queue-6.1/rust-fix-regexp-in-scripts-is_rust_module.sh.patch new file mode 100644 index 00000000000..ba367be200f --- /dev/null +++ b/queue-6.1/rust-fix-regexp-in-scripts-is_rust_module.sh.patch @@ -0,0 +1,58 @@ +From ccc4505454db10402d5284f22d8b7db62e636fc5 Mon Sep 17 00:00:00 2001 +From: Andrea Righi +Date: Fri, 10 Feb 2023 16:26:22 +0100 +Subject: rust: fix regexp in scripts/is_rust_module.sh + +From: Andrea Righi + +commit ccc4505454db10402d5284f22d8b7db62e636fc5 upstream. + +nm can use "R" or "r" to show read-only data sections, but +scripts/is_rust_module.sh can only recognize "r", so with some versions +of binutils it can fail to detect if a module is a Rust module or not. + +Right now we're using this script only to determine if we need to skip +BTF generation (that is disabled globally if CONFIG_RUST is enabled), +but it's still nice to fix this script to do the proper job. + +Moreover, with this patch applied I can also relax the constraint of +"RUST depends on !DEBUG_INFO_BTF" and build a kernel with Rust and BTF +enabled at the same time (of course BTF generation is still skipped for +Rust modules). + +[ Miguel: The actual reason is likely to be a change on the Rust + compiler between 1.61.0 and 1.62.0: + + echo '#[used] static S: () = ();' | + rustup run 1.61.0 rustc --emit=obj --crate-type=lib - && + nm rust_out.o + + echo '#[used] static S: () = ();' | + rustup run 1.62.0 rustc --emit=obj --crate-type=lib - && + nm rust_out.o + + Gives: + + 0000000000000000 r _ZN8rust_out1S17h48027ce0da975467E + 0000000000000000 R _ZN8rust_out1S17h58e1f3d9c0e97cefE + + See https://godbolt.org/z/KE6jneoo4. ] + +Signed-off-by: Andrea Righi +Reviewed-by: Vincenzo Palazzo +Reviewed-by: Eric Curtin +Reviewed-by: Martin Rodriguez Reboredo +Signed-off-by: Miguel Ojeda +Signed-off-by: Greg Kroah-Hartman +--- + scripts/is_rust_module.sh | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +--- a/scripts/is_rust_module.sh ++++ b/scripts/is_rust_module.sh +@@ -13,4 +13,4 @@ set -e + # + # In the future, checking for the `.comment` section may be another + # option, see https://github.com/rust-lang/rust/pull/97550. +-${NM} "$*" | grep -qE '^[0-9a-fA-F]+ r _R[^[:space:]]+16___IS_RUST_MODULE[^[:space:]]*$' ++${NM} "$*" | grep -qE '^[0-9a-fA-F]+ [Rr] _R[^[:space:]]+16___IS_RUST_MODULE[^[:space:]]*$' diff --git a/queue-6.1/rust-macros-fix-soundness-issue-in-module-macro.patch b/queue-6.1/rust-macros-fix-soundness-issue-in-module-macro.patch new file mode 100644 index 00000000000..c086860d675 --- /dev/null +++ b/queue-6.1/rust-macros-fix-soundness-issue-in-module-macro.patch @@ -0,0 +1,261 @@ +From 7044dcff8301b29269016ebd17df27c4736140d2 Mon Sep 17 00:00:00 2001 +From: Benno Lossin +Date: Mon, 1 Apr 2024 18:52:50 +0000 +Subject: rust: macros: fix soundness issue in `module!` macro +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +From: Benno Lossin + +commit 7044dcff8301b29269016ebd17df27c4736140d2 upstream. + +The `module!` macro creates glue code that are called by C to initialize +the Rust modules using the `Module::init` function. Part of this glue +code are the local functions `__init` and `__exit` that are used to +initialize/destroy the Rust module. + +These functions are safe and also visible to the Rust mod in which the +`module!` macro is invoked. This means that they can be called by other +safe Rust code. But since they contain `unsafe` blocks that rely on only +being called at the right time, this is a soundness issue. + +Wrap these generated functions inside of two private modules, this +guarantees that the public functions cannot be called from the outside. +Make the safe functions `unsafe` and add SAFETY comments. + +Cc: stable@vger.kernel.org +Reported-by: Björn Roy Baron +Closes: https://github.com/Rust-for-Linux/linux/issues/629 +Fixes: 1fbde52bde73 ("rust: add `macros` crate") +Signed-off-by: Benno Lossin +Reviewed-by: Wedson Almeida Filho +Link: https://lore.kernel.org/r/20240401185222.12015-1-benno.lossin@proton.me +[ Moved `THIS_MODULE` out of the private-in-private modules since it + should remain public, as Dirk Behme noticed [1]. Capitalized comments, + avoided newline in non-list SAFETY comments and reworded to add + Reported-by and newline. ] +Link: https://rust-for-linux.zulipchat.com/#narrow/stream/291565-Help/topic/x/near/433512583 [1] +Signed-off-by: Miguel Ojeda +Signed-off-by: Greg Kroah-Hartman +--- + rust/macros/module.rs | 190 ++++++++++++++++++++++++++++++-------------------- + 1 file changed, 115 insertions(+), 75 deletions(-) + +--- a/rust/macros/module.rs ++++ b/rust/macros/module.rs +@@ -179,17 +179,6 @@ pub(crate) fn module(ts: TokenStream) -> + /// Used by the printing macros, e.g. [`info!`]. + const __LOG_PREFIX: &[u8] = b\"{name}\\0\"; + +- /// The \"Rust loadable module\" mark. +- // +- // This may be best done another way later on, e.g. as a new modinfo +- // key or a new section. For the moment, keep it simple. +- #[cfg(MODULE)] +- #[doc(hidden)] +- #[used] +- static __IS_RUST_MODULE: () = (); +- +- static mut __MOD: Option<{type_}> = None; +- + // SAFETY: `__this_module` is constructed by the kernel at load time and will not be + // freed until the module is unloaded. + #[cfg(MODULE)] +@@ -201,81 +190,132 @@ pub(crate) fn module(ts: TokenStream) -> + kernel::ThisModule::from_ptr(core::ptr::null_mut()) + }}; + +- // Loadable modules need to export the `{{init,cleanup}}_module` identifiers. +- /// # Safety +- /// +- /// This function must not be called after module initialization, because it may be +- /// freed after that completes. +- #[cfg(MODULE)] +- #[doc(hidden)] +- #[no_mangle] +- #[link_section = \".init.text\"] +- pub unsafe extern \"C\" fn init_module() -> core::ffi::c_int {{ +- __init() +- }} +- +- #[cfg(MODULE)] +- #[doc(hidden)] +- #[no_mangle] +- pub extern \"C\" fn cleanup_module() {{ +- __exit() +- }} ++ // Double nested modules, since then nobody can access the public items inside. ++ mod __module_init {{ ++ mod __module_init {{ ++ use super::super::{type_}; ++ ++ /// The \"Rust loadable module\" mark. ++ // ++ // This may be best done another way later on, e.g. as a new modinfo ++ // key or a new section. For the moment, keep it simple. ++ #[cfg(MODULE)] ++ #[doc(hidden)] ++ #[used] ++ static __IS_RUST_MODULE: () = (); ++ ++ static mut __MOD: Option<{type_}> = None; ++ ++ // Loadable modules need to export the `{{init,cleanup}}_module` identifiers. ++ /// # Safety ++ /// ++ /// This function must not be called after module initialization, because it may be ++ /// freed after that completes. ++ #[cfg(MODULE)] ++ #[doc(hidden)] ++ #[no_mangle] ++ #[link_section = \".init.text\"] ++ pub unsafe extern \"C\" fn init_module() -> core::ffi::c_int {{ ++ // SAFETY: This function is inaccessible to the outside due to the double ++ // module wrapping it. It is called exactly once by the C side via its ++ // unique name. ++ unsafe {{ __init() }} ++ }} + +- // Built-in modules are initialized through an initcall pointer +- // and the identifiers need to be unique. +- #[cfg(not(MODULE))] +- #[cfg(not(CONFIG_HAVE_ARCH_PREL32_RELOCATIONS))] +- #[doc(hidden)] +- #[link_section = \"{initcall_section}\"] +- #[used] +- pub static __{name}_initcall: extern \"C\" fn() -> core::ffi::c_int = __{name}_init; ++ #[cfg(MODULE)] ++ #[doc(hidden)] ++ #[no_mangle] ++ pub extern \"C\" fn cleanup_module() {{ ++ // SAFETY: ++ // - This function is inaccessible to the outside due to the double ++ // module wrapping it. It is called exactly once by the C side via its ++ // unique name, ++ // - furthermore it is only called after `init_module` has returned `0` ++ // (which delegates to `__init`). ++ unsafe {{ __exit() }} ++ }} + +- #[cfg(not(MODULE))] +- #[cfg(CONFIG_HAVE_ARCH_PREL32_RELOCATIONS)] +- core::arch::global_asm!( +- r#\".section \"{initcall_section}\", \"a\" +- __{name}_initcall: +- .long __{name}_init - . +- .previous +- \"# +- ); ++ // Built-in modules are initialized through an initcall pointer ++ // and the identifiers need to be unique. ++ #[cfg(not(MODULE))] ++ #[cfg(not(CONFIG_HAVE_ARCH_PREL32_RELOCATIONS))] ++ #[doc(hidden)] ++ #[link_section = \"{initcall_section}\"] ++ #[used] ++ pub static __{name}_initcall: extern \"C\" fn() -> core::ffi::c_int = __{name}_init; ++ ++ #[cfg(not(MODULE))] ++ #[cfg(CONFIG_HAVE_ARCH_PREL32_RELOCATIONS)] ++ core::arch::global_asm!( ++ r#\".section \"{initcall_section}\", \"a\" ++ __{name}_initcall: ++ .long __{name}_init - . ++ .previous ++ \"# ++ ); ++ ++ #[cfg(not(MODULE))] ++ #[doc(hidden)] ++ #[no_mangle] ++ pub extern \"C\" fn __{name}_init() -> core::ffi::c_int {{ ++ // SAFETY: This function is inaccessible to the outside due to the double ++ // module wrapping it. It is called exactly once by the C side via its ++ // placement above in the initcall section. ++ unsafe {{ __init() }} ++ }} + +- #[cfg(not(MODULE))] +- #[doc(hidden)] +- #[no_mangle] +- pub extern \"C\" fn __{name}_init() -> core::ffi::c_int {{ +- __init() +- }} ++ #[cfg(not(MODULE))] ++ #[doc(hidden)] ++ #[no_mangle] ++ pub extern \"C\" fn __{name}_exit() {{ ++ // SAFETY: ++ // - This function is inaccessible to the outside due to the double ++ // module wrapping it. It is called exactly once by the C side via its ++ // unique name, ++ // - furthermore it is only called after `__{name}_init` has returned `0` ++ // (which delegates to `__init`). ++ unsafe {{ __exit() }} ++ }} + +- #[cfg(not(MODULE))] +- #[doc(hidden)] +- #[no_mangle] +- pub extern \"C\" fn __{name}_exit() {{ +- __exit() +- }} ++ /// # Safety ++ /// ++ /// This function must only be called once. ++ unsafe fn __init() -> core::ffi::c_int {{ ++ match <{type_} as kernel::Module>::init(&super::super::THIS_MODULE) {{ ++ Ok(m) => {{ ++ // SAFETY: No data race, since `__MOD` can only be accessed by this ++ // module and there only `__init` and `__exit` access it. These ++ // functions are only called once and `__exit` cannot be called ++ // before or during `__init`. ++ unsafe {{ ++ __MOD = Some(m); ++ }} ++ return 0; ++ }} ++ Err(e) => {{ ++ return e.to_errno(); ++ }} ++ }} ++ }} + +- fn __init() -> core::ffi::c_int {{ +- match <{type_} as kernel::Module>::init(&THIS_MODULE) {{ +- Ok(m) => {{ ++ /// # Safety ++ /// ++ /// This function must ++ /// - only be called once, ++ /// - be called after `__init` has been called and returned `0`. ++ unsafe fn __exit() {{ ++ // SAFETY: No data race, since `__MOD` can only be accessed by this module ++ // and there only `__init` and `__exit` access it. These functions are only ++ // called once and `__init` was already called. + unsafe {{ +- __MOD = Some(m); ++ // Invokes `drop()` on `__MOD`, which should be used for cleanup. ++ __MOD = None; + }} +- return 0; +- }} +- Err(e) => {{ +- return e.to_errno(); + }} +- }} +- }} + +- fn __exit() {{ +- unsafe {{ +- // Invokes `drop()` on `__MOD`, which should be used for cleanup. +- __MOD = None; ++ {modinfo} + }} + }} +- +- {modinfo} + ", + type_ = info.type_, + name = info.name, diff --git a/queue-6.1/rust-module-place-generated-init_module-function-in-.init.text.patch b/queue-6.1/rust-module-place-generated-init_module-function-in-.init.text.patch new file mode 100644 index 00000000000..e1ea4d3d1be --- /dev/null +++ b/queue-6.1/rust-module-place-generated-init_module-function-in-.init.text.patch @@ -0,0 +1,68 @@ +From 1b6170ff7a203a5e8354f19b7839fe8b897a9c0d Mon Sep 17 00:00:00 2001 +From: Thomas Bertschinger +Date: Tue, 6 Feb 2024 08:38:06 -0700 +Subject: rust: module: place generated init_module() function in .init.text + +From: Thomas Bertschinger + +commit 1b6170ff7a203a5e8354f19b7839fe8b897a9c0d upstream. + +Currently Rust kernel modules have their init code placed in the `.text` +section of the .ko file. I don't think this causes any real problems +for Rust modules as long as all code called during initialization lives +in `.text`. + +However, if a Rust `init_module()` function (that lives in `.text`) +calls a function marked with `__init` (in C) or +`#[link_section = ".init.text"]` (in Rust), then a warning is +generated by modpost because that function lives in `.init.text`. +For example: + +WARNING: modpost: fs/bcachefs/bcachefs: section mismatch in reference: init_module+0x6 (section: .text) -> _RNvXCsj7d3tFpT5JS_15bcachefs_moduleNtB2_8BcachefsNtCsjDtqRIL3JAG_6kernel6Module4init (section: .init.text) + +I ran into this while experimenting with converting the bcachefs kernel +module from C to Rust. The module's `init()`, written in Rust, calls C +functions like `bch2_vfs_init()` which are placed in `.init.text`. + +This patch places the macro-generated `init_module()` Rust function in +the `.init.text` section. It also marks `init_module()` as unsafe--now +it may not be called after module initialization completes because it +may be freed already. + +Note that this is not enough on its own to actually get all the module +initialization code in that section. The module author must still add +the `#[link_section = ".init.text"]` attribute to the Rust `init()` in +the `impl kernel::Module` block in order to then call `__init` +functions. However, this patch enables module authors do so, when +previously it would not be possible (without warnings). + +Signed-off-by: Thomas Bertschinger +Reviewed-by: Martin Rodriguez Reboredo +Reviewed-by: Alice Ryhl +Link: https://lore.kernel.org/r/20240206153806.567055-1-tahbertschinger@gmail.com +[ Reworded title to add prefix. ] +Signed-off-by: Miguel Ojeda +Signed-off-by: Greg Kroah-Hartman +--- + rust/macros/module.rs | 7 ++++++- + 1 file changed, 6 insertions(+), 1 deletion(-) + +--- a/rust/macros/module.rs ++++ b/rust/macros/module.rs +@@ -202,10 +202,15 @@ pub(crate) fn module(ts: TokenStream) -> + }}; + + // Loadable modules need to export the `{{init,cleanup}}_module` identifiers. ++ /// # Safety ++ /// ++ /// This function must not be called after module initialization, because it may be ++ /// freed after that completes. + #[cfg(MODULE)] + #[doc(hidden)] + #[no_mangle] +- pub extern \"C\" fn init_module() -> core::ffi::c_int {{ ++ #[link_section = \".init.text\"] ++ pub unsafe extern \"C\" fn init_module() -> core::ffi::c_int {{ + __init() + }} + diff --git a/queue-6.1/series b/queue-6.1/series index f93727f73b2..93c77a4ac51 100644 --- a/queue-6.1/series +++ b/queue-6.1/series @@ -184,3 +184,10 @@ drm-amdgpu-once-more-fix-the-call-oder-in-amdgpu_ttm_move-v2.patch btrfs-fix-kvcalloc-arguments-order-in-btrfs_ioctl_send.patch firewire-nosy-ensure-user_length-is-taken-into-account-when-fetching-packet-contents.patch reapply-drm-qxl-simplify-qxl_fence_wait.patch +rust-error-rename-to_kernel_errno-to_errno.patch +rust-fix-regexp-in-scripts-is_rust_module.sh.patch +btf-scripts-rust-drop-is_rust_module.sh.patch +rust-module-place-generated-init_module-function-in-.init.text.patch +rust-macros-fix-soundness-issue-in-module-macro.patch +usb-typec-ucsi-check-for-notifications-after-init.patch +usb-typec-ucsi-fix-connector-check-on-init.patch diff --git a/queue-6.1/usb-typec-ucsi-check-for-notifications-after-init.patch b/queue-6.1/usb-typec-ucsi-check-for-notifications-after-init.patch new file mode 100644 index 00000000000..596a665cb4f --- /dev/null +++ b/queue-6.1/usb-typec-ucsi-check-for-notifications-after-init.patch @@ -0,0 +1,64 @@ +From 808a8b9e0b87bbc72bcc1f7ddfe5d04746e7ce56 Mon Sep 17 00:00:00 2001 +From: "Christian A. Ehrhardt" +Date: Wed, 20 Mar 2024 08:39:23 +0100 +Subject: usb: typec: ucsi: Check for notifications after init + +From: Christian A. Ehrhardt + +commit 808a8b9e0b87bbc72bcc1f7ddfe5d04746e7ce56 upstream. + +The completion notification for the final SET_NOTIFICATION_ENABLE +command during initialization can include a connector change +notification. However, at the time this completion notification is +processed, the ucsi struct is not ready to handle this notification. +As a result the notification is ignored and the controller +never sends an interrupt again. + +Re-check CCI for a pending connector state change after +initialization is complete. Adjust the corresponding debug +message accordingly. + +Fixes: 71a1fa0df2a3 ("usb: typec: ucsi: Store the notification mask") +Cc: stable@vger.kernel.org +Signed-off-by: Christian A. Ehrhardt +Reviewed-by: Heikki Krogerus +Tested-by: Neil Armstrong # on SM8550-QRD +Link: https://lore.kernel.org/r/20240320073927.1641788-3-lk@c--e.de +Signed-off-by: Greg Kroah-Hartman +--- + drivers/usb/typec/ucsi/ucsi.c | 10 +++++++++- + 1 file changed, 9 insertions(+), 1 deletion(-) + +--- a/drivers/usb/typec/ucsi/ucsi.c ++++ b/drivers/usb/typec/ucsi/ucsi.c +@@ -855,7 +855,7 @@ void ucsi_connector_change(struct ucsi * + struct ucsi_connector *con = &ucsi->connector[num - 1]; + + if (!(ucsi->ntfy & UCSI_ENABLE_NTFY_CONNECTOR_CHANGE)) { +- dev_dbg(ucsi->dev, "Bogus connector change event\n"); ++ dev_dbg(ucsi->dev, "Early connector change event\n"); + return; + } + +@@ -1248,6 +1248,7 @@ static int ucsi_init(struct ucsi *ucsi) + { + struct ucsi_connector *con, *connector; + u64 command, ntfy; ++ u32 cci; + int ret; + int i; + +@@ -1300,6 +1301,13 @@ static int ucsi_init(struct ucsi *ucsi) + + ucsi->connector = connector; + ucsi->ntfy = ntfy; ++ ++ ret = ucsi->ops->read(ucsi, UCSI_CCI, &cci, sizeof(cci)); ++ if (ret) ++ return ret; ++ if (UCSI_CCI_CONNECTOR(READ_ONCE(cci))) ++ ucsi_connector_change(ucsi, cci); ++ + return 0; + + err_unregister: diff --git a/queue-6.1/usb-typec-ucsi-fix-connector-check-on-init.patch b/queue-6.1/usb-typec-ucsi-fix-connector-check-on-init.patch new file mode 100644 index 00000000000..a0e006a02f3 --- /dev/null +++ b/queue-6.1/usb-typec-ucsi-fix-connector-check-on-init.patch @@ -0,0 +1,42 @@ +From ce4c8d21054ae9396cd759fe6e8157b525616dc4 Mon Sep 17 00:00:00 2001 +From: "Christian A. Ehrhardt" +Date: Mon, 1 Apr 2024 23:05:15 +0200 +Subject: usb: typec: ucsi: Fix connector check on init + +From: Christian A. Ehrhardt + +commit ce4c8d21054ae9396cd759fe6e8157b525616dc4 upstream. + +Fix issues when initially checking for a connector change: +- Use the correct connector number not the entire CCI. +- Call ->read under the PPM lock. +- Remove a bogus READ_ONCE. + +Fixes: 808a8b9e0b87 ("usb: typec: ucsi: Check for notifications after init") +Cc: stable@kernel.org +Signed-off-by: Christian A. Ehrhardt +Reviewed-by: Heikki Krogerus +Link: https://lore.kernel.org/r/20240401210515.1902048-1-lk@c--e.de +Signed-off-by: Greg Kroah-Hartman +--- + drivers/usb/typec/ucsi/ucsi.c | 6 ++++-- + 1 file changed, 4 insertions(+), 2 deletions(-) + +--- a/drivers/usb/typec/ucsi/ucsi.c ++++ b/drivers/usb/typec/ucsi/ucsi.c +@@ -1302,11 +1302,13 @@ static int ucsi_init(struct ucsi *ucsi) + ucsi->connector = connector; + ucsi->ntfy = ntfy; + ++ mutex_lock(&ucsi->ppm_lock); + ret = ucsi->ops->read(ucsi, UCSI_CCI, &cci, sizeof(cci)); ++ mutex_unlock(&ucsi->ppm_lock); + if (ret) + return ret; +- if (UCSI_CCI_CONNECTOR(READ_ONCE(cci))) +- ucsi_connector_change(ucsi, cci); ++ if (UCSI_CCI_CONNECTOR(cci)) ++ ucsi_connector_change(ucsi, UCSI_CCI_CONNECTOR(cci)); + + return 0; + -- 2.47.2