From nobody Fri Jul 24 05:21:27 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 BDAC31D5ABA; Thu, 23 Jul 2026 02:11:22 +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=1784772682; cv=none; b=FinsX+R1VnFPMkFOrozzuGAoJ8vylJRxAQ6avKTxQooeGjMeIu1vUpTUWZEMqX6OJwj8WicmkSrONq5XR+k4qAj1mR8zKDKDAENgE8D9+ONFwXZxGkMauNkI6vyYWU1vj/d36jE3Ps7v8ULRWKrUqLMjf5sqDMcoqQsbHx9s3eI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784772682; c=relaxed/simple; bh=FT3/WulpuLQqdHMgqAgW77HrCQngGC4CA6LCy+g7YBc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=o5zdFFJqZ3eTUcoADDf7Scw6xwFSIZ2Mdy95hmJq6VaMKZgVJYkBYdxXMjbk7k6QQ0mJEuCULzROJ91VoIliygkFoQkquagIq21n9wK5NglEhz434UG36VZKveTbh7gscHJvaLp2ICTFnIRzeQSBBwjUS5J8+zW4XvR7p1njgw0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=Vh5rm+3U; 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="Vh5rm+3U" Received: by smtp.kernel.org (Postfix) with ESMTPS id 53DCBC2BCC6; Thu, 23 Jul 2026 02:11:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux.dev; s=korg; t=1784772682; bh=FT3/WulpuLQqdHMgqAgW77HrCQngGC4CA6LCy+g7YBc=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=Vh5rm+3U89ISPv1sQB+73zx7zBhtyGyf1pIF3A7BWhXYYzHfRLmgOXa44++yMOf93 jNM7SkQMkMnI9wBW5VnsvPBqb9e0lGM+eTq6VkYWVs7EtWMSzPByoWq/GS28N20x7n p/fWOqfdUaJmOdjsHP7j8V9jT42VKehPrKbuVM6k= 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 2FF7EC4453A; Thu, 23 Jul 2026 02:11:22 +0000 (UTC) From: Alvin Sun Date: Thu, 23 Jul 2026 10:10:24 +0800 Subject: [PATCH v9 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: <20260723-fix-fops-owner-v9-1-c1c3af7f7bcb@linux.dev> References: <20260723-fix-fops-owner-v9-0-c1c3af7f7bcb@linux.dev> In-Reply-To: <20260723-fix-fops-owner-v9-0-c1c3af7f7bcb@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=1784772679; l=10377; i=alvin.sun@linux.dev; s=20260317; h=from:subject:message-id; bh=FT3/WulpuLQqdHMgqAgW77HrCQngGC4CA6LCy+g7YBc=; b=Zasg9d0wKrlEN4U3lWTJMxhmSh/fY7B/NTQvphEX+niiuiJkNcf//sYzdHrXSAz15aHI1H7bX jLwZ9XF5SOkAwkVknnJhdJbefts3ButkZ/A9qN+ddR6/LrTWo3jyGUp 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 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 93c0db1f66555..4a02f83240be3 100644 --- a/rust/kernel/auxiliary.rs +++ b/rust/kernel/auxiliary.rs @@ -63,7 +63,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 7b908f0c5a58d..24eff08f47123 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 b72b2fbe046d6..040ae85056509 100644 --- a/rust/kernel/lib.rs +++ b/rust/kernel/lib.rs @@ -93,6 +93,7 @@ pub mod maple_tree; pub mod miscdevice; pub mod mm; +pub mod module; pub mod module_param; #[cfg(CONFIG_NET)] pub mod net; @@ -139,79 +140,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 af74ddff6114d..916ed2cb6b70b 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 8917d4ee499fb..9fdbafd53bc21 100644 --- a/rust/kernel/platform.rs +++ b/rust/kernel/platform.rs @@ -82,7 +82,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) }) + to_result(unsafe { bindings::__platform_driver_register(pdrv.get()= , module.as_ptr()) }) } =20 unsafe fn unregister(pdrv: &Opaque) { diff --git a/rust/kernel/usb.rs b/rust/kernel/usb.rs index 9c17a672cd275..213db32727c17 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 Fri Jul 24 05:21:27 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 BDB612472B6; Thu, 23 Jul 2026 02:11:22 +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=1784772682; cv=none; b=rREUsgpgRWVJmMQmDPSructhccjTbLOV9WGOIdg6dJ8Erpd0+bMHeOP/Kh4DndNO1vvWLKxWSlWS/5OMpseTLc0d3Tje84Kk1vV5lIr4pu7A/fyyFT0OU4Ijk0kPcfVPcc9CzqPuwFcbBGoU7MRcFAWUzjHNhiTWu0uwUACFsD8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784772682; c=relaxed/simple; bh=ouhDi1wJe8VGK20MEf1IZFZ5IYEJfw377WQZ4ejJ8YI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ARb1AUH5R6ePPiCNsLNC8OWAH96ZaGsvt8AZKGlEGMBWCO+0DNLOA4b0x3Tbm4oj9CfwUpnccsGibqXMZlVf41Nzb/ovM1t+ZgGL484AkLjyStPd1bjX5BgpTs9AeCHNof1LrFbwgq5nhfHI5f5uzfLiWSKKNpPE8v/5S/n71tE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=soKETOWc; 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="soKETOWc" Received: by smtp.kernel.org (Postfix) with ESMTPS id 6470AC2BCB3; Thu, 23 Jul 2026 02:11:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux.dev; s=korg; t=1784772682; bh=ouhDi1wJe8VGK20MEf1IZFZ5IYEJfw377WQZ4ejJ8YI=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=soKETOWc/MwjdYmmA62S5oe8slwJMNtmiFHqqMk99cysO7lga8HDQfxsrZJ2VPrWi uo+M3P6QWW6YY1hWjHDDB7RhCDeBEWptJjwTfTEtT/puBirrZFtJ6Rwgyl71z9Gdqn GSjEMc2kHrCeCVo0IhUk1cmOOHXfSv0yQvQfidtQ= 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 424EEC4453D; Thu, 23 Jul 2026 02:11:22 +0000 (UTC) From: Alvin Sun Date: Thu, 23 Jul 2026 10:10:25 +0800 Subject: [PATCH v9 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: <20260723-fix-fops-owner-v9-2-c1c3af7f7bcb@linux.dev> References: <20260723-fix-fops-owner-v9-0-c1c3af7f7bcb@linux.dev> In-Reply-To: <20260723-fix-fops-owner-v9-0-c1c3af7f7bcb@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=1784772679; l=3642; i=alvin.sun@linux.dev; s=20260317; h=from:subject:message-id; bh=ouhDi1wJe8VGK20MEf1IZFZ5IYEJfw377WQZ4ejJ8YI=; b=1IKe3MdMXW65w8esAMoVSrL3diqwoJGtpM/+HNPOuMlkFzxOm7NUOZ2S91rib+uGuo4IBgoTz NIVnyw3PMd/BWesjoKp8gg1gsMInp4ft0T9Re7q6mixm5fscFiPZhqS 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 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 Fri Jul 24 05:21:27 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 BE63E264612; Thu, 23 Jul 2026 02:11:22 +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=1784772682; cv=none; b=TcHKZMzA2m2qwgVruNIRZ6+Z9ckjZ3Ao2NupHc+ACj/sG1P8LmtztsmA2g1eAbph0UqrnWy9jL6F/sxNMZUEITf9XCSJibX0+0js4MQ7EZ/zjOk9gn3CHXRcfRduoDDVkeWwha6xaZ0FBs2q7Hiqdr8SMalJaLUqYW1nrQlXTfQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784772682; c=relaxed/simple; bh=ESjStQdmlknQnDN11JwGEzcIvjttoeIr5V6aNECIncg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=He9k0Weiag5mGt62K4197QTTW/QLmxln4LYus1kvwmUTh+a/1SglbOIHiEIdSil8RPz3DZWrquE9+1eIGtQKLHSpgmDKFyQN7wnlBbpFGB+CeMzADMPbDwTy6NJBFVGiYwp1nusWR5YmAqLC912u1/33LpWJwL/4KrrSNGYHSLg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=GVxSjdK1; 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="GVxSjdK1" Received: by smtp.kernel.org (Postfix) with ESMTPS id 7AC92C2BD04; Thu, 23 Jul 2026 02:11:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux.dev; s=korg; t=1784772682; bh=ESjStQdmlknQnDN11JwGEzcIvjttoeIr5V6aNECIncg=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=GVxSjdK1R6Fb+4koUBEku6vQO1kXwg/tiXE/Z5740kMqwF4qLruKbUUQlNE+XE171 +x2ZqxZnChaELKEW6PXtb0nZnNtMT62hfYzn81vnxelrvy/36BQ4svZ6BhvcaUi4wJ DmC4ye13HHKHVrW2LkP54VxaWBSq1Nv7NO9xRlVs= 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 63AD7C531C7; Thu, 23 Jul 2026 02:11:22 +0000 (UTC) From: Alvin Sun Date: Thu, 23 Jul 2026 10:10:26 +0800 Subject: [PATCH v9 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: <20260723-fix-fops-owner-v9-3-c1c3af7f7bcb@linux.dev> References: <20260723-fix-fops-owner-v9-0-c1c3af7f7bcb@linux.dev> In-Reply-To: <20260723-fix-fops-owner-v9-0-c1c3af7f7bcb@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=1784772679; l=1377; i=alvin.sun@linux.dev; s=20260317; h=from:subject:message-id; bh=ESjStQdmlknQnDN11JwGEzcIvjttoeIr5V6aNECIncg=; b=0V1lvzkTeSKzwK4603cLNWuoSLrUbyq2/uGNBBZl/R228cq0Sz06kESuqjlzFq3qsaCTCUwh8 Aq9oQWxzNxyBC0gQK1UfXpX3cxs1txivtdXRqX8rs+lynQbFj5Nr1UW 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 ee76e96b41eea..198af4e446c8c 100644 --- a/scripts/rustdoc_test_gen.rs +++ b/scripts/rustdoc_test_gen.rs @@ -239,6 +239,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 Fri Jul 24 05:21:27 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 D59E5269B1C; Thu, 23 Jul 2026 02:11:22 +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=1784772683; cv=none; b=Ny4OCflF71FELUmzVPAeuo1GdiGIeG04qWbnM0e1pRoyzvCcfVkT72LQICpk3KFbFPv+NDQVieQhzZBQy7C7sUhI2C1ruf0bMDLhSOlDqqOmxQOO+r2Ja/meFQ1xZjlwCrSLQdD1bg3mAaGDlI/TYnvcekQ9rM5cZkk/49lqWys= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784772683; c=relaxed/simple; bh=GfenyU+iQ7LfW2CcQt+3A3S0sIo6Xlatlci9hGheLLA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=U4yOmSjeY0GIBnMLASfTDjdFpwWpDK28hLsUyWNM8raySFi86wX1yiicWU7XUxI6Jl59EmwsD0IDHFbcOVPXO2TkbPsAx0JGgvHqlzwYJo6ZrT+AAhKVLSVelQG5Kyp8uQ/GMM6GlnhbmJH9vm4vF/U5YXS/HZ8YqvWB1bOPtrU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=Gljd2ual; 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="Gljd2ual" Received: by smtp.kernel.org (Postfix) with ESMTPS id 90FA2C4AF18; Thu, 23 Jul 2026 02:11:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux.dev; s=korg; t=1784772682; bh=GfenyU+iQ7LfW2CcQt+3A3S0sIo6Xlatlci9hGheLLA=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=Gljd2ualOMT0jKmDJHBOAx9JYGYu/9M0rzmeMoD7wxaj0quiTHVArJ2Iw+io472eI WLZEvJxIpyC/z8r/xtywO2nxV3TytdQZMMqLjUsmjuYs1toFlMEwBN4VzQJTWAnqkX Rga3StXCWVopO/Ca1tl7K+Ot4yUVj3fd8C+wSImo= 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 77F0DC531C9; Thu, 23 Jul 2026 02:11:22 +0000 (UTC) From: Alvin Sun Date: Thu, 23 Jul 2026 10:10:27 +0800 Subject: [PATCH v9 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: <20260723-fix-fops-owner-v9-4-c1c3af7f7bcb@linux.dev> References: <20260723-fix-fops-owner-v9-0-c1c3af7f7bcb@linux.dev> In-Reply-To: <20260723-fix-fops-owner-v9-0-c1c3af7f7bcb@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=1784772679; l=4626; i=alvin.sun@linux.dev; s=20260317; h=from:subject:message-id; bh=GfenyU+iQ7LfW2CcQt+3A3S0sIo6Xlatlci9hGheLLA=; b=IFAmI0CbKm/Jd7mf1yJUeJdyA+TI3CZv5Fo1grMCqGgc4X06NczK8OigT7qDtk4FRIrqc+ju5 4VX2TaBAbMfBEX8fRFS9A+hCeSPc2Aiz+HpUNeQy8+x6AOdVcVOhWoq 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 2cfd59e0f9e7c..bc7ded353c5ca 100644 --- a/rust/macros/lib.rs +++ b/rust/macros/lib.rs @@ -176,6 +176,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 Fri Jul 24 05:21:27 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 58726345CD3; Thu, 23 Jul 2026 02:11:23 +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=1784772683; cv=none; b=IO3R5PtkZ32higty2Cbb3pP+MjlaB1lLJgewzl4ye0h2qgM7G5/gqpfmsI1FyBLykSfJ3TBPO7tajyzYFn5CFQgDUZQ+S07/VzLYVgpmU9sSgd22qNxkLHRjFI/vVqBuVb4hwbakHuSeQC6kyfrPyxH/uB1eaVjRonZvU4MKPFg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784772683; c=relaxed/simple; bh=k5xxEVp2A4xqsFhkitSEUch1ZX63t/r/rS7gAki1dEA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=fJLZNWvm+bSpVQ2ZoivoOvgWDUGQg+LdjT/H3LEDvkD6l39OLzI/+p+5d4/suY+BEC/OLsnRSVFi/nF2i1tpXUN24PPQVzYqNIoLZ7NJmJ7G4wz6VwU3amfzdVH/rznBmBQRI3nIlD8Wit80P/+7r/goYVMfbVQogreJOJay5Ow= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=rDEyneBI; 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="rDEyneBI" Received: by smtp.kernel.org (Postfix) with ESMTPS id A8E21C4AF64; Thu, 23 Jul 2026 02:11:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux.dev; s=korg; t=1784772682; bh=k5xxEVp2A4xqsFhkitSEUch1ZX63t/r/rS7gAki1dEA=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=rDEyneBISkuE0LrmbFv8twzBsXLTGtRLUC/Nc7b/FGnn30LON1sZ9tpw+eE7XR3cC h3hZvSVdYyyWXrzXHYcOXc4YJxtW/hXJsKEKkgt93O/sPoD1ay6LlJSk7gpNj3Kd7A LfTdjNZHTStvoapHk4OMWRYSbuVIyUkZfs1GIn1o= 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 91A8FC4453A; Thu, 23 Jul 2026 02:11:22 +0000 (UTC) From: Alvin Sun Date: Thu, 23 Jul 2026 10:10:28 +0800 Subject: [PATCH v9 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: <20260723-fix-fops-owner-v9-5-c1c3af7f7bcb@linux.dev> References: <20260723-fix-fops-owner-v9-0-c1c3af7f7bcb@linux.dev> In-Reply-To: <20260723-fix-fops-owner-v9-0-c1c3af7f7bcb@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=1784772679; l=1974; i=alvin.sun@linux.dev; s=20260317; h=from:subject:message-id; bh=k5xxEVp2A4xqsFhkitSEUch1ZX63t/r/rS7gAki1dEA=; b=bBkLRbJhlzN+H1DZVJT0nwP1siJ4I9WkTlt9d75UdadjjdQHzQt3WAT+hnvUPWGbJB4RJXObk suHcFM83LetDT7COhtLGpPb94gnoL434sqJ14cBqlipMgaKWZ/SvrWg 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 403fc35353c74..d92cacb665366 100644 --- a/rust/kernel/drm/device.rs +++ b/rust/kernel/drm/device.rs @@ -111,7 +111,8 @@ impl Device { 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 `drm::Device` for a `drm::Driver`. pub fn new(dev: &device::Device, data: impl PinInit) -= > Result> { diff --git a/rust/kernel/drm/gem/mod.rs b/rust/kernel/drm/gem/mod.rs index 01b5bd47a3332..9a203efc59116 100644 --- a/rust/kernel/drm/gem/mod.rs +++ b/rust/kernel/drm/gem/mod.rs @@ -357,10 +357,10 @@ impl AllocImpl for 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 Fri Jul 24 05:21:27 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 59B7B345EA7; Thu, 23 Jul 2026 02:11:23 +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=1784772683; cv=none; b=KR8YA1bPuXpBe5AxiRyZek9EPA6glC5u7rLKJa2CkvwE4b22YXLHRp18I+jCD0UQjYx0HZRmwTGnUwD7jPWW6Ns8ZCrn3ctRcJ9Vcho/6HcN+ZNSU9yVpMls0Umv3UOelWRG2/K755XT6OYS5k2J4QCHfdEZn+LqYAbF3GFYq6g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784772683; c=relaxed/simple; bh=F2CI+FBdyNzgpm/+lalqrgOCl4op0DIet6QiBNuXJNI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=E1HfSTXqEH2V0HHVubRqOBdYgcNg1p0x5V2Q1h6gKmJDsi+zIpf8EwKKgxmqacMYe+Ef//EH/LL2iPgc9s/1ZZypv1PwctzQZ+lSnHLGyFb8QpaZg1gqCDfhuuhuFmrSzE9trgJRn3rRp4/6Hv0PS7e32l0sEYK7oev/6bap5e8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=qhUcu1OD; 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="qhUcu1OD" Received: by smtp.kernel.org (Postfix) with ESMTPS id C0582C4DDE8; Thu, 23 Jul 2026 02:11:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux.dev; s=korg; t=1784772682; bh=F2CI+FBdyNzgpm/+lalqrgOCl4op0DIet6QiBNuXJNI=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=qhUcu1ODNgrlW2FGiwWAntJqTBAeyzWa/VchunRLoi5nbaHQfGDGVfc5z4WZpL7mg MY8ZMB4xPI68EnviLVHBtuqLU4wDF7K4zCYWSx1Bc4eujg3FPGDnUFhhWXyjAIApGI dgWy95WaPD0aQfvnmKxiKGHtNDxx/0MNxjaTW8Fo= 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 A91E9C44536; Thu, 23 Jul 2026 02:11:22 +0000 (UTC) From: Alvin Sun Date: Thu, 23 Jul 2026 10:10:29 +0800 Subject: [PATCH v9 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: <20260723-fix-fops-owner-v9-6-c1c3af7f7bcb@linux.dev> References: <20260723-fix-fops-owner-v9-0-c1c3af7f7bcb@linux.dev> In-Reply-To: <20260723-fix-fops-owner-v9-0-c1c3af7f7bcb@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=1784772679; l=1259; i=alvin.sun@linux.dev; s=20260317; h=from:subject:message-id; bh=F2CI+FBdyNzgpm/+lalqrgOCl4op0DIet6QiBNuXJNI=; b=b1YiLB/69Su44v2ps7laeoetpRGghonjYzajdU0tUf089j7rW4bO8E1v6QG6ciuRN8OhQ0vn/ BSLz4daJXirBqvGF2coxaGuxm7sPbiDxeIYLc3vzgdLWZsq7KnM6Lmu 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 Fri Jul 24 05:21:27 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 6ECE2347521; Thu, 23 Jul 2026 02:11:23 +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=1784772683; cv=none; b=D6vMGtvnOxeZryF/lt0FsgUJTs3IpQQPHBU7xL/avgMbnLfdcIYspASXl/900YgCswGUYnuBS7jyVUI9mYoFUHpIuL1VvUqOz9YkhQ6/3KqhCH1M8r4y1zbHpcgtbBoqD0li0HvstXpqmgucZk4jKsI7znS+AqCEWGY9fhFYrCQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784772683; c=relaxed/simple; bh=t9D2Px8pUwrEcOg/YTzMXGqqQKBGT5HfYznSBGN9YqI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=g7pUeiDRLGu1cZgmFuVlChF6bFRaVOO6QobM9/dOOwVYsa3zzPnnaR2ojjIlbos6vzNVNyiGZnDH2MvMIeyBqiBRbgUwFNyt/FB0B+Qo1lKhGma7icdvee1Bm6x3fMaZxy+B+acOulQ+JeOSqy/Tt4HH2IiVfP5Ug+Nc90xJR2w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=N+wSgFUP; 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="N+wSgFUP" Received: by smtp.kernel.org (Postfix) with ESMTPS id D83A8C2BCFC; Thu, 23 Jul 2026 02:11:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux.dev; s=korg; t=1784772682; bh=t9D2Px8pUwrEcOg/YTzMXGqqQKBGT5HfYznSBGN9YqI=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=N+wSgFUPaBD8171l+J3Xvph9ARrvPMb+adPAc72ucMIdok9l2pihAzvE9AAA2ogVM owO5k6LWXV2Ttrrncp24de7KOXSgWR6jcnDdCdQpLft203ZHFpuoJQ0z9suRdOeBRx 90SH7Jx+EZuSRBx5fc6Tb5CSa+1usyV0FU70M8kc= 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 C0704C4453D; Thu, 23 Jul 2026 02:11:22 +0000 (UTC) From: Alvin Sun Date: Thu, 23 Jul 2026 10:10:30 +0800 Subject: [PATCH v9 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: <20260723-fix-fops-owner-v9-7-c1c3af7f7bcb@linux.dev> References: <20260723-fix-fops-owner-v9-0-c1c3af7f7bcb@linux.dev> In-Reply-To: <20260723-fix-fops-owner-v9-0-c1c3af7f7bcb@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=1784772679; l=2926; i=alvin.sun@linux.dev; s=20260317; h=from:subject:message-id; bh=t9D2Px8pUwrEcOg/YTzMXGqqQKBGT5HfYznSBGN9YqI=; b=QZpTbDGCiPyQZWT6ru0P3y8GEoRjWyDK+AFBRqjSgxVq0X4noWfmwaxT70UPXQMMvr7jlF35Z vgBLVuANHIaAGbw26r2bwD49K5AuQ3MeM01jwmBqEq0KNl1K5JUsYXA 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 Fri Jul 24 05:21:27 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 6D432347514; Thu, 23 Jul 2026 02:11:23 +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=1784772683; cv=none; b=pfwkzv3e1/ZdcAVR9Av9f1h71TpPaiK6f1261EfeA2p9oFerj8GUwvxJAJSZP8eyiJSYPHXCYakExwE/Kn56gik09AU2lfcSE7UWXWYr1f/Qh2bfaXKV5lOWf3VzL+lEPCBXJDdWDHvqOsVWdDleYLKX/7yV2iVqALOIMxGJksI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784772683; 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=a2aR9zjHrkSIDPQkQsaipnzpKs3bM5HsB9bbHuAHzenIE+KhXQsPYieXAMJ9mzQqGvgFkpPlROTCyj5yT045VXGNSLNAlOeapmOS+LFKzsXCDidVQZzOLfD9bW7h3B9UjxYwmZcrUoPoLmF33YRDHG4E8aF59q2CpNjoyblqry8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=EYNvYe0R; 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="EYNvYe0R" Received: by smtp.kernel.org (Postfix) with ESMTPS id E741EC2BCF7; Thu, 23 Jul 2026 02:11:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux.dev; s=korg; t=1784772683; bh=Y+g5XGXUpaEPEpNu/2z6EYlrPFXE16lF+w/ttECZ4PY=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=EYNvYe0RUvsPYAGRhDw6q1NgLASdi2GaHVZRr+nnpYYwkRyNgoZMCBCPAAuQOi3vf 1j83/s+AndcNzDQkMgLWuZvpYDKhG8/SJpjmeP23xpYs1kWkChERamTejEkx62PxOc jwO8h1oeuDWHZzqi862nREsclb+qHz/jVWTR3D/U= 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 D5057C531C8; Thu, 23 Jul 2026 02:11:22 +0000 (UTC) From: Alvin Sun Date: Thu, 23 Jul 2026 10:10:31 +0800 Subject: [PATCH v9 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: <20260723-fix-fops-owner-v9-8-c1c3af7f7bcb@linux.dev> References: <20260723-fix-fops-owner-v9-0-c1c3af7f7bcb@linux.dev> In-Reply-To: <20260723-fix-fops-owner-v9-0-c1c3af7f7bcb@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=1784772679; l=1425; i=alvin.sun@linux.dev; s=20260317; h=from:subject:message-id; bh=Y+g5XGXUpaEPEpNu/2z6EYlrPFXE16lF+w/ttECZ4PY=; b=B4b7u6KtkI40/woTUYD5H6mrDul6s2qfLFISdlbTRo0/o03h6wBZ90jKOEBGacucKVjUzUEtk tyWBvcyuVlqCc2XrmP2l7nPaOux5ez8JPCBwAMGoQP4+pkpUn244pEB 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 Fri Jul 24 05:21:27 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 8805434E75A; Thu, 23 Jul 2026 02:11:23 +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=1784772683; cv=none; b=GF/6uWv9GujnJ9qriFMBqHpxZ4xkf2HBbC+xoU6xvpZ3+EcGii1/fG9hvVLJZaQr2eJpfxFpm/TpRTW1Lb7We/2OjU2qdv/gBCDj6UTsT3CkLa5a+p0Qlho+WL2/xJ629mCwwv+/5Xen8fZz4K1SHGFa4CMCE/q1mvzFTGKdd48= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784772683; c=relaxed/simple; bh=b7bgA4GS9lfKOXMTzjt9PgQ7i+Hg/NN96aHcSylK5wQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=pmVqimW+oL/2+CRAKVIt4EUpUK/VF3stfAjRz5iVxZXugTPrbOI+XS6MH6+MZnIp3hZRsTM7kUYjJjyP6SConX3KPyjsTjX4mdfIcKOa4Wo8VbYLLnoPtQXNpp9eXkP46VnxEXNtDMFjy63ux7J9N5YEzBbN1Zim5KAmeoOUU7w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=trMrDaTU; 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="trMrDaTU" Received: by smtp.kernel.org (Postfix) with ESMTPS id 0C57CC19425; Thu, 23 Jul 2026 02:11:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux.dev; s=korg; t=1784772683; bh=b7bgA4GS9lfKOXMTzjt9PgQ7i+Hg/NN96aHcSylK5wQ=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=trMrDaTU9oGMpWKQv3StYauGZvFQGni9gGjJprxxwViNz+ngzk0i6E/qzFl21akXt Y5j9kkJ9OG1v5AmIe8T6sXWUiqc+H0XvHHitamFcknVTvuQwpsDXt9GkuRZkQM7L2x UpwINa+wnJFjarMDzhnBISO5zuIqy9lQXiRAYcuM= 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 EA82DC531C7; Thu, 23 Jul 2026 02:11:22 +0000 (UTC) From: Alvin Sun Date: Thu, 23 Jul 2026 10:10:32 +0800 Subject: [PATCH v9 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: <20260723-fix-fops-owner-v9-9-c1c3af7f7bcb@linux.dev> References: <20260723-fix-fops-owner-v9-0-c1c3af7f7bcb@linux.dev> In-Reply-To: <20260723-fix-fops-owner-v9-0-c1c3af7f7bcb@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=1784772679; l=1856; i=alvin.sun@linux.dev; s=20260317; h=from:subject:message-id; bh=b7bgA4GS9lfKOXMTzjt9PgQ7i+Hg/NN96aHcSylK5wQ=; b=XZI9XPcXFxW6ssnwu4RjhBeXuypNQUNTuRBLu+ygEQQcqK4O5f5EZ9xXYVaZ0tSYL3E4VYAqA kQqOLDz0hgIBLPSVtrfyYU82hXV4JZXZ6HWkCmNGPBS3X3KR6l5/Bur 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 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 Fri Jul 24 05:21:27 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 8D4FB350285; Thu, 23 Jul 2026 02:11:23 +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=1784772683; cv=none; b=Umia1WZQop4MCGRN886sIdBP290+FGAISfEh3psj+AAww0eNFO6V5zBVRVb4i386wwWJmpPSwOfx/dJZ/dXNjYbIud48GCFw99T4n+t1WrTZI6d8Sj2Q2R30wNOfwlH8XTlUAYg9ywNe7jNiFIE30riHZ2aYLtMfg25vwKbeUn4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784772683; c=relaxed/simple; bh=/+TJBprKftruu09PkIGYhOVPOJy49bvIvHvN98E4jqA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=qOlY6H9iPWTe/jJXKBE0bPrz2TOIbIxjt7i6TCJh0VrYc8QTbqNliIWVJfR4KQAhTffk8FpgR5e2HFTlce5WTea7czYppuI2F1GgtkyIPJEWUwVXPH4rXTE9PaBI+Z78pVn0IbIGtiAAgAkuPmzp/pe3I799vSg9Pd5Sl5WBiLM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=HJ0N5ZtQ; 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="HJ0N5ZtQ" Received: by smtp.kernel.org (Postfix) with ESMTPS id 3EC78C2BCFB; Thu, 23 Jul 2026 02:11:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux.dev; s=korg; t=1784772683; bh=/+TJBprKftruu09PkIGYhOVPOJy49bvIvHvN98E4jqA=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=HJ0N5ZtQKqWYDxSEPnLM1z5BMGS8Nj0FhoofJCdkdmx2DmTrCYZGUuQICBgnTKbk8 cZzCpXoCSx2XYpV09HHNxRB8JKxdpGmbyXN0oOgUlMRzkeZZwLqy4an08dfuLTPv6K CDrjIFYNg3jpReV8oVUnKrQ8xW3Dja4PB2AuZSVk= 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 28104C4453D; Thu, 23 Jul 2026 02:11:23 +0000 (UTC) From: Alvin Sun Date: Thu, 23 Jul 2026 10:10:33 +0800 Subject: [PATCH v9 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: <20260723-fix-fops-owner-v9-10-c1c3af7f7bcb@linux.dev> References: <20260723-fix-fops-owner-v9-0-c1c3af7f7bcb@linux.dev> In-Reply-To: <20260723-fix-fops-owner-v9-0-c1c3af7f7bcb@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=1784772679; l=1000; i=alvin.sun@linux.dev; s=20260317; h=from:subject:message-id; bh=/+TJBprKftruu09PkIGYhOVPOJy49bvIvHvN98E4jqA=; b=86V23XzkQz5CzfR0RCwwYpyhbOuNvPOIf5ft8ndFw7YOO8vPwxWQ+942au721djMIOqpu04SV 5zRRTRmoKtyBerwGXttIDGfn87cB2KrhTBTBvapSB9SU79lCsGeHGhF 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 Signed-off-by: Alvin Sun --- MAINTAINERS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MAINTAINERS b/MAINTAINERS index e035a3be797c4..74733de3e41ee 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -17984,7 +17984,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