linux-pci.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v4 0/5] Improvements for Devres
@ 2025-06-26 20:00 Danilo Krummrich
  2025-06-26 20:00 ` [PATCH v4 1/5] rust: revocable: support fallible PinInit types Danilo Krummrich
                   ` (5 more replies)
  0 siblings, 6 replies; 35+ messages in thread
From: Danilo Krummrich @ 2025-06-26 20:00 UTC (permalink / raw)
  To: gregkh, rafael, ojeda, alex.gaynor, boqun.feng, gary, bjorn3_gh,
	lossin, a.hindborg, aliceryhl, tmgross, david.m.ertman, ira.weiny,
	leon, kwilczynski, bhelgaas
  Cc: rust-for-linux, linux-kernel, linux-pci, Danilo Krummrich

This patch series provides some optimizations for Devres:

  1) Provide a more lightweight replacement for Devres::new_foreign_owned().

  2) Get rid of Devres' inner Arc and instead consume and provide an
     impl PinInit instead.

     Additionally, having the resulting explicit synchronization in
     Devres::drop() prevents potential subtle undesired side effects of the
     devres callback dropping the final Arc reference asynchronously within
     the devres callback.

  3) An optimization for when we never need to access the resource or release
     it manually.

Thanks to Alice and Benno for some great offline discussions on this topic.

This patch series depends on the Opaque patch in [1] and the pin-init patch in
[2], which Benno will provide a signed tag for. A branch containing the patches
can be found in [3].

[1] https://lore.kernel.org/lkml/20250610-b4-rust_miscdevice_registrationdata-v6-1-b03f5dfce998@gmail.com/
[2] https://lore.kernel.org/rust-for-linux/20250529081027.297648-2-lossin@kernel.org/
[3] https://git.kernel.org/pub/scm/linux/kernel/git/dakr/linux.git/log/?h=rust/devres

Changes in v4:
  - devres::register:
    - require T: Send and ForeignOwnable: Send
  - Devres:
    - require T: Send
    - document possible changes when switching from Opaque to UnsafePinned, once
      possible
  - devres::register_release():
    - rework to Benno's proposal of Release::Ptr
    - require P::Target: Send
  - add a patch adding ForeignOwnable::Target, i.e. the type of the payload data
    (required for devres::register_release())

Changes in v3:
  - devres::register:
    - add 'static bound for ForeignOwnable
    - use drop() instead of `let _ =`
  - Devres:
    - use ptr::from_ref() instead of Inner::as_ptr()
    - use &raw mut instead of addr_of_mut!()
    - use SAFETY comment proposal from Benno
    - add invariant for `Devres::inner`
    - use ScopeGuard in devres_callback()
  - devres::register_release():
    - add impl<T: Release> Release for &T
    - add 'static bound for ForeignOwnable
    - use drop() instead of `let _ =`

Changes in v2:
  - Revocable:
    - remove Error: From<E> bound
  - devres::register:
    - rename devres::register_foreign_boxed() to just devres::register()
    - move T: 'static bound to the function rather than the impl block
  - Devres:
    - Fix aliasing issue by using an Opaque<Inner>; should be
      UnsafePinned<Inner> once available.
    - Add doc-comments for a couple of private fields.
    - Link Revocable on 'revoke' in Devres::new().
  - devres::register_release():
    - expand documentation of Release
    - rename devres::register_foreign_release() for devres::register_release()

Danilo Krummrich (5):
  rust: revocable: support fallible PinInit types
  rust: devres: replace Devres::new_foreign_owned()
  rust: devres: get rid of Devres' inner Arc
  rust: types: ForeignOwnable: Add type Target
  rust: devres: implement register_release()

 drivers/gpu/nova-core/driver.rs |   7 +-
 drivers/gpu/nova-core/gpu.rs    |   6 +-
 rust/helpers/device.c           |   7 +
 rust/kernel/alloc/kbox.rs       |   2 +
 rust/kernel/cpufreq.rs          |  11 +-
 rust/kernel/devres.rs           | 361 +++++++++++++++++++++++---------
 rust/kernel/drm/driver.rs       |  14 +-
 rust/kernel/pci.rs              |  20 +-
 rust/kernel/revocable.rs        |   6 +-
 rust/kernel/sync/arc.rs         |   1 +
 rust/kernel/types.rs            |   4 +
 samples/rust/rust_driver_pci.rs |  19 +-
 12 files changed, 323 insertions(+), 135 deletions(-)


base-commit: 7be11f5d927a548254be5c07291b32a6aa50917f
-- 
2.49.0


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

end of thread, other threads:[~2025-07-01 11:49 UTC | newest]

Thread overview: 35+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-26 20:00 [PATCH v4 0/5] Improvements for Devres Danilo Krummrich
2025-06-26 20:00 ` [PATCH v4 1/5] rust: revocable: support fallible PinInit types Danilo Krummrich
2025-06-26 20:00 ` [PATCH v4 2/5] rust: devres: replace Devres::new_foreign_owned() Danilo Krummrich
2025-06-26 20:00 ` [PATCH v4 3/5] rust: devres: get rid of Devres' inner Arc Danilo Krummrich
2025-06-26 20:14   ` Boqun Feng
2025-06-26 23:33   ` Benno Lossin
2025-06-26 23:53     ` Danilo Krummrich
2025-06-27  9:01       ` Benno Lossin
2025-06-27 19:59   ` Benno Lossin
2025-06-26 20:00 ` [PATCH v4 4/5] rust: types: ForeignOwnable: Add type Target Danilo Krummrich
2025-06-26 20:20   ` Boqun Feng
2025-06-26 23:17     ` Benno Lossin
2025-06-26 23:21       ` Boqun Feng
2025-06-26 23:36         ` Benno Lossin
2025-06-26 23:45           ` Boqun Feng
2025-06-26 23:55             ` Boqun Feng
2025-06-27  9:05               ` Benno Lossin
2025-06-26 23:22   ` Benno Lossin
2025-06-27 19:53   ` Miguel Ojeda
2025-07-01 11:49   ` Alice Ryhl
2025-06-26 20:00 ` [PATCH v4 5/5] rust: devres: implement register_release() Danilo Krummrich
2025-06-26 20:37   ` Boqun Feng
2025-06-26 20:48     ` Danilo Krummrich
2025-06-26 21:16       ` Boqun Feng
2025-06-26 21:20         ` Danilo Krummrich
2025-06-26 21:21           ` Boqun Feng
2025-06-26 23:19       ` Benno Lossin
2025-06-27 22:06         ` Boqun Feng
2025-06-28  6:06           ` Benno Lossin
2025-06-28  6:38             ` Boqun Feng
2025-06-28  7:53               ` Benno Lossin
2025-06-28  9:58                 ` Danilo Krummrich
2025-06-28 12:13                   ` Benno Lossin
2025-06-28 12:32                     ` Danilo Krummrich
2025-06-29 15:11 ` [PATCH v4 0/5] Improvements for Devres Danilo Krummrich

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).