Skip to content

RFC rust: Reimplement ThisModule to fix ownership problems

Kari Argillander linux-modules lkml rust-for-linux 3 versions – In review

Get series with b4
b4 am [email protected] change-id 20251230-this_module_fix-a390bff24897

Versions newest first

  1. v3 RFC Latest15 patches 5 repliesIn review
  2. v2 RFC11 patches 0 repliesSuperseded
  3. v1 RFC6 patches 0 repliesSuperseded

Changes in v3 from the cover letter

- Edit cover.
- Seperate module name changes to seperate patches.
- Rebase top of next 20260109
- Seperate configfs changes to own commit.
- Fix one place still used M over TM for ThisModule.
- Link to v2: https://lore.kernel.org/r/[email protected]

Patches in v3 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/15rust: enable const_refs_to_static featurerust/kernel/lib.rs+1 -00 replies
2/15rust: add new ThisModule trait and THIS_MODULE implrust/kernel/configfs.rs rust/kernel/lib.rs rust/macros/module.rs +1 more+166 -171 reply
3/15rust: miscdevice: fix use after free because missing .ownerrust/kernel/miscdevice.rs samples/rust/rust_misc_device.rs+6 -00 replies
4/15rust: block: fix missing owner field in block_device_operationsdrivers/block/rnull/rnull.rs rust/kernel/block/mq.rs rust/kernel/block/mq/gen_disk.rs +1 more+36 -260 replies
5/15rust: drm: fix missing owner in file_operationsdrivers/gpu/drm/nova/driver.rs drivers/gpu/drm/tyr/driver.rs rust/kernel/drm/device.rs +2 more+12 -30 replies
6/15rust: configfs: use new THIS_MODULEdrivers/block/rnull/configfs.rs rust/kernel/configfs.rs+25 -230 replies
7/15rust: binder: use new THIS_MODULEdrivers/android/binder/rust_binder_main.rs+2 -10 replies
8/15rust: firmware: use THIS_MODULE over LocalModule for namerust/kernel/firmware.rs+1 -10 replies
9/15gpu: nova-core: use THIS_MODULE over LocalModule for namedrivers/gpu/nova-core/nova_core.rs+1 -10 replies
10/15samples: rust: auxiliary: use THIS_MODULE over LocalModule for namesamples/rust/rust_driver_auxiliary.rs+1 -10 replies
11/15rust: driver: make RegistrationOps::register() to use new ThisModulerust/kernel/auxiliary.rs rust/kernel/driver.rs rust/kernel/i2c.rs +4 more+41 -610 replies
12/15rust: phy: make Registration::register() use new ThisModulerust/kernel/net/phy.rs+19 -100 replies
13/15rust: remove module argument from InPlaceModule::init()drivers/android/binder/rust_binder_main.rs drivers/block/rnull/rnull.rs lib/find_bit_benchmark_rust.rs +15 more+23 -270 replies
14/15rust: remove kernel::ModuleMetadatarust/kernel/lib.rs rust/macros/module.rs+0 -140 replies
15/15rust: remove old version of ThisModulerust/kernel/lib.rs rust/kernel/prelude.rs+1 -480 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v3 yet.

Read the v3 thread

Cover letter [PATCH RFC v3 00/15] rust: Reimplement ThisModule to fix ownership problems

Still RFC. Not all people for each subsystems are not included yet as this touch quite lot of things. I would like to get feed back is this resonable seperation and how we will land this. I have tried my best so that it can be applied in multiple staged if needed. I have not receive any feedback on this series and that is little bit worrying.

Introduce new ThisModule trait and THIS_MODULE impl.

So currently we have problem that we are not always filling .owner field example for file_operations. I think we can enable const_refs_to_static already as that is in 1.78 and is stable in 1.83. So that fits perfecly for us. This also seems to be quite request feature but I did not found that no one has ever suggested that we just enable this.

So basic idea is that we will have ThisModule trait which is used kernel side. Module side we will always use THIS_MODULE. That is completly private for modules and kernel crate cannot use it. Currently we have THIS_MODULE, LocalModule and

module: &' static ThisModule

on init functions. As we anyway need THIS_MODULE just use that for all of these things.

Patches 1-2 introduce THIS_MODULE and ThisModule trait. Patches 3-12 can be applied any order after 1-2. Patch 13 depends on patches 11-12.
Patches 14-15 are clean up patches and depends 1-13.

Argillander

To: Miguel Ojeda <[email protected]>
To: Boqun Feng <[email protected]>
To: Gary Guo <[email protected]>
To: Björn Roy Baron <[email protected]>
To: Benno Lossin <[email protected]>
To: Andreas Hindborg <[email protected]>
To: Alice Ryhl <[email protected]>
To: Trevor Gross <[email protected]>
To: Danilo Krummrich <[email protected]>

To: Alexandre Courbot <[email protected]>

Cc Luis Chamberlain <[email protected]>
Cc Petr Pavlu <[email protected]>
Cc Daniel Gomez <[email protected]>
Cc Sami Tolvanen <[email protected]>
Cc Aaron Tomlin <[email protected]>

---
Changes in v3:
- Edit cover.
- Seperate module name changes to seperate patches.
- Rebase top of next 20260109
- Seperate configfs changes to own commit.
- Fix one place still used M over TM for ThisModule.
- Link to v2: https://lore.kernel.org/r/[email protected]

Changes in v2:
- Patches are now sepereted properly.
- Removed debugfs changes as that is not so clear to me.
- Remove module parameter and just used THIS_MODULE everywhere.
- Made macro to make THIS_MODULE.
- Doc tests also have THIS_MODULE.
- Link to v1: https://lore.kernel.org/r/[email protected]

---
Kari Argillander (15):
rust: enable const_refs_to_static feature
rust: add new ThisModule trait and THIS_MODULE impl
rust: miscdevice: fix use after free because missing .owner
rust: block: fix missing owner field in block_device_operations
rust: drm: fix missing owner in file_operations
rust: configfs: use new THIS_MODULE
rust: binder: use new THIS_MODULE
rust: firmware: use THIS_MODULE over LocalModule for name
gpu: nova-core: use THIS_MODULE over LocalModule for name
samples: rust: auxiliary: use THIS_MODULE over LocalModule for name
rust: driver: make RegistrationOps::register() to use new ThisModule
rust: phy: make Registration::register() use new ThisModule
rust: remove module argument from InPlaceModule::init()
rust: remove kernel::ModuleMetadata
rust: remove old version of ThisModule

 drivers/android/binder/rust_binder_main.rs |   5 +-
 drivers/block/rnull/configfs.rs            |   2 +-
 drivers/block/rnull/rnull.rs               |   3 +-
 drivers/gpu/drm/nova/driver.rs             |   2 +
 drivers/gpu/drm/tyr/driver.rs              |   2 +
 drivers/gpu/nova-core/nova_core.rs         |   2 +-
 lib/find_bit_benchmark_rust.rs             |   3 +-
 rust/kernel/auxiliary.rs                   |  16 +--
 rust/kernel/block/mq.rs                    |   1 +
 rust/kernel/block/mq/gen_disk.rs           |  30 +-----
 rust/kernel/block/mq/operations.rs         |  30 ++++++
 rust/kernel/configfs.rs                    |  49 ++++-----
 rust/kernel/driver.rs                      |  31 +++---
 rust/kernel/drm/device.rs                  |   2 +-
 rust/kernel/drm/driver.rs                  |   4 +
 rust/kernel/drm/gem/mod.rs                 |   5 +-
 rust/kernel/firmware.rs                    |   4 +-
 rust/kernel/i2c.rs                         |  11 +-
 rust/kernel/lib.rs                         | 161 ++++++++++++++++++++++++-----
 rust/kernel/miscdevice.rs                  |   5 +
 rust/kernel/net/phy.rs                     |  29 ++++--
 rust/kernel/pci.rs                         |  15 +--
 rust/kernel/platform.rs                    |  12 +--
 rust/kernel/prelude.rs                     |   2 +-
 rust/kernel/sync/lock/global.rs            |   4 +-
 rust/kernel/usb.rs                         |  13 +--
 rust/macros/lib.rs                         |   4 +-
 rust/macros/module.rs                      |  24 +----
 samples/rust/rust_configfs.rs              |   2 +-
 samples/rust/rust_debugfs_scoped.rs        |   2 +-
 samples/rust/rust_driver_auxiliary.rs      |   8 +-
 samples/rust/rust_driver_faux.rs           |   2 +-
 samples/rust/rust_minimal.rs               |   2 +-
 samples/rust/rust_misc_device.rs           |   3 +-
 samples/rust/rust_print_main.rs            |   2 +-
 scripts/rustdoc_test_gen.rs                |   2 +
 36 files changed, 298 insertions(+), 196 deletions(-)

---
base-commit: f417b7ffcbef7d76b0d8860518f50dae0e7e5eda
change-id: 20251230-this_module_fix-a390bff24897

Best regards,

Signature · 1 line
Kari Argillander <[email protected]>