Re: [PATCH v2 1/2] rust: io: gate ioremap/iounmap on CONFIG_HAS_IOMEM

From: Arnd Bergmann

Date: Wed Aug 05 2026 - 17:45:43 EST


On Wed, Aug 5, 2026, at 23:28, Danilo Krummrich wrote:
> s390 does not provide ioremap()/iounmap() when CONFIG_HAS_IOMEM is not
> set (which requires CONFIG_PCI on that architecture). This causes a
> build failure with Rust enabled on e.g. s390 allnoconfig:
>
> In file included from rust/helpers/helpers.c:68:
> rust/helpers/io.c:8:9: error: call to undeclared function 'ioremap';
> ISO C99 and later do not support implicit function declarations
> [-Wimplicit-function-declaration]
> 8 | return ioremap(offset, size);
> | ^
> rust/helpers/io.c:19:2: error: call to undeclared function 'iounmap';
> ISO C99 and later do not support implicit function declarations
> [-Wimplicit-function-declaration]
> 19 | iounmap(addr);
>
> Guard the C helpers behind #ifdef CONFIG_HAS_IOMEM and cfg-gate the Rust
> io::mem module, such that IoMem, ExclusiveIoMem and IoRequest are not
> available without CONFIG_HAS_IOMEM.
>
> Note that the C API is inconsistent about this. For instance,
> devm_ioremap() has no stub and produces a link failure without
> CONFIG_HAS_IOMEM, whereas devm_platform_ioremap_resource() provides an
> inline stub returning -EINVAL.
>
> The approach taken here (compile-time gating) matches the former, which
> is slightly more appropriate since any driver performing MMIO currently
> requires CONFIG_HAS_IOMEM.
>
> Ideally, s390 should provide ioremap()/iounmap() stubs unconditionally
> (as UML already does), removing the need for any config gating as
> discussed in [1]; a follow-up patch for s390 is expected.
>
> Cc: Arnd Bergmann <arnd@xxxxxxxx>
> Reported-by: Miguel Ojeda <ojeda@xxxxxxxxxx>
> Closes: https://lore.kernel.org/all/20260803180931.97202-1-ojeda@xxxxxxxxxx [1]
> Fixes: 3f70ebe63858 ("s390: Enable Rust support")
> Signed-off-by: Danilo Krummrich <dakr@xxxxxxxxxx>

Looks good to me overall.

Reviewed-by: Arnd Bergmann <arnd@xxxxxxxx>

One question:

> }
> +#endif /* CONFIG_HAS_IOMEM */
>
> __rust_helper u8 rust_helper_readb(const void __iomem *addr)

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().

Arnd