Rust for Linux List
 help / color / mirror / Atom feed
* [PATCH v2 0/7] rust: drm: Higher-Ranked Lifetime private data
@ 2026-06-03  1:15 Danilo Krummrich
  2026-06-03  1:15 ` [PATCH v2 1/7] rust: drm: Add Driver::ParentDevice associated type Danilo Krummrich
                   ` (6 more replies)
  0 siblings, 7 replies; 13+ messages in thread
From: Danilo Krummrich @ 2026-06-03  1:15 UTC (permalink / raw)
  To: dakr, aliceryhl, daniel.almeida, acourbot, ecourtney, ojeda,
	boqun, gary, bjorn3_gh, lossin, a.hindborg, tmgross,
	deborah.brouwer, boris.brezillon
  Cc: driver-core, linux-kernel, nova-gpu, dri-devel, rust-for-linux

DRM ioctls run in process context without any guarantee that the parent
bus device is still bound. This series solves the problem by introducing
UnbindGuard -- a guard representing a drm_dev_enter/exit SRCU critical
section that proves the parent bus device is bound for the lifetime of
the guard.

On top of that, add RegistrationData as a ForLt associated type on
drm::Driver, allowing drivers to store data whose lifetime is tied to
the parent bus device binding scope. The data is allocated in
Registration::new(), lifetime-erased to 'static for storage, and made
accessible through UnbindGuard::registration_data_with(). The closure's
HRTB ties the lifetime to the closure scope, and ForLt::cast_ref_unchecked
shortens it from 'static internally. The reference is valid for the
duration of the drm_dev_enter/exit critical section held by UnbindGuard.

Also update the ioctl dispatch macro to wrap every handler in an
UnbindGuard, returning ENODEV if the device has been unplugged, and
pass both the bound parent bus device and the registration data as
arguments to handlers.

This series is based on [1]; a branch with all patches can be found
in [2].

[1] https://lore.kernel.org/driver-core/20260603011020.2073650-1-dakr@kernel.org/
[2] https://git.kernel.org/pub/scm/linux/kernel/git/dakr/linux.git/log/?h=drm-lifetime

Changes in v2:
- Replace unsafe direct registration data access in ioctl dispatch with
  safe UnbindGuard::registration_data_with() closure
- Eliminate unbind_guard() free function; use type-inference anchor to
  enable direct dev.unbind_guard() method call in the ioctl macro
- UnbindGuard::registration_data_with() provides both parent device and
  registration data to the closure
- Add nova-drm conversion patch demonstrating lifetime-aware registration
  data with &'bound auxiliary::Device<Bound>
- Various safety comment and documentation improvements

Danilo Krummrich (7):
  rust: drm: Add Driver::ParentDevice associated type
  rust: drm: Add UnbindGuard for drm_dev_enter/exit critical sections
  rust: drm: Add RegistrationData to drm::Driver
  rust: drm: Wrap ioctl dispatch in UnbindGuard
  rust: drm: Pass bound parent device to ioctl handlers
  rust: drm: Pass registration data to ioctl handlers
  drm: nova: convert to use DRM registration data

 drivers/gpu/drm/nova/driver.rs |  38 +++++----
 drivers/gpu/drm/nova/file.rs   |  21 +++--
 drivers/gpu/drm/tyr/driver.rs  |  22 ++++--
 drivers/gpu/drm/tyr/file.rs    |   4 +
 rust/kernel/drm/device.rs      | 138 ++++++++++++++++++++++++++++++++-
 rust/kernel/drm/driver.rs      | 134 ++++++++++++++++++++++++--------
 rust/kernel/drm/ioctl.rs       |  33 +++++++-
 rust/kernel/drm/mod.rs         |   1 +
 8 files changed, 325 insertions(+), 66 deletions(-)


base-commit: e3b6e4c944a174277729dced5ab4ad5c0e53ff92
-- 
2.54.0


^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2026-06-03 23:29 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-03  1:15 [PATCH v2 0/7] rust: drm: Higher-Ranked Lifetime private data Danilo Krummrich
2026-06-03  1:15 ` [PATCH v2 1/7] rust: drm: Add Driver::ParentDevice associated type Danilo Krummrich
2026-06-03  1:15 ` [PATCH v2 2/7] rust: drm: Add UnbindGuard for drm_dev_enter/exit critical sections Danilo Krummrich
2026-06-03 11:47   ` Gary Guo
2026-06-03  1:15 ` [PATCH v2 3/7] rust: drm: Add RegistrationData to drm::Driver Danilo Krummrich
2026-06-03 11:51   ` Gary Guo
2026-06-03 22:24     ` Danilo Krummrich
2026-06-03 22:36       ` Gary Guo
2026-06-03 23:29   ` Deborah Brouwer
2026-06-03  1:15 ` [PATCH v2 4/7] rust: drm: Wrap ioctl dispatch in UnbindGuard Danilo Krummrich
2026-06-03  1:15 ` [PATCH v2 5/7] rust: drm: Pass bound parent device to ioctl handlers Danilo Krummrich
2026-06-03  1:15 ` [PATCH v2 6/7] rust: drm: Pass registration data " Danilo Krummrich
2026-06-03  1:15 ` [PATCH v2 7/7] drm: nova: convert to use DRM registration data Danilo Krummrich

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox