From nobody Sat Jul 25 22:03:05 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 C4E682236F0; Mon, 13 Jul 2026 06:48:38 +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=1783925318; cv=none; b=b5OLlngiRlhSHEjKV1J91M/t5zD+SrjK7EYEqRjmr/ECWO/uSlKz4PiQL7w9zZexcU5T2NSMd3KXOjzCIC9RYo282POSgvAiLrQKRI4kSSP9nciaqy3jFuler9rLO8WOMLYaS4m5dQlyZkm0xKFFBWVEVj185wJs6g1ZFhza52E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783925318; c=relaxed/simple; bh=eD883EAohdVL+339OOyxXIWIwuIJobN2Dv/+cXmJ1mM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=BndrKaaPGs9U9w1E570VdOFxK5TTKgBSxJyL1gYlobuDfPn87kdZf2pb6OyUUblxufnJFcusL3WU44Nh2Osi1FAUWMRlYEuUCnmuI9xwllcKeqMso7WIzcas3lVfDc1EjvZM11zdct8t+XKW4IPS6TAm6bVB7HwtTWCdsQCcAbo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=iE0rw7jY; 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="iE0rw7jY" Received: by smtp.kernel.org (Postfix) with ESMTPS id 6F4C9C2BCF4; Mon, 13 Jul 2026 06:48:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux.dev; s=korg; t=1783925318; bh=eD883EAohdVL+339OOyxXIWIwuIJobN2Dv/+cXmJ1mM=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=iE0rw7jYlaGhTMD8UcmT5OwptkxJvokGn+F7urQXiFTKz4t7EbMUh+ZZmgmg0kF+s OtHFByZUQaOFX3z8PM7jfKaUzezO8UkN87+Mt3FIwuw2QCFieUUomMgNSYoBDO4xRG YFEGpUfnB8NsHVc141OMVm0LdIBv3KoCmLM31I4Y= 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 485A2C44501; Mon, 13 Jul 2026 06:48:38 +0000 (UTC) From: Alvin Sun Date: Mon, 13 Jul 2026 14:45:22 +0800 Subject: [PATCH v8 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: <20260713-fix-fops-owner-v8-1-2495cfa82d47@linux.dev> References: <20260713-fix-fops-owner-v8-0-2495cfa82d47@linux.dev> In-Reply-To: <20260713-fix-fops-owner-v8-0-2495cfa82d47@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=1783925315; l=10329; i=alvin.sun@linux.dev; s=20260317; h=from:subject:message-id; bh=eD883EAohdVL+339OOyxXIWIwuIJobN2Dv/+cXmJ1mM=; b=XDsfXyaHx28qGT2ewJFm2NnEvVHtwOAwTYgzMR/Dfytws17FcQ2l7iIb6PO+l3SyvWWft3MYP /s7vdf9V71VD+jSdonMxlgfqBtgC1z6Ri04G42F5Amt4XH7I15vewVA 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 Signed-off-by: Alvin Sun Reviewed-by: Alice Ryhl --- 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 Sat Jul 25 22:03:05 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 C4E0A17A300; Mon, 13 Jul 2026 06:48:38 +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=1783925318; cv=none; b=oRl1LnOrfhCvn3mSqeTsL8Gb1X7mvFfoSnKVvXKY+WJG+T367NiizO5bLGVd+VKokZ8r0ukXMnjZLSwCLIunHlVAQV3EvistuSXIgF0RnB678DP3voR82OD6PVCX7MHyn9zl53dnP7FyzOqWASGYFm00xFFGFX0bPgJpO4b58Mo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783925318; c=relaxed/simple; bh=aF47iLMPZHY8ikZj0/3fPMH5Q4mRqmYCLQexdlk5/mo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=DM2NaLYTX50U/xxxow8Co3xi7FKy3Jd2dx4qGNtMMxPlnnMvvAeYDNH7rFHY1pXzmELRLrEYfRN+9SwAQyX86uhp27yqKJ8aMVuuEzk6C4Udq+YBzci42Hbdwaa6wXF16JLscvhLCK8Ligtz4anISVrTk6mLcJlN/wm2pzNzBdg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=Nk/H4GWE; 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="Nk/H4GWE" Received: by smtp.kernel.org (Postfix) with ESMTPS id 7BF08C4AF0E; Mon, 13 Jul 2026 06:48:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux.dev; s=korg; t=1783925318; bh=aF47iLMPZHY8ikZj0/3fPMH5Q4mRqmYCLQexdlk5/mo=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=Nk/H4GWEC1G3ljwWjl/RPZn81zppqgdCuFj/5IPYiYXeNvKHJTSZHFIiNZz6JJw+o rXPZmS7XHUcvDY5Hny+iOmhuIaUDVXZshwLwsrOEQXadqbFOZZ76je6jrlE7Cuv5qK eBYuIcTbMfr2qMy4ZYo8ee1ARl+8CSOWcpqzxV2Q= 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 5BF8EC44506; Mon, 13 Jul 2026 06:48:38 +0000 (UTC) From: Alvin Sun Date: Mon, 13 Jul 2026 14:45:23 +0800 Subject: [PATCH v8 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: <20260713-fix-fops-owner-v8-2-2495cfa82d47@linux.dev> References: <20260713-fix-fops-owner-v8-0-2495cfa82d47@linux.dev> In-Reply-To: <20260713-fix-fops-owner-v8-0-2495cfa82d47@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=1783925315; l=3594; i=alvin.sun@linux.dev; s=20260317; h=from:subject:message-id; bh=aF47iLMPZHY8ikZj0/3fPMH5Q4mRqmYCLQexdlk5/mo=; b=KD3Zyzbn7jRK/dQ8MUOgMLyaZFAQKRhRfDNkn/mVbczDhNcrZ237isvWV08DsrpsF3AMGxM20 7WzG/DPMcw0BvnQ8Tpl9jEZ2eFDxId3TevKsipUYKKjPOxnBesfhmpL 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 Signed-off-by: Alvin Sun Reviewed-by: Alice Ryhl --- 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 Sat Jul 25 22:03:05 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 D8A632FE07D; Mon, 13 Jul 2026 06:48:38 +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=1783925319; cv=none; b=r5rCK0XTI8iqW0HiroxfRjFV61qfiGWUOFrxuCufpJuyY4JhXXIf6veWQD1wRf5XXHM70JH3QEvQgiDFi2AJ09Rilnp0MDp4/XUS+gBebO66sWSMDtfw1Nh3752c/ycNkoejc2p4BCIXspDQUfn9h3yuYxephB87OkwieXZiQJw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783925319; c=relaxed/simple; bh=f19XCtBPrdV1fkgcubKrKRKRYVaBwil44TIB/tWiXTo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=WjVha5/Wa7YbgZlo7ui9LUl57vT6v9fGu6J0iTkBlCVkrGqlEhdcjUb5TjT/q0DaEI9Mk4VKajsd8YMc/bkwNJq3p4htx/8sUqjEbMRkF8l5RePwi+GH30zfGx7AnBk1vqmiMHC3clDJ+9JK2/ItfIm1ZXTfRmUhrZB6HUBqBQg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=BXVjhzeZ; 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="BXVjhzeZ" Received: by smtp.kernel.org (Postfix) with ESMTPS id 87E37C2BCFF; Mon, 13 Jul 2026 06:48:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux.dev; s=korg; t=1783925318; bh=f19XCtBPrdV1fkgcubKrKRKRYVaBwil44TIB/tWiXTo=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=BXVjhzeZwahs+QSBGxRaEQberUUsAY6ye/bAc8jOFXC3o89DcjSKDgBIkWPfNZ7pp sv5hzhl8mFV6uauuUaYCC2q6P4H3kqRRcJRqFvIBBscD0nXA+uSPuChCb6iuc7emOy 7ZqNjfLuQzA1MFpF8upjxidZkyRzz543EnFfeEBg= 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 6DDD2C44508; Mon, 13 Jul 2026 06:48:38 +0000 (UTC) From: Alvin Sun Date: Mon, 13 Jul 2026 14:45:24 +0800 Subject: [PATCH v8 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: <20260713-fix-fops-owner-v8-3-2495cfa82d47@linux.dev> References: <20260713-fix-fops-owner-v8-0-2495cfa82d47@linux.dev> In-Reply-To: <20260713-fix-fops-owner-v8-0-2495cfa82d47@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=1783925315; l=1329; i=alvin.sun@linux.dev; s=20260317; h=from:subject:message-id; bh=f19XCtBPrdV1fkgcubKrKRKRYVaBwil44TIB/tWiXTo=; b=pARwJxVcVRoXymIcGQkDnow+q6ikOGmiQ4rE0dnkq/TcJlojyMxZzqzh1CwphkdeHA11KajRg nJIHFGtIelqCc4wXIGt+qScHDx9PAjITpWZcK9AYEYxozWl5BQSqsZV 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 Signed-off-by: Alvin Sun Reviewed-by: Alice Ryhl --- 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 Sat Jul 25 22:03:05 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 4395F369D6A; Mon, 13 Jul 2026 06:48:39 +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=1783925319; cv=none; b=YIdHdP1A8T8x3eRu43L3DaB1q7geJvA8S3seeHsaSt1WXc9kcctacWlvi7Iccgj4CzqBNOF/S6OwdXrASpgMeVPqfozdKWUFyckus8yPbcdVRaBdMUkTTS1hq8z3xkqpnJtZUBT3gTUsJlnF0jfooi9Npk5WadpYu5EMDSmrif8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783925319; c=relaxed/simple; bh=iQHGWPaM+K+cKo+H5JDtUc/37urf23KbdiF6XVV5Cf0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ntiU4tNpPbIi1MI/E5o1zEuXW4XTXYbAe2NAPR3Jd00mpm1aV2ZTOMiSLNT1HfTpRZTkI3gAbdlNFL2wrznMzYkAviV//Q5MTy/G0fEsWZlyR8EMnUA5H1UzsDq6JoMN2PxWMq81CVIwhW+rZoBrLULidS5s+6FLN+63qW53/24= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=wCTgDKeW; 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="wCTgDKeW" Received: by smtp.kernel.org (Postfix) with ESMTPS id 9EDDAC2BCB8; Mon, 13 Jul 2026 06:48:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux.dev; s=korg; t=1783925318; bh=iQHGWPaM+K+cKo+H5JDtUc/37urf23KbdiF6XVV5Cf0=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=wCTgDKeWarJUCl8AkeL/m3xRdDD9ELnmc8S3O7t0K5GjGAeyOy4DP5lA7FgjRAHFu kBKLIz9q+Hu2LoEbS64ZjvcDxuiVjwYfl+vDVnr+v1Faj6m1d58OHzMSPuSccczsaj Nw9PB2CZyadHRBCnJUHD6jzml0NIiGWP1ALQA0KU= 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 80A76C43458; Mon, 13 Jul 2026 06:48:38 +0000 (UTC) From: Alvin Sun Date: Mon, 13 Jul 2026 14:45:25 +0800 Subject: [PATCH v8 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: <20260713-fix-fops-owner-v8-4-2495cfa82d47@linux.dev> References: <20260713-fix-fops-owner-v8-0-2495cfa82d47@linux.dev> In-Reply-To: <20260713-fix-fops-owner-v8-0-2495cfa82d47@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=1783925315; l=4578; i=alvin.sun@linux.dev; s=20260317; h=from:subject:message-id; bh=iQHGWPaM+K+cKo+H5JDtUc/37urf23KbdiF6XVV5Cf0=; b=7OZIrzLAHxzmcofhzJzheThoFHX9outNCA/o4INLUP1uS7dQdE1ujWjY9Yy5iD4BFZDZiQDVW bvN7aol1F1jCoxPO7xyoLlV6U1Ka9Qk1iBE5GqKe6MGeKkNBZpQwP0n 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 Signed-off-by: Alvin Sun Reviewed-by: Alice Ryhl --- 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 Sat Jul 25 22:03:05 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 262AC368D5A; Mon, 13 Jul 2026 06:48:39 +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=1783925319; cv=none; b=QwEeb3UBZch2KEBMIynIQylJlwv5TbQn+egmL1nDKlDTQ0H1YmU8uNlbyu19veMqT5ltyZ/QIxOOjiW7gkuLWe10Fi2aaqFCZyCKjDcKj1IImpPs5qCTDUdM2BKO+krPQ0CSoL6MKsXCMabTP+Plbwc/6ApO7qswAxL1OQcA8i8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783925319; c=relaxed/simple; bh=et7aLWDdt16IGyYP6zeuD/W5wjktc0zJWIypSVqeW1w=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Ln07iuCZjx7mhb5U3OypFVzN2gClaHm4lo9pIRgFgj+7/BPV90eeGF0qa+DERLmx3ETt+j5/biuBszkzA6+W5DxRdRTC5winhJ6rWsQHRnxbR4sD0BCnrtw1PDfGmBnhAkUBHcUZxSCC01vapxkgKEPk+k+w+zlZawJaRrVfJK4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=ZVvzRiqn; 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="ZVvzRiqn" Received: by smtp.kernel.org (Postfix) with ESMTPS id AD243C2BCFD; Mon, 13 Jul 2026 06:48:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux.dev; s=korg; t=1783925318; bh=et7aLWDdt16IGyYP6zeuD/W5wjktc0zJWIypSVqeW1w=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=ZVvzRiqnTFf47jTWWTn4+68/F18BQdl/nFLOBNlTrsPQb6HvdFf8V43RbTnUlChN0 CkRoOjRa3dSwmZ9T5n3e8t+iPd1AsQ0+yMj9GyEIqM8Ag143gu118MJYrshn92PU1X prBa/YUXs7AuW4duxL9v81o8oZ3uPr1O/l9+vYP0= 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 91573C44509; Mon, 13 Jul 2026 06:48:38 +0000 (UTC) From: Alvin Sun Date: Mon, 13 Jul 2026 14:45:26 +0800 Subject: [PATCH v8 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: <20260713-fix-fops-owner-v8-5-2495cfa82d47@linux.dev> References: <20260713-fix-fops-owner-v8-0-2495cfa82d47@linux.dev> In-Reply-To: <20260713-fix-fops-owner-v8-0-2495cfa82d47@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=1783925315; l=1926; i=alvin.sun@linux.dev; s=20260317; h=from:subject:message-id; bh=et7aLWDdt16IGyYP6zeuD/W5wjktc0zJWIypSVqeW1w=; b=ViJAZiZboYRX7UQnX1FE7n+1pM+1JyAq+6/45ULnIluxKelHubkncLrd+vYyQTe69UQXGISnT dzY8VDb0KbsCvPFUs6U31jOnJHuTKOu1G1yi/q0I0KvFtk6D4TajX85 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 Signed-off-by: Alvin Sun Reviewed-by: Alice Ryhl --- 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 Sat Jul 25 22:03:05 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 41DB9369D61; Mon, 13 Jul 2026 06:48:39 +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=1783925319; cv=none; b=o3K3lBzCQiLV+DeDNWNOIYaFyF1j/AZMNvaDtvde7HC6nIkTnTNcqBGQ4uWFekfn4kooo6Emi5qZBya9MCUJrZmZqpmLlwoEtecfYRrlhfHEIi8m70DRJuTTwBaEw7iIEUS7EcDc1C6mKDXjuZ++cAGTPm77s0BFEX5zizKxWQc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783925319; c=relaxed/simple; bh=Db4jVbnkOdnxpPP/DxxrroJ15a5rGmjRI3btLuaJQas=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=leS4W96uSiODXe9ZQ7DVSFDwZFn63sRzh5qjiByObhzhrZYJQty0b9MJknbIvnDTHH+6FnyiFFRl8ez1A0P+y26bpKxeNBBElncb2PkZ+E8Q7h81+HTeKw8iBqgBOVKUyN5hfSVs9moO1MnyB5wctLCRAWQ6YoJR8kRCWQfxHMA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=W4bDSYUv; 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="W4bDSYUv" Received: by smtp.kernel.org (Postfix) with ESMTPS id C4707C4AF49; Mon, 13 Jul 2026 06:48:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux.dev; s=korg; t=1783925318; bh=Db4jVbnkOdnxpPP/DxxrroJ15a5rGmjRI3btLuaJQas=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=W4bDSYUvCuexIdLaABkouwUh9vvt5mwwj6m2BkIr8JUQJRFCjV+YWZ0xMM3fXtS00 yj9TLyAn8S2CinH9aexF/eG1c0rGg3etQnzTUW3TYtv89cQzxPxrsJycB9Ave1jB+R E57F0evYtVLHB0uXKGe0s7kem0EK5lB3Y9wGqvxk= 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 A6710C44506; Mon, 13 Jul 2026 06:48:38 +0000 (UTC) From: Alvin Sun Date: Mon, 13 Jul 2026 14:45:27 +0800 Subject: [PATCH v8 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: <20260713-fix-fops-owner-v8-6-2495cfa82d47@linux.dev> References: <20260713-fix-fops-owner-v8-0-2495cfa82d47@linux.dev> In-Reply-To: <20260713-fix-fops-owner-v8-0-2495cfa82d47@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=1783925315; l=1152; i=alvin.sun@linux.dev; s=20260317; h=from:subject:message-id; bh=Db4jVbnkOdnxpPP/DxxrroJ15a5rGmjRI3btLuaJQas=; b=iVaCdmNAPFGlDsUNfSCgVkw8kSu7CTexrMLKzcsGzX5gaQSOwbz2wnjHXC7Vv3tWmZbSe7tkt MdggjgUKt8rAX2LehhrOgVokCxTH4ps8lg3zRFNtOABC8n/33cJsxgu 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 Signed-off-by: Alvin Sun Acked-by: Greg Kroah-Hartman Reviewed-by: Alice Ryhl --- 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 Sat Jul 25 22:03:05 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 43D80369D6D; Mon, 13 Jul 2026 06:48:39 +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=1783925319; cv=none; b=CtyoX//Sn/QgUdoYU5m4RVpMCQlqpOsqsjxlH4sNBYM+IyHxYz5LSKXrV8dULlNBiEb2PoR0z8SiYA0LhvQ/NpW6+RIkQI/ccwYkPsmDK84cj9UHQNqM04yr4NLF+ynBVbJpReD+Sp4eHuT55M0joRPMsthu7HeDtDyUTBtJiTc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783925319; c=relaxed/simple; bh=uKMCf9D/JKTMs7JHu+JGuw1l/MDmYGvfbfSnKCku75E=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=TriF5P+PE6cbDS4RmgqtsL+6oz4KE0wawCZU9wo7wY0juqteBWR4IJabBOd8zSBS/g7XVAT7xREKyR5+OMSEF8SUmLKoztadvQWX/rr6lAjgQ6VttfSAvi49JlrMqFNodfeqx5TRLIzDJ85pEOTQwCNUAM4DRPqwz7CdH3ezm+w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=EcaFPC6s; 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="EcaFPC6s" Received: by smtp.kernel.org (Postfix) with ESMTPS id D19E3C2BCF7; Mon, 13 Jul 2026 06:48:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux.dev; s=korg; t=1783925318; bh=uKMCf9D/JKTMs7JHu+JGuw1l/MDmYGvfbfSnKCku75E=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=EcaFPC6snedk55JtK2Gjj8BzK8zi4SUAJKP3PE8ZpVhAhVvlb+M/qMow7hspuemAt Dso+U31/Gg1AGU/uJhhVrrGrKV0rbcD/7z1zU2XToV6xtqKHXLrmsuy3wj/I6AWCaM V9L7fm7Z8M/3Yt0Mhr87bYN5lOqL9Saz6NKfNNkg= 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 B8A88C44507; Mon, 13 Jul 2026 06:48:38 +0000 (UTC) From: Alvin Sun Date: Mon, 13 Jul 2026 14:45:28 +0800 Subject: [PATCH v8 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: <20260713-fix-fops-owner-v8-7-2495cfa82d47@linux.dev> References: <20260713-fix-fops-owner-v8-0-2495cfa82d47@linux.dev> In-Reply-To: <20260713-fix-fops-owner-v8-0-2495cfa82d47@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=1783925315; l=2784; i=alvin.sun@linux.dev; s=20260317; h=from:subject:message-id; bh=uKMCf9D/JKTMs7JHu+JGuw1l/MDmYGvfbfSnKCku75E=; b=5yxwCnpWzbxSeK1SF8cTkaX+tyZ2QIbiLyb2o0aTlxw4y4+Dc+dS5MZj0TVfqml78fze6RHZx 1JkkADmRYtmDNSoMIamfBuBTbiLcUOa4B62b8NBRHnYAXB20Evd5UH2 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 Signed-off-by: Alvin Sun Acked-by: Andreas Hindborg Reviewed-by: Alice Ryhl Reviewed-by: Gary Guo --- 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 Sat Jul 25 22:03:05 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 55BED36CDF3; Mon, 13 Jul 2026 06:48:39 +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=1783925319; cv=none; b=GqbsN1oiPRBVpvP1zszVmsxuBgKzY1pN87YxYtnXLgku5ENiTjUFKcnTN8UaW2h5blQyVCa8ZqiOtXIxGWYCRUbnSRdKWY5MqD9RB9Z6E5ZqIknEW3F7JMmeqMi/W/rLg3epFbVdgy87ka+8g09DWDLBA6AEFCARwcCWbthU7nE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783925319; c=relaxed/simple; bh=0iEJ9CoHu7M3V0ejPEkK0764ck94VjFLyF6WPTDVWGc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=MEDdMKAw2DNgUKJsFb7b7yW8e1zCb4hn4t1lqgWX5IkOha2nD8h4w3oZpi+Bos3ezqpxHslwLT6oMn55OMPl7FEujvgRY8jsY1li1uJ8qAYsYbcKXcopT9/lxrU8LjAxFp39RRz1/7RFdsEKhNs9FY54YbFcacg4hbNbYlp2SIs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=cLFLk92I; 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="cLFLk92I" Received: by smtp.kernel.org (Postfix) with ESMTPS id E46A1C2BD04; Mon, 13 Jul 2026 06:48:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux.dev; s=korg; t=1783925319; bh=0iEJ9CoHu7M3V0ejPEkK0764ck94VjFLyF6WPTDVWGc=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=cLFLk92ItbsYpdLZZGxK4vdg7pF8pVKORa/xN95zv1WLvfNeM+uumh3irGhyIVBiC IshiS7KB6H30pXNddWKaXyEv8UHTp/pYO6PN3TGfvHjI4h4f1h/kgfkTqd6UO4FOJU TE9M4+2Kpi4CqkLy0v0sd4ZuMOC01YtUsips4pn4= 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 CA743C44508; Mon, 13 Jul 2026 06:48:38 +0000 (UTC) From: Alvin Sun Date: Mon, 13 Jul 2026 14:45:29 +0800 Subject: [PATCH v8 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: <20260713-fix-fops-owner-v8-8-2495cfa82d47@linux.dev> References: <20260713-fix-fops-owner-v8-0-2495cfa82d47@linux.dev> In-Reply-To: <20260713-fix-fops-owner-v8-0-2495cfa82d47@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=1783925315; l=1377; i=alvin.sun@linux.dev; s=20260317; h=from:subject:message-id; bh=0iEJ9CoHu7M3V0ejPEkK0764ck94VjFLyF6WPTDVWGc=; b=cK7QM2qYq0GIpcaTTO9bkIt+jwSeH2Vs0bhnRqQG7Ihjg7Jl+u0w0FYqX1zLxiW42PrYEiFpt 9A6fn/tGlkwCX0rwmak7em6InXzQ40vC+Pw6GDqrZ8orzkLjFH82m0z 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 Signed-off-by: Alvin Sun Reviewed-by: Alice Ryhl --- 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 Sat Jul 25 22:03:05 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 6E2C236EAB1; Mon, 13 Jul 2026 06:48:39 +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=1783925319; cv=none; b=KqbYz9KnYd+2eGGNUp+zMR2t9xLVzF68f1FcwnmE5OVhY/a1ikCXU+Kr4JQ4hxNFpJgTDDxb21ITRU+FhZhcxrINVNmvZV9tOVLhFwAjNzu3jOBtUi4I1RLfOcb6pmB5lF5t7OrbPy7+/6/SYmbgcb+K/z+m5jRBc+YpGUu3HKU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783925319; c=relaxed/simple; bh=DgPxSWJm3yP+ocMCPSZPYulAvRJygW/tBHfG7di1GFE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=cFHhkiN44YkgE+gPQLi+Ttdw+4hS+fImss19HUxsQ60fowvE+mjL02AgwaCgkMHTJNPzk0z2VJrxg8hDTjn3w9eIMkHTApGo+w5MSiGT2ETbIoQmNRL4Op9qpgC6CxlCcDvpIR36VjHt+smK0rPJ8oKflT+CaN1NpK4UmCVKcoI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=Zk0zQkO8; 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="Zk0zQkO8" Received: by smtp.kernel.org (Postfix) with ESMTPS id F1E39C4AF0C; Mon, 13 Jul 2026 06:48:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux.dev; s=korg; t=1783925319; bh=DgPxSWJm3yP+ocMCPSZPYulAvRJygW/tBHfG7di1GFE=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=Zk0zQkO8N3gbKJh5tvrFS9kZDOyVmA77DvUWiEDGtB/y7uMEjXGBdTrvfm5xgIUw9 pLe2zPc/shwdxyRVRIsYvnGbGhA1ztRM4tI9Z5RZtwb5bmmA3Nqp9IYmOxVNwNxUQk RjT2o887E3fqiCnZalcPFZn2QjWBCQk3fWaL2+IQ= 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 DBFD9C44501; Mon, 13 Jul 2026 06:48:38 +0000 (UTC) From: Alvin Sun Date: Mon, 13 Jul 2026 14:45:30 +0800 Subject: [PATCH v8 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: <20260713-fix-fops-owner-v8-9-2495cfa82d47@linux.dev> References: <20260713-fix-fops-owner-v8-0-2495cfa82d47@linux.dev> In-Reply-To: <20260713-fix-fops-owner-v8-0-2495cfa82d47@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=1783925315; l=1808; i=alvin.sun@linux.dev; s=20260317; h=from:subject:message-id; bh=DgPxSWJm3yP+ocMCPSZPYulAvRJygW/tBHfG7di1GFE=; b=0bMb7aggACd9FRq5WcroeqBFFGecghQ54SD2IERllW9OS+qB6EeO+kiF962Fq39UNSAHmtmww 8MfJNW4P3nqD0RWVk6IMZZy7B1O4J5zB0OmnzD/F5/hMmDz8UHag7jY 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 Signed-off-by: Alvin Sun Reviewed-by: Alice Ryhl --- 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 Sat Jul 25 22:03:05 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 7B2B536F8F3; Mon, 13 Jul 2026 06:48:39 +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=1783925319; cv=none; b=MKseNI9H8WkdwrWUYJaEBCAC6w3shYCqOjPGL/y3gwjPrefkJaHvdxK3GVmN533DcWmp5ZlLGLORJ0QMSs3X9P5gchmqaVwBMQ7/T8gBL4pOo7PMl91PNXnPdJrLOh8aUkxlxEwHoWauBKaaVGRIEnpcl8I1ZQh1CL1+84IDT84= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783925319; c=relaxed/simple; bh=QmTLOgo7aXA9zuZDrP9v2Yja8XJBBoTtumcmBNGhRbE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=C7WjN8mu3XwYBj7hkppy8rYYz4E1WZI+Ahi2RAWvGZwdWQx75ZKKI3cO9gKUGszkHDfpMZxHKEMDasZGY6CsoEjZC+1mnXFqINvOOF6ZKtOEmy5en3dDHl25UDfWh2CkKyUI48gXxqn5+GH8QDiTh2mRzMcG8RasRDQjigJA7cw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=kpu6iM1O; 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="kpu6iM1O" Received: by smtp.kernel.org (Postfix) with ESMTPS id 0DA11C4DDE4; Mon, 13 Jul 2026 06:48:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux.dev; s=korg; t=1783925319; bh=QmTLOgo7aXA9zuZDrP9v2Yja8XJBBoTtumcmBNGhRbE=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=kpu6iM1OURuiXn11BOuY+KjkzB0fwkDfS5EVp/B86KIsbzFl5ljBkhh7qvKFqrePY WxM0Vg74rMbWM+sMJnfy2vg6UrgvqWu1tdbYrVyLmSeRWkFPk7SGe4eFbYNGMI+aBg WZH7KAZpgAI9837KpTIeguOZcptHTKPMd2weXDdY= 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 ECF77C43458; Mon, 13 Jul 2026 06:48:38 +0000 (UTC) From: Alvin Sun Date: Mon, 13 Jul 2026 14:45:31 +0800 Subject: [PATCH v8 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: <20260713-fix-fops-owner-v8-10-2495cfa82d47@linux.dev> References: <20260713-fix-fops-owner-v8-0-2495cfa82d47@linux.dev> In-Reply-To: <20260713-fix-fops-owner-v8-0-2495cfa82d47@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=1783925315; l=906; i=alvin.sun@linux.dev; s=20260317; h=from:subject:message-id; bh=QmTLOgo7aXA9zuZDrP9v2Yja8XJBBoTtumcmBNGhRbE=; b=S9aChhiKKu65DEXGmqAdOf61niEqmE03VUZFyaC/krJ78x9IDgK+ouwFQEUrljjCCtrw6f6v4 CFgVQqjN4XbDllbnVsX9hu9npp0s0DPYaKJ6eUcdZjUC3DlskQQCdiC 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 Signed-off-by: Alvin Sun Reviewed-by: Alice Ryhl --- 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