[PATCH v6 0/1] Rust PCI capability infrastructure and SR-IOV support

From: Zhi Wang

Date: Thu Jul 30 2026 - 15:17:05 EST


This is a follow-up to v5 [8], reworked to address the Sashiko review
[9]. This version is based on drm-rust-next.

This patch has been used in the Boot GSP with vGPU enabled series [6].

The patch defines an ExtCapability trait that associates an extended
capability ID with its register layout. The generic
ConfigSpace::find_ext_capability() finder locates the capability, bounds
it at the next capability or the end of extended configuration space,
and projects the ConfigSpace view to the requested layout. This lets the
existing I/O projection and access macros operate on capability registers.

ExtSriovRegs provides the SR-IOV register layout.
ConfigSpace::read_vf_bar() decodes a VF memory BAR into ExtSriovVfBar,
which exposes its address and 64-bit status, plus the configuration-space
slot of the next logical BAR. ExtSriovCapability remains as a convenience
alias.

Changes since v5:
- Removed the unused ConfigSpace<Region<0>> offset() and size() inherent
methods; ConfigSpace already provides size through the Io trait.
(Sashiko, Zhi)
- Removed the doctest write to the SR-IOV NumVFs register, avoiding an
example that bypasses PCI core SR-IOV state management. (Sashiko)
- Corrected Function Dependency Link to an 8-bit field followed by its
reserved byte, matching the PCIe SR-IOV register layout. (Sashiko)

Changes since v4:
- Replaced the separate is_vf_bar_64bit() and read_vf_bar64() helpers
with read_vf_bar(), returning a decoded ExtSriovVfBar. (Zhi)
- Moved memory BAR attribute stripping into the PCI abstraction and used
named PCI attribute definitions rather than an open-coded mask. (Zhi)
- Exposed the next logical BAR slot so callers can walk mixed 32-bit and
64-bit VF BAR layouts without duplicating slot arithmetic. (Zhi)
- Updated the doctest and PCI exports for the decoded BAR API. (Zhi)

Changes since v3:
- Replaced the custom ExtCapability<T> I/O wrapper with the existing
ConfigSpace view infrastructure. (Alex)
- Reused ExtCapability as a trait carrying the capability ID, and made
ConfigSpace::find_ext_capability() generic over register layouts.
(Alex)
- Removed public cast_sized() and unused find_next_ext_capability().
(Alex)
- Kept capability construction in the generic finder and documented
calculate_ext_cap_size(). (Alex)
- Used PCI_SRIOV_NUM_BARS rather than a literal VF BAR count.
(Alex, Zhi)
- Added is_vf_bar_64bit() and made read_vf_bar64() reject BARs that are
not 64-bit memory BARs. (Alex, Zhi)
- Kept indexed VF BAR helpers because the Nova user accesses fixed BAR
slots rather than iterating over them. (Alex)
- Adapted the implementation and doctest to the current ConfigSpace I/O
APIs. (Zhi)

Changes since RFC v2:
- Hardened calculate_ext_cap_size() against corrupt capability lists.
(Zhi)
- Added // INVARIANT: comments at all ExtCapability construction sites
(make_ext_capability and cast_sized). (Zhi)
- Added #[inline] to small forwarding methods (find, read_vf_bar64).
(Zhi)

Changes since RFC:
- Rebased on io_projection branch, using Gary's Io/IoCapable traits.
(Gary)
- ExtCapability implements Io and delegates IoCapable to ConfigSpace
instead of duplicating config read/write logic. (Gary)
- Dropped the fallible I/O patch (now upstream in this tree). (Zhi)
- Added Rust helper for PCI_EXT_CAP_NEXT() macro. (Zhi)
- Replaced raw `as` casts with From conversions where possible. (Zhi)
- Renamed SriovRegs/SriovCapability to ExtSriovRegs/ExtSriovCapability.
(Zhi)

[1] https://lore.kernel.org/rust-for-linux/20260409185254.3869808-1-zhiw@xxxxxxxxxx/
[2] https://lore.kernel.org/rust-for-linux/DHRTUAF52GNI.1J98TSAG1LS6Q@xxxxxxxxxx/
[3] https://lore.kernel.org/rust-for-linux/DI2SL4G5INLY.2W1IFTR081ID3@xxxxxxxxxx/
[4] https://lore.kernel.org/rust-for-linux/20260225180449.1813833-1-zhiw@xxxxxxxxxx/
[5] https://lore.kernel.org/rust-for-linux/20260323153807.1360705-1-gary@xxxxxxxxxx/
[6] https://lore.kernel.org/rust-for-linux/20260313165336.935771-1-zhiw@xxxxxxxxxx/
[7] https://lore.kernel.org/rust-for-linux/20260714165827.2937960-1-zhiw@xxxxxxxxxx/
[8] https://lore.kernel.org/rust-for-linux/20260730180349.771719-1-zhiw@xxxxxxxxxx/
[9] https://sashiko.dev/#/patchset/20260730180349.771719-2-zhiw@xxxxxxxxxx?part=1

Zhi Wang (1):
rust: pci: add extended capability and SR-IOV support

rust/helpers/pci.c | 5 +
rust/kernel/pci.rs | 8 ++
rust/kernel/pci/cap.rs | 236 +++++++++++++++++++++++++++++++++++++++++
3 files changed, 249 insertions(+)
create mode 100644 rust/kernel/pci/cap.rs


base-commit: 93b9511a3bba7f31d95502e5f912f0a476b0cf4a
--
2.53.0