Skip to content

rust: io: turn IoCapable into a functional trait

Alexandre Courbot driver-core linux-pci lkml rust-for-linux 2 versions – In review

Get series with b4
b4 am [email protected] change-id 20260202-io-81fd368f7565

Versions newest first

  1. v2 Latest6 patches 18 repliesIn review
  2. v16 patches 11 repliesSuperseded

Changes in v2 from the cover letter

- Turn RelaxedMmio into an actual wrapper type and make it available through a Mmio::relaxed() method.
- Link to v1: https://patch.msgid.link/[email protected]

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/6rust: io: turn IoCapable into a functional traitrust/kernel/io.rs rust/kernel/pci/io.rs+163 -4311 replies
2/6rust: io: mem: use non-relaxed I/O ops in examplesrust/kernel/io/mem.rs+6 -40 replies
3/6rust: io: provide Mmio relaxed ops through a wrapper typerust/kernel/io.rs+62 -01 reply
4/6rust: io: remove legacy relaxed accessors of Mmiorust/kernel/io.rs+0 -400 replies
5/6rust: pci: io: remove overloaded Io methods of ConfigSpacerust/kernel/io.rs rust/kernel/pci/io.rs+0 -730 replies
6/6rust: io: remove overloaded Io methods of Mmiorust/kernel/io.rs+0 -1610 replies

Reviews trailers per patch

All 6 patches have a Reviewed-by or Acked-by of their own; the series has one for all of them.

PatchDaniel AlmeidaAlice RyhlGary Guo
SeriesR-b
1/6R-b A-b
2/6R-b A-b
3/6R-b A-b
4/6R-b A-b
5/6R-b A-b
6/6R-b A-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 3 reviewers.

Read the v2 thread

Cover letter [PATCH v2 0/6] rust: io: turn IoCapable into a functional trait

IoCapable<T> is currently used as a marker trait to signal that the methods of the Io trait corresponding to T have been overridden by the implementor (the default implementations triggering a build-time error).

This goes against the DRY principle and separates the signaling of the capability from its implementation, making it possible to forget a step while implementing a new Io.

Another undesirable side-effect is that it makes the implementation of I/O backends boilerplate-y and convoluted: currently this is done using two levels of imbricated macros that generate unsafe code.

This patchset fixes these issues by turning IoCapable into a functional trait including the raw implementation of the I/O accessors for T using unsafe methods that work with an arbitrary address, and making the default methods of Io call into these implementations after checking the bounds.

This makes overriding these accessors on all I/O backends unneeded, resulting in a net -90 LoCs while avoiding a violation of the DRY principle and reducing (and simplifying) the use of macros generating unsafe code.

Patch 1 adds the io_read and io_write unsafe methods to IoCapable, provides the required implementations for Mmio and pci::ConfigSpace, and make the default I/O accessors of Io call into them instead of failing.

Patches 2 to 4 get rid of the _relaxed variants we had in Mmio, since these are not usable in code generic against Io and makes use of the macros we want to remove. They are replaced by a RelaxedMmio wrapper type that implements the required IoCapables and is thus usable in generic code.

Patches 5 and 6 remove the overloaded implementations of the Io methods for pci::ConfigSpace and Mmio, respectively, while also deleting the macros that have become unused.

There is more work coming on top of this patchset (notably the register! macro with proper I/O), but I wanted to send this work first as it stands on its own IMHO and is more digestible from a review perspective.

The base for this patchset is driver-core-testing.

Cc Zhi Wang <[email protected]>
Cc Lyude Paul <[email protected]>
Cc Eliot Courtney <[email protected]>

---
Changes in v2:
- Turn RelaxedMmio into an actual wrapper type and make it available through a Mmio::relaxed() method.
- Link to v1: https://patch.msgid.link/[email protected]

---
Alexandre Courbot (6):
rust: io: turn IoCapable into a functional trait
rust: io: mem: use non-relaxed I/O ops in examples
rust: io: provide Mmio relaxed ops through a wrapper type
rust: io: remove legacy relaxed accessors of Mmio
rust: pci: io: remove overloaded Io methods of ConfigSpace
rust: io: remove overloaded Io methods of Mmio

 rust/kernel/io.rs     | 435 ++++++++++++++++++++++----------------------------
 rust/kernel/io/mem.rs |  10 +-
 rust/kernel/pci/io.rs |  99 ++++--------
 3 files changed, 227 insertions(+), 317 deletions(-)

---
base-commit: f55ae0bfa00e446ea751d09f468daeafc303e03f
change-id: 20260202-io-81fd368f7565

Best regards,

Signature · 1 line
Alexandre Courbot <[email protected]>