From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from sender4-op-o11.zoho.com (sender4-op-o11.zoho.com [136.143.188.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DBA3636073E; Wed, 8 Jul 2026 14:49:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=136.143.188.11 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783522152; cv=pass; b=rXh9ZVET6/MbzgU9Cj7Iv9ObswCCuOWQq4UYyvIgOIjC7tC7pD2w9FMwIbYSQC/Pfi0m4QpOhLw9ZucN+KVSZT0dRpoeEDIn+4x95O4HKXh65tFw4R1uPeAFiLpb96/AGe7LH2L+0QDIeKcFOVTwiQEJIBdHjwtkG3GOmaOQkx4= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783522152; c=relaxed/simple; bh=p9UVZdQviaIM7RRmMiAoAltcfQyAv+LLnchHDDFUqR8=; h=Content-Type:Mime-Version:Subject:From:In-Reply-To:Date:Cc: Message-Id:References:To; b=Kl6yIclpmTc6Ba+e4esM6lVbDw1f/Nno0qpON2Zk+VdnqyTfmkMH9hmQHfQcNY1lESIV5KET6QDw2ebUQlx4XXczzv2Q2Hgm/8tFYUOIkyjlcVvOPW8OCBbPM7gvVD1UK200Xwmm2b4j1WPte/QRK0JvGXmPmtjtoxauBVr+Dbk= ARC-Authentication-Results:i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass (1024-bit key) header.d=collabora.com header.i=daniel.almeida@collabora.com header.b=BqgX68aZ; arc=pass smtp.client-ip=136.143.188.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=collabora.com header.i=daniel.almeida@collabora.com header.b="BqgX68aZ" ARC-Seal: i=1; a=rsa-sha256; t=1783522135; cv=none; d=zohomail.com; s=zohoarc; b=bpdfpAPoLcSj38gcmEk2W/IMuf6DLCeA1M8IV40jkNqT5xVAIxBmWxuxqB7ExufSghrKFbSVfQcs5J27DAy2Ut8z+NZbwCCnr8FUYKxZ9o1xQ2idOIp/hlNVhyywtN6G9wYvS2eVzalpAgO2OV8UYnxgPIqZIidkV+dzJd9igX8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1783522135; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:Subject:To:To:Message-Id:Reply-To; bh=4szMuqOI9JIjS8/kOAhVMC5VSKoQ9b+UCMsEA4pJKao=; b=Q9Q2usmguFIY0JgQ8ctP2lfmqHIvDkwdj5XxEO0ghHgtG1xSNAeu3lzU70jxmsPU0lL3ept8wRTIbfssk0ZyqguMLJyijIna5ZOYLyzNsEOXMc1olPEt1MfHPNuMebvHmVGrdVBL8YhjBFlrsMdAEDnlKAH7iWIeyMcaonpBc54= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=collabora.com; spf=pass smtp.mailfrom=daniel.almeida@collabora.com; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1783522135; s=zohomail; d=collabora.com; i=daniel.almeida@collabora.com; h=Content-Type:Mime-Version:Subject:Subject:From:From:In-Reply-To:Date:Date:Cc:Cc:Content-Transfer-Encoding:Message-Id:Message-Id:References:To:To:Reply-To; bh=4szMuqOI9JIjS8/kOAhVMC5VSKoQ9b+UCMsEA4pJKao=; b=BqgX68aZ2rJ5M0QZeOx8Q+mChiooQJyvC8he/hgev0iHS+XBMjSR779q2FrhT3W7 l8lWrFxj4G9ICt6BRakEGDBlQBJitE8uoetb4bKLUc7muIoR6m/XnuWdmXU51Zlm4zp IbKX1oM2tbfP+poX6TmhAwenoHQCtzdU7wMUZKks= Received: by mx.zohomail.com with SMTPS id 1783522133821946.0992772309626; Wed, 8 Jul 2026 07:48:53 -0700 (PDT) Content-Type: text/plain; charset=us-ascii Precedence: bulk X-Mailing-List: nova-gpu@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3826.700.81\)) Subject: Re: [PATCH v6 11/20] rust: io: remove `MmioOwned` From: Daniel Almeida In-Reply-To: <20260706-io_projection-v6-11-72cd5d055d54@garyguo.net> Date: Wed, 8 Jul 2026 11:48:33 -0300 Cc: Alice Ryhl , Greg Kroah-Hartman , "Rafael J. Wysocki" , Miguel Ojeda , Boqun Feng , =?utf-8?Q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Trevor Gross , Tamir Duberstein , =?utf-8?Q?Onur_=C3=96zkan?= , Bjorn Helgaas , =?utf-8?Q?Krzysztof_Wilczy=C5=84ski?= , Abdiel Janulgue , Robin Murphy , Alexandre Courbot , David Airlie , Simona Vetter , Michal Wilczynski , =?utf-8?Q?Uwe_Kleine-K=C3=B6nig?= , Danilo Krummrich , 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, linux-pwm@vger.kernel.org Content-Transfer-Encoding: quoted-printable Message-Id: References: <20260706-io_projection-v6-0-72cd5d055d54@garyguo.net> <20260706-io_projection-v6-11-72cd5d055d54@garyguo.net> To: Gary Guo X-Mailer: Apple Mail (2.3826.700.81) X-ZohoMailClient: External > On 6 Jul 2026, at 09:44, Gary Guo wrote: >=20 > `Io` trait is now very easy to implement. Thus, implement it on `Bar` = and > `IoMem` directly and remove the `MmioOwned` struct. >=20 > Reviewed-by: Alexandre Courbot > Signed-off-by: Gary Guo > --- > rust/kernel/devres.rs | 12 +++--- > rust/kernel/io.rs | 103 = +------------------------------------------------- > rust/kernel/io/mem.rs | 26 +++++++------ > rust/kernel/pci/io.rs | 16 ++++---- > 4 files changed, 32 insertions(+), 125 deletions(-) >=20 > diff --git a/rust/kernel/devres.rs b/rust/kernel/devres.rs > index aed0c994fd30..3545ffc5345d 100644 > --- a/rust/kernel/devres.rs > +++ b/rust/kernel/devres.rs > @@ -68,8 +68,9 @@ struct Inner { > /// devres::Devres, > /// io::{ > /// Io, > -/// MmioOwned, > +/// Mmio, > /// MmioRaw, > +/// MmioBackend, > /// PhysAddr, > /// Region, // > /// }, > @@ -104,12 +105,13 @@ struct Inner { > /// } > /// } > /// > -/// impl Deref for IoMem { > -/// type Target =3D MmioOwned; > +/// impl<'a, const SIZE: usize> Io<'a> for &'a IoMem { > +/// type Backend =3D MmioBackend; > +/// type Target =3D Region; > /// > -/// fn deref(&self) -> &Self::Target { > +/// fn as_view(self) -> Mmio<'a, Region> { > /// // SAFETY: The memory range stored in `self` has been = properly mapped in `Self::new`. > -/// unsafe { MmioOwned::from_raw(&self.0) } > +/// unsafe { Mmio::from_raw(self.0) } > /// } > /// } > /// # fn no_run(dev: &Device) -> Result<(), Error> { > diff --git a/rust/kernel/io.rs b/rust/kernel/io.rs > index 89039b3defd5..c7533d605678 100644 > --- a/rust/kernel/io.rs > +++ b/rust/kernel/io.rs > @@ -98,8 +98,8 @@ fn size(p: *const Self) -> usize { > /// the represented MMIO region does exist or is properly mapped. > /// > /// Instead, the bus specific MMIO implementation must convert this = raw representation into an > -/// `MmioOwned` instance providing the actual memory accessors. Only = by the conversion into an > -/// `MmioOwned` structure any guarantees are given. > +/// `Mmio` instance providing the actual memory accessors. Only by = the conversion into an `Mmio` > +/// structure any guarantees are given. > pub struct MmioRaw { > /// Pointer is in I/O address space. > /// > @@ -156,80 +156,6 @@ pub fn size(&self) -> usize { > } > } >=20 > -/// IO-mapped memory region. > -/// > -/// The creator (usually a subsystem / bus such as PCI) is = responsible for creating the > -/// mapping, performing an additional region request etc. > -/// > -/// # Invariant > -/// > -/// `addr` is the start and `maxsize` the length of valid I/O mapped = memory region of size > -/// `maxsize`. > -/// > -/// # Examples > -/// > -/// ```no_run > -/// use kernel::{ > -/// bindings, > -/// ffi::c_void, > -/// io::{ > -/// Io, > -/// MmioOwned, > -/// MmioRaw, > -/// PhysAddr, > -/// Region, > -/// }, > -/// }; > -/// use core::ops::Deref; > -/// > -/// // See also `pci::Bar` for a real example. > -/// struct IoMem(MmioRaw>); > -/// > -/// impl IoMem { > -/// /// # Safety > -/// /// > -/// /// [`paddr`, `paddr` + `SIZE`) must be a valid MMIO region = that is mappable into the CPUs > -/// /// virtual address space. > -/// unsafe fn new(paddr: usize) -> Result{ > -/// // SAFETY: By the safety requirements of this function = [`paddr`, `paddr` + `SIZE`) is > -/// // valid for `ioremap`. > -/// let addr =3D unsafe { bindings::ioremap(paddr as = PhysAddr, SIZE) }; > -/// if addr.is_null() { > -/// return Err(ENOMEM); > -/// } > -/// > -/// Ok(IoMem(MmioRaw::new_region(addr as usize, SIZE)?)) > -/// } > -/// } > -/// > -/// impl Drop for IoMem { > -/// 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); = }; > -/// } > -/// } > -/// > -/// impl Deref for IoMem { > -/// type Target =3D MmioOwned; > -/// > -/// fn deref(&self) -> &Self::Target { > -/// // SAFETY: The memory range stored in `self` has been = properly mapped in `Self::new`. > -/// unsafe { MmioOwned::from_raw(&self.0) } > -/// } > -/// } > -/// > -///# fn no_run() -> Result<(), Error> { > -/// // SAFETY: Invalid usage for example purposes. > -/// let iomem =3D unsafe { IoMem::<{ core::mem::size_of::() = }>::new(0xBAAAAAAD)? }; > -/// iomem.write32(0x42, 0x0); > -/// assert!(iomem.try_write32(0x42, 0x0).is_ok()); > -/// assert!(iomem.try_write32(0x42, 0x4).is_err()); > -/// # Ok(()) > -/// # } > -/// ``` > -#[repr(transparent)] > -pub struct MmioOwned(MmioRaw>); > - > /// Checks whether an access of type `U` at the given `base` and the = given `offset` > /// is valid within this region. > /// > @@ -957,31 +883,6 @@ fn io_write(view: <$backend as = IoBackend>::View<'_, $ty>, value: $ty) { > #[cfg(CONFIG_64BIT)] > impl_mmio_io_capable!(MmioBackend, u64, readq, writeq); >=20 > -impl<'a, const SIZE: usize> Io<'a> for &'a MmioOwned { > - type Backend =3D MmioBackend; > - type Target =3D Region; > - > - #[inline] > - fn as_view(self) -> Mmio<'a, Self::Target> { > - // SAFETY: `Mmio` has same invariant as `MmioOwned` > - unsafe { Mmio::from_raw(self.0) } > - } > -} > - > -impl MmioOwned { > - /// Converts an `MmioRaw` into an `MmioOwned` instance, providing = the accessors to the MMIO > - /// mapping. > - /// > - /// # Safety > - /// > - /// Callers must ensure that `addr` is the start of a valid I/O = mapped memory region of size > - /// `maxsize`. > - pub unsafe fn from_raw(raw: &MmioRaw>) -> &Self { > - // SAFETY: `MmioOwned` is a transparent wrapper around = `MmioRaw`. > - unsafe { &*core::ptr::from_ref(raw).cast() } > - } > -} > - > /// [`Mmio`] but using relaxed accessors. > /// > /// This type provides an implementation of [`Io`] that uses relaxed = I/O MMIO operands instead of > diff --git a/rust/kernel/io/mem.rs b/rust/kernel/io/mem.rs > index 8f6c257c5b8e..d9b3189d09b4 100644 > --- a/rust/kernel/io/mem.rs > +++ b/rust/kernel/io/mem.rs > @@ -2,8 +2,6 @@ >=20 > //! Generic memory-mapped IO. >=20 > -use core::ops::Deref; > - > use crate::{ > device::{ > Bound, > @@ -16,7 +14,9 @@ > Region, > Resource, // > }, > - MmioOwned, > + Io, > + Mmio, > + MmioBackend, > MmioRaw, // > }, > prelude::*, > @@ -210,11 +210,13 @@ pub fn into_devres(self) -> = Result>> { > } > } >=20 > -impl Deref for ExclusiveIoMem<'_, SIZE> { > - type Target =3D MmioOwned; > +impl<'a, const SIZE: usize> Io<'a> for &'a ExclusiveIoMem<'_, SIZE> { > + type Backend =3D MmioBackend; > + type Target =3D super::Region; >=20 > - fn deref(&self) -> &Self::Target { > - &self.iomem > + #[inline] > + fn as_view(self) -> Mmio<'a, Self::Target> { > + self.iomem.as_view() > } > } >=20 > @@ -290,11 +292,13 @@ fn drop(&mut self) { > } > } >=20 > -impl Deref for IoMem<'_, SIZE> { > - type Target =3D MmioOwned; > +impl<'a, const SIZE: usize> Io<'a> for &'a IoMem<'_, SIZE> { > + type Backend =3D MmioBackend; > + type Target =3D super::Region; >=20 > - fn deref(&self) -> &Self::Target { > + #[inline] > + fn as_view(self) -> Mmio<'a, Self::Target> { > // SAFETY: Safe as by the invariant of `IoMem`. > - unsafe { MmioOwned::from_raw(&self.io) } > + unsafe { Mmio::from_raw(self.io) } > } > } > diff --git a/rust/kernel/pci/io.rs b/rust/kernel/pci/io.rs > index e67c1e3694fb..4be33ecb4192 100644 > --- a/rust/kernel/pci/io.rs > +++ b/rust/kernel/pci/io.rs > @@ -11,16 +11,14 @@ > Io, > IoBackend, > IoCapable, > - MmioOwned, > + Mmio, > + MmioBackend, > MmioRaw, > Region, // > }, > prelude::*, > ptr::KnownSize, // > }; > -use core::{ > - ops::Deref, // > -}; >=20 > /// Represents the size of a PCI configuration space. > /// > @@ -269,12 +267,14 @@ fn drop(&mut self) { > } > } >=20 > -impl Deref for Bar<'_, SIZE> { > - type Target =3D MmioOwned; > +impl<'a, const SIZE: usize> Io<'a> for &'a Bar<'_, SIZE> { > + type Backend =3D MmioBackend; > + type Target =3D crate::io::Region; >=20 > - fn deref(&self) -> &Self::Target { > + #[inline] > + fn as_view(self) -> Mmio<'a, Self::Target> { > // SAFETY: By the type invariant of `Self`, the MMIO range in = `self.io` is properly mapped. > - unsafe { MmioOwned::from_raw(&self.io) } > + unsafe { Mmio::from_raw(self.io) } > } > } >=20 >=20 > --=20 > 2.54.0 >=20 >=20 Reviewed-by: Daniel Almeida =