From: "Gary Guo" <gary@garyguo.net>
To: "Andreas Hindborg" <a.hindborg@kernel.org>,
"Gary Guo" <gary@garyguo.net>,
"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
"Rafael J. Wysocki" <rafael@kernel.org>,
"Danilo Krummrich" <dakr@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>,
"Alice Ryhl" <aliceryhl@google.com>,
"Trevor Gross" <tmgross@umich.edu>,
"Daniel Almeida" <daniel.almeida@collabora.com>,
"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>,
<nouveau@lists.freedesktop.org>,
<dri-devel@lists.freedesktop.org>
Subject: Re: [PATCH v2 03/11] rust: io: use pointer types instead of address
Date: Mon, 27 Apr 2026 16:27:22 +0100 [thread overview]
Message-ID: <DI41K5J2FKE1.DF81VQ146J5T@garyguo.net> (raw)
In-Reply-To: <87cxzkqybd.fsf@t14s.mail-host-address-is-not-set>
On Mon Apr 27, 2026 at 3:20 PM BST, Andreas Hindborg wrote:
> Gary Guo <gary@garyguo.net> writes:
>
>> This carries the size information with the pointer type and metadata, makes
>> it possible to use I/O projections and paves the way for IO view types.
>>
>> With this change, minimum size information becomes available through types;
>> so `KnownSize::MIN_SIZE` can be used and `IoKnownSize` trait is no longer
>> necessary. The trait is kept for compatibility and can be removed when
>> users stop using it for bounds.
>>
>> PCI config space uses only offsets and not pointers like MMIO; for this
>> null pointers (with proper size metadata) is used. This is okay as I/O
>> trait impl and I/O projections can operate on invalid pointers, and for PCI
>> config space we will only use address info and ignore the provenance.
>>
>> Signed-off-by: Gary Guo <gary@garyguo.net>
>> ---
>> rust/kernel/devres.rs | 2 +-
>> rust/kernel/io.rs | 123 +++++++++++++++++++++-----------------------------
>> rust/kernel/io/mem.rs | 2 +-
>> rust/kernel/pci/io.rs | 74 ++++++++++++++++++------------
>> 4 files changed, 99 insertions(+), 102 deletions(-)
>>
>> diff --git a/rust/kernel/devres.rs b/rust/kernel/devres.rs
>> index 3e22c63efb98..ea86e9c62cdf 100644
>> --- a/rust/kernel/devres.rs
>> +++ b/rust/kernel/devres.rs
>> @@ -101,7 +101,7 @@ struct Inner<T> {
>> /// impl<const SIZE: usize> Drop for IoMem<SIZE> {
>> /// fn drop(&mut self) {
>> /// // SAFETY: `self.0.addr()` is guaranteed to be properly mapped by `Self::new`.
>> -/// unsafe { bindings::iounmap(self.0.addr() as *mut c_void); };
>> +/// unsafe { bindings::iounmap(self.0.as_ptr().cast()); };
>> /// }
>> /// }
>> ///
>> diff --git a/rust/kernel/io.rs b/rust/kernel/io.rs
>> index 0b9c97c0a1d7..1682f2a0d20d 100644
>> --- a/rust/kernel/io.rs
>> +++ b/rust/kernel/io.rs
>> @@ -105,8 +105,8 @@ pub fn new_region(addr: usize, size: usize) -> Result<Self> {
>> impl<T: ?Sized + KnownSize> MmioRaw<T> {
>> /// Returns the base address of the MMIO region.
>> #[inline]
>> - pub fn addr(&self) -> usize {
>> - self.addr.addr()
>> + pub fn as_ptr(&self) -> *mut T {
>> + self.addr
>> }
>>
>> /// Returns the size of the MMIO region.
>> @@ -166,7 +166,7 @@ pub fn size(&self) -> usize {
>> /// impl<const SIZE: usize> Drop for IoMem<SIZE> {
>> /// fn drop(&mut self) {
>> /// // SAFETY: `self.0.addr()` is guaranteed to be properly mapped by `Self::new`.
>> -/// unsafe { bindings::iounmap(self.0.addr() as *mut c_void); };
>> +/// unsafe { bindings::iounmap(self.0.as_ptr().cast()); };
>> /// }
>> /// }
>> ///
>> @@ -217,14 +217,14 @@ pub trait IoCapable<T> {
>> /// # Safety
>> ///
>> /// The range `[address..address + size_of::<T>()]` must be within the bounds of `Self`.
>> - unsafe fn io_read(&self, address: usize) -> T;
>> + unsafe fn io_read(&self, address: *mut T) -> T;
>>
>> /// Performs an I/O write of `value` at `address`.
>> ///
>> /// # Safety
>> ///
>> /// The range `[address..address + size_of::<T>()]` must be within the bounds of `Self`.
>> - unsafe fn io_write(&self, value: T, address: usize);
>> + unsafe fn io_write(&self, value: T, address: *mut T);
>> }
>>
>
> In v1 you had a requirement for `address` to be aligned. Why did you
> drop that?
In v1 Alex wants me to split this part to a separate commit as this is a
pre-existing requirement that is just not documented. The patch 4 is that
change.
Best,
Gary
>
>
> Best regards,
> Andreas Hindborg
next prev parent reply other threads:[~2026-04-27 15:27 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
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
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=DI41K5J2FKE1.DF81VQ146J5T@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=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=nouveau@lists.freedesktop.org \
--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