Skip to content

ForLt/CovariantForLt split, auxiliary closure API and DevresLt

Danilo Krummrich dri-devel driver-core linux-pwm lkml nova-gpu rust-for-linux 3 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. v4 Latest7 patches 6 repliesApplied
  2. v37 patches 12 repliesSuperseded
  3. v27 patches 3 repliesSuperseded

Changes in v4 from the cover letter

- ForLt! macro: run the Prover and emit ProveWf structs for well-formedness checks
- DevresLt: change Send bound from F::Of<'static>: Send to the correct for<'a> F::Of<'a>: Send
- Add #[inline] to forwarding functions in registration_data_with, registration_data, and all DevresLt accessors

Patches in v4 Applied

#Subject and filesSizeRepliesApplied
1/7rust: types: rename ForLt to CovariantForLtdrivers/gpu/nova-core/driver.rs rust/kernel/auxiliary.rs rust/kernel/types.rs +4 more+56 -551 reply
2/7rust: types: introduce ForLt base trait for CovariantForLtrust/kernel/types.rs rust/kernel/types/for_lt.rs rust/macros/for_lt.rs +1 more+123 -374 replies
3/7rust: auxiliary: add registration_data_with() for ForLt typesrust/kernel/auxiliary.rs+67 -260 replies
4/7rust: auxiliary: sample: demonstrate ForLt with invariant Mutex typesamples/rust/rust_driver_auxiliary.rs+68 -260 replies
5/7rust: devres: add DevresLt for ForLt-aware device resource accessrust/kernel/devres.rs+106 -00 replies
6/7rust: pci: return DevresLt from Bar::into_devres()rust/kernel/pci.rs rust/kernel/pci/io.rs+27 -110 replies
7/7rust: io: mem: return DevresLt from IoMem/ExclusiveIoMem::into_devres()drivers/pwm/pwm_th1520.rs rust/kernel/io/mem.rs+47 -230 replies

Reviews trailers per patch

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

PatchAlexandre CourbotGary GuoMiguel Ojeda
1/7R-b R-b A-b
2/7R-b A-b
3/7R-b R-b
4/7R-b R-b
5/7R-b
6/7R-b
7/7R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 3 reviewers.

Read the v4 thread

Cover letter [PATCH v4 0/7] ForLt/CovariantForLt split, auxiliary closure API and DevresLt

The ForLt trait currently guarantees covariance, which allows safe lifetime shortening via cast_ref(). However, some types (e.g. those containing Mutex<&'bound T>) are invariant over their lifetime parameter and cannot safely use cast_ref().

This series splits ForLt into two traits:

- ForLt: base trait for all lifetime-parameterized types, providing only the Of<'a> GAT.

- CovariantForLt: unsafe subtrait that guarantees covariance, providing a safe cast_ref() method.

For invariant types, a closure-based API (registration_data_with()) is added to the auxiliary subsystem. The closure's HRTB prevents the caller from choosing a concrete lifetime, which would be unsound for invariant types.

On top of that, this series adds DevresLt<F: ForLt>, a thin wrapper around Devres<F::Of<'static>> that shortens the stored 'static lifetime back to the caller's borrow scope. DevresLt provides both closure-based access (access_with/try_access_with for ForLt types) and direct reference access (access/try_access for CovariantForLt types).

Also implement ForLt and CovariantForLt for Bar, IoMem and ExclusiveIoMem, and update their into_devres() methods to return DevresLt. Provide convenience type aliases DevresBar, DevresIoMem and DevresExclusiveIoMem.

Changes in v4:
- ForLt! macro: run the Prover and emit ProveWf structs for well-formedness checks
- DevresLt: change Send bound from F::Of<'static>: Send to the correct for<'a> F::Of<'a>: Send
- Add #[inline] to forwarding functions in registration_data_with, registration_data, and all DevresLt accessors

Changes in v3:
- Keep UnsafeForLtImpl as the shared helper for both ForLt! and CovariantForLt!, distinguished by const generic N
- Remove cast_ref_unchecked() from ForLt; lifetime shortening is handled by borrowing with the target lifetime directly or by decoupling the HRTB from the outer reference lifetime

Changes in v2:
- Fold the ForLt -> CovariantForLt rename and the new ForLt base trait into this series
- Add closure-based registration_data_with() for auxiliary ForLt types
- Add auxiliary sample demonstrating ForLt with an invariant Mutex type
- DevresLt: add closure-based access_with()/try_access_with() for ForLt types alongside direct access()/try_access() for CovariantForLt types
- Make DevresLt::new() unsafe; callers must guarantee the data outlives the device binding
- Implement both ForLt and CovariantForLt (previously just ForLt) for Bar, IoMem, ExclusiveIoMem
- Various safety comment and documentation improvements

Danilo Krummrich (7):
rust: types: rename ForLt to CovariantForLt
rust: types: introduce ForLt base trait for CovariantForLt
rust: auxiliary: add registration_data_with() for ForLt types
rust: auxiliary: sample: demonstrate ForLt with invariant Mutex type
rust: devres: add DevresLt for ForLt-aware device resource access
rust: pci: return DevresLt from Bar::into_devres()
rust: io: mem: return DevresLt from
IoMem/ExclusiveIoMem::into_devres()

 drivers/gpu/nova-core/driver.rs       |   4 +-
 drivers/pwm/pwm_th1520.rs             |   5 +-
 rust/kernel/auxiliary.rs              |  78 ++++++++++++++-----
 rust/kernel/devres.rs                 | 106 ++++++++++++++++++++++++++
 rust/kernel/io/mem.rs                 |  65 +++++++++++-----
 rust/kernel/pci.rs                    |   1 +
 rust/kernel/pci/io.rs                 |  37 ++++++---
 rust/kernel/types.rs                  |   1 +
 rust/kernel/types/for_lt.rs           |  95 ++++++++++++++++-------
 rust/macros/for_lt.rs                 |  72 +++++++++++------
 rust/macros/lib.rs                    |  18 ++++-
 samples/rust/rust_driver_auxiliary.rs |  96 ++++++++++++++++-------
 12 files changed, 447 insertions(+), 131 deletions(-)

base-commit: 51cb1aa1250c36269474b8b6ca6b6319e170f5a5

Signature · 1 line
2.54.0