rust-for-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/9] Implement "Bound" device context
@ 2025-04-13 17:36 Danilo Krummrich
  2025-04-13 17:36 ` [PATCH v2 1/9] rust: device: implement impl_device_context_deref! Danilo Krummrich
                   ` (9 more replies)
  0 siblings, 10 replies; 27+ messages in thread
From: Danilo Krummrich @ 2025-04-13 17:36 UTC (permalink / raw)
  To: bhelgaas, kwilczynski, gregkh, rafael, abdiel.janulgue
  Cc: ojeda, alex.gaynor, boqun.feng, gary, bjorn3_gh, benno.lossin,
	a.hindborg, aliceryhl, tmgross, daniel.almeida, robin.murphy,
	linux-pci, rust-for-linux, linux-kernel, Danilo Krummrich

Currently, we do not ensure that APIs that require a bound device instance can
only be called with a bound device.

Examples of such APIs are Devres, dma::CoherentAllocation and
pci::Device::iomap_region().

This patch series introduces the "Bound" device context such that we can ensure
to only ever pass a bound device to APIs that require this precondition.

In order to get there, we need some prerequisites:

(1) Implement macros to consistently derive Deref implementations for the
    different device contexts. For instance, Device<Core> can be dereferenced to
    Device<Bound>, since all device references we get from "core" bus callbacks
    are guaranteed to be from a bound device. Device<Bound> can always be
    dereferenced to Device (i.e. Device<Normal>), since the "Normal" device
    context has no specific requirements.

(2) Implement device context support for the generic Device type. Some APIs such
    as Devres and dma::CoherentAllocation work with generic devices.

(3) Preserve device context generics in bus specific device' AsRef
    implementation, such that we can derive the device context when converting
    from a bus specific device reference to a generic device reference.

With this, Devres::new(), for instance, can take a &Device<Bound> argument and
hence ensure that it can't be called with a Device reference that is not
guaranteed to be bound to a driver.

A branch containing the patches can be found in [1].

[1] https://web.git.kernel.org/pub/scm/linux/kernel/git/dakr/linux.git/log/?h=rust/device-bound

Changes in v2:
  - add a safety requirement for impl_device_context_deref! (thanks to Benno for
    working this out)

Danilo Krummrich (9):
  rust: device: implement impl_device_context_deref!
  rust: device: implement impl_device_context_into_aref!
  rust: device: implement device context for Device
  rust: platform: preserve device context in AsRef
  rust: pci: preserve device context in AsRef
  rust: device: implement Bound device context
  rust: pci: move iomap_region() to impl Device<Bound>
  rust: devres: require a bound device
  rust: dma: require a bound device

 rust/kernel/device.rs   | 90 ++++++++++++++++++++++++++++++++++++++++-
 rust/kernel/devres.rs   | 17 ++++----
 rust/kernel/dma.rs      | 14 +++----
 rust/kernel/pci.rs      | 33 +++++----------
 rust/kernel/platform.rs | 32 ++++-----------
 5 files changed, 121 insertions(+), 65 deletions(-)


base-commit: 0af2f6be1b4281385b618cb86ad946eded089ac8
-- 
2.49.0


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

end of thread, other threads:[~2025-04-17 15:14 UTC | newest]

Thread overview: 27+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-13 17:36 [PATCH v2 0/9] Implement "Bound" device context Danilo Krummrich
2025-04-13 17:36 ` [PATCH v2 1/9] rust: device: implement impl_device_context_deref! Danilo Krummrich
2025-04-13 19:38   ` Christian Schrefl
2025-04-14 10:41   ` Benno Lossin
2025-04-13 17:36 ` [PATCH v2 2/9] rust: device: implement impl_device_context_into_aref! Danilo Krummrich
2025-04-14 10:26   ` Benno Lossin
2025-04-13 17:36 ` [PATCH v2 3/9] rust: device: implement device context for Device Danilo Krummrich
2025-04-14 10:31   ` Benno Lossin
2025-04-15 20:47   ` Bjorn Helgaas
2025-04-13 17:36 ` [PATCH v2 4/9] rust: platform: preserve device context in AsRef Danilo Krummrich
2025-04-14 10:32   ` Benno Lossin
2025-04-13 17:37 ` [PATCH v2 5/9] rust: pci: " Danilo Krummrich
2025-04-14 10:33   ` Benno Lossin
2025-04-13 17:37 ` [PATCH v2 6/9] rust: device: implement Bound device context Danilo Krummrich
2025-04-14 10:44   ` Benno Lossin
2025-04-14 11:13     ` Danilo Krummrich
2025-04-14 12:15       ` Benno Lossin
2025-04-14 10:49   ` Benno Lossin
2025-04-14 10:56     ` Danilo Krummrich
2025-04-14 11:10       ` Benno Lossin
2025-04-15 20:44   ` Bjorn Helgaas
2025-04-13 17:37 ` [PATCH v2 7/9] rust: pci: move iomap_region() to impl Device<Bound> Danilo Krummrich
2025-04-14 10:44   ` Benno Lossin
2025-04-15 20:43   ` Bjorn Helgaas
2025-04-13 17:37 ` [PATCH v2 8/9] rust: devres: require a bound device Danilo Krummrich
2025-04-13 17:37 ` [PATCH v2 9/9] rust: dma: " Danilo Krummrich
2025-04-17 15:14 ` [PATCH v2 0/9] Implement "Bound" device context 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).