Skip to contentSkip to conversation

rust: pci: document Bar's endianness conversion

PATCH Applied Marko Turk 3 participants 6 messages Dec 10, 2025 – Dec 17, 2025

Subsystems (4)
lore
Share & tools
lore

Marko Turk

author
#0 lore raw

PATCH 1/2 rust: pci: document Bar's endianness conversion

Document that the Bar's MMIO backend always assumes little-endian devices and that its operations automatically convert to CPU endianness.

---
 rust/kernel/pci/io.rs | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
rust/kernel/pci/io.rs +4 -1
index 0d55c3139b6f..bfa9df9e9bb9 100644
@@ -18,9 +18,12 @@
 
 /// A PCI BAR to perform I/O-Operations on.
 ///
+/// I/O backend assumes that the device is little-endian and will automatically
+/// convert from little-endian to CPU endianness.
+///
 /// # Invariants
 ///
-/// `Bar` always holds an `IoRaw` inststance that holds a valid pointer to the start of the I/O
+/// `Bar` always holds an `IoRaw` instance that holds a valid pointer to the start of the I/O
 /// memory mapped PCI BAR and its size.
 pub struct Bar<const SIZE: usize = 0> {
     pdev: ARef<Device>,
Signature · 1 line
2.51.0
author
#1 lore raw

PATCH 2/2 samples: rust: fix endianness issue in rust_driver_pci

MMIO backend of PCI Bar always assumes little-endian devices and will convert to CPU endianness automatically. Remove the u32::from_le conversion which would cause a bug on big-endian machines.

Fixes 685376d18e9a ("samples: rust: add Rust PCI sample driver")
---
 samples/rust/rust_driver_pci.rs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
samples/rust/rust_driver_pci.rs +1 -1
index 5823787bea8e..fa677991a5c4 100644
@@ -48,7 +48,7 @@ fn testdev(index: &TestIndex, bar: &Bar0) -> Result<u32> {
         // Select the test.
         bar.write8(index.0, Regs::TEST);
 
-        let offset = u32::from_le(bar.read32(Regs::OFFSET)) as usize;
+        let offset = bar.read32(Regs::OFFSET) as usize;
         let data = bar.read8(Regs::DATA);
 
         // Write `data` to `offset` to increase `count` by one.
Signature · 1 line
2.51.0
Reviewed-by on v1 2/2
#2 lore raw

Re: [PATCH 2/2] samples: rust: fix endianness issue in rust_driver_pci

Quoted 15 lines · Marko Turk

MMIO backend of PCI Bar always assumes little-endian devices and will convert to CPU endianness automatically. Remove the u32::from_le conversion which would cause a bug on big-endian machines.

Fixes 685376d18e9a ("samples: rust: add Rust PCI sample driver")
---
 samples/rust/rust_driver_pci.rs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
samples/rust/rust_driver_pci.rs +0 -0
index 5823787bea8e..fa677991a5c4 100644

samples/rust/rust_driver_pci.rs fn testdev(index: &TestIndex, bar: &Bar0) -> Result<u32> { · line 51

Quoted 5 lines
samples/rust/rust_driver_pci.rs +1 -1
@@ -48,7 +48,7 @@ fn testdev(index: &TestIndex, bar: &Bar0) -> Result<u32> {
         // Select the test.
         bar.write8(index.0, Regs::TEST);
 
-        let offset = u32::from_le(bar.read32(Regs::OFFSET)) as usize;
+        let offset = bar.read32(Regs::OFFSET) as usize;

Yes, dropping from_le() is what we talked about:

Thanks

Dirk

P.S.: I'm not sure if the Fixes is required: As far as I understood there are no big-endian machines supported by Rust, yet. On all other supported little-endian machines this is a no-op. So I think it is at least debatable if this is a "bug" which needs back porting.

maintainer Applied
#3 lore raw

Re: [PATCH 2/2] samples: rust: fix endianness issue in rust_driver_pci

In reply to Marko Turk

(Cc: [email protected])

Quoted 6 lines · Marko Turk

MMIO backend of PCI Bar always assumes little-endian devices and will convert to CPU endianness automatically. Remove the u32::from_le conversion which would cause a bug on big-endian machines.

Fixes 685376d18e9a ("samples: rust: add Rust PCI sample driver")

Applied to driver-core-linus, thanks!

maintainer
#4 lore raw
In reply to Marko Turk
Quoted 14 lines · Marko Turk

Document that the Bar's MMIO backend always assumes little-endian devices and that its operations automatically convert to CPU endianness.

---
 rust/kernel/pci/io.rs | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
rust/kernel/pci/io.rs +0 -0
index 0d55c3139b6f..bfa9df9e9bb9 100644

rust/kernel/pci/io.rs line 26

Quoted 10 lines
rust/kernel/pci/io.rs +4 -1
@@ -18,9 +18,12 @@
 
 /// A PCI BAR to perform I/O-Operations on.
 ///
+/// I/O backend assumes that the device is little-endian and will automatically
+/// convert from little-endian to CPU endianness.
+///
 /// # Invariants
 ///
-/// `Bar` always holds an `IoRaw` inststance that holds a valid pointer to the start of the I/O
+/// `Bar` always holds an `IoRaw` instance that holds a valid pointer to the start of the I/O

Can you please send this typo fix as a separate patch?

No need to resend this one though, I can change it up on my end.

- Danilo