From: "Benno Lossin" <lossin@kernel.org>
To: "Gary Guo" <gary@garyguo.net>,
"Daniel Almeida" <daniel.almeida@collabora.com>,
"Danilo Krummrich" <dakr@kernel.org>,
"Abdiel Janulgue" <abdiel.janulgue@gmail.com>,
"Robin Murphy" <robin.murphy@arm.com>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Miguel Ojeda" <ojeda@kernel.org>,
"Boqun Feng" <boqun@kernel.org>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Alice Ryhl" <aliceryhl@google.com>,
"Trevor Gross" <tmgross@umich.edu>,
"Tamir Duberstein" <tamird@kernel.org>,
"Alexandre Courbot" <acourbot@nvidia.com>,
"Onur Özkan" <work@onurozkan.dev>,
"Bjorn Helgaas" <bhelgaas@google.com>,
"Krzysztof Wilczyński" <kwilczynski@kernel.org>,
"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>,
<dri-devel@lists.freedesktop.org>
Subject: Re: [PATCH 5/7] rust: io: let I/O locations carry an access mode
Date: Wed, 21 Oct 2026 11:05:09 +0100 [thread overview]
Message-ID: <DMAFJVM431FZ.R5XWZBIAR0UE@kernel.org> (raw)
In-Reply-To: <DM9NV8ICWRKK.2Q6FSBE476G5M@garyguo.net>
On Tue Oct 20, 2026 at 1:23 PM BST, Gary Guo wrote:
> On Thu Oct 15, 2026 at 1:39 PM BST, Daniel Almeida wrote:
>> `Io::read`, `Io::write`, `Io::update` and their fallible variants
>> project the view to the given `IoLoc` and access it there. A location
>> has no say in which accesses are allowed, so a register cannot be
>> declared read-only or write-only.
>>
>> Add the `io::access` module with the `Mode` trait and the `ReadWrite`,
>> `ReadOnly` and `WriteOnly` modes, and add an `Access` associated type to
>> `IoLoc`. Projecting through a location applies its mode: `ReadWrite`
>> leaves the view as it is, while `ReadOnly` and `WriteOnly` wrap it in the
>> `ReadOnly` and `WriteOnly` views. The bounds of the generic accessors now
>> apply to the backend of the restricted view, so a write to a read-only
>> location, or a read from a write-only one, does not compile.
>>
>> Raw offsets are `ReadWrite`. `OffsetLoc` takes the mode as a type
>> parameter that defaults to `ReadWrite`, and `RegisterArray` gets an
>> `Access` type, which `register!` sets to `ReadWrite` for now.
>>
>> No existing location changes its mode, so there is no functional change.
>> A following patch lets `register!` declare read-only and write-only
>> registers.
>
> So far, without considering access modes, we have a clean mapping after the
> register projection series that a `register!()` macro just generates a custom
> projection. However, this commit makes it special again and this isn't possible
> with struct definitions, so it breaks feature composibility. It is also somewhat
> surprising in the sense that it changes the base view type.
>
> What about making RO/WO wrapper types on actual data? Something like
>
> Mmio<'_, ReadOnly<T>>
>
> and
>
> Mmio<'_, WriteOnly<T>>
>
> Then we can implement
>
> impl<T, B> IoRead<ReadOnly<T>> for B where B: IoRead<T> {}
>
> and
>
> impl<T, B> IoWrite<WriteOnly<T>> for B where B: IoWrite<T> {}
>
> ReadOnly will not implement FromBytes, and WriteOnly will not implement
> IntoBytes, to avoid people using them with `copy_read`/`copy_write` API.
>
> This way, the design works for struct too. One issue of this, though, is that
> you cannot project from `Mmio<'_, ReadOnly<Struct>>` to `Mmio<'_,
> ReadOnly<Field>>` currently. However, I believe this is solved with the "place
> wrapper" concept in field projection.
indeed. if you implement `PlaceWrapper` for `ReadOnly` correctly, then
you can do that projection "as if the wrapper wasn't there".
> Regardless, before we proceed with any design, I'd like to hear opinions from
> Benno on how this interacts with the field projection design as language
> feature.
not sure what interaction you are referring to. I read Daniel's patch,
but I can't infer what you mean by "this" :)
best,
Benno
next prev parent reply other threads:[~2026-10-21 10:05 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-15 12:39 [PATCH 0/7] rust: io: add read-only and write-only views and registers Daniel Almeida
2026-10-15 12:39 ` [PATCH 1/7] rust: io: split IoCapable into IoReadable and IoWritable Daniel Almeida
2026-10-20 12:04 ` Gary Guo
2026-10-20 14:01 ` Vishal Moola (Fractile)
2026-10-15 12:39 ` [PATCH 2/7] rust: io: split IoCopyable into IoCopyReadable and IoCopyWritable Daniel Almeida
2026-10-15 12:39 ` [PATCH 3/7] rust: io: add read-only and write-only views Daniel Almeida
2026-10-15 12:39 ` [PATCH 4/7] rust: io: project primitive accessors directly Daniel Almeida
2026-10-15 12:39 ` [PATCH 5/7] rust: io: let I/O locations carry an access mode Daniel Almeida
2026-10-20 12:23 ` Gary Guo
2026-10-21 10:05 ` Benno Lossin [this message]
2026-10-15 12:39 ` [PATCH 6/7] rust: io: register: add `#[ro]` and `#[wo]` attributes Daniel Almeida
2026-10-15 12:39 ` [PATCH 7/7] drm/tyr: mark read-only and write-only registers Daniel Almeida
2026-10-20 8:01 ` [PATCH 0/7] rust: io: add read-only and write-only views and registers Alice Ryhl
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=DMAFJVM431FZ.R5XWZBIAR0UE@kernel.org \
--to=lossin@kernel.org \
--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=gary@garyguo.net \
--cc=kwilczynski@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=ojeda@kernel.org \
--cc=robin.murphy@arm.com \
--cc=rust-for-linux@vger.kernel.org \
--cc=simona@ffwll.ch \
--cc=tamird@kernel.org \
--cc=tmgross@umich.edu \
--cc=work@onurozkan.dev \
/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®