public inbox for rust-for-linux@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 00/11] rust: I/O type generalization and projection
@ 2026-04-21 14:56 Gary Guo
  2026-04-21 14:56 ` [PATCH v2 01/11] rust: io: generalize `MmioRaw` to pointer to arbitrary type Gary Guo
                   ` (10 more replies)
  0 siblings, 11 replies; 32+ messages in thread
From: Gary Guo @ 2026-04-21 14:56 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Rafael J. Wysocki, Danilo Krummrich,
	Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
	Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
	Daniel Almeida, Bjorn Helgaas, Krzysztof Wilczyński,
	Abdiel Janulgue, Robin Murphy, Alexandre Courbot, David Airlie,
	Simona Vetter
  Cc: driver-core, rust-for-linux, linux-kernel, linux-pci, nouveau,
	dri-devel

This series generalize `Mmio`/`MmioRaw` type from just an untyped region
to typed representations (so `MmioRaw<T>` is `__iomem *T`). This allows
us to remove the `IoKnownSize` trait; the information is sourced from
just the pointer from the `KnownSize` trait instead.

This enables us to implement `Io` trait for `Coherent<T>`, enabling
unified handling of MMIO and DMA coherent memory. It also paves the way
to uniformly support shared system memory, which Tyr will likely need
[1].

Built on this generalization, this series also add a `io::View` type
which represents a subview of a bigger I/O region, and a `io_project!()`
macro that provides a safe way to perform this. Some Nova code has been
converted in this series to demonstrate cleanups possible with this
addition.

New `io_read!()`, `io_write!()` has been added that supersedes
`dma_read!()`, `dma_write!()` macro. Although, they work for primitives
only (to be exact, types that the backend is `IoCapable` of).
One feature that was lost from the old `dma_read!()` and `dma_write!()`
series was the ability to read/write a large structs. However, the
semantics was unclear to begin with, as there was no guarantee about their
atomicity even for structs that were small enough to fit in u32.

In this series, I've introduced a new patch that re-introduces the
capability in the form of copying methods.

    dma_read!(foo, bar) -> io_project!(foo, bar).copy_read()
    dma_write!(foo, bar, baz) -> io_project!(foo, bar).copy_write(baz)

The semantics for these are modelled after memcpy so it has clear
semantics. This also makes it work for MMIO, which maps to
`memcpy_{from,to}io`.

This series depend on the projection syntax rework series [2].

Link: https://rust-for-linux.zulipchat.com/#narrow/channel/288089-General/topic/Generic.20I.2FO.20backends/near/572377073 [1]
Link: https://lore.kernel.org/rust-for-linux/20260415-projection-syntax-rework-v1-0-450723cb3727@garyguo.net/ [2]

Changes since v1:
- Rebased on projection syntax rework
- Added a new patch to forbid use of untyped I/O accessors and register
  macros on typed I/O structs (Alex).
- Fixed a few safety comments (Andreas).
- Added a new patch that implements copying methods (see above).
- Link to v1: https://lore.kernel.org/rust-for-linux/20260323153807.1360705-1-gary@kernel.org/

---
Gary Guo (11):
      rust: io: generalize `MmioRaw` to pointer to arbitrary type
      rust: io: generalize `Mmio` to arbitrary type
      rust: io: use pointer types instead of address
      rust: io: add missing safety requirement in `IoCapable` methods
      rust: io: restrict untyped IO access and `register!` to `Region`
      rust: io: add view type
      rust: dma: add methods to unsafely create reference from subview
      rust: io: add `read_val` and `write_val` function on I/O view
      gpu: nova-core: use I/O projection for cleaner encapsulation
      rust: dma: drop `dma_read!` and `dma_write!` API
      rust: io: add copying methods

 drivers/gpu/nova-core/gsp.rs      |  44 ++-
 drivers/gpu/nova-core/gsp/cmdq.rs |  65 ++--
 drivers/gpu/nova-core/gsp/fw.rs   |  84 ++---
 rust/kernel/devres.rs             |  11 +-
 rust/kernel/dma.rs                | 232 ++++++------
 rust/kernel/io.rs                 | 769 ++++++++++++++++++++++++++++++++------
 rust/kernel/io/mem.rs             |  10 +-
 rust/kernel/io/poll.rs            |   6 +-
 rust/kernel/io/register.rs        |  40 +-
 rust/kernel/pci/io.rs             |  80 ++--
 rust/kernel/ptr.rs                |   7 +
 samples/rust/rust_dma.rs          |  14 +-
 12 files changed, 948 insertions(+), 414 deletions(-)
---
base-commit: 77a9bb0193d790fb71c0edfc567bddc1b56fb3ff
change-id: 20260421-io_projection-16e7dc5ba7e4
prerequisite-change-id: 20260415-projection-syntax-rework-b790a305bc52:v1
prerequisite-patch-id: 110c29f61d0e7259d64057b6f364587c5ee501f5
prerequisite-patch-id: c157387d475fa22e32fc87d831a1ec384d256ca4
prerequisite-patch-id: 4109733485cae727763b2cd9ece69742e3d17cbf
prerequisite-patch-id: 5b686696f7dada42bb0768d255699dda0252234b
prerequisite-patch-id: a736703c95dc35a23e8c52bbdcba0ca9f38b55fb

Best regards,
--  
Gary Guo <gary@garyguo.net>


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

end of thread, other threads:[~2026-04-29  8:04 UTC | newest]

Thread overview: 32+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-21 14:56 [PATCH v2 00/11] rust: I/O type generalization and projection Gary Guo
2026-04-21 14:56 ` [PATCH v2 01/11] rust: io: generalize `MmioRaw` to pointer to arbitrary type Gary Guo
2026-04-27 13:44   ` Andreas Hindborg
2026-04-21 14:56 ` [PATCH v2 02/11] rust: io: generalize `Mmio` " Gary Guo
2026-04-27 14:10   ` Andreas Hindborg
2026-04-21 14:56 ` [PATCH v2 03/11] rust: io: use pointer types instead of address Gary Guo
2026-04-27 14:20   ` Andreas Hindborg
2026-04-27 15:27     ` Gary Guo
2026-04-28  7:12   ` Andreas Hindborg
2026-04-21 14:56 ` [PATCH v2 04/11] rust: io: add missing safety requirement in `IoCapable` methods Gary Guo
2026-04-28  7:16   ` Andreas Hindborg
2026-04-21 14:56 ` [PATCH v2 05/11] rust: io: restrict untyped IO access and `register!` to `Region` Gary Guo
2026-04-28  9:02   ` Andreas Hindborg
2026-04-28 11:14     ` Gary Guo
2026-04-28 12:08       ` Andreas Hindborg
2026-04-28 12:55         ` Gary Guo
2026-04-28 14:41           ` Andreas Hindborg
2026-04-28 14:54             ` Danilo Krummrich
2026-04-29  8:04               ` Andreas Hindborg
2026-04-21 14:56 ` [PATCH v2 06/11] rust: io: add view type Gary Guo
2026-04-28 10:53   ` Andreas Hindborg
2026-04-28 11:20     ` Gary Guo
2026-04-21 14:56 ` [PATCH v2 07/11] rust: dma: add methods to unsafely create reference from subview Gary Guo
2026-04-28 12:10   ` Andreas Hindborg
2026-04-21 14:56 ` [PATCH v2 08/11] rust: io: add `read_val` and `write_val` function on I/O view Gary Guo
2026-04-28 12:53   ` Andreas Hindborg
2026-04-21 14:56 ` [PATCH v2 09/11] gpu: nova-core: use I/O projection for cleaner encapsulation Gary Guo
2026-04-21 14:56 ` [PATCH v2 10/11] rust: dma: drop `dma_read!` and `dma_write!` API Gary Guo
2026-04-28 11:16   ` Andreas Hindborg
2026-04-21 14:56 ` [PATCH v2 11/11] rust: io: add copying methods Gary Guo
2026-04-28 13:22   ` Andreas Hindborg
2026-04-28 14:08     ` Gary Guo

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