From: "Danilo Krummrich" <dakr@kernel.org>
To: "Arnd Bergmann" <arnd@arndb.de>
Cc: "Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
"Rafael J . Wysocki" <rafael@kernel.org>,
"Alice Ryhl" <aliceryhl@google.com>,
"Daniel Almeida" <daniel.almeida@collabora.com>,
"Miguel Ojeda" <ojeda@kernel.org>,
"Boqun Feng" <boqun@kernel.org>, "Gary Guo" <gary@garyguo.net>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Benno Lossin" <lossin@kernel.org>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Trevor Gross" <tmgross@umich.edu>,
"Tamir Duberstein" <tamird@kernel.org>,
acourbot@nvidia.com, "Onur Özkan" <work@onurozkan.dev>,
driver-core@lists.linux.dev, rust-for-linux@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 1/2] rust: io: gate ioremap/iounmap on CONFIG_HAS_IOMEM
Date: Thu, 06 Aug 2026 17:47:28 +0200 [thread overview]
Message-ID: <DKHZ8KNRT5WY.2GPNFMJGZVEX2@kernel.org> (raw)
In-Reply-To: <9fbff830-d1b3-428b-b7b2-205eff41b6d5@app.fastmail.com>
On Wed Aug 5, 2026 at 11:39 PM CEST, Arnd Bergmann wrote:
> Can you also hide the actual I/O accessors in this case?
> While s390 without CONFIG_PCI still provides the asm-generic
> version of those, that is technically a mistake, and it would
> be nice not to.
>
> I'm guessing that there is enough kernel code that still expects
> these to be present for C, but if all rust code has the correct
> HAS_IOMEM dependencies, it would be cleaner not to reference
> since there is no correct way to call them without ioremap().
As things are right now, I think something like in [1] should work, but we'd
also need to cfg-gate every single doc-test that uses I/O primitives, which is
slightly annoying.
In any case, I'm not sure it would be a huge benefit anyway. Unlike in C, where
I/O accessors operate on raw void pointers, the Rust primitives are typed. So,
users have no way of actually calling them without being able to obtain a
mapping in the first place.
- Danilo
[1]
diff --git a/rust/helpers/io.c b/rust/helpers/io.c
index 1edbc274951c..29120ea9d7d8 100644
--- a/rust/helpers/io.c
+++ b/rust/helpers/io.c
@@ -19,7 +19,6 @@ __rust_helper void rust_helper_iounmap(void __iomem *addr)
{
iounmap(addr);
}
-#endif /* CONFIG_HAS_IOMEM */
__rust_helper u8 rust_helper_readb(const void __iomem *addr)
{
@@ -108,6 +107,7 @@ __rust_helper void rust_helper_writeq_relaxed(u64 value, void __iomem *addr)
writeq_relaxed(value, addr);
}
#endif
+#endif /* CONFIG_HAS_IOMEM */
__rust_helper resource_size_t rust_helper_resource_size(struct resource *res)
{
diff --git a/rust/kernel/io.rs b/rust/kernel/io.rs
index d4063ee41200..d91fc2e4ae9b 100644
--- a/rust/kernel/io.rs
+++ b/rust/kernel/io.rs
@@ -728,6 +728,7 @@ fn io_addr_assert<U>(&self, offset: usize) -> usize {
}
}
+#[cfg(CONFIG_HAS_IOMEM)]
/// Implements [`IoCapable`] on `$mmio` for `$ty` using `$read_fn` and `$write_fn`.
macro_rules! impl_mmio_io_capable {
($mmio:ident, $(#[$attr:meta])* $ty:ty, $read_fn:ident, $write_fn:ident) => {
@@ -746,10 +747,14 @@ unsafe fn io_write(&self, value: $ty, address: usize) {
};
}
+#[cfg(CONFIG_HAS_IOMEM)]
// MMIO regions support 8, 16, and 32-bit accesses.
impl_mmio_io_capable!(Mmio, u8, readb, writeb);
+#[cfg(CONFIG_HAS_IOMEM)]
impl_mmio_io_capable!(Mmio, u16, readw, writew);
+#[cfg(CONFIG_HAS_IOMEM)]
impl_mmio_io_capable!(Mmio, u32, readl, writel);
+#[cfg(CONFIG_HAS_IOMEM)]
// MMIO regions on 64-bit systems also support 64-bit accesses.
impl_mmio_io_capable!(
Mmio,
@@ -843,10 +848,14 @@ pub fn relaxed(&self) -> &RelaxedMmio<SIZE> {
}
}
+#[cfg(CONFIG_HAS_IOMEM)]
// MMIO regions support 8, 16, and 32-bit accesses.
impl_mmio_io_capable!(RelaxedMmio, u8, readb_relaxed, writeb_relaxed);
+#[cfg(CONFIG_HAS_IOMEM)]
impl_mmio_io_capable!(RelaxedMmio, u16, readw_relaxed, writew_relaxed);
+#[cfg(CONFIG_HAS_IOMEM)]
impl_mmio_io_capable!(RelaxedMmio, u32, readl_relaxed, writel_relaxed);
+#[cfg(CONFIG_HAS_IOMEM)]
// MMIO regions on 64-bit systems also support 64-bit accesses.
impl_mmio_io_capable!(
RelaxedMmio,
next prev parent reply other threads:[~2026-08-06 15:47 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-05 21:28 [PATCH v2 1/2] rust: io: gate ioremap/iounmap on CONFIG_HAS_IOMEM Danilo Krummrich
2026-08-05 21:28 ` [PATCH v2 2/2] rust: io: gate ioremap doctests " Danilo Krummrich
2026-08-05 21:40 ` Arnd Bergmann
2026-08-05 21:39 ` [PATCH v2 1/2] rust: io: gate ioremap/iounmap " Arnd Bergmann
2026-08-06 15:47 ` Danilo Krummrich [this message]
2026-08-06 16:09 ` Arnd Bergmann
2026-08-06 15:58 ` Danilo Krummrich
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=DKHZ8KNRT5WY.2GPNFMJGZVEX2@kernel.org \
--to=dakr@kernel.org \
--cc=a.hindborg@kernel.org \
--cc=acourbot@nvidia.com \
--cc=aliceryhl@google.com \
--cc=arnd@arndb.de \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun@kernel.org \
--cc=daniel.almeida@collabora.com \
--cc=driver-core@lists.linux.dev \
--cc=gary@garyguo.net \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=ojeda@kernel.org \
--cc=rafael@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.