From nobody Tue Sep 29 06:58:39 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D39E03FE35A; Tue, 11 Aug 2026 06:41:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786430467; cv=none; b=EEN3CvYlOi5FpzwE07qxiJDXoW/Cc+7Ff9qLiyHl0MzNaPkIgnH3FmruzTMqBfJpDz7M1IVsSl6h8wT9906jAgtJO+065VMEpN0X9YABJJ+rdVr7QAf6GTAU8sNbb7hhlCYSRvia+8IGE4SaFiz6g+z52nC/mrJVWeefDvCdw0c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786430467; c=relaxed/simple; bh=1YTeZVLATNwjBM3mInj+MrWbU8MnHTpzhn3R//d7HTc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=fbsLILA5af/3QivuLJNvGVqVOf3BzglR2ULzIR4nhYGG0G7e7adstoFXC9piM5NlS6+YyViAjNihU3SGJ6I2N+JANNItXZsnrrffBWlnTTACKijBOWhgKCgs2TYJ58BhwzTo1C81sXBc25s56FkWt0aTMnah0CUPwodI1l1+JEQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=yBjEAEzU; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="yBjEAEzU" Received: by smtp.kernel.org (Postfix) with ESMTPS id 0B7F0C2BCF7; Tue, 11 Aug 2026 06:41:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux.dev; s=korg; t=1786430466; bh=1YTeZVLATNwjBM3mInj+MrWbU8MnHTpzhn3R//d7HTc=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=yBjEAEzUjM6zPErQuN31Ab7iqxXu+SwU+6dC+OxrzF+e2Jegpuv/BBTfwyXc5LkcG EotUpbk4JJumoAybp8gTfuucEE7aA2YnlAhEKRfytS8xqwC5iaf7fkkF43yoSDnvQ8 Rw3OcT7gsd0TPGzoH/Ada0A7hkdqjAhNw3k5NbZQ= Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id DC2E6C5AC67; Tue, 11 Aug 2026 06:41:05 +0000 (UTC) From: Alvin Sun Date: Tue, 11 Aug 2026 14:39:43 +0800 Subject: [PATCH v10 01/10] rust: module: move module types into `module.rs` Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260811-fix-fops-owner-v10-1-7e71776f9dbe@linux.dev> References: <20260811-fix-fops-owner-v10-0-7e71776f9dbe@linux.dev> In-Reply-To: <20260811-fix-fops-owner-v10-0-7e71776f9dbe@linux.dev> To: Miguel Ojeda , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich , Luis Chamberlain , Petr Pavlu , Daniel Gomez , Sami Tolvanen , Aaron Tomlin , Greg Kroah-Hartman , "Rafael J. Wysocki" , David Airlie , Simona Vetter , Daniel Almeida , Arnd Bergmann , Brendan Higgins , David Gow , Rae Moar , Breno Leitao , Jens Axboe , Dave Ertman , Leon Romanovsky , Igor Korotin , FUJITA Tomonori , Bjorn Helgaas , =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= , =?utf-8?q?Arve_Hj=C3=B8nnev=C3=A5g?= , Todd Kjos , Christian Brauner , Carlos Llamas Cc: rust-for-linux@vger.kernel.org, linux-modules@vger.kernel.org, driver-core@lists.linux.dev, dri-devel@lists.freedesktop.org, nova-gpu@lists.linux.dev, linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-pci@vger.kernel.org, Alvin Sun X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1786430463; l=10393; i=alvin.sun@linux.dev; s=20260317; h=from:subject:message-id; bh=1YTeZVLATNwjBM3mInj+MrWbU8MnHTpzhn3R//d7HTc=; b=u25RTiv29ff9S/2sq4DPEEhelQImggVHcA6NhcWbAQgIjDG9Jdip2s4+KbDRmePdcojhpP2rW PMwFuoSuCzIB4gcDvmWnXpGpQ0cWCW2LGi8fduwRTfy409U8VGa1crn X-Developer-Key: i=alvin.sun@linux.dev; a=ed25519; pk=CHcwQp8GSoj25V/L1ZWNSQjWp9eSIb0s9LKr0Nm3WuE= X-Endpoint-Received: by B4 Relay for alvin.sun@linux.dev/20260317 with auth_id=684 Move `Module`, `InPlaceModule`, `ModuleMetadata` and `ThisModule` from `lib.rs` into a new `rust/kernel/module.rs`. Re-export them from `lib.rs` to avoid tree-wide changes. Switch six bus driver registrations from `module.0` to the public `ThisModule::as_ptr()` accessor, since the field is no longer visible outside the new `module` submodule. No functional change. Assisted-by: opencode:glm-5.2 Suggested-by: Gary Guo Link: https://lore.kernel.org/all/DJFIQPLOVO4T.1K8T0VZM30LDA@garyguo.net/ Reviewed-by: Gary Guo Acked-by: Danilo Krummrich Reviewed-by: Alice Ryhl Acked-by: Petr Pavlu Signed-off-by: Alvin Sun --- rust/kernel/auxiliary.rs | 2 +- rust/kernel/i2c.rs | 2 +- rust/kernel/lib.rs | 75 +++++---------------------------------------= ---- rust/kernel/module.rs | 71 +++++++++++++++++++++++++++++++++++++++++++++ rust/kernel/net/phy.rs | 6 +++- rust/kernel/pci.rs | 2 +- rust/kernel/platform.rs | 2 +- rust/kernel/usb.rs | 2 +- 8 files changed, 88 insertions(+), 74 deletions(-) diff --git a/rust/kernel/auxiliary.rs b/rust/kernel/auxiliary.rs index c42928d5a2393..cc9745fbf179e 100644 --- a/rust/kernel/auxiliary.rs +++ b/rust/kernel/auxiliary.rs @@ -69,7 +69,7 @@ unsafe fn register( =20 // SAFETY: `adrv` is guaranteed to be a valid `DriverType`. to_result(unsafe { - bindings::__auxiliary_driver_register(adrv.get(), module.0, na= me.as_char_ptr()) + bindings::__auxiliary_driver_register(adrv.get(), module.as_pt= r(), name.as_char_ptr()) }) } =20 diff --git a/rust/kernel/i2c.rs b/rust/kernel/i2c.rs index 624b971ca8b0b..dd9271af5eb8b 100644 --- a/rust/kernel/i2c.rs +++ b/rust/kernel/i2c.rs @@ -142,7 +142,7 @@ unsafe fn register( } =20 // SAFETY: `idrv` is guaranteed to be a valid `DriverType`. - to_result(unsafe { bindings::i2c_register_driver(module.0, idrv.ge= t()) }) + to_result(unsafe { bindings::i2c_register_driver(module.as_ptr(), = idrv.get()) }) } =20 unsafe fn unregister(idrv: &Opaque) { diff --git a/rust/kernel/lib.rs b/rust/kernel/lib.rs index 9512af7156df2..2e175dcb145aa 100644 --- a/rust/kernel/lib.rs +++ b/rust/kernel/lib.rs @@ -94,6 +94,7 @@ pub mod maple_tree; pub mod miscdevice; pub mod mm; +pub mod module; pub mod module_param; #[cfg(CONFIG_NET)] pub mod net; @@ -140,79 +141,17 @@ #[doc(hidden)] pub use bindings; pub use macros; +pub use module::{ + InPlaceModule, + Module, + ModuleMetadata, + ThisModule, // +}; pub use uapi; =20 /// Prefix to appear before log messages printed from within the `kernel` = crate. const __LOG_PREFIX: &[u8] =3D b"rust_kernel\0"; =20 -/// The top level entrypoint to implementing a kernel module. -/// -/// For any teardown or cleanup operations, your type may implement [`Drop= `]. -pub trait Module: Sized + Sync + Send { - /// Called at module initialization time. - /// - /// Use this method to perform whatever setup or registration your mod= ule - /// should do. - /// - /// Equivalent to the `module_init` macro in the C API. - fn init(module: &'static ThisModule) -> error::Result; -} - -/// A module that is pinned and initialised in-place. -pub trait InPlaceModule: Sync + Send { - /// Creates an initialiser for the module. - /// - /// It is called when the module is loaded. - fn init(module: &'static ThisModule) -> impl pin_init::PinInit; -} - -impl InPlaceModule for T { - fn init(module: &'static ThisModule) -> impl pin_init::PinInit { - let initer =3D move |slot: *mut Self| { - let m =3D ::init(module)?; - - // SAFETY: `slot` is valid for write per the contract with `pi= n_init_from_closure`. - unsafe { slot.write(m) }; - Ok(()) - }; - - // SAFETY: On success, `initer` always fully initialises an instan= ce of `Self`. - unsafe { pin_init::pin_init_from_closure(initer) } - } -} - -/// Metadata attached to a [`Module`] or [`InPlaceModule`]. -pub trait ModuleMetadata { - /// The name of the module as specified in the `module!` macro. - const NAME: &'static crate::str::CStr; -} - -/// Equivalent to `THIS_MODULE` in the C API. -/// -/// C header: [`include/linux/init.h`](srctree/include/linux/init.h) -pub struct ThisModule(*mut bindings::module); - -// SAFETY: `THIS_MODULE` may be used from all threads within a module. -unsafe impl Sync for ThisModule {} - -impl ThisModule { - /// Creates a [`ThisModule`] given the `THIS_MODULE` pointer. - /// - /// # Safety - /// - /// The pointer must be equal to the right `THIS_MODULE`. - pub const unsafe fn from_ptr(ptr: *mut bindings::module) -> ThisModule= { - ThisModule(ptr) - } - - /// Access the raw pointer for this module. - /// - /// It is up to the user to use it correctly. - pub const fn as_ptr(&self) -> *mut bindings::module { - self.0 - } -} - #[cfg(not(testlib))] #[panic_handler] fn panic(info: &core::panic::PanicInfo<'_>) -> ! { diff --git a/rust/kernel/module.rs b/rust/kernel/module.rs new file mode 100644 index 0000000000000..be242a82e86d2 --- /dev/null +++ b/rust/kernel/module.rs @@ -0,0 +1,71 @@ +// SPDX-License-Identifier: GPL-2.0 + +//! Module-related types and helpers. + +/// The entrypoint to implementing a kernel module. +/// +/// For any teardown or cleanup operations, your type may implement [`Drop= `]. +pub trait Module: Sized + Sync + Send { + /// Called at module initialization time. + /// + /// Use this method to perform whatever setup or registration your mod= ule + /// should do. + /// + /// Equivalent to the `module_init` macro in the C API. + fn init(module: &'static ThisModule) -> crate::error::Result; +} + +/// A module that is pinned and initialised in-place. +pub trait InPlaceModule: Sync + Send { + /// Creates an initialiser for the module. + /// + /// It is called when the module is loaded. + fn init(module: &'static ThisModule) -> impl pin_init::PinInit; +} + +impl InPlaceModule for T { + fn init(module: &'static ThisModule) -> impl pin_init::PinInit { + let initer =3D move |slot: *mut Self| { + let m =3D ::init(module)?; + + // SAFETY: `slot` is valid for write per the contract with `pi= n_init_from_closure`. + unsafe { slot.write(m) }; + Ok(()) + }; + + // SAFETY: On success, `initer` always fully initialises an instan= ce of `Self`. + unsafe { pin_init::pin_init_from_closure(initer) } + } +} + +/// Metadata attached to a [`Module`] or [`InPlaceModule`]. +pub trait ModuleMetadata { + /// The name of the module as specified in the `module!` macro. + const NAME: &'static crate::str::CStr; +} + +/// Equivalent to `THIS_MODULE` in the C API. +/// +/// C header: [`include/linux/init.h`](srctree/include/linux/init.h) +pub struct ThisModule(*mut crate::bindings::module); + +// SAFETY: `THIS_MODULE` may be used from all threads within a module. +unsafe impl Sync for ThisModule {} + +impl ThisModule { + /// Creates a [`ThisModule`] given the `THIS_MODULE` pointer. + /// + /// # Safety + /// + /// The pointer must be equal to the right `THIS_MODULE`. + pub const unsafe fn from_ptr(ptr: *mut crate::bindings::module) -> Thi= sModule { + ThisModule(ptr) + } + + /// Access the raw pointer for this module. + /// + /// It is up to the user to use it correctly. + pub const fn as_ptr(&self) -> *mut crate::bindings::module { + self.0 + } +} diff --git a/rust/kernel/net/phy.rs b/rust/kernel/net/phy.rs index 3ca99db5cccf2..8b7036b8fe480 100644 --- a/rust/kernel/net/phy.rs +++ b/rust/kernel/net/phy.rs @@ -659,7 +659,11 @@ pub fn register( // the `drivers` slice are initialized properly. `drivers` will no= t be moved. // So it's just an FFI call. to_result(unsafe { - bindings::phy_drivers_register(drivers[0].0.get(), drivers.len= ().try_into()?, module.0) + bindings::phy_drivers_register( + drivers[0].0.get(), + drivers.len().try_into()?, + module.as_ptr(), + ) })?; // INVARIANT: The `drivers` slice is successfully registered to th= e kernel via `phy_drivers_register`. Ok(Registration { drivers }) diff --git a/rust/kernel/pci.rs b/rust/kernel/pci.rs index 5071cae6543fd..4def9ca1824ce 100644 --- a/rust/kernel/pci.rs +++ b/rust/kernel/pci.rs @@ -86,7 +86,7 @@ unsafe fn register( =20 // SAFETY: `pdrv` is guaranteed to be a valid `DriverType`. to_result(unsafe { - bindings::__pci_register_driver(pdrv.get(), module.0, name.as_= char_ptr()) + bindings::__pci_register_driver(pdrv.get(), module.as_ptr(), n= ame.as_char_ptr()) }) } =20 diff --git a/rust/kernel/platform.rs b/rust/kernel/platform.rs index d41555a4b31d2..5a5f4156d79be 100644 --- a/rust/kernel/platform.rs +++ b/rust/kernel/platform.rs @@ -83,7 +83,7 @@ unsafe fn register( =20 // SAFETY: `pdrv` is guaranteed to be a valid `DriverType`. to_result(unsafe { - bindings::__platform_driver_register(pdrv.get(), module.0, nam= e.as_char_ptr()) + bindings::__platform_driver_register(pdrv.get(), module.as_ptr= (), name.as_char_ptr()) }) } =20 diff --git a/rust/kernel/usb.rs b/rust/kernel/usb.rs index 7aff0c82d0afc..870423806e4f5 100644 --- a/rust/kernel/usb.rs +++ b/rust/kernel/usb.rs @@ -63,7 +63,7 @@ unsafe fn register( =20 // SAFETY: `udrv` is guaranteed to be a valid `DriverType`. to_result(unsafe { - bindings::usb_register_driver(udrv.get(), module.0, name.as_ch= ar_ptr()) + bindings::usb_register_driver(udrv.get(), module.as_ptr(), nam= e.as_char_ptr()) }) } =20 --=20 2.43.0 From nobody Tue Sep 29 06:58:39 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D0C0F3B6359; Tue, 11 Aug 2026 06:41:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786430467; cv=none; b=QXEYuWOgxKb6ixT418Jk+9oa4gEkSg+tOTa19mm17DLX0xK9guj87PhegRtThsvUv/ZgGVMnhbbK149z6nJZnn//AZrFoTCs90jmtd+LbCXqIc3cWnb72d308i8TgtPidFavXQ3CxoNGypcjTu2NxiNQ2X/E3BS6xyJMMTxZgu0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786430467; c=relaxed/simple; bh=5g0b55B6S/yvpbDZLPQQ4JslG2F9/7Iv2yWJsU/nQqQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=GpicwIzpbc8txuVjFTl9EIIusK4BmL9OVK8bdd1D0F78RfO7YURq76k/VprcnZfAjHIA4TsNhfU1DppWQcB6U4XmzJVdaAJ9kRMHUMLaIST34T/UaFDP0WHzVZnFtmLP0jnrtR6BCCTtuDNd/9s68doqBLnQF3oNVF2pw+uzA7Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=Qj0aA8a2; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="Qj0aA8a2" Received: by smtp.kernel.org (Postfix) with ESMTPS id 18E83C2BCFC; Tue, 11 Aug 2026 06:41:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux.dev; s=korg; t=1786430466; bh=5g0b55B6S/yvpbDZLPQQ4JslG2F9/7Iv2yWJsU/nQqQ=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=Qj0aA8a2FoJH8FGaBBoCqhjXSSEEOYaSkxfQHcyxD7zN5P2foVbuRpmOdhtGLeVKj J9ap4tpG25cDkOriDnh4ue/Q3GwkxMq5dbABUxUE/H5n04xdP+TWjx9m3bPanWUJcE BYlmnmDCn4CZ181Z18kuOYXhczuKTP9ce3kGwNa8= Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id EDB95C5B572; Tue, 11 Aug 2026 06:41:05 +0000 (UTC) From: Alvin Sun Date: Tue, 11 Aug 2026 14:39:44 +0800 Subject: [PATCH v10 02/10] rust: module: add `THIS_MODULE` const to `ModuleMetadata` trait Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260811-fix-fops-owner-v10-2-7e71776f9dbe@linux.dev> References: <20260811-fix-fops-owner-v10-0-7e71776f9dbe@linux.dev> In-Reply-To: <20260811-fix-fops-owner-v10-0-7e71776f9dbe@linux.dev> To: Miguel Ojeda , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich , Luis Chamberlain , Petr Pavlu , Daniel Gomez , Sami Tolvanen , Aaron Tomlin , Greg Kroah-Hartman , "Rafael J. Wysocki" , David Airlie , Simona Vetter , Daniel Almeida , Arnd Bergmann , Brendan Higgins , David Gow , Rae Moar , Breno Leitao , Jens Axboe , Dave Ertman , Leon Romanovsky , Igor Korotin , FUJITA Tomonori , Bjorn Helgaas , =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= , =?utf-8?q?Arve_Hj=C3=B8nnev=C3=A5g?= , Todd Kjos , Christian Brauner , Carlos Llamas Cc: rust-for-linux@vger.kernel.org, linux-modules@vger.kernel.org, driver-core@lists.linux.dev, dri-devel@lists.freedesktop.org, nova-gpu@lists.linux.dev, linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-pci@vger.kernel.org, Alvin Sun X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1786430463; l=3686; i=alvin.sun@linux.dev; s=20260317; h=from:subject:message-id; bh=5g0b55B6S/yvpbDZLPQQ4JslG2F9/7Iv2yWJsU/nQqQ=; b=5qBQF/1C8pGNUIzZ/6zcrZeog3L/b0vn5XTS1q7ArLxYhVH25uxlWi3sbyxHidxZa+WoS2cMK Mwt2oJcJCvoBVWBI+Ih6Su8aqg/lZf8kjKCCmHE5WK0OKTObhNZ02pL X-Developer-Key: i=alvin.sun@linux.dev; a=ed25519; pk=CHcwQp8GSoj25V/L1ZWNSQjWp9eSIb0s9LKr0Nm3WuE= X-Endpoint-Received: by B4 Relay for alvin.sun@linux.dev/20260317 with auth_id=684 Since `const_refs_to_static` has been stable as of the MSRV bump, a `ThisModule` pointer can now be used in const contexts. Add a `THIS_MODULE` const to the `ModuleMetadata` trait so that modules can provide their `ThisModule` pointer in const contexts such as static `file_operations`. Add a `this_module()` helper to retrieve the `THIS_MODULE` pointer of a given module type, and update `__init` to use it instead of the `THIS_MODULE` static generated by the `module!` macro. The `static THIS_MODULE` generated by the `module!` macro is retained for backwards compatibility with existing users and removed in a later patch once all references have been migrated. Assisted-by: opencode:glm-5.2 Reviewed-by: Andreas Hindborg Reviewed-by: Gary Guo Acked-by: Danilo Krummrich Reviewed-by: Alice Ryhl Acked-by: Petr Pavlu Signed-off-by: Alvin Sun --- rust/kernel/module.rs | 9 +++++++++ rust/macros/module.rs | 18 +++++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/rust/kernel/module.rs b/rust/kernel/module.rs index be242a82e86d2..d713705984477 100644 --- a/rust/kernel/module.rs +++ b/rust/kernel/module.rs @@ -42,6 +42,15 @@ fn init(module: &'static ThisModule) -> impl pin_init::P= inInit() -> &'static ThisModule { + &M::THIS_MODULE } =20 /// Equivalent to `THIS_MODULE` in the C API. diff --git a/rust/macros/module.rs b/rust/macros/module.rs index 06c18e2075083..aa9a618d5d19e 100644 --- a/rust/macros/module.rs +++ b/rust/macros/module.rs @@ -519,6 +519,22 @@ pub(crate) fn module(info: ModuleInfo) -> Result { =20 impl ::kernel::ModuleMetadata for #type_ { const NAME: &'static ::kernel::str::CStr =3D #name_cstr; + + #[cfg(MODULE)] + const THIS_MODULE: ::kernel::ThisModule =3D { + extern "C" { + static __this_module: ::kernel::types::Opaque<::kernel= ::bindings::module>; + } + + // SAFETY: `__this_module` is constructed by the kernel at= load time + // and lives until the module is unloaded. + unsafe { ::kernel::ThisModule::from_ptr(__this_module.get(= )) } + }; + + #[cfg(not(MODULE))] + const THIS_MODULE: ::kernel::ThisModule =3D unsafe { + ::kernel::ThisModule::from_ptr(::core::ptr::null_mut()) + }; } =20 // Double nested modules, since then nobody can access the public = items inside. @@ -616,7 +632,7 @@ pub extern "C" fn #ident_exit() { /// This function must only be called once. unsafe fn __init() -> ::kernel::ffi::c_int { let initer =3D ::init( - &super::super::THIS_MODULE + ::kernel::module::this_module::() ); // SAFETY: No data race, since `__MOD` can only be acc= essed by this module // and there only `__init` and `__exit` access it. The= se functions are only --=20 2.43.0 From nobody Tue Sep 29 06:58:39 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D2A703FC5DD; Tue, 11 Aug 2026 06:41:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786430467; cv=none; b=LiGbqnyYptlC/gx5b3QRJdMaR74ah+BweD1eWILLexUHIw/lGwR5mIyAr47ZADydJpF3co1v9wcl1AzwGt5kVFGQ3kzXzTbxkztMUBFsHjY4SuD6LR1jiBtFB9iJaS3+K+FIO4+kj2WyS2/t+Qf5Bf44x1AZxlNmlmxjKl08uY0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786430467; c=relaxed/simple; bh=4Odon41wn3POG2a/8uxgoozDkAx9LipJnGNGbya68aQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=rbT21S6/UIFFU2Dm7tVOMA2agYeWAXdQlHcxDQz1XZPfoz4rG4k8E2azdMWWvJMUBdmMT8ahCeXC35bgGW/hubbJ8HX2lAnfLZnVFdUnH41TJzY9mcmvds0HxfLwPagBFSctT4+2txw1Q/Zgg4uF9/TdI85k0PvTS0Bl12+xGkk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=k5cY7JJs; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="k5cY7JJs" Received: by smtp.kernel.org (Postfix) with ESMTPS id 24FC9C2BCFF; Tue, 11 Aug 2026 06:41:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux.dev; s=korg; t=1786430466; bh=4Odon41wn3POG2a/8uxgoozDkAx9LipJnGNGbya68aQ=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=k5cY7JJsugmfCg74kXPW43wgpSf9z++eX37e34YE/HVltGFqobp6+42YjQ5bhEQEx wO+UXprUO4NEAwMC0vn3Q6fW70uVqMJFl0o2qYfqOOGjW2uifBfv2ghrkoxCoDhuXn iEYtrGmUnY041jMmNQSjM5Jc5VK+8yheP9O31y9o= Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0CAD4C5B573; Tue, 11 Aug 2026 06:41:06 +0000 (UTC) From: Alvin Sun Date: Tue, 11 Aug 2026 14:39:45 +0800 Subject: [PATCH v10 03/10] rust: doctest: add LocalModule fallback for #[vtable] ThisModule Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260811-fix-fops-owner-v10-3-7e71776f9dbe@linux.dev> References: <20260811-fix-fops-owner-v10-0-7e71776f9dbe@linux.dev> In-Reply-To: <20260811-fix-fops-owner-v10-0-7e71776f9dbe@linux.dev> To: Miguel Ojeda , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich , Luis Chamberlain , Petr Pavlu , Daniel Gomez , Sami Tolvanen , Aaron Tomlin , Greg Kroah-Hartman , "Rafael J. Wysocki" , David Airlie , Simona Vetter , Daniel Almeida , Arnd Bergmann , Brendan Higgins , David Gow , Rae Moar , Breno Leitao , Jens Axboe , Dave Ertman , Leon Romanovsky , Igor Korotin , FUJITA Tomonori , Bjorn Helgaas , =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= , =?utf-8?q?Arve_Hj=C3=B8nnev=C3=A5g?= , Todd Kjos , Christian Brauner , Carlos Llamas Cc: rust-for-linux@vger.kernel.org, linux-modules@vger.kernel.org, driver-core@lists.linux.dev, dri-devel@lists.freedesktop.org, nova-gpu@lists.linux.dev, linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-pci@vger.kernel.org, Alvin Sun X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1786430463; l=1377; i=alvin.sun@linux.dev; s=20260317; h=from:subject:message-id; bh=4Odon41wn3POG2a/8uxgoozDkAx9LipJnGNGbya68aQ=; b=5jzWxvtwEM0NRDV/ItXwJKlqZLPjSdPgzdn4CbZtR6SbhakWPFbJPR4lYpQlRmLkk0OlgTZs7 4Snb5CFs1AZBTNvViiofuBpxSUZ1p6eK98KNCffcLTzVQ/84Q8ecmMa X-Developer-Key: i=alvin.sun@linux.dev; a=ed25519; pk=CHcwQp8GSoj25V/L1ZWNSQjWp9eSIb0s9LKr0Nm3WuE= X-Endpoint-Received: by B4 Relay for alvin.sun@linux.dev/20260317 with auth_id=684 Add a `LocalModule` struct with a null-pointer `ModuleMetadata` impl in the doctest harness, so that `crate::LocalModule` (auto-inserted by `#[vtable]`) resolves correctly when there is no `module!` macro. Assisted-by: opencode:glm-5.2 Reviewed-by: Andreas Hindborg Reviewed-by: Gary Guo Acked-by: Danilo Krummrich Reviewed-by: Alice Ryhl Signed-off-by: Alvin Sun --- scripts/rustdoc_test_gen.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/scripts/rustdoc_test_gen.rs b/scripts/rustdoc_test_gen.rs index d61a77219a8c2..9913f78650365 100644 --- a/scripts/rustdoc_test_gen.rs +++ b/scripts/rustdoc_test_gen.rs @@ -232,6 +232,22 @@ macro_rules! assert_eq {{ =20 const __LOG_PREFIX: &[u8] =3D b"rust_doctests_kernel\0"; =20 +/// Dummy module type for doctest context. +struct LocalModule; + +use kernel::{{ + str::CStr, + ModuleMetadata, + ThisModule, // +}}; +use core::ptr::null_mut; + +impl ModuleMetadata for LocalModule {{ + const NAME: &'static CStr =3D c"rust_doctests_kernel"; + // SAFETY: `try_module_get`/`module_put` handle null module pointers g= racefully. + const THIS_MODULE: ThisModule =3D unsafe {{ ThisModule::from_ptr(null_= mut()) }}; +}} + {rust_tests} "# ) --=20 2.43.0 From nobody Tue Sep 29 06:58:39 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2780D40B100; Tue, 11 Aug 2026 06:41:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786430468; cv=none; b=A5DJ7zBA4Wb/0EzlsE6qUpCdY+KCTH1eVCiVMiDO3kLu/0Ocy6ObzofwA23OHCqG630UJUW/cXwHS2WVV0ZbGFdex+oS5XHtbTgzRbamoLQIN3tInjunY0I2tJJVwwF4H2DTJIk0rc70QFd+6nYTcmAX5khpRhy0lFY8w0rNQRY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786430468; c=relaxed/simple; bh=Nv3zGXf5UtcJRT1/eR1fHVz+qZ5Gti15bQLLVlFnmuQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Tv6nB92x3iZKZiqZiHKDk+ahCJ4ZJ8E+MSrv85ImMTbpWY+v7Vv/qHuk2NNlb2wXhD83y737dTa6vTtneb276Ns+FX4PSxIyJmolqUCuKqd85XokCYOvCXI1n5bef/uNDpLz3C7glbBPHcdZGeN6XKNrYG2Hm2fnV03uU6umdjM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=SoYkBEDZ; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="SoYkBEDZ" Received: by smtp.kernel.org (Postfix) with ESMTPS id 3A26FC4AF15; Tue, 11 Aug 2026 06:41:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux.dev; s=korg; t=1786430466; bh=Nv3zGXf5UtcJRT1/eR1fHVz+qZ5Gti15bQLLVlFnmuQ=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=SoYkBEDZrix2GhHlm2FjjWHljB7LH/VGGNP1OGr4o8WzAyUREypdahSoirHuGRq4J liANZlP3goHjOULggreoy/vagNUbwJK+nZ4sD+mwZ4A0Rrh+jJ3QfpZ1YfutD8ZRFY aNTn+OYOCpzCtQP0DHPsXHxnflmgB4DHL0h0I0Fo= Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1EFD1C5B570; Tue, 11 Aug 2026 06:41:06 +0000 (UTC) From: Alvin Sun Date: Tue, 11 Aug 2026 14:39:46 +0800 Subject: [PATCH v10 04/10] rust: macros: auto-insert OwnerModule in #[vtable] Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260811-fix-fops-owner-v10-4-7e71776f9dbe@linux.dev> References: <20260811-fix-fops-owner-v10-0-7e71776f9dbe@linux.dev> In-Reply-To: <20260811-fix-fops-owner-v10-0-7e71776f9dbe@linux.dev> To: Miguel Ojeda , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich , Luis Chamberlain , Petr Pavlu , Daniel Gomez , Sami Tolvanen , Aaron Tomlin , Greg Kroah-Hartman , "Rafael J. Wysocki" , David Airlie , Simona Vetter , Daniel Almeida , Arnd Bergmann , Brendan Higgins , David Gow , Rae Moar , Breno Leitao , Jens Axboe , Dave Ertman , Leon Romanovsky , Igor Korotin , FUJITA Tomonori , Bjorn Helgaas , =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= , =?utf-8?q?Arve_Hj=C3=B8nnev=C3=A5g?= , Todd Kjos , Christian Brauner , Carlos Llamas Cc: rust-for-linux@vger.kernel.org, linux-modules@vger.kernel.org, driver-core@lists.linux.dev, dri-devel@lists.freedesktop.org, nova-gpu@lists.linux.dev, linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-pci@vger.kernel.org, Alvin Sun X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1786430463; l=4626; i=alvin.sun@linux.dev; s=20260317; h=from:subject:message-id; bh=Nv3zGXf5UtcJRT1/eR1fHVz+qZ5Gti15bQLLVlFnmuQ=; b=PFnAVW6hOOtSEnzZMgMp1/De4eUBix1/CuXzS8+dUZ/YUGrGikMhLTJHrdkqo+64ZPO47zWC5 9oDIIe0C1tVDZF2yiJ//7Uy8nzSL4umFv9AfeRabt3J8M79nhZPSfQ+ X-Developer-Key: i=alvin.sun@linux.dev; a=ed25519; pk=CHcwQp8GSoj25V/L1ZWNSQjWp9eSIb0s9LKr0Nm3WuE= X-Endpoint-Received: by B4 Relay for alvin.sun@linux.dev/20260317 with auth_id=684 Auto-add `type OwnerModule: ::kernel::ModuleMetadata;` as a required associated type on the trait side if not already defined, and auto-insert `type OwnerModule =3D crate::LocalModule;` on the impl side if not explicitly provided, eliminating the need to manually declare and implement `OwnerModule` in every vtable trait and impl. Assisted-by: opencode:glm-5.2 Reviewed-by: Andreas Hindborg Suggested-by: Gary Guo Link: https://lore.kernel.org/all/DIMMWHUOLPSH.13JFRHDKDQJGO@garyguo.net Reviewed-by: Gary Guo Acked-by: Danilo Krummrich Reviewed-by: Alice Ryhl Signed-off-by: Alvin Sun --- rust/macros/lib.rs | 6 ++++++ rust/macros/vtable.rs | 41 ++++++++++++++++++++++++++++++++++++----- 2 files changed, 42 insertions(+), 5 deletions(-) diff --git a/rust/macros/lib.rs b/rust/macros/lib.rs index 4a48fabbc2682..3f4a980f5ae68 100644 --- a/rust/macros/lib.rs +++ b/rust/macros/lib.rs @@ -177,6 +177,12 @@ pub fn module(input: TokenStream) -> TokenStream { /// /// This macro should not be used when all functions are required. /// +/// Additionally, this macro automatically handles the `OwnerModule` +/// associated type: on the trait side, `type OwnerModule: ModuleMetadata;` +/// is added as a required associated type if not already defined; on the +/// impl side, `type OwnerModule =3D LocalModule;` is automatically insert= ed +/// if not explicitly defined. +/// /// # Examples /// /// ``` diff --git a/rust/macros/vtable.rs b/rust/macros/vtable.rs index c6510b0c4ea1d..be9a5ed8abe5e 100644 --- a/rust/macros/vtable.rs +++ b/rust/macros/vtable.rs @@ -30,6 +30,22 @@ fn handle_trait(mut item: ItemTrait) -> Result { const USE_VTABLE_ATTR: (); }); =20 + // Add `type OwnerModule: ModuleMetadata` as a required associated typ= e if + // the trait does not already define it. + if !item + .items + .iter() + .any(|i| matches!(i, TraitItem::Type(t) if t.ident =3D=3D "OwnerMo= dule")) + { + gen_items.push(parse_quote! { + /// The module implementing this vtable trait. + /// + /// Automatically set to `crate::LocalModule` by the `#[vtable= ]` + /// impl macro. + type OwnerModule: ::kernel::ModuleMetadata; + }); + } + for item in &item.items { if let TraitItem::Fn(fn_item) =3D item { let name =3D &fn_item.sig.ident; @@ -57,12 +73,18 @@ fn handle_trait(mut item: ItemTrait) -> Result { =20 fn handle_impl(mut item: ItemImpl) -> Result { let mut gen_items =3D Vec::new(); - let mut defined_consts =3D HashSet::new(); + let mut defined_items =3D HashSet::new(); =20 - // Iterate over all user-defined constants to gather any possible expl= icit overrides. + // Iterate over all user-defined items to gather any possible explicit= overrides. for item in &item.items { - if let ImplItem::Const(const_item) =3D item { - defined_consts.insert(const_item.ident.clone()); + match item { + ImplItem::Const(const_item) =3D> { + defined_items.insert(const_item.ident.clone()); + } + ImplItem::Type(type_item) =3D> { + defined_items.insert(type_item.ident.clone()); + } + _ =3D> {} } } =20 @@ -70,6 +92,15 @@ fn handle_impl(mut item: ItemImpl) -> Result { const USE_VTABLE_ATTR: () =3D (); }); =20 + // Auto-insert `type OwnerModule =3D crate::LocalModule` if not explic= itly defined. + // `crate::LocalModule` resolves to the real module type (via `module!= `) or a + // dummy fallback in non-module contexts (e.g., doctests). + if !defined_items.contains(&parse_quote!(OwnerModule)) { + gen_items.push(parse_quote! { + type OwnerModule =3D crate::LocalModule; + }); + } + for item in &item.items { if let ImplItem::Fn(fn_item) =3D item { let name =3D &fn_item.sig.ident; @@ -78,7 +109,7 @@ fn handle_impl(mut item: ItemImpl) -> Result { name.span(), ); // Skip if it's declared already -- this allows user override. - if defined_consts.contains(&gen_const_name) { + if defined_items.contains(&gen_const_name) { continue; } let cfg_attrs =3D crate::helpers::gather_cfg_attrs(&fn_item.at= trs); --=20 2.43.0 From nobody Tue Sep 29 06:58:39 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 65E7F408611; Tue, 11 Aug 2026 06:41:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786430467; cv=none; b=kgnLPJYHQzo71qbC8kGxAZtMyyCEhMXga6CdJKeq6gqUcoAt8Gmc8gakOR8vauB63gupDssP7PYDFmD/mqd3RwdCjgF0+WOwOxR45Xh/ojf117eg7sijjGN2T4yV4BD3U0Gna47YAKo5dJvb4tF20+hrnGn4nvnTyL2UliWCMu8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786430467; c=relaxed/simple; bh=VfzbZNd9bdUa4BN3WHg5N3MuqGNhCA7R5iDzpO0AVjE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=R0hsgzJxmxRFB2zXBPI0vlT9Qfa9gEcKe7YcMei3JatYwInMYP3nNXBUIWG19H/25UVF3bTO12V+kDfIWsbzs9Q46Hntl7fNStvNnQkIxi1ee+tWvlWfD9d57AUH39nvJgQYIH52GW37RQXy9ndxonRCAoGSIEsE57uhQ54MKUY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=NZMU6BNp; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="NZMU6BNp" Received: by smtp.kernel.org (Postfix) with ESMTPS id 4A026C2BCF4; Tue, 11 Aug 2026 06:41:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux.dev; s=korg; t=1786430466; bh=VfzbZNd9bdUa4BN3WHg5N3MuqGNhCA7R5iDzpO0AVjE=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=NZMU6BNp7lj/LcoSD+X4mAu1qz7LI+8Kaf351PiJwEj9LykJN69+TP1xnAKFsFMax 56Z0D51R4aE/qXbCMnxDPOtHJmWMgoYvPYlcvY1lR/1dhxN9CEwGHGxzNFwQ9I/xDQ 3Y4BELaOo3T9xXtQ8QHxpm439lzaEXoFLUU0Qam8= Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2F273C5B574; Tue, 11 Aug 2026 06:41:06 +0000 (UTC) From: Alvin Sun Date: Tue, 11 Aug 2026 14:39:47 +0800 Subject: [PATCH v10 05/10] rust: drm: set fops.owner from driver module pointer Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260811-fix-fops-owner-v10-5-7e71776f9dbe@linux.dev> References: <20260811-fix-fops-owner-v10-0-7e71776f9dbe@linux.dev> In-Reply-To: <20260811-fix-fops-owner-v10-0-7e71776f9dbe@linux.dev> To: Miguel Ojeda , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich , Luis Chamberlain , Petr Pavlu , Daniel Gomez , Sami Tolvanen , Aaron Tomlin , Greg Kroah-Hartman , "Rafael J. Wysocki" , David Airlie , Simona Vetter , Daniel Almeida , Arnd Bergmann , Brendan Higgins , David Gow , Rae Moar , Breno Leitao , Jens Axboe , Dave Ertman , Leon Romanovsky , Igor Korotin , FUJITA Tomonori , Bjorn Helgaas , =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= , =?utf-8?q?Arve_Hj=C3=B8nnev=C3=A5g?= , Todd Kjos , Christian Brauner , Carlos Llamas Cc: rust-for-linux@vger.kernel.org, linux-modules@vger.kernel.org, driver-core@lists.linux.dev, dri-devel@lists.freedesktop.org, nova-gpu@lists.linux.dev, linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-pci@vger.kernel.org, Alvin Sun X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1786430463; l=1921; i=alvin.sun@linux.dev; s=20260317; h=from:subject:message-id; bh=VfzbZNd9bdUa4BN3WHg5N3MuqGNhCA7R5iDzpO0AVjE=; b=d4F2HSgrhOfkX+lYUKfNjW1DIuNhdyt8fUln5qoPruM6cFTKHU4bqLtTN5ew0uiQMZZlRGIlM 3K64Q9fCk7NDRF5tZYWTNN462LU1Z7b/GSP/YptEYVqRfe9P2jb350s X-Developer-Key: i=alvin.sun@linux.dev; a=ed25519; pk=CHcwQp8GSoj25V/L1ZWNSQjWp9eSIb0s9LKr0Nm3WuE= X-Endpoint-Received: by B4 Relay for alvin.sun@linux.dev/20260317 with auth_id=684 Change `create_fops()` to accept an owner module pointer instead of hardcoding `null_mut()`, ensuring the kernel correctly tracks the module owning the DRM device's file operations. Assisted-by: opencode:glm-5.2 Reviewed-by: Andreas Hindborg Reviewed-by: Gary Guo Acked-by: Danilo Krummrich Reviewed-by: Alice Ryhl Signed-off-by: Alvin Sun --- rust/kernel/drm/device.rs | 3 ++- rust/kernel/drm/gem/mod.rs | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/rust/kernel/drm/device.rs b/rust/kernel/drm/device.rs index 477cf771fb10e..73fbd551f0811 100644 --- a/rust/kernel/drm/device.rs +++ b/rust/kernel/drm/device.rs @@ -203,7 +203,8 @@ const fn compute_features() -> u32 { fops: &Self::GEM_FOPS, }; =20 - const GEM_FOPS: bindings::file_operations =3D drm::gem::create_fops(); + const GEM_FOPS: bindings::file_operations =3D + drm::gem::create_fops(crate::module::this_module::= ().as_ptr()); =20 /// Create a new `UnregisteredDevice` for a `drm::Driver`. /// diff --git a/rust/kernel/drm/gem/mod.rs b/rust/kernel/drm/gem/mod.rs index c8b66d8168719..a7ba1453d40b9 100644 --- a/rust/kernel/drm/gem/mod.rs +++ b/rust/kernel/drm/gem/mod.rs @@ -387,10 +387,10 @@ impl AllocImpl f= or Object { }; } =20 -pub(super) const fn create_fops() -> bindings::file_operations { +pub(super) const fn create_fops(owner: *mut bindings::module) -> bindings:= :file_operations { let mut fops: bindings::file_operations =3D pin_init::zeroed(); =20 - fops.owner =3D core::ptr::null_mut(); + fops.owner =3D owner; fops.open =3D Some(bindings::drm_open); fops.release =3D Some(bindings::drm_release); fops.unlocked_ioctl =3D Some(bindings::drm_ioctl); --=20 2.43.0 From nobody Tue Sep 29 06:58:39 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2C4F1400DE9; Tue, 11 Aug 2026 06:41:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786430468; cv=none; b=KDx+c2d4zZG0uTs1aj7dI3LrOqr3pIXZ5QEFt8uttm1Noxe1Ep9ErGXB8oJwfz5GfKbgeI4viBIwwAUa4qqUgQorZgl6jKuWaucXr/5G/A8KS0eCxkBC9pJBn5Xwu3xGHTfWUYTCvcQyfAcLchplLiBrUxQwFksLS34vx35+QPA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786430468; c=relaxed/simple; bh=F2CI+FBdyNzgpm/+lalqrgOCl4op0DIet6QiBNuXJNI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=hHXT2YH/tslbrawmUjyE6xpuzheThRs5n5G78TeaJmVsS/C9t33mPtt3GQJsAbkVGaNIAA984/2E6aEoIVrwTu9Yx63c7ZmafCca5+cHEdC6gCzfuvLRAUKLJYa7/rrzi5R3eNnM+nspVIHWO+8rQMdxJCVUuxtxr2oEB7CqPIo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=ufE6cNt8; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="ufE6cNt8" Received: by smtp.kernel.org (Postfix) with ESMTPS id 55300C2BD01; Tue, 11 Aug 2026 06:41:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux.dev; s=korg; t=1786430466; bh=F2CI+FBdyNzgpm/+lalqrgOCl4op0DIet6QiBNuXJNI=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=ufE6cNt8jyTWXj0/mNEc4dX0t4TBjYEveM2h84ST9bNNuA2+nc+dih6QfJ+RXBL/c rCuvvC1ThTHO2rKfqpLiwt+BywYUPBTx21Yn7maCAC3Os7OBa+NsdeJjyxX7Riotjt AxOqxrKLjfvsf1muvwnoxSk3n5CZk2/De8Q7f+po= Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 405E5C5B575; Tue, 11 Aug 2026 06:41:06 +0000 (UTC) From: Alvin Sun Date: Tue, 11 Aug 2026 14:39:48 +0800 Subject: [PATCH v10 06/10] rust: miscdevice: set fops.owner from driver module pointer Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260811-fix-fops-owner-v10-6-7e71776f9dbe@linux.dev> References: <20260811-fix-fops-owner-v10-0-7e71776f9dbe@linux.dev> In-Reply-To: <20260811-fix-fops-owner-v10-0-7e71776f9dbe@linux.dev> To: Miguel Ojeda , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich , Luis Chamberlain , Petr Pavlu , Daniel Gomez , Sami Tolvanen , Aaron Tomlin , Greg Kroah-Hartman , "Rafael J. Wysocki" , David Airlie , Simona Vetter , Daniel Almeida , Arnd Bergmann , Brendan Higgins , David Gow , Rae Moar , Breno Leitao , Jens Axboe , Dave Ertman , Leon Romanovsky , Igor Korotin , FUJITA Tomonori , Bjorn Helgaas , =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= , =?utf-8?q?Arve_Hj=C3=B8nnev=C3=A5g?= , Todd Kjos , Christian Brauner , Carlos Llamas Cc: rust-for-linux@vger.kernel.org, linux-modules@vger.kernel.org, driver-core@lists.linux.dev, dri-devel@lists.freedesktop.org, nova-gpu@lists.linux.dev, linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-pci@vger.kernel.org, Alvin Sun X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1786430463; l=1259; i=alvin.sun@linux.dev; s=20260317; h=from:subject:message-id; bh=F2CI+FBdyNzgpm/+lalqrgOCl4op0DIet6QiBNuXJNI=; b=EJ3bMKafIBn0BzL/3jyQvOv2GiyZE2Njy0dBDaRcyZM4AO0JV7ER9G1TyS7H86j2XJlNkOGSK bAdKReXiJpYDqauJju9Kb5cBEWogL3s343zXeLqnY1fst0Qphr1aMSg X-Developer-Key: i=alvin.sun@linux.dev; a=ed25519; pk=CHcwQp8GSoj25V/L1ZWNSQjWp9eSIb0s9LKr0Nm3WuE= X-Endpoint-Received: by B4 Relay for alvin.sun@linux.dev/20260317 with auth_id=684 Set the miscdevice fops owner field from the driver module pointer via the `this_module::()` helper, instead of defaulting to null. Assisted-by: opencode:glm-5.2 Reviewed-by: Andreas Hindborg Reviewed-by: Gary Guo Acked-by: Danilo Krummrich Acked-by: Greg Kroah-Hartman Reviewed-by: Alice Ryhl Signed-off-by: Alvin Sun --- rust/kernel/miscdevice.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/rust/kernel/miscdevice.rs b/rust/kernel/miscdevice.rs index 83ce50def5ac9..2a4329f98614e 100644 --- a/rust/kernel/miscdevice.rs +++ b/rust/kernel/miscdevice.rs @@ -24,12 +24,13 @@ IovIterSource, // }, mm::virt::VmaNew, + module::this_module, prelude::*, seq_file::SeqFile, types::{ ForeignOwnable, Opaque, // - }, + }, // }; use core::marker::PhantomData; =20 @@ -430,6 +431,7 @@ impl MiscdeviceVTable { } else { None }, + owner: this_module::().as_ptr(), ..pin_init::zeroed() }; =20 --=20 2.43.0 From nobody Tue Sep 29 06:58:39 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8107640B397; Tue, 11 Aug 2026 06:41:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786430468; cv=none; b=Vj2+1hVQnw1JuVIxNELZWxEpOwU3i1hdCq2Yb7NK43SEuwD2ibSPvrI1UupRgygOA6CayRYZVqYibvQSKOxmHB8a08u+CAO48Yjr/JPjeAgd1Y7bwnsdOnk64Lh+2aB4DHfbUCm7CZD7zb72/Wx4SsfBV4oYRojhCT7XzSCeJcc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786430468; c=relaxed/simple; bh=t9D2Px8pUwrEcOg/YTzMXGqqQKBGT5HfYznSBGN9YqI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=CUdwvtm++oeKDhB9CkXDiw89JBF2opyaVEEqIue1d52jWiVbhAL6mFTY0Nus/BdwzcJSumc8Wm3rseMDk5gIY5oObYt9aMMLSvR9FzOE5TxZC4cgvsa3MUJrdJTiS8nCqORQ0XAg1eJL8HoKdeauhRrPd+k9nnWQJV0xk3LQKaE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=JFSor2hS; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="JFSor2hS" Received: by smtp.kernel.org (Postfix) with ESMTPS id 67B00C2BCFA; Tue, 11 Aug 2026 06:41:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux.dev; s=korg; t=1786430466; bh=t9D2Px8pUwrEcOg/YTzMXGqqQKBGT5HfYznSBGN9YqI=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=JFSor2hS5saK23uNOWSFZthothWmaXMnxBe0i93x7kOdIMBPvKjJhM1NXYcp18763 ePvhNPHsnbi1K/5lHMTjAJGU1XH2ord61ZCfKBgqfcdj/JfWaTyjr6aUIsi3E2q77R ZNad6prv175RY5/mqFrJ49LkUWPd2DHKCUfiZcYs= Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 50EE1C5B569; Tue, 11 Aug 2026 06:41:06 +0000 (UTC) From: Alvin Sun Date: Tue, 11 Aug 2026 14:39:49 +0800 Subject: [PATCH v10 07/10] rust: configfs: use `LocalModule` for `THIS_MODULE` Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260811-fix-fops-owner-v10-7-7e71776f9dbe@linux.dev> References: <20260811-fix-fops-owner-v10-0-7e71776f9dbe@linux.dev> In-Reply-To: <20260811-fix-fops-owner-v10-0-7e71776f9dbe@linux.dev> To: Miguel Ojeda , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich , Luis Chamberlain , Petr Pavlu , Daniel Gomez , Sami Tolvanen , Aaron Tomlin , Greg Kroah-Hartman , "Rafael J. Wysocki" , David Airlie , Simona Vetter , Daniel Almeida , Arnd Bergmann , Brendan Higgins , David Gow , Rae Moar , Breno Leitao , Jens Axboe , Dave Ertman , Leon Romanovsky , Igor Korotin , FUJITA Tomonori , Bjorn Helgaas , =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= , =?utf-8?q?Arve_Hj=C3=B8nnev=C3=A5g?= , Todd Kjos , Christian Brauner , Carlos Llamas Cc: rust-for-linux@vger.kernel.org, linux-modules@vger.kernel.org, driver-core@lists.linux.dev, dri-devel@lists.freedesktop.org, nova-gpu@lists.linux.dev, linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-pci@vger.kernel.org, Alvin Sun X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1786430463; l=2926; i=alvin.sun@linux.dev; s=20260317; h=from:subject:message-id; bh=t9D2Px8pUwrEcOg/YTzMXGqqQKBGT5HfYznSBGN9YqI=; b=qtMV7yeXqhaYZVvul4NqGhUUdcVoBe2tah6MnJR9lmmRAMqMf9KCsSFMqum5YtQXu+Xwjb+DI 5rNSgQBEO78AV7CBlIRkWjPfI8WZtXa/o3bEw/LNmfHh2b/LISgMfT0 X-Developer-Key: i=alvin.sun@linux.dev; a=ed25519; pk=CHcwQp8GSoj25V/L1ZWNSQjWp9eSIb0s9LKr0Nm3WuE= X-Endpoint-Received: by B4 Relay for alvin.sun@linux.dev/20260317 with auth_id=684 Replace the `THIS_MODULE` static reference in the `configfs_attrs!` macro with `this_module::()`, and update rnull to import `LocalModule` instead of `THIS_MODULE`, consistent with the move of `THIS_MODULE` into the `ModuleMetadata` trait. Assisted-by: opencode:glm-5.2 Reviewed-by: Andreas Hindborg Acked-by: Danilo Krummrich Reviewed-by: Gary Guo Acked-by: Andreas Hindborg Reviewed-by: Alice Ryhl Signed-off-by: Alvin Sun --- drivers/block/rnull/configfs.rs | 5 +---- rust/kernel/configfs.rs | 9 ++++++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/drivers/block/rnull/configfs.rs b/drivers/block/rnull/configfs= .rs index c10a55fc58948..9b28be2150933 100644 --- a/drivers/block/rnull/configfs.rs +++ b/drivers/block/rnull/configfs.rs @@ -1,9 +1,6 @@ // SPDX-License-Identifier: GPL-2.0 =20 -use super::{ - NullBlkDevice, - THIS_MODULE, // -}; +use super::NullBlkDevice; use kernel::{ block::mq::gen_disk::{ GenDisk, diff --git a/rust/kernel/configfs.rs b/rust/kernel/configfs.rs index 2339c6467325d..cd082b83e9e74 100644 --- a/rust/kernel/configfs.rs +++ b/rust/kernel/configfs.rs @@ -875,13 +875,14 @@ fn as_ptr(&self) -> *const bindings::config_item_type= { /// configfs::Subsystem, /// Configuration /// >::new_with_child_ctor::( -/// &THIS_MODULE, +/// ::kernel::module::this_module::(), /// &CONFIGURATION_ATTRS /// ); /// /// &CONFIGURATION_TPE /// } /// ``` +#[allow(clippy::crate_in_macro_def)] #[macro_export] macro_rules! configfs_attrs { ( @@ -1021,7 +1022,8 @@ macro_rules! configfs_attrs { =20 static [< $data:upper _TPE >] : $crate::configfs::Item= Type<$container, $data> =3D $crate::configfs::ItemType::<$container, $data>::n= ew::( - &THIS_MODULE, &[<$ data:upper _ATTRS >] + $crate::module::this_module::(), + &[<$ data:upper _ATTRS >] ); )? =20 @@ -1030,7 +1032,8 @@ macro_rules! configfs_attrs { $crate::configfs::ItemType<$container, $data> =3D $crate::configfs::ItemType::<$container, $data= >:: new_with_child_ctor::( - &THIS_MODULE, &[<$ data:upper _ATTRS >] + $crate::module::this_module::(), + &[<$ data:upper _ATTRS >] ); )? =20 --=20 2.43.0 From nobody Tue Sep 29 06:58:39 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 99DD83FCB32; Tue, 11 Aug 2026 06:41:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786430468; cv=none; b=KBFGjKdPLG9fmTSG4IL7mAmpAFhu/VovcaaKjtrw15+3FZghrx7Gl7VpaEHJNgRgRM8uEnJoQLVcPBdfw/+3PHwRmwFbWeTgruXjtgBe99MWcqhECxmGbfGieWBUpODNGs+XThlYpt+n6YIM9jG3OGZ9j2O7ww+/altRAuwOqEk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786430468; c=relaxed/simple; bh=Y+g5XGXUpaEPEpNu/2z6EYlrPFXE16lF+w/ttECZ4PY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ihCq6W2OZwjR57BBuomwtFJI31EEgt6tnRG0TVtkp3KlvLIHqWzo9v4yJ6YNKSZgUUc1ce/4dIRqGVpaBTt9t67rNxZIEGJ0rCmY8tRpaI+ffuHi9e6Djt2lYJAmS5q6fz+MIMx7Qxph4olOUeRsxLIPliXn7LvCJ5RwEOJX2O4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=VSJb9/OB; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="VSJb9/OB" Received: by smtp.kernel.org (Postfix) with ESMTPS id 79F89C4AF12; Tue, 11 Aug 2026 06:41:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux.dev; s=korg; t=1786430466; bh=Y+g5XGXUpaEPEpNu/2z6EYlrPFXE16lF+w/ttECZ4PY=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=VSJb9/OB0joa9XhxpWkPGcjfNW+4y83dpQ9OTeK5wH6MkVHjmoq6o0svtcqQbr1Zr Gmq2DqwGZj4F5WNh5uKINkpfsT81Nfk5k9bA6EbiK9V9lWfRiaJ8+FNOvQZD/8rtLe L3k9DYOSgo5odP7RvX1OwDJT+HaMf4cVIOGYWInc= Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 631DDC5B572; Tue, 11 Aug 2026 06:41:06 +0000 (UTC) From: Alvin Sun Date: Tue, 11 Aug 2026 14:39:50 +0800 Subject: [PATCH v10 08/10] rust_binder: use `LocalModule` for `THIS_MODULE` Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260811-fix-fops-owner-v10-8-7e71776f9dbe@linux.dev> References: <20260811-fix-fops-owner-v10-0-7e71776f9dbe@linux.dev> In-Reply-To: <20260811-fix-fops-owner-v10-0-7e71776f9dbe@linux.dev> To: Miguel Ojeda , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich , Luis Chamberlain , Petr Pavlu , Daniel Gomez , Sami Tolvanen , Aaron Tomlin , Greg Kroah-Hartman , "Rafael J. Wysocki" , David Airlie , Simona Vetter , Daniel Almeida , Arnd Bergmann , Brendan Higgins , David Gow , Rae Moar , Breno Leitao , Jens Axboe , Dave Ertman , Leon Romanovsky , Igor Korotin , FUJITA Tomonori , Bjorn Helgaas , =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= , =?utf-8?q?Arve_Hj=C3=B8nnev=C3=A5g?= , Todd Kjos , Christian Brauner , Carlos Llamas Cc: rust-for-linux@vger.kernel.org, linux-modules@vger.kernel.org, driver-core@lists.linux.dev, dri-devel@lists.freedesktop.org, nova-gpu@lists.linux.dev, linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-pci@vger.kernel.org, Alvin Sun X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1786430463; l=1425; i=alvin.sun@linux.dev; s=20260317; h=from:subject:message-id; bh=Y+g5XGXUpaEPEpNu/2z6EYlrPFXE16lF+w/ttECZ4PY=; b=wuist2Y7evoWdYNP5wCetrUO8g0Zyp2qFyp/lrFrzl5GEv+uOR39Tkb7fGA3n/X+NR1byOdye R8btYsCJOWWARHHJavwcrV9JguGqWiKKnZeebYGpLkBpHBurbz3rCRn X-Developer-Key: i=alvin.sun@linux.dev; a=ed25519; pk=CHcwQp8GSoj25V/L1ZWNSQjWp9eSIb0s9LKr0Nm3WuE= X-Endpoint-Received: by B4 Relay for alvin.sun@linux.dev/20260317 with auth_id=684 Replace the `THIS_MODULE` static reference in the binder fops with `this_module::()`, consistent with the move of `THIS_MODULE` into the `ModuleMetadata` trait. Assisted-by: opencode:glm-5.2 Reviewed-by: Gary Guo Acked-by: Danilo Krummrich Reviewed-by: Alice Ryhl Signed-off-by: Alvin Sun --- drivers/android/binder/rust_binder_main.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/android/binder/rust_binder_main.rs b/drivers/android/b= inder/rust_binder_main.rs index dc1941cd2407b..d6ceebbd5f94e 100644 --- a/drivers/android/binder/rust_binder_main.rs +++ b/drivers/android/binder/rust_binder_main.rs @@ -17,6 +17,7 @@ bindings::{self, seq_file}, fs::File, list::{ListArc, ListArcSafe, ListLinksSelfPtr, TryNewListArc}, + module::this_module, prelude::*, seq_file::SeqFile, seq_print, @@ -318,7 +319,7 @@ unsafe impl Sync for AssertSync {} let zeroed_ops =3D unsafe { core::mem::MaybeUninit::zeroed().assume_in= it() }; =20 let ops =3D kernel::bindings::file_operations { - owner: THIS_MODULE.as_ptr(), + owner: this_module::().as_ptr(), poll: Some(rust_binder_poll), unlocked_ioctl: Some(rust_binder_ioctl), compat_ioctl: bindings::compat_ptr_ioctl, --=20 2.43.0 From nobody Tue Sep 29 06:58:39 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2756B40B0FF; Tue, 11 Aug 2026 06:41:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786430468; cv=none; b=AQetlsa+s6h1z2dIrntqeBrx9yC4OB/LvINlgOxpR73QMIe5mbYMopbegqOR4R7R94rAiXFqJ64esNyXuQWeLd4iSDo2353ojkvvZaSSR7hlRSpIYBDWwI/ogGa6Ek7L4s4vdSqiYgHz5Lw0l+rC4JJnNSLWWNJjPV1ZsIxIAvM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786430468; c=relaxed/simple; bh=zEzC1bDm4qRA6ByKIEshYxS19LhaxWKaqPARicYVbSg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=k88C4J7kmyvZNHYyh04U8vClG1V2frcwy0sqHn3zDxPmkiKiyDGF4gCWtvWAb/MqzirlEaFFYpoCxhvbL064gwVG8MyuJ6fJAHRRw2I6MfGaePBIUK/wkI/h4LM96RCn17K9DaipiQt3w5EwiLSnSJ+K0/Mjm7uC3E52d9yDN6A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=gVnrPEdQ; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="gVnrPEdQ" Received: by smtp.kernel.org (Postfix) with ESMTPS id 8CA27C2BCFB; Tue, 11 Aug 2026 06:41:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux.dev; s=korg; t=1786430466; bh=zEzC1bDm4qRA6ByKIEshYxS19LhaxWKaqPARicYVbSg=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=gVnrPEdQyYQrhY0CGZgW9mqhSovyj0KXiXIkzCwjd8sZL6dnbOx4Qt9e+wbfmZ4ck GoOuW+qMngYtkZ3LGsKH3eoemVxWp5u5uTu0wejFg5X91LisNDXCfzagmjCuutvUQh RXON1VjUvXChdcDxP5WTnym5S7OIxQtS8edlyhD8= Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 74074C5B573; Tue, 11 Aug 2026 06:41:06 +0000 (UTC) From: Alvin Sun Date: Tue, 11 Aug 2026 14:39:51 +0800 Subject: [PATCH v10 09/10] rust: macros: remove `THIS_MODULE` static from `module!` Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260811-fix-fops-owner-v10-9-7e71776f9dbe@linux.dev> References: <20260811-fix-fops-owner-v10-0-7e71776f9dbe@linux.dev> In-Reply-To: <20260811-fix-fops-owner-v10-0-7e71776f9dbe@linux.dev> To: Miguel Ojeda , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich , Luis Chamberlain , Petr Pavlu , Daniel Gomez , Sami Tolvanen , Aaron Tomlin , Greg Kroah-Hartman , "Rafael J. Wysocki" , David Airlie , Simona Vetter , Daniel Almeida , Arnd Bergmann , Brendan Higgins , David Gow , Rae Moar , Breno Leitao , Jens Axboe , Dave Ertman , Leon Romanovsky , Igor Korotin , FUJITA Tomonori , Bjorn Helgaas , =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= , =?utf-8?q?Arve_Hj=C3=B8nnev=C3=A5g?= , Todd Kjos , Christian Brauner , Carlos Llamas Cc: rust-for-linux@vger.kernel.org, linux-modules@vger.kernel.org, driver-core@lists.linux.dev, dri-devel@lists.freedesktop.org, nova-gpu@lists.linux.dev, linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-pci@vger.kernel.org, Alvin Sun X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1786430463; l=1900; i=alvin.sun@linux.dev; s=20260317; h=from:subject:message-id; bh=zEzC1bDm4qRA6ByKIEshYxS19LhaxWKaqPARicYVbSg=; b=1SXXwL7/69fdog+H6q3ZRl9P8x/rjYjfRmiehW4bWBKNYp4nPWk+Je87t4b4KfsnjyrypfK/1 Lxu1/mVohceBQLDHbZR5t5DJznfUigOJPExFIKwJMlSTyvnqql21+v2 X-Developer-Key: i=alvin.sun@linux.dev; a=ed25519; pk=CHcwQp8GSoj25V/L1ZWNSQjWp9eSIb0s9LKr0Nm3WuE= X-Endpoint-Received: by B4 Relay for alvin.sun@linux.dev/20260317 with auth_id=684 All users have been migrated to `ModuleMetadata::THIS_MODULE` const or `this_module::()` helper. The `static THIS_MODULE` generated by the `module!` macro is no longer referenced anywhere, so remove it to avoid having two sources of the same `ThisModule` pointer. Assisted-by: opencode:glm-5.2 Reviewed-by: Andreas Hindborg Reviewed-by: Gary Guo Acked-by: Danilo Krummrich Reviewed-by: Alice Ryhl Acked-by: Petr Pavlu Signed-off-by: Alvin Sun --- rust/macros/module.rs | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/rust/macros/module.rs b/rust/macros/module.rs index aa9a618d5d19e..23b6a1b456b80 100644 --- a/rust/macros/module.rs +++ b/rust/macros/module.rs @@ -497,22 +497,6 @@ pub(crate) fn module(info: ModuleInfo) -> Result { /// Used by the printing macros, e.g. [`info!`]. const __LOG_PREFIX: &[u8] =3D #name_cstr.to_bytes_with_nul(); =20 - // SAFETY: `__this_module` is constructed by the kernel at load ti= me and will not be - // freed until the module is unloaded. - #[cfg(MODULE)] - static THIS_MODULE: ::kernel::ThisModule =3D unsafe { - extern "C" { - static __this_module: ::kernel::types::Opaque<::kernel::bi= ndings::module>; - }; - - ::kernel::ThisModule::from_ptr(__this_module.get()) - }; - - #[cfg(not(MODULE))] - static THIS_MODULE: ::kernel::ThisModule =3D unsafe { - ::kernel::ThisModule::from_ptr(::core::ptr::null_mut()) - }; - /// The `LocalModule` type is the type of the module created by `m= odule!`, /// `module_pci_driver!`, `module_platform_driver!`, etc. type LocalModule =3D #type_; --=20 2.43.0 From nobody Tue Sep 29 06:58:39 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CEF6D40BCC8; Tue, 11 Aug 2026 06:41:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786430469; cv=none; b=eYmzzV3zU0lnhticotpavj+uy8X1D50X4kYM5vey5zHp2dYJDrCXwctP+bijNuPV/5fHpS6OEIrJASoOV3ybfSmfhmX4ZI0SduRqjSbz9ELCit0s5JequyIQQStw9BkVQYqJdQTNinRy74SnBK+ZAHo4iQfKVLDxYfwsi01dV1M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786430469; c=relaxed/simple; bh=210BZtuiFJIMwjT+et+SglHzrJZ9Rn2bfw11ACWgPTs=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=lrB6pCEQtoqx0vCiSSYlNvdOqS/iCjKt4aMgcy9rrB36hil5UHpgvyYY2oncZuxVW8ZZF55TNpUyZiC/As+MpKKAYcZ7xN2RuwgH5j+kgXncJjmgw2dgTIjhfLeBbjbl0Nxcu3EL0CjO4ie4zSQgxSHfhp3GT2GTBnwQVEAL7Yc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=yetFBTRb; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="yetFBTRb" Received: by smtp.kernel.org (Postfix) with ESMTPS id 9D8E0C2BD05; Tue, 11 Aug 2026 06:41:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux.dev; s=korg; t=1786430466; bh=210BZtuiFJIMwjT+et+SglHzrJZ9Rn2bfw11ACWgPTs=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=yetFBTRb+VDdSuviGdTBHAvdWGnnuFzZs4qh2DkEjzU41gcnMzZnILkH4cXkWjbhN 8cj42rGCLWyubK2od2kv4BQ5msMNNokOKDIo58z3ptv2XdrRlsm4+7AKBWYJ0WoCDL MAyA71JbdlW9+QOBaDyf4dOo0Tmfg22esov/A6zU= Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 859D4C5B574; Tue, 11 Aug 2026 06:41:06 +0000 (UTC) From: Alvin Sun Date: Tue, 11 Aug 2026 14:39:52 +0800 Subject: [PATCH v10 10/10] rust: module: update MAINTAINERS to cover module.rs Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260811-fix-fops-owner-v10-10-7e71776f9dbe@linux.dev> References: <20260811-fix-fops-owner-v10-0-7e71776f9dbe@linux.dev> In-Reply-To: <20260811-fix-fops-owner-v10-0-7e71776f9dbe@linux.dev> To: Miguel Ojeda , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich , Luis Chamberlain , Petr Pavlu , Daniel Gomez , Sami Tolvanen , Aaron Tomlin , Greg Kroah-Hartman , "Rafael J. Wysocki" , David Airlie , Simona Vetter , Daniel Almeida , Arnd Bergmann , Brendan Higgins , David Gow , Rae Moar , Breno Leitao , Jens Axboe , Dave Ertman , Leon Romanovsky , Igor Korotin , FUJITA Tomonori , Bjorn Helgaas , =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= , =?utf-8?q?Arve_Hj=C3=B8nnev=C3=A5g?= , Todd Kjos , Christian Brauner , Carlos Llamas Cc: rust-for-linux@vger.kernel.org, linux-modules@vger.kernel.org, driver-core@lists.linux.dev, dri-devel@lists.freedesktop.org, nova-gpu@lists.linux.dev, linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-pci@vger.kernel.org, Alvin Sun X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1786430463; l=1044; i=alvin.sun@linux.dev; s=20260317; h=from:subject:message-id; bh=210BZtuiFJIMwjT+et+SglHzrJZ9Rn2bfw11ACWgPTs=; b=/IQwQTiwkzMVV5LHOI+tN4/Y4FQ0j0tCL7otA/BSzNwTy46tm7weLpFMixrl/crEC7PWZXm1P uT4fRPfNqlKCZFKlsMEq+apubZLWaSyV+hd6WmthWnSyp756fuVsZAb X-Developer-Key: i=alvin.sun@linux.dev; a=ed25519; pk=CHcwQp8GSoj25V/L1ZWNSQjWp9eSIb0s9LKr0Nm3WuE= X-Endpoint-Received: by B4 Relay for alvin.sun@linux.dev/20260317 with auth_id=684 Module types now live in `rust/kernel/module.rs` alongside `rust/kernel/module_param.rs`. Update the MODULE SUPPORT file pattern from `rust/kernel/module_param.rs` to `rust/kernel/module*.rs` so both files are covered. Cc: Petr Pavlu Assisted-by: opencode:glm-5.2 Link: https://lore.kernel.org/rust-for-linux/8ea21b29-9baf-4926-a16f-7d21c5= a1a1b8@suse.com Reviewed-by: Alice Ryhl Acked-by: Danilo Krummrich Acked-by: Petr Pavlu Signed-off-by: Alvin Sun --- MAINTAINERS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MAINTAINERS b/MAINTAINERS index 8014b9f8253ed..ce84c56f21375 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -18189,7 +18189,7 @@ F: include/linux/module*.h F: kernel/module/ F: lib/test_kmod.c F: lib/tests/module/ -F: rust/kernel/module_param.rs +F: rust/kernel/module*.rs F: rust/macros/module.rs F: scripts/module* F: tools/testing/selftests/kmod/ --=20 2.43.0