Skip to content

rust: auxiliary: replace drvdata() with registration data

Danilo Krummrich dri-devel driver-core lkml nova-gpu rust-for-linux 2 versions – Applied

Status from this message: Applied, thanks!

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest3 patches 9 repliesApplied
  2. v12 patches 10 repliesSuperseded

Changes in v2 from the cover letter

- Introduce Box::zeroed()
- Add Sync bound to Registration<T> impl block
- Use KBox::zeroed() instead of KBox::new(Opaque::zeroed(), ...)
- Use drop() instead of let _ = { ... }
- Fix invariant doc reference

Patches in v2 Applied

#Subject and filesSizeRepliesApplied
1/3rust: alloc: add Box::zeroed()rust/kernel/alloc/kbox.rs+22 -04 replies
2/3rust: auxiliary: add registration data to auxiliary devicesdrivers/gpu/nova-core/driver.rs include/linux/auxiliary_bus.h rust/kernel/auxiliary.rs +1 more+180 -824 replies
3/3rust: driver core: remove drvdata() and driver_typedrivers/base/base.h rust/kernel/device.rs+0 -760 replies

Reviews trailers per patch

All 3 patches have a Reviewed-by or Acked-by.

PatchAlice Ryhl
1/3R-b
2/3R-b
3/3R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v2 thread

Cover letter [PATCH v2 0/3] rust: auxiliary: replace drvdata() with registration data

When drvdata() was introduced in commit 6f61a2637abe ("rust: device: introduce Device::drvdata()"), its commit message already noted that a direct accessor to the driver's bus device private data is not commonly required -- bus callbacks provide access through &self, and other entry points (IRQs, workqueues, IOCTLs, etc.) carry their own private data.

The sole motivation for drvdata() was inter-driver interaction, e.g. a parent driver deriving its bus device private data from the child driver via the auxiliary bus.

However, drvdata() exposes the driver's bus device private data beyond the driver's own scope. This creates ordering constraints -- drvdata may not be set yet when the first caller of drvdata() can appear -- and forces the driver's bus device private data to outlive all registrations that access it; a requirement that causes unnecessary complications.

Private data should be private to the entity that issues it; bus device private data belongs to bus callbacks, class device private data to class callbacks, IRQ private data to the IRQ handler, etc.

This series replaces drvdata() with a dedicated registration_data pointer on struct auxiliary_device. The parent stores its private data explicitly during registration; the data is private to the registration and lives as long as the Registration object.

On teardown, Registration::drop() first triggers auxiliary_device_delete() (unbinding the child), then frees the registration data. Ordering constraints are structural -- the child's lifecycle is scoped to the registration by construction, not by convention.

With no remaining use case for drvdata(), drvdata(), match_type_id(), set_type_id() and struct driver_type are removed.

This is a prerequisite for [1], which builds on the removal of drvdata() to enable Higher-Ranked Lifetime Types (HRT) for Rust device drivers.

[1] https://lore.kernel.org/driver-core/[email protected]/

Changes in v2:
- Introduce Box::zeroed()
- Add Sync bound to Registration<T> impl block
- Use KBox::zeroed() instead of KBox::new(Opaque::zeroed(), ...)
- Use drop() instead of let _ = { ... }
- Fix invariant doc reference

Danilo Krummrich (3):
rust: alloc: add Box::zeroed()
rust: auxiliary: add registration data to auxiliary devices
rust: driver core: remove drvdata() and driver_type

 drivers/base/base.h                   |  16 --
 drivers/gpu/nova-core/driver.rs       |  10 +-
 include/linux/auxiliary_bus.h         |   4 +
 rust/kernel/alloc/kbox.rs             |  22 +++
 rust/kernel/auxiliary.rs              | 208 ++++++++++++++++++--------
 rust/kernel/device.rs                 |  60 --------
 samples/rust/rust_driver_auxiliary.rs |  40 +++--
 7 files changed, 202 insertions(+), 158 deletions(-)

base-commit: 30c878ed169983190f77940594f8ba8948debe6b

Signature · 1 line
2.54.0