* [PATCH 1/8] rust: module: add `MODULE_PTR` const to `ModuleMetadata` trait
2026-05-19 6:26 [PATCH 0/8] Fix missing fops.owner in Rust DRM/misc abstractions Alvin Sun
@ 2026-05-19 6:26 ` Alvin Sun
2026-05-19 11:57 ` Gary Guo
2026-05-19 6:26 ` [PATCH 2/8] rust: driver: make `DriverModule` struct pub(crate) in `module_driver!` Alvin Sun
` (6 subsequent siblings)
7 siblings, 1 reply; 14+ messages in thread
From: Alvin Sun @ 2026-05-19 6:26 UTC (permalink / raw)
To: Miguel Ojeda, Boqun Feng, Gary Guo, Björn 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
Cc: rust-for-linux, linux-kernel, linux-modules, driver-core,
dri-devel, nova-gpu, Alvin Sun
Add a `MODULE_PTR` const to the `ModuleMetadata` trait so that
modules can provide a constant pointer to their `struct module`
usable in const contexts such as static file_operations.
Signed-off-by: Alvin Sun <alvin.sun@linux.dev>
---
rust/kernel/lib.rs | 3 +++
rust/macros/module.rs | 14 ++++++++++++++
2 files changed, 17 insertions(+)
diff --git a/rust/kernel/lib.rs b/rust/kernel/lib.rs
index b72b2fbe046d6..c7e809636e1a9 100644
--- a/rust/kernel/lib.rs
+++ b/rust/kernel/lib.rs
@@ -184,6 +184,9 @@ fn init(module: &'static ThisModule) -> impl pin_init::PinInit<Self, error::Erro
pub trait ModuleMetadata {
/// The name of the module as specified in the `module!` macro.
const NAME: &'static crate::str::CStr;
+
+ /// The pointer to the kernel `struct module` for this module.
+ const MODULE_PTR: *mut bindings::module;
}
/// Equivalent to `THIS_MODULE` in the C API.
diff --git a/rust/macros/module.rs b/rust/macros/module.rs
index 06c18e2075083..7204fe604f24a 100644
--- a/rust/macros/module.rs
+++ b/rust/macros/module.rs
@@ -519,6 +519,20 @@ pub(crate) fn module(info: ModuleInfo) -> Result<TokenStream> {
impl ::kernel::ModuleMetadata for #type_ {
const NAME: &'static ::kernel::str::CStr = #name_cstr;
+
+ #[cfg(MODULE)]
+ const MODULE_PTR: *mut ::kernel::bindings::module = {
+ 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 { __this_module.get() }
+ };
+
+ #[cfg(not(MODULE))]
+ const MODULE_PTR: *mut ::kernel::bindings::module = ::core::ptr::null_mut();
}
// Double nested modules, since then nobody can access the public items inside.
--
2.43.0
^ permalink raw reply related [flat|nested] 14+ messages in thread* Re: [PATCH 1/8] rust: module: add `MODULE_PTR` const to `ModuleMetadata` trait
2026-05-19 6:26 ` [PATCH 1/8] rust: module: add `MODULE_PTR` const to `ModuleMetadata` trait Alvin Sun
@ 2026-05-19 11:57 ` Gary Guo
0 siblings, 0 replies; 14+ messages in thread
From: Gary Guo @ 2026-05-19 11:57 UTC (permalink / raw)
To: Alvin Sun, Miguel Ojeda, Boqun Feng, Gary Guo,
Björn 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
Cc: rust-for-linux, linux-kernel, linux-modules, driver-core,
dri-devel, nova-gpu
On Tue May 19, 2026 at 7:26 AM BST, Alvin Sun wrote:
> Add a `MODULE_PTR` const to the `ModuleMetadata` trait so that
> modules can provide a constant pointer to their `struct module`
> usable in const contexts such as static file_operations.
Please design a consistent API surface that integrates with the `THIS_MODULE`
that we have today, and avoid two ways of doing things.
Best,
Gary
>
> Signed-off-by: Alvin Sun <alvin.sun@linux.dev>
> ---
> rust/kernel/lib.rs | 3 +++
> rust/macros/module.rs | 14 ++++++++++++++
> 2 files changed, 17 insertions(+)
>
> diff --git a/rust/kernel/lib.rs b/rust/kernel/lib.rs
> index b72b2fbe046d6..c7e809636e1a9 100644
> --- a/rust/kernel/lib.rs
> +++ b/rust/kernel/lib.rs
> @@ -184,6 +184,9 @@ fn init(module: &'static ThisModule) -> impl pin_init::PinInit<Self, error::Erro
> pub trait ModuleMetadata {
> /// The name of the module as specified in the `module!` macro.
> const NAME: &'static crate::str::CStr;
> +
> + /// The pointer to the kernel `struct module` for this module.
> + const MODULE_PTR: *mut bindings::module;
> }
>
> /// Equivalent to `THIS_MODULE` in the C API.
> diff --git a/rust/macros/module.rs b/rust/macros/module.rs
> index 06c18e2075083..7204fe604f24a 100644
> --- a/rust/macros/module.rs
> +++ b/rust/macros/module.rs
> @@ -519,6 +519,20 @@ pub(crate) fn module(info: ModuleInfo) -> Result<TokenStream> {
>
> impl ::kernel::ModuleMetadata for #type_ {
> const NAME: &'static ::kernel::str::CStr = #name_cstr;
> +
> + #[cfg(MODULE)]
> + const MODULE_PTR: *mut ::kernel::bindings::module = {
> + 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 { __this_module.get() }
> + };
> +
> + #[cfg(not(MODULE))]
> + const MODULE_PTR: *mut ::kernel::bindings::module = ::core::ptr::null_mut();
> }
>
> // Double nested modules, since then nobody can access the public items inside.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH 2/8] rust: driver: make `DriverModule` struct pub(crate) in `module_driver!`
2026-05-19 6:26 [PATCH 0/8] Fix missing fops.owner in Rust DRM/misc abstractions Alvin Sun
2026-05-19 6:26 ` [PATCH 1/8] rust: module: add `MODULE_PTR` const to `ModuleMetadata` trait Alvin Sun
@ 2026-05-19 6:26 ` Alvin Sun
2026-05-19 11:53 ` Gary Guo
2026-05-19 6:26 ` [PATCH 3/8] rust: drm: add `ThisModule` associated type to `Driver` trait Alvin Sun
` (5 subsequent siblings)
7 siblings, 1 reply; 14+ messages in thread
From: Alvin Sun @ 2026-05-19 6:26 UTC (permalink / raw)
To: Miguel Ojeda, Boqun Feng, Gary Guo, Björn 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
Cc: rust-for-linux, linux-kernel, linux-modules, driver-core,
dri-devel, nova-gpu, Alvin Sun
Expose the generated `DriverModule` struct as `pub(crate)` so that
driver implementations can reference it via `super::DriverModule`
for the `ThisModule` associated type.
Signed-off-by: Alvin Sun <alvin.sun@linux.dev>
---
rust/kernel/driver.rs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/rust/kernel/driver.rs b/rust/kernel/driver.rs
index 36de8098754d0..9c7c69c4d2af0 100644
--- a/rust/kernel/driver.rs
+++ b/rust/kernel/driver.rs
@@ -253,7 +253,7 @@ macro_rules! module_driver {
type Ops<$gen_type> = $driver_ops;
#[$crate::prelude::pin_data]
- struct DriverModule {
+ pub(crate) struct DriverModule {
#[pin]
_driver: $crate::driver::Registration<Ops<$type>>,
}
--
2.43.0
^ permalink raw reply related [flat|nested] 14+ messages in thread* Re: [PATCH 2/8] rust: driver: make `DriverModule` struct pub(crate) in `module_driver!`
2026-05-19 6:26 ` [PATCH 2/8] rust: driver: make `DriverModule` struct pub(crate) in `module_driver!` Alvin Sun
@ 2026-05-19 11:53 ` Gary Guo
2026-05-21 7:57 ` Alvin Sun
0 siblings, 1 reply; 14+ messages in thread
From: Gary Guo @ 2026-05-19 11:53 UTC (permalink / raw)
To: Alvin Sun, Miguel Ojeda, Boqun Feng, Gary Guo,
Björn 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
Cc: rust-for-linux, linux-kernel, linux-modules, driver-core,
dri-devel, nova-gpu
On Tue May 19, 2026 at 7:26 AM BST, Alvin Sun wrote:
> Expose the generated `DriverModule` struct as `pub(crate)` so that
> driver implementations can reference it via `super::DriverModule`
> for the `ThisModule` associated type.
Why is this needed? Child modules can see items super modules.
Best,
Gary
>
> Signed-off-by: Alvin Sun <alvin.sun@linux.dev>
> ---
> rust/kernel/driver.rs | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/rust/kernel/driver.rs b/rust/kernel/driver.rs
> index 36de8098754d0..9c7c69c4d2af0 100644
> --- a/rust/kernel/driver.rs
> +++ b/rust/kernel/driver.rs
> @@ -253,7 +253,7 @@ macro_rules! module_driver {
> type Ops<$gen_type> = $driver_ops;
>
> #[$crate::prelude::pin_data]
> - struct DriverModule {
> + pub(crate) struct DriverModule {
> #[pin]
> _driver: $crate::driver::Registration<Ops<$type>>,
> }
^ permalink raw reply [flat|nested] 14+ messages in thread* Re: [PATCH 2/8] rust: driver: make `DriverModule` struct pub(crate) in `module_driver!`
2026-05-19 11:53 ` Gary Guo
@ 2026-05-21 7:57 ` Alvin Sun
0 siblings, 0 replies; 14+ messages in thread
From: Alvin Sun @ 2026-05-21 7:57 UTC (permalink / raw)
To: Gary Guo, Miguel Ojeda, Boqun Feng, Björn 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
Cc: rust-for-linux, linux-kernel, linux-modules, driver-core,
dri-devel, nova-gpu
On 5/19/26 19:53, Gary Guo wrote:
> On Tue May 19, 2026 at 7:26 AM BST, Alvin Sun wrote:
>> Expose the generated `DriverModule` struct as `pub(crate)` so that
>> driver implementations can reference it via `super::DriverModule`
>> for the `ThisModule` associated type.
> Why is this needed? Child modules can see items super modules.
I misread it — I've already used LocalModule directly in v2.
Best regards,
Alvin
>
> Best,
> Gary
>
>> Signed-off-by: Alvin Sun <alvin.sun@linux.dev>
>> ---
>> rust/kernel/driver.rs | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/rust/kernel/driver.rs b/rust/kernel/driver.rs
>> index 36de8098754d0..9c7c69c4d2af0 100644
>> --- a/rust/kernel/driver.rs
>> +++ b/rust/kernel/driver.rs
>> @@ -253,7 +253,7 @@ macro_rules! module_driver {
>> type Ops<$gen_type> = $driver_ops;
>>
>> #[$crate::prelude::pin_data]
>> - struct DriverModule {
>> + pub(crate) struct DriverModule {
>> #[pin]
>> _driver: $crate::driver::Registration<Ops<$type>>,
>> }
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH 3/8] rust: drm: add `ThisModule` associated type to `Driver` trait
2026-05-19 6:26 [PATCH 0/8] Fix missing fops.owner in Rust DRM/misc abstractions Alvin Sun
2026-05-19 6:26 ` [PATCH 1/8] rust: module: add `MODULE_PTR` const to `ModuleMetadata` trait Alvin Sun
2026-05-19 6:26 ` [PATCH 2/8] rust: driver: make `DriverModule` struct pub(crate) in `module_driver!` Alvin Sun
@ 2026-05-19 6:26 ` Alvin Sun
2026-05-19 11:58 ` Gary Guo
2026-05-19 6:26 ` [PATCH 4/8] gpu: nova: implement `ThisModule` Alvin Sun
` (4 subsequent siblings)
7 siblings, 1 reply; 14+ messages in thread
From: Alvin Sun @ 2026-05-19 6:26 UTC (permalink / raw)
To: Miguel Ojeda, Boqun Feng, Gary Guo, Björn 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
Cc: rust-for-linux, linux-kernel, linux-modules, driver-core,
dri-devel, nova-gpu, Alvin Sun
Add a `ThisModule` associated type bound by `ModuleMetadata` to the
`drm::Driver` trait, allowing DRM drivers to expose their module
pointer for use in file operations.
Signed-off-by: Alvin Sun <alvin.sun@linux.dev>
---
rust/kernel/drm/driver.rs | 3 +++
1 file changed, 3 insertions(+)
diff --git a/rust/kernel/drm/driver.rs b/rust/kernel/drm/driver.rs
index 5233bdebc9fcd..c798961650c1a 100644
--- a/rust/kernel/drm/driver.rs
+++ b/rust/kernel/drm/driver.rs
@@ -115,6 +115,9 @@ pub trait Driver {
/// IOCTL list. See `kernel::drm::ioctl::declare_drm_ioctls!{}`.
const IOCTLS: &'static [drm::ioctl::DrmIoctlDescriptor];
+
+ /// The module implementing this driver.
+ type ThisModule: crate::ModuleMetadata;
}
/// The registration type of a `drm::Device`.
--
2.43.0
^ permalink raw reply related [flat|nested] 14+ messages in thread* Re: [PATCH 3/8] rust: drm: add `ThisModule` associated type to `Driver` trait
2026-05-19 6:26 ` [PATCH 3/8] rust: drm: add `ThisModule` associated type to `Driver` trait Alvin Sun
@ 2026-05-19 11:58 ` Gary Guo
2026-05-21 7:59 ` Alvin Sun
0 siblings, 1 reply; 14+ messages in thread
From: Gary Guo @ 2026-05-19 11:58 UTC (permalink / raw)
To: Alvin Sun, Miguel Ojeda, Boqun Feng, Gary Guo,
Björn 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
Cc: rust-for-linux, linux-kernel, linux-modules, driver-core,
dri-devel, nova-gpu
On Tue May 19, 2026 at 7:26 AM BST, Alvin Sun wrote:
> Add a `ThisModule` associated type bound by `ModuleMetadata` to the
> `drm::Driver` trait, allowing DRM drivers to expose their module
> pointer for use in file operations.
FWIW, I was considering adding this automatically to the `#[vtable]` macro
(associated types/consts won't have any costs if they're unused anyway).
But requiring an explicit specification isn't too bad either.
Best,
Gary
>
> Signed-off-by: Alvin Sun <alvin.sun@linux.dev>
> ---
> rust/kernel/drm/driver.rs | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/rust/kernel/drm/driver.rs b/rust/kernel/drm/driver.rs
> index 5233bdebc9fcd..c798961650c1a 100644
> --- a/rust/kernel/drm/driver.rs
> +++ b/rust/kernel/drm/driver.rs
> @@ -115,6 +115,9 @@ pub trait Driver {
>
> /// IOCTL list. See `kernel::drm::ioctl::declare_drm_ioctls!{}`.
> const IOCTLS: &'static [drm::ioctl::DrmIoctlDescriptor];
> +
> + /// The module implementing this driver.
> + type ThisModule: crate::ModuleMetadata;
> }
>
> /// The registration type of a `drm::Device`.
^ permalink raw reply [flat|nested] 14+ messages in thread* Re: [PATCH 3/8] rust: drm: add `ThisModule` associated type to `Driver` trait
2026-05-19 11:58 ` Gary Guo
@ 2026-05-21 7:59 ` Alvin Sun
0 siblings, 0 replies; 14+ messages in thread
From: Alvin Sun @ 2026-05-21 7:59 UTC (permalink / raw)
To: Gary Guo, Miguel Ojeda, Boqun Feng, Björn 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
Cc: rust-for-linux, linux-kernel, linux-modules, driver-core,
dri-devel, nova-gpu
On 5/19/26 19:58, Gary Guo wrote:
> On Tue May 19, 2026 at 7:26 AM BST, Alvin Sun wrote:
>> Add a `ThisModule` associated type bound by `ModuleMetadata` to the
>> `drm::Driver` trait, allowing DRM drivers to expose their module
>> pointer for use in file operations.
> FWIW, I was considering adding this automatically to the `#[vtable]` macro
> (associated types/consts won't have any costs if they're unused anyway).
That's a great suggestion. I've implemented it in v2 — please review.
Best regards,
Alvin
>
> But requiring an explicit specification isn't too bad either.
>
> Best,
> Gary
>
>> Signed-off-by: Alvin Sun <alvin.sun@linux.dev>
>> ---
>> rust/kernel/drm/driver.rs | 3 +++
>> 1 file changed, 3 insertions(+)
>>
>> diff --git a/rust/kernel/drm/driver.rs b/rust/kernel/drm/driver.rs
>> index 5233bdebc9fcd..c798961650c1a 100644
>> --- a/rust/kernel/drm/driver.rs
>> +++ b/rust/kernel/drm/driver.rs
>> @@ -115,6 +115,9 @@ pub trait Driver {
>>
>> /// IOCTL list. See `kernel::drm::ioctl::declare_drm_ioctls!{}`.
>> const IOCTLS: &'static [drm::ioctl::DrmIoctlDescriptor];
>> +
>> + /// The module implementing this driver.
>> + type ThisModule: crate::ModuleMetadata;
>> }
>>
>> /// The registration type of a `drm::Device`.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH 4/8] gpu: nova: implement `ThisModule`
2026-05-19 6:26 [PATCH 0/8] Fix missing fops.owner in Rust DRM/misc abstractions Alvin Sun
` (2 preceding siblings ...)
2026-05-19 6:26 ` [PATCH 3/8] rust: drm: add `ThisModule` associated type to `Driver` trait Alvin Sun
@ 2026-05-19 6:26 ` Alvin Sun
2026-05-19 6:26 ` [PATCH 5/8] gpu: tyr: " Alvin Sun
` (3 subsequent siblings)
7 siblings, 0 replies; 14+ messages in thread
From: Alvin Sun @ 2026-05-19 6:26 UTC (permalink / raw)
To: Miguel Ojeda, Boqun Feng, Gary Guo, Björn 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
Cc: rust-for-linux, linux-kernel, linux-modules, driver-core,
dri-devel, nova-gpu, Alvin Sun
Set `ThisModule = super::DriverModule` to provide the correct module
pointer for file operations ownership.
Signed-off-by: Alvin Sun <alvin.sun@linux.dev>
---
drivers/gpu/drm/nova/driver.rs | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/gpu/drm/nova/driver.rs b/drivers/gpu/drm/nova/driver.rs
index b1af0a099551d..6353c19d319c6 100644
--- a/drivers/gpu/drm/nova/driver.rs
+++ b/drivers/gpu/drm/nova/driver.rs
@@ -68,6 +68,7 @@ impl drm::Driver for NovaDriver {
type Data = NovaData;
type File = File;
type Object = gem::Object<NovaObject>;
+ type ThisModule = super::DriverModule;
const INFO: drm::DriverInfo = INFO;
--
2.43.0
^ permalink raw reply related [flat|nested] 14+ messages in thread* [PATCH 5/8] gpu: tyr: implement `ThisModule`
2026-05-19 6:26 [PATCH 0/8] Fix missing fops.owner in Rust DRM/misc abstractions Alvin Sun
` (3 preceding siblings ...)
2026-05-19 6:26 ` [PATCH 4/8] gpu: nova: implement `ThisModule` Alvin Sun
@ 2026-05-19 6:26 ` Alvin Sun
2026-05-19 6:26 ` [PATCH 6/8] rust: drm: set fops.owner from driver module pointer Alvin Sun
` (2 subsequent siblings)
7 siblings, 0 replies; 14+ messages in thread
From: Alvin Sun @ 2026-05-19 6:26 UTC (permalink / raw)
To: Miguel Ojeda, Boqun Feng, Gary Guo, Björn 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
Cc: rust-for-linux, linux-kernel, linux-modules, driver-core,
dri-devel, nova-gpu, Alvin Sun
Set `ThisModule = super::DriverModule` to provide the correct module
pointer for file operations ownership.
Signed-off-by: Alvin Sun <alvin.sun@linux.dev>
---
drivers/gpu/drm/tyr/driver.rs | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/gpu/drm/tyr/driver.rs b/drivers/gpu/drm/tyr/driver.rs
index 279710b36a104..9eb4561ab831d 100644
--- a/drivers/gpu/drm/tyr/driver.rs
+++ b/drivers/gpu/drm/tyr/driver.rs
@@ -176,6 +176,7 @@ impl drm::Driver for TyrDrmDriver {
type Data = TyrDrmDeviceData;
type File = TyrDrmFileData;
type Object = drm::gem::Object<TyrObject>;
+ type ThisModule = super::DriverModule;
const INFO: drm::DriverInfo = INFO;
--
2.43.0
^ permalink raw reply related [flat|nested] 14+ messages in thread* [PATCH 6/8] rust: drm: set fops.owner from driver module pointer
2026-05-19 6:26 [PATCH 0/8] Fix missing fops.owner in Rust DRM/misc abstractions Alvin Sun
` (4 preceding siblings ...)
2026-05-19 6:26 ` [PATCH 5/8] gpu: tyr: " Alvin Sun
@ 2026-05-19 6:26 ` Alvin Sun
2026-05-19 6:26 ` [PATCH 7/8] rust: miscdevice: add `ThisModule` associated type to `MiscDevice` trait Alvin Sun
2026-05-19 6:26 ` [PATCH 8/8] samples: rust: rust_misc_device: implement `ThisModule` for `RustMiscDevice` Alvin Sun
7 siblings, 0 replies; 14+ messages in thread
From: Alvin Sun @ 2026-05-19 6:26 UTC (permalink / raw)
To: Miguel Ojeda, Boqun Feng, Gary Guo, Björn 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
Cc: rust-for-linux, linux-kernel, linux-modules, driver-core,
dri-devel, nova-gpu, Alvin Sun
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.
Signed-off-by: Alvin Sun <alvin.sun@linux.dev>
---
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..97bee53823346 100644
--- a/rust/kernel/drm/device.rs
+++ b/rust/kernel/drm/device.rs
@@ -111,7 +111,8 @@ impl<T: drm::Driver> Device<T> {
fops: &Self::GEM_FOPS,
};
- const GEM_FOPS: bindings::file_operations = drm::gem::create_fops();
+ const GEM_FOPS: bindings::file_operations =
+ drm::gem::create_fops(<T::ThisModule as crate::ModuleMetadata>::MODULE_PTR);
/// Create a new `drm::Device` for a `drm::Driver`.
pub fn new(dev: &device::Device, data: impl PinInit<T::Data, Error>) -> Result<ARef<Self>> {
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<T: DriverObject> AllocImpl for Object<T> {
};
}
-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 = pin_init::zeroed();
- fops.owner = core::ptr::null_mut();
+ fops.owner = owner;
fops.open = Some(bindings::drm_open);
fops.release = Some(bindings::drm_release);
fops.unlocked_ioctl = Some(bindings::drm_ioctl);
--
2.43.0
^ permalink raw reply related [flat|nested] 14+ messages in thread* [PATCH 7/8] rust: miscdevice: add `ThisModule` associated type to `MiscDevice` trait
2026-05-19 6:26 [PATCH 0/8] Fix missing fops.owner in Rust DRM/misc abstractions Alvin Sun
` (5 preceding siblings ...)
2026-05-19 6:26 ` [PATCH 6/8] rust: drm: set fops.owner from driver module pointer Alvin Sun
@ 2026-05-19 6:26 ` Alvin Sun
2026-05-19 6:26 ` [PATCH 8/8] samples: rust: rust_misc_device: implement `ThisModule` for `RustMiscDevice` Alvin Sun
7 siblings, 0 replies; 14+ messages in thread
From: Alvin Sun @ 2026-05-19 6:26 UTC (permalink / raw)
To: Miguel Ojeda, Boqun Feng, Gary Guo, Björn 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
Cc: rust-for-linux, linux-kernel, linux-modules, driver-core,
dri-devel, nova-gpu, Alvin Sun
Add a `ThisModule` associated type bound by `ModuleMetadata` to the
`MiscDevice` trait, and use it to set the miscdevice fops owner field
instead of defaulting to null.
Signed-off-by: Alvin Sun <alvin.sun@linux.dev>
---
rust/kernel/miscdevice.rs | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/rust/kernel/miscdevice.rs b/rust/kernel/miscdevice.rs
index 05a6b6b9770f2..007caaae62697 100644
--- a/rust/kernel/miscdevice.rs
+++ b/rust/kernel/miscdevice.rs
@@ -38,6 +38,7 @@
ForeignOwnable,
Opaque, //
},
+ ModuleMetadata, //
};
use core::{
marker::PhantomData,
@@ -137,6 +138,9 @@ pub trait MiscDevice: Sized {
/// What kind of pointer should `Self` be wrapped in.
type Ptr: ForeignOwnable + Send + Sync;
+ /// The module implementing this driver.
+ type ThisModule: ModuleMetadata;
+
/// Called when the misc device is opened.
///
/// The returned pointer will be stored as the private data for the file.
@@ -441,6 +445,7 @@ impl<T: MiscDevice> MiscdeviceVTable<T> {
} else {
None
},
+ owner: <T::ThisModule as ModuleMetadata>::MODULE_PTR,
..pin_init::zeroed()
};
--
2.43.0
^ permalink raw reply related [flat|nested] 14+ messages in thread* [PATCH 8/8] samples: rust: rust_misc_device: implement `ThisModule` for `RustMiscDevice`
2026-05-19 6:26 [PATCH 0/8] Fix missing fops.owner in Rust DRM/misc abstractions Alvin Sun
` (6 preceding siblings ...)
2026-05-19 6:26 ` [PATCH 7/8] rust: miscdevice: add `ThisModule` associated type to `MiscDevice` trait Alvin Sun
@ 2026-05-19 6:26 ` Alvin Sun
7 siblings, 0 replies; 14+ messages in thread
From: Alvin Sun @ 2026-05-19 6:26 UTC (permalink / raw)
To: Miguel Ojeda, Boqun Feng, Gary Guo, Björn 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
Cc: rust-for-linux, linux-kernel, linux-modules, driver-core,
dri-devel, nova-gpu, Alvin Sun
Set `ThisModule = RustMiscDeviceModule` to provide the correct module
pointer for file operations ownership.
Signed-off-by: Alvin Sun <alvin.sun@linux.dev>
---
samples/rust/rust_misc_device.rs | 1 +
1 file changed, 1 insertion(+)
diff --git a/samples/rust/rust_misc_device.rs b/samples/rust/rust_misc_device.rs
index 41e26c825060b..a4b012a35b5ec 100644
--- a/samples/rust/rust_misc_device.rs
+++ b/samples/rust/rust_misc_device.rs
@@ -176,6 +176,7 @@ struct RustMiscDevice {
#[vtable]
impl MiscDevice for RustMiscDevice {
type Ptr = Pin<KBox<Self>>;
+ type ThisModule = RustMiscDeviceModule;
fn open(_file: &File, misc: &MiscDeviceRegistration<Self>) -> Result<Pin<KBox<Self>>> {
let dev = ARef::from(misc.device());
--
2.43.0
^ permalink raw reply related [flat|nested] 14+ messages in thread