Skip to contentSkip to conversation

rust: helpers: Remove volatile qualifier from io helpers

PATCH Applied FUJITA Tomonori 4 participants 7 messages Apr 12, 2025 – Apr 15, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 rust: helpers: Remove volatile qualifier from io helpers

Remove the volatile qualifier used with __iomem in helper functions in io.c. These helper functions are just wrappers around the corresponding accessors so they are unnecessary.

This fixes the following UML build error with CONFIG_RUST enabled:

In file included from /home/fujita/git/linux-rust/rust/helpers/helpers.c:19:
/home/fujita/git/linux-rust/rust/helpers/io.c:12:10: error: passing 'volatile void *' to parameter of type 'void *' discards qualifiers [-Werror,-Wincompatible-pointer-types-discards-qualifiers]
12 | iounmap(addr);
| ^~~~
/home/fujita/git/linux-rust/arch/um/include/asm/io.h:19:42: note: passing argument to parameter 'addr' here
19 | static inline void iounmap(void __iomem *addr)
| ^
1 error generated.

Fixes ce30d94e6855 ("rust: add `io::{Io, IoRaw}` base types")

---
v2:
- remove all the volatile in io helpers instead of aligning UML's iounmap() with other
v1: https://lore.kernel.org/lkml/[email protected]/

---
 rust/helpers/io.c | 34 +++++++++++++++++-----------------
 1 file changed, 17 insertions(+), 17 deletions(-)
rust/helpers/io.c +17 -17
index 4c2401ccd720..15ea187c5466 100644
@@ -7,94 +7,94 @@ void __iomem *rust_helper_ioremap(phys_addr_t offset, size_t size)
 	return ioremap(offset, size);
 }
 
-void rust_helper_iounmap(volatile void __iomem *addr)
+void rust_helper_iounmap(void __iomem *addr)
 {
 	iounmap(addr);
 }
 
-u8 rust_helper_readb(const volatile void __iomem *addr)
+u8 rust_helper_readb(const void __iomem *addr)
 {
 	return readb(addr);
 }
 
-u16 rust_helper_readw(const volatile void __iomem *addr)
+u16 rust_helper_readw(const void __iomem *addr)
 {
 	return readw(addr);
 }
 
-u32 rust_helper_readl(const volatile void __iomem *addr)
+u32 rust_helper_readl(const void __iomem *addr)
 {
 	return readl(addr);
 }
 
 #ifdef CONFIG_64BIT
-u64 rust_helper_readq(const volatile void __iomem *addr)
+u64 rust_helper_readq(const void __iomem *addr)
 {
 	return readq(addr);
 }
 #endif
 
-void rust_helper_writeb(u8 value, volatile void __iomem *addr)
+void rust_helper_writeb(u8 value, void __iomem *addr)
 {
 	writeb(value, addr);
 }
 
-void rust_helper_writew(u16 value, volatile void __iomem *addr)
+void rust_helper_writew(u16 value, void __iomem *addr)
 {
 	writew(value, addr);
 }
 
-void rust_helper_writel(u32 value, volatile void __iomem *addr)
+void rust_helper_writel(u32 value, void __iomem *addr)
 {
 	writel(value, addr);
 }
 
 #ifdef CONFIG_64BIT
-void rust_helper_writeq(u64 value, volatile void __iomem *addr)
+void rust_helper_writeq(u64 value, void __iomem *addr)
 {
 	writeq(value, addr);
 }
 #endif
 
-u8 rust_helper_readb_relaxed(const volatile void __iomem *addr)
+u8 rust_helper_readb_relaxed(const void __iomem *addr)
 {
 	return readb_relaxed(addr);
 }
 
-u16 rust_helper_readw_relaxed(const volatile void __iomem *addr)
+u16 rust_helper_readw_relaxed(const void __iomem *addr)
 {
 	return readw_relaxed(addr);
 }
 
-u32 rust_helper_readl_relaxed(const volatile void __iomem *addr)
+u32 rust_helper_readl_relaxed(const void __iomem *addr)
 {
 	return readl_relaxed(addr);
 }
 
 #ifdef CONFIG_64BIT
-u64 rust_helper_readq_relaxed(const volatile void __iomem *addr)
+u64 rust_helper_readq_relaxed(const void __iomem *addr)
 {
 	return readq_relaxed(addr);
 }
 #endif
 
-void rust_helper_writeb_relaxed(u8 value, volatile void __iomem *addr)
+void rust_helper_writeb_relaxed(u8 value, void __iomem *addr)
 {
 	writeb_relaxed(value, addr);
 }
 
-void rust_helper_writew_relaxed(u16 value, volatile void __iomem *addr)
+void rust_helper_writew_relaxed(u16 value, void __iomem *addr)
 {
 	writew_relaxed(value, addr);
 }
 
-void rust_helper_writel_relaxed(u32 value, volatile void __iomem *addr)
+void rust_helper_writel_relaxed(u32 value, void __iomem *addr)
 {
 	writel_relaxed(value, addr);
 }
 
 #ifdef CONFIG_64BIT
-void rust_helper_writeq_relaxed(u64 value, volatile void __iomem *addr)
+void rust_helper_writeq_relaxed(u64 value, void __iomem *addr)
 {
 	writeq_relaxed(value, addr);
 }

base-commit: c59026c0570a2a97ce2e7d5ae5e9c48fc841542b

Signature · 1 line
2.43.0
reviewer Reviewed-by on v2 1/1
#1 lore raw
Quoted 15 lines · FUJITA Tomonori

Remove the volatile qualifier used with __iomem in helper functions in io.c. These helper functions are just wrappers around the corresponding accessors so they are unnecessary.

This fixes the following UML build error with CONFIG_RUST enabled:

In file included from /home/fujita/git/linux-rust/rust/helpers/helpers.c:19:
/home/fujita/git/linux-rust/rust/helpers/io.c:12:10: error: passing 'volatile void *' to parameter of type 'void *' discards qualifiers [-Werror,-Wincompatible-pointer-types-discards-qualifiers]
12 | iounmap(addr);
| ^~~~
/home/fujita/git/linux-rust/arch/um/include/asm/io.h:19:42: note: passing argument to parameter 'addr' here
19 | static inline void iounmap(void __iomem *addr)
| ^
1 error generated.

Quoted 2 lines
Fixes ce30d94e6855 ("rust: add `io::{Io, IoRaw}` base types")

@Miguel: This originally landed through driver-core, but I guess subsequent patches should go through the Rust tree.

#2 lore raw
In reply to FUJITA Tomonori
Quoted 16 lines · FUJITA Tomonori

Remove the volatile qualifier used with __iomem in helper functions in io.c. These helper functions are just wrappers around the corresponding accessors so they are unnecessary.

This fixes the following UML build error with CONFIG_RUST enabled:

In file included from /home/fujita/git/linux-rust/rust/helpers/helpers.c:19:
/home/fujita/git/linux-rust/rust/helpers/io.c:12:10: error: passing 'volatile void *' to parameter of type 'void *' discards qualifiers [-Werror,-Wincompatible-pointer-types-discards-qualifiers]
12 | iounmap(addr);
| ^~~~
/home/fujita/git/linux-rust/arch/um/include/asm/io.h:19:42: note: passing argument to parameter 'addr' here
19 | static inline void iounmap(void __iomem *addr)
| ^
1 error generated.

Quoted 2 lines
Fixes ce30d94e6855 ("rust: add `io::{Io, IoRaw}` base types")

I don't particularly like having different signatures than the other side (since we could e.g. eventually have a check that they match etc.), but given v1 it seems they could also be eventually gone from the C side anyway.

Cc stable, I assume, too?

Thanks!

Cheers,
Miguel

#3 lore raw
Quoted 7 lines · Miguel Ojeda
Quoted 6 lines · FUJITA Tomonori

/home/fujita/git/linux-rust/arch/um/include/asm/io.h:19:42: note: passing argument to parameter 'addr' here
19 | static inline void iounmap(void __iomem *addr)
| ^
1 error generated.

Quoted 7 lines
Quoted 2 lines
Fixes ce30d94e6855 ("rust: add `io::{Io, IoRaw}` base types")

I don't particularly like having different signatures than the other side (since we could e.g. eventually have a check that they match etc.), but given v1 it seems they could also be eventually gone from the C side anyway.

Rihgt, I tried this last week when it came up first, removing the 'volatile' annotations in the asm-generic/io.h header and then all the ones that caused build regressions on arm/arm64/x86 randconfig and allmodconfig builds. This patch is a little longer than my original version as I did run into a few regressions later.

As far as I can tell, none of these volatile annotations have any actual effect, and most of them date back to ancient kernels where this may have been required.

Leaving it out of the rust interface is clearly the right way, and it shouldn't be too hard to upstream the changes below when we need to, but I also don't see any priority to send these. If anyone wants to help out, I can send them the whole patch.

Arnd

 arch/sh/include/cpu-sh4/cpu/sh7786.h            |   2 +-
 arch/x86/include/asm/io.h                       |  14 +-
 arch/x86/include/asm/uv/uv_hub.h                |   2 +-
 arch/x86/lib/iomem.c                            |  18 +-
 arch/x86/mm/ioremap.c                           |   5 +-
 drivers/accel/qaic/qaic_timesync.c              |   4 +-
 drivers/atm/fore200e.c                          |  12 +-
 drivers/atm/fore200e.h                          |  10 +-
 drivers/char/agp/amd-k7-agp.c                   |   4 +-
 drivers/char/agp/ati-agp.c                      |   6 +-
 drivers/char/agp/nvidia-agp.c                   |   5 +-
 drivers/char/agp/sworks-agp.c                   |   4 +-
 drivers/media/pci/bt8xx/bt878.c                 |   2 +-
 drivers/media/pci/bt8xx/bt878.h                 |   2 +-
 drivers/media/pci/ivtv/ivtv-driver.h            |   8 +-
 drivers/media/pci/ivtv/ivtv-firmware.c          |  10 +-
 drivers/media/pci/ivtv/ivtv-ioctl.c             |   2 +-
 drivers/media/pci/ivtv/ivtv-mailbox.c           |   6 +-
 drivers/media/pci/ivtv/ivtvfb.c                 |   2 +-
 drivers/mtd/devices/spear_smi.c                 |   2 +-
 drivers/net/ethernet/broadcom/bnxt/bnxt.h       |   5 +-
 drivers/net/ethernet/chelsio/cxgb4/cxgb4.h      |   4 +-
 drivers/net/ethernet/chelsio/cxgb4vf/adapter.h  |   4 +-
 drivers/net/ethernet/via/via-velocity.h         | 184 ++++++------
 drivers/net/wireless/ath/wil6210/fw.c           |   4 +-
 drivers/net/wireless/ath/wil6210/main.c         |   8 +-
 drivers/net/wireless/ath/wil6210/wil6210.h      |   6 +-
 drivers/scsi/aacraid/aacraid.h                  |   5 +-
 drivers/scsi/aacraid/rx.c                       |   2 +-
 drivers/scsi/aic7xxx/aic79xx_osm.h              |   2 +-
 drivers/scsi/aic7xxx/aic7xxx_osm.h              |   2 +-
 drivers/scsi/megaraid/megaraid_sas.h            |   2 +-
 drivers/scsi/megaraid/megaraid_sas_base.c       |   2 +-
 drivers/scsi/mpi3mr/mpi3mr.h                    |   2 +-
 drivers/scsi/mpi3mr/mpi3mr_fw.c                 |   4 +-
 drivers/scsi/mpt3sas/mpt3sas_base.c             |   7 +-
 drivers/scsi/nsp32_io.h                         |  52 ++--
 drivers/scsi/qla1280.c                          |   4 +-
 drivers/scsi/qla2xxx/qla_def.h                  |  18 +-
 drivers/scsi/qla2xxx/qla_inline.h               |   2 +-
 drivers/scsi/smartpqi/smartpqi_init.c           |   2 +-
 drivers/spi/spi-s3c64xx.c                       |   4 +-
 drivers/staging/sm750fb/sm750.h                 |   6 +-
 drivers/video/fbdev/imsttfb.c                   |   4 +-
 drivers/video/fbdev/kyro/STG4000InitDevice.c    |   4 +-
 drivers/video/fbdev/kyro/STG4000Interface.h     |  26 +-
 drivers/video/fbdev/kyro/STG4000OverlayDevice.c |  10 +-
 drivers/video/fbdev/kyro/STG4000Ramdac.c        |   6 +-
 drivers/video/fbdev/kyro/STG4000Reg.h           | 376 ++++++++++++------------
 drivers/video/fbdev/kyro/STG4000VTG.c           |   8 +-
 drivers/video/fbdev/nvidia/nv_type.h            |  38 +--
 drivers/video/fbdev/nvidia/nvidia.c             |   9 +-
 drivers/video/fbdev/riva/fbdev.c                |   2 +-
 drivers/video/fbdev/riva/nv_driver.c            |  26 +-
 drivers/video/fbdev/riva/riva_hw.h              |  60 ++--
 drivers/video/fbdev/savage/savagefb.h           |   4 +-
 drivers/video/fbdev/vga16fb.c                   |   2 +-
 include/asm-generic/io.h                        | 136 ++++-----
 include/asm-generic/video.h                     |  22 +-
 include/linux/io-64-nonatomic-hi-lo.h           |  12 +-
 include/linux/io-64-nonatomic-lo-hi.h           |  12 +-
 include/linux/io.h                              |   2 +-
 include/video/neomagic.h                        |   2 +-
 lib/check_signature.c                           |   2 +-
 lib/iomem_copy.c                                |   6 +-
 lib/trace_readwrite.c                           |   8 +-
 mm/ioremap.c                                    |   4 +-
 tools/testing/nvdimm/test/iomap.c               |   2 +-
 tools/testing/nvdimm/test/nfit_test.h           |   2 +-
 69 files changed, 613 insertions(+), 623 deletions(-)
#4 lore raw
Quoted 8 lines · Arnd Bergmann

Rihgt, I tried this last week when it came up first, removing the 'volatile' annotations in the asm-generic/io.h header and then all the ones that caused build regressions on arm/arm64/x86 randconfig and allmodconfig builds. This patch is a little longer than my original version as I did run into a few regressions later.

Quoted 8 lines

As far as I can tell, none of these volatile annotations have any actual effect, and most of them date back to ancient kernels where this may have been required.

Leaving it out of the rust interface is clearly the right way, and it shouldn't be too hard to upstream the changes below when we need to, but I also don't see any priority to send these. If anyone wants to help out, I can send them the whole patch.

Thanks a lot Arnd -- then let's go without them on the Rust side. I will pick it as a fix.

I added an issue in case someone wants to help:

    https://github.com/Rust-for-Linux/linux/issues/1156

Cheers,
Miguel

Applied
#5 lore raw
In reply to FUJITA Tomonori
Quoted 6 lines · FUJITA Tomonori

Remove the volatile qualifier used with __iomem in helper functions in io.c. These helper functions are just wrappers around the corresponding accessors so they are unnecessary.

This fixes the following UML build error with CONFIG_RUST enabled:

Applied to rust-fixes -- thanks everyone!

[ Reworded for relative paths. - Miguel ]

Cheers,
Miguel

#6 lore raw
Quoted 4 lines · Miguel Ojeda

Applied to rust-fixes -- thanks everyone!

[ Reworded for relative paths. - Miguel ]

Also:

[ Arnd explains [1] that removing the qualifier is the way forward
(thanks!):

Rihgt, I tried this last week when it came up first, removing the 'volatile' annotations in the asm-generic/io.h header and then all the ones that caused build regressions on arm/arm64/x86 randconfig and allmodconfig builds. This patch is a little longer than my original version as I did run into a few regressions later.

As far as I can tell, none of these volatile annotations have any actual effect, and most of them date back to ancient kernels where this may have been required.

Leaving it out of the rust interface is clearly the right way, and it shouldn't be too hard to upstream the changes below when we need to, but I also don't see any priority to send these. If anyone wants to help out, I can send them the whole patch.

I created an issue [2] in case someone wants to help. - Miguel ]

Cheers,
Miguel