From: "Gary Guo" <gary@garyguo.net>
To: "Gary Guo" <gary@garyguo.net>,
"Danilo Krummrich" <dakr@kernel.org>,
"Alice Ryhl" <aliceryhl@google.com>,
"Daniel Almeida" <daniel.almeida@collabora.com>,
"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
"Rafael J. Wysocki" <rafael@kernel.org>,
"Miguel Ojeda" <ojeda@kernel.org>,
"Boqun Feng" <boqun@kernel.org>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Benno Lossin" <lossin@kernel.org>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Trevor Gross" <tmgross@umich.edu>,
"Bjorn Helgaas" <bhelgaas@google.com>,
"Krzysztof Wilczyński" <kwilczynski@kernel.org>,
"Abdiel Janulgue" <abdiel.janulgue@gmail.com>,
"Robin Murphy" <robin.murphy@arm.com>,
"Alexandre Courbot" <acourbot@nvidia.com>,
"David Airlie" <airlied@gmail.com>,
"Simona Vetter" <simona@ffwll.ch>
Cc: <driver-core@lists.linux.dev>, <rust-for-linux@vger.kernel.org>,
<linux-kernel@vger.kernel.org>, <linux-pci@vger.kernel.org>,
<nova-gpu@lists.linux.dev>, <dri-devel@lists.freedesktop.org>,
"Laura Nao" <laura.nao@collabora.com>
Subject: Re: [PATCH v3 00/19] rust: I/O type generalization and projection
Date: Tue, 09 Jun 2026 13:44:51 +0100 [thread overview]
Message-ID: <DJ4J15P03MPL.QU45B7NZNN0A@garyguo.net> (raw)
In-Reply-To: <20260608-io_projection-v3-0-c5cde13a5ec4@garyguo.net>
On Mon Jun 8, 2026 at 8:58 PM BST, Gary Guo wrote:
> This series present a major rework of I/O types, as a summary:
>
> - Make I/O regions typed. The existing untyped region still exists
> with a dynamically sized `Region` type.
>
> - Create I/O view types to represent subregion of a full I/O region mapped.
> A projection macro is added to allow safely create such subviews.
>
> - Split I/O traits, make I/O views play a central role, avoid
> duplicate monomorphization and less `unsafe` code.
>
> - Add a `SysMem` backend, and make `Coherent` implement `Io`.
>
> - Add copying methods (memcpy_{from,to}io and friends).
>
> This series generalize `Mmio` 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.
>
> Building on top of that, `Mmio` and `ConfigSpace` have been converted to
> typed views of I/O regions rather than just a big chunk of untyped I/O
> memory. These changes made it possible to implement `Io` trait for
> `Coherent<T>`.
>
> Shared system memory, `SysMem` is also added to the series, given it
> similarity in implementation compared to `Coherent`. In fact, the series
> use `SysMem` to implement `Coherent`'s I/O methods.
>
> Built on these generalization, this series add `io_project!()`.
> `io_project!()` performs a safe way to project a bigger view to a small
> subviews, and 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.
>
> For completeness, I've also included the support for copying methods,
> although this does not need to be taken together and can become a follow
> up.
>
> The last commit in the series is included for reference only, as a
> demonstration on how you can use all of this to implement `iosys_map` using
> `Either` type. It automatically gains all the methods via `Io` trait and
> can be projected with the macros.
Sashiko points out a few issues. It repeatedly reported issues in multiple
places, but ultimately there're just 3 issues:
* `Region`'s alignment. Discussed on Zulip
https://rust-for-linux.zulipchat.com/#narrow/channel/288089-General/topic/Generic.20I.2FO.20backends/with/601411822
I'll just make this 4-byte aligned (and also check that size is multiple of
4). Luckily none of the existing driver depends on 8-byte aligned regions.
* Missing `unsafe impl Send/Sync`. This is actually quite low severity (Sashiko
reported high) given it doesn't break drivers today (otherwise I'd noted them
during compilation test). But I'll fix add in the next spin.
* `copy_from_io_slice` can trigger memcpy between two `SysMem` regions which
overlap. This can be fixed by either using `memmove`, or perhaps dropping
`copy_from_io_slice` methods until users arise (this method was asked by
Danilo, maybe Danilo has some use cases in mind?), and we can change it to
`memmove` then. Anyhow copying methods can be delayed to its own patch series
if there needs more discussion.
I'll leave the series on the list for a while before I send out a new version.
If you're reviewing you can assume the first two bullets points will be fixed.
Best,
Gary
>
> ---
> Changes in v3:
> - This version presents a major rework from the last version, mostly inspired
> by discussions that happen during RustWeek. Notably, the new individual
> view types are now the central piece of `Io` traits rather than an ad-hoc
> addon using the `View` type. They also benefit from type-erasure; the
> original type of `Mmio` or `Coherent` doesn't matter anymore for subviews.
> This removes the need of specifying generics on types that take
> `CoherentView` on Nova code, which is something that I'm not fully happy
> with in the last version.
> - Add `SysMem` backend and use it for `Coherent` (Laura Nao).
> - Add examples to copying methods and read_val/write_val (Andreas).
> - Add a reference patch on `Either` implementation.
> - Link to v2: https://patch.msgid.link/20260421-io_projection-v2-0-4c251c692ef4@garyguo.net
>
> Changes in v2:
> - 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/
prev parent reply other threads:[~2026-06-09 12:44 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-08 19:58 Gary Guo
2026-06-08 19:58 ` [PATCH v3 01/19] rust: io: add dynamically-sized `Region` type Gary Guo
2026-06-08 23:52 ` Gary Guo
2026-06-08 19:58 ` [PATCH v3 02/19] rust: io: add missing safety requirement in `IoCapable` methods Gary Guo
2026-06-08 19:59 ` [PATCH v3 03/19] rust: io: restrict untyped IO access and `register!` to `Region` Gary Guo
2026-06-08 19:59 ` [PATCH v3 04/19] rust: io: implement `Io` on reference types instead Gary Guo
2026-06-08 19:59 ` [PATCH v3 05/19] rust: io: generalize `MmioRaw` to pointer to arbitrary type Gary Guo
2026-06-08 19:59 ` [PATCH v3 06/19] rust: io: rename `Mmio` to `MmioOwned` Gary Guo
2026-06-08 19:59 ` [PATCH v3 07/19] rust: io: implement `Mmio` as view type Gary Guo
2026-06-08 19:59 ` [PATCH v3 08/19] rust: pci: io: make `ConfigSpace` a view Gary Guo
2026-06-08 19:59 ` [PATCH v3 09/19] rust: io: use view types instead of addresses for `Io` Gary Guo
2026-06-08 19:59 ` [PATCH v3 10/19] rust: io: remove `MmioOwned` Gary Guo
2026-06-08 19:59 ` [PATCH v3 11/19] rust: io: move `Io` methods to extension trait Gary Guo
2026-06-08 19:59 ` [PATCH v3 12/19] rust: io: add projection macro and methods Gary Guo
2026-06-08 19:59 ` [PATCH v3 13/19] rust: io: add I/O backend for system memory with volatile access Gary Guo
2026-06-08 19:59 ` [PATCH v3 14/19] rust: io: implement a view type for `Coherent` Gary Guo
2026-06-08 19:59 ` [PATCH v3 15/19] rust: io: add `read_val` and `write_val` function on `Io` Gary Guo
2026-06-08 19:59 ` [PATCH v3 16/19] gpu: nova-core: use I/O projection for cleaner encapsulation Gary Guo
2026-06-08 19:59 ` [PATCH v3 17/19] rust: dma: drop `dma_read!` and `dma_write!` API Gary Guo
2026-06-08 19:59 ` [PATCH v3 18/19] rust: io: add copying methods Gary Guo
2026-06-08 19:59 ` [PATCH v3 19/19] rust: io: implement `Io` for `Either` Gary Guo
2026-06-11 5:09 ` Miguel Ojeda
2026-06-08 21:22 ` [PATCH v3 00/19] rust: I/O type generalization and projection Danilo Krummrich
2026-06-09 12:44 ` Gary Guo [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=DJ4J15P03MPL.QU45B7NZNN0A@garyguo.net \
--to=gary@garyguo.net \
--cc=a.hindborg@kernel.org \
--cc=abdiel.janulgue@gmail.com \
--cc=acourbot@nvidia.com \
--cc=airlied@gmail.com \
--cc=aliceryhl@google.com \
--cc=bhelgaas@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun@kernel.org \
--cc=dakr@kernel.org \
--cc=daniel.almeida@collabora.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=driver-core@lists.linux.dev \
--cc=gregkh@linuxfoundation.org \
--cc=kwilczynski@kernel.org \
--cc=laura.nao@collabora.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=nova-gpu@lists.linux.dev \
--cc=ojeda@kernel.org \
--cc=rafael@kernel.org \
--cc=robin.murphy@arm.com \
--cc=rust-for-linux@vger.kernel.org \
--cc=simona@ffwll.ch \
--cc=tmgross@umich.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®