* [PATCH v5 0/2] rust: pci: add capability lookup helpers
@ 2026-02-01 7:42 Zijing Zhang
2026-02-01 7:42 ` [PATCH v5 1/2] " Zijing Zhang
` (3 more replies)
0 siblings, 4 replies; 8+ messages in thread
From: Zijing Zhang @ 2026-02-01 7:42 UTC (permalink / raw)
To: dakr, linux-pci, rust-for-linux
Cc: bhelgaas, kwilczynski, ojeda, gary, dirk.behme, lianux.mm,
Zijing Zhang
It introduces `pci::Device::{find_capability, find_ext_capability}`, thin
wrappers around the PCI core helpers (`pci_find_capability()` and
`pci_find_ext_capability()`), returning the config-space offset when present.
In `pci::CapabilityId` and `pci::ExtendedCapabilityId`, Capability IDs are
wrapped as newtypes with `from_raw()` plus a set of common constants.
An in-tree user is added to Rust PCI driver sample to exercise the new API.
Previous versions (v4)
https://lore.kernel.org/rust-for-linux/20260201071450.1614172-1-zijing.zhang@ry.rs/
Testing
---
Build
- x86_64 defconfig-based kernel with Rust enabled (out-of-tree build)
- `CONFIG_SAMPLES_RUST=y`
- `CONFIG_SAMPLE_RUST_DRIVER_PCI=y`
Runtime
- QEMU x86_64 (i440FX) with `-device pci-testdev`
- QEMU x86_64 (q35) with an NVMe device
Changelog
---
v2
- Run rustfmt on samples/rust/rust_driver_pci.rs to fix rustfmtcheck.
v3
- Base on pci/next.
- Add `CapabilityId`/`ExtendedCapabilityId`, switch `find_*capability()`
to use them.
- Document the common ID constants.
- Update the sample to use typed IDs and exercise the new helpers.
v4
- Minor doc/style nits.
- Use early-return style in `find_*capability()`.
v5 (current)
- Fix sample build by using `pdev.as_ref()` for `dev_info!`.
- Use `as _` in constant definitions.
Zijing Zhang (2):
rust: pci: add capability lookup helpers
samples: rust: pci: exercise capability lookup
rust/kernel/pci.rs | 150 ++++++++++++++++++++++++++++++++
samples/rust/rust_driver_pci.rs | 31 +++++++
2 files changed, 181 insertions(+)
base-commit: ff0e2f679ab0de50a2e9e88fabc1026bc3be04ba
--
2.52.0
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v5 1/2] rust: pci: add capability lookup helpers
2026-02-01 7:42 [PATCH v5 0/2] rust: pci: add capability lookup helpers Zijing Zhang
@ 2026-02-01 7:42 ` Zijing Zhang
2026-02-01 7:42 ` [PATCH v5 2/2] samples: rust: pci: exercise capability lookup Zijing Zhang
` (2 subsequent siblings)
3 siblings, 0 replies; 8+ messages in thread
From: Zijing Zhang @ 2026-02-01 7:42 UTC (permalink / raw)
To: dakr, linux-pci, rust-for-linux
Cc: bhelgaas, kwilczynski, ojeda, gary, dirk.behme, lianux.mm,
Zijing Zhang
Add thin wrappers around `pci_find_capability()` and
`pci_find_ext_capability()`.
The helpers return the capability offset in config space, or `None` if the
capability is not present.
Introduce `CapabilityId` and `ExtendedCapabilityId` newtypes so drivers can
use named constants without importing raw bindgen constants, while still
allowing uncommon IDs via `from_raw()`.
Signed-off-by: Zijing Zhang <zijing.zhang@ry.rs>
---
rust/kernel/pci.rs | 150 +++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 150 insertions(+)
diff --git a/rust/kernel/pci.rs b/rust/kernel/pci.rs
index 82e128431f08..d1ce64078a51 100644
--- a/rust/kernel/pci.rs
+++ b/rust/kernel/pci.rs
@@ -41,6 +41,119 @@
Vendor, //
};
pub use self::io::Bar;
+
+/// A standard PCI capability ID.
+///
+/// This is a thin wrapper around the underlying numeric capability ID.
+#[repr(transparent)]
+#[derive(Clone, Copy, Debug, Eq, PartialEq)]
+pub struct CapabilityId(u8);
+
+impl CapabilityId {
+ /// Creates a [`CapabilityId`] from a raw value.
+ #[inline]
+ pub const fn from_raw(id: u8) -> Self {
+ Self(id)
+ }
+
+ /// Returns the raw value.
+ #[inline]
+ pub const fn as_raw(self) -> u8 {
+ self.0
+ }
+
+ /// Power Management.
+ pub const PM: Self = Self(bindings::PCI_CAP_ID_PM as _);
+ /// Accelerated Graphics Port.
+ pub const AGP: Self = Self(bindings::PCI_CAP_ID_AGP as _);
+ /// Vital Product Data.
+ pub const VPD: Self = Self(bindings::PCI_CAP_ID_VPD as _);
+ /// Slot Identification.
+ pub const SLOTID: Self = Self(bindings::PCI_CAP_ID_SLOTID as _);
+ /// Message Signalled Interrupts.
+ pub const MSI: Self = Self(bindings::PCI_CAP_ID_MSI as _);
+ /// CompactPCI HotSwap.
+ pub const CHSWP: Self = Self(bindings::PCI_CAP_ID_CHSWP as _);
+ /// PCI-X.
+ pub const PCIX: Self = Self(bindings::PCI_CAP_ID_PCIX as _);
+ /// HyperTransport.
+ pub const HT: Self = Self(bindings::PCI_CAP_ID_HT as _);
+ /// Vendor-Specific.
+ pub const VNDR: Self = Self(bindings::PCI_CAP_ID_VNDR as _);
+ /// Debug port.
+ pub const DBG: Self = Self(bindings::PCI_CAP_ID_DBG as _);
+ /// CompactPCI Central Resource Control.
+ pub const CCRC: Self = Self(bindings::PCI_CAP_ID_CCRC as _);
+ /// PCI Standard Hot-Plug Controller.
+ pub const SHPC: Self = Self(bindings::PCI_CAP_ID_SHPC as _);
+ /// Bridge subsystem vendor/device ID.
+ pub const SSVID: Self = Self(bindings::PCI_CAP_ID_SSVID as _);
+ /// AGP 8x.
+ pub const AGP3: Self = Self(bindings::PCI_CAP_ID_AGP3 as _);
+ /// Secure Device.
+ pub const SECDEV: Self = Self(bindings::PCI_CAP_ID_SECDEV as _);
+ /// PCI Express.
+ pub const EXP: Self = Self(bindings::PCI_CAP_ID_EXP as _);
+ /// MSI-X.
+ pub const MSIX: Self = Self(bindings::PCI_CAP_ID_MSIX as _);
+ /// Serial ATA Data/Index Configuration.
+ pub const SATA: Self = Self(bindings::PCI_CAP_ID_SATA as _);
+ /// PCI Advanced Features.
+ pub const AF: Self = Self(bindings::PCI_CAP_ID_AF as _);
+ /// PCI Enhanced Allocation.
+ pub const EA: Self = Self(bindings::PCI_CAP_ID_EA as _);
+}
+
+/// A PCIe extended capability ID.
+///
+/// This is a thin wrapper around the underlying numeric capability ID.
+#[repr(transparent)]
+#[derive(Clone, Copy, Debug, Eq, PartialEq)]
+pub struct ExtendedCapabilityId(u16);
+
+impl ExtendedCapabilityId {
+ /// Creates an [`ExtendedCapabilityId`] from a raw value.
+ #[inline]
+ pub const fn from_raw(id: u16) -> Self {
+ Self(id)
+ }
+
+ /// Returns the raw value.
+ #[inline]
+ pub const fn as_raw(self) -> u16 {
+ self.0
+ }
+
+ /// Advanced Error Reporting.
+ pub const ERR: Self = Self(bindings::PCI_EXT_CAP_ID_ERR as _);
+ /// Virtual Channel.
+ pub const VC: Self = Self(bindings::PCI_EXT_CAP_ID_VC as _);
+ /// Device Serial Number.
+ pub const DSN: Self = Self(bindings::PCI_EXT_CAP_ID_DSN as _);
+ /// Vendor-Specific Extended Capability.
+ pub const VNDR: Self = Self(bindings::PCI_EXT_CAP_ID_VNDR as _);
+ /// Access Control Services.
+ pub const ACS: Self = Self(bindings::PCI_EXT_CAP_ID_ACS as _);
+ /// Alternate Routing-ID Interpretation.
+ pub const ARI: Self = Self(bindings::PCI_EXT_CAP_ID_ARI as _);
+ /// Address Translation Services.
+ pub const ATS: Self = Self(bindings::PCI_EXT_CAP_ID_ATS as _);
+ /// Single Root I/O Virtualization.
+ pub const SRIOV: Self = Self(bindings::PCI_EXT_CAP_ID_SRIOV as _);
+ /// Resizable BAR.
+ pub const REBAR: Self = Self(bindings::PCI_EXT_CAP_ID_REBAR as _);
+ /// Latency Tolerance Reporting.
+ pub const LTR: Self = Self(bindings::PCI_EXT_CAP_ID_LTR as _);
+ /// Downstream Port Containment.
+ pub const DPC: Self = Self(bindings::PCI_EXT_CAP_ID_DPC as _);
+ /// L1 PM Substates.
+ pub const L1SS: Self = Self(bindings::PCI_EXT_CAP_ID_L1SS as _);
+ /// Precision Time Measurement.
+ pub const PTM: Self = Self(bindings::PCI_EXT_CAP_ID_PTM as _);
+ /// Designated Vendor-Specific Extended Capability.
+ pub const DVSEC: Self = Self(bindings::PCI_EXT_CAP_ID_DVSEC as _);
+}
+
pub use self::irq::{
IrqType,
IrqTypes,
@@ -427,6 +540,43 @@ pub fn pci_class(&self) -> Class {
// SAFETY: `self.as_raw` is a valid pointer to a `struct pci_dev`.
Class::from_raw(unsafe { (*self.as_raw()).class })
}
+
+ /// Finds a PCI capability by ID and returns its config-space offset.
+ ///
+ /// Returns `None` if the capability is not present.
+ ///
+ /// This is a thin wrapper around `pci_find_capability()`.
+ #[inline]
+ pub fn find_capability(&self, id: CapabilityId) -> Option<u8> {
+ // SAFETY: By its type invariant `self.as_raw` is always a valid pointer to a
+ // `struct pci_dev`.
+ let offset = unsafe { bindings::pci_find_capability(self.as_raw(), id.as_raw().into()) };
+
+ if offset == 0 {
+ return None;
+ }
+
+ Some(offset)
+ }
+
+ /// Finds an extended capability by ID and returns its config-space offset.
+ ///
+ /// Returns `None` if the capability is not present.
+ ///
+ /// This is a thin wrapper around `pci_find_ext_capability()`.
+ #[inline]
+ pub fn find_ext_capability(&self, id: ExtendedCapabilityId) -> Option<u16> {
+ // SAFETY: By its type invariant `self.as_raw` is always a valid pointer to a
+ // `struct pci_dev`.
+ let offset =
+ unsafe { bindings::pci_find_ext_capability(self.as_raw(), id.as_raw().into()) };
+
+ if offset == 0 {
+ return None;
+ }
+
+ Some(offset)
+ }
}
impl Device<device::Core> {
--
2.52.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH v5 2/2] samples: rust: pci: exercise capability lookup
2026-02-01 7:42 [PATCH v5 0/2] rust: pci: add capability lookup helpers Zijing Zhang
2026-02-01 7:42 ` [PATCH v5 1/2] " Zijing Zhang
@ 2026-02-01 7:42 ` Zijing Zhang
2026-02-02 14:13 ` [PATCH v5 0/2] rust: pci: add capability lookup helpers Gary Guo
2026-02-02 15:02 ` Gary Guo
3 siblings, 0 replies; 8+ messages in thread
From: Zijing Zhang @ 2026-02-01 7:42 UTC (permalink / raw)
To: dakr, linux-pci, rust-for-linux
Cc: bhelgaas, kwilczynski, ojeda, gary, dirk.behme, lianux.mm,
Zijing Zhang
Use the new `pci::Device` capability helpers to locate a few common
capabilities (standard and extended).
Also try a best-effort self-check to exercise the `Some(offset)` path
when the device advertises a standard capability list or an ext-cap header.
Signed-off-by: Zijing Zhang <zijing.zhang@ry.rs>
---
samples/rust/rust_driver_pci.rs | 31 +++++++++++++++++++++++++++++++
1 file changed, 31 insertions(+)
diff --git a/samples/rust/rust_driver_pci.rs b/samples/rust/rust_driver_pci.rs
index 5823787bea8e..aea7d5cbe421 100644
--- a/samples/rust/rust_driver_pci.rs
+++ b/samples/rust/rust_driver_pci.rs
@@ -58,6 +58,35 @@ fn testdev(index: &TestIndex, bar: &Bar0) -> Result<u32> {
Ok(bar.read32(Regs::COUNT))
}
+
+ fn log_capabilities(pdev: &pci::Device<Core>) {
+ for (name, id) in [
+ ("PM", pci::CapabilityId::PM),
+ ("MSI", pci::CapabilityId::MSI),
+ ("PCIe", pci::CapabilityId::EXP),
+ ] {
+ if let Some(pos) = pdev.find_capability(id) {
+ dev_info!(pdev.as_ref(), "pci-testdev {name} cap @ 0x{:02x}\n", pos);
+ } else {
+ dev_info!(pdev.as_ref(), "pci-testdev has no {name} capability\n");
+ }
+ }
+
+ for (name, id) in [
+ ("DSN", pci::ExtendedCapabilityId::DSN),
+ ("SR-IOV", pci::ExtendedCapabilityId::SRIOV),
+ ] {
+ if let Some(pos) = pdev.find_ext_capability(id) {
+ dev_info!(
+ pdev.as_ref(),
+ "pci-testdev {name} ext cap @ 0x{:04x}\n",
+ pos
+ );
+ } else {
+ dev_info!(pdev.as_ref(), "pci-testdev has no {name} ext capability\n");
+ }
+ }
+ }
}
impl pci::Driver for SampleDriver {
@@ -89,6 +118,8 @@ fn probe(pdev: &pci::Device<Core>, info: &Self::IdInfo) -> impl PinInit<Self, Er
"pci-testdev data-match count: {}\n",
Self::testdev(info, bar)?
);
+
+ Self::log_capabilities(pdev);
},
pdev: pdev.into(),
}))
--
2.52.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH v5 0/2] rust: pci: add capability lookup helpers
2026-02-01 7:42 [PATCH v5 0/2] rust: pci: add capability lookup helpers Zijing Zhang
2026-02-01 7:42 ` [PATCH v5 1/2] " Zijing Zhang
2026-02-01 7:42 ` [PATCH v5 2/2] samples: rust: pci: exercise capability lookup Zijing Zhang
@ 2026-02-02 14:13 ` Gary Guo
2026-02-02 15:02 ` Gary Guo
3 siblings, 0 replies; 8+ messages in thread
From: Gary Guo @ 2026-02-02 14:13 UTC (permalink / raw)
To: Zijing Zhang, dakr, linux-pci, rust-for-linux
Cc: bhelgaas, kwilczynski, ojeda, gary, dirk.behme, lianux.mm
On Sun Feb 1, 2026 at 7:42 AM GMT, Zijing Zhang wrote:
> It introduces `pci::Device::{find_capability, find_ext_capability}`, thin
> wrappers around the PCI core helpers (`pci_find_capability()` and
> `pci_find_ext_capability()`), returning the config-space offset when present.
>
> In `pci::CapabilityId` and `pci::ExtendedCapabilityId`, Capability IDs are
> wrapped as newtypes with `from_raw()` plus a set of common constants.
>
> An in-tree user is added to Rust PCI driver sample to exercise the new API.
>
> Previous versions (v4)
> https://lore.kernel.org/rust-for-linux/20260201071450.1614172-1-zijing.zhang@ry.rs/
Hi Zijing,
Please give people enough time to review your patch and provide feedbacks before
sending out a new version.
Sending out 5 versions during a weekend is excessive.
Thanks,
Gary
>
> Testing
> ---
>
> Build
> - x86_64 defconfig-based kernel with Rust enabled (out-of-tree build)
> - `CONFIG_SAMPLES_RUST=y`
> - `CONFIG_SAMPLE_RUST_DRIVER_PCI=y`
>
> Runtime
> - QEMU x86_64 (i440FX) with `-device pci-testdev`
> - QEMU x86_64 (q35) with an NVMe device
>
> Changelog
> ---
>
> v2
> - Run rustfmt on samples/rust/rust_driver_pci.rs to fix rustfmtcheck.
>
> v3
> - Base on pci/next.
> - Add `CapabilityId`/`ExtendedCapabilityId`, switch `find_*capability()`
> to use them.
> - Document the common ID constants.
> - Update the sample to use typed IDs and exercise the new helpers.
>
> v4
> - Minor doc/style nits.
> - Use early-return style in `find_*capability()`.
>
>
> v5 (current)
> - Fix sample build by using `pdev.as_ref()` for `dev_info!`.
> - Use `as _` in constant definitions.
>
> Zijing Zhang (2):
> rust: pci: add capability lookup helpers
> samples: rust: pci: exercise capability lookup
>
> rust/kernel/pci.rs | 150 ++++++++++++++++++++++++++++++++
> samples/rust/rust_driver_pci.rs | 31 +++++++
> 2 files changed, 181 insertions(+)
>
>
> base-commit: ff0e2f679ab0de50a2e9e88fabc1026bc3be04ba
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v5 0/2] rust: pci: add capability lookup helpers
2026-02-01 7:42 [PATCH v5 0/2] rust: pci: add capability lookup helpers Zijing Zhang
` (2 preceding siblings ...)
2026-02-02 14:13 ` [PATCH v5 0/2] rust: pci: add capability lookup helpers Gary Guo
@ 2026-02-02 15:02 ` Gary Guo
2026-02-02 15:41 ` Zijing Zhang
3 siblings, 1 reply; 8+ messages in thread
From: Gary Guo @ 2026-02-02 15:02 UTC (permalink / raw)
To: Zijing Zhang, dakr, linux-pci, rust-for-linux
Cc: bhelgaas, kwilczynski, ojeda, gary, dirk.behme, lianux.mm
On Sun Feb 1, 2026 at 7:42 AM GMT, Zijing Zhang wrote:
> It introduces `pci::Device::{find_capability, find_ext_capability}`, thin
> wrappers around the PCI core helpers (`pci_find_capability()` and
> `pci_find_ext_capability()`), returning the config-space offset when present.
>
> In `pci::CapabilityId` and `pci::ExtendedCapabilityId`, Capability IDs are
> wrapped as newtypes with `from_raw()` plus a set of common constants.
>
> An in-tree user is added to Rust PCI driver sample to exercise the new API.
>
> Previous versions (v4)
> https://lore.kernel.org/rust-for-linux/20260201071450.1614172-1-zijing.zhang@ry.rs/
Also I'd like to mention that Zhi Wang already have a version adding the same
feature on the list, sent before your v1:
https://lore.kernel.org/rust-for-linux/20260126215957.541180-3-zhiw@nvidia.com/
I'd recommend to work together for the feature rather than creating competing
series.
Thanks,
Gary
>
> Testing
> ---
>
> Build
> - x86_64 defconfig-based kernel with Rust enabled (out-of-tree build)
> - `CONFIG_SAMPLES_RUST=y`
> - `CONFIG_SAMPLE_RUST_DRIVER_PCI=y`
>
> Runtime
> - QEMU x86_64 (i440FX) with `-device pci-testdev`
> - QEMU x86_64 (q35) with an NVMe device
>
> Changelog
> ---
>
> v2
> - Run rustfmt on samples/rust/rust_driver_pci.rs to fix rustfmtcheck.
>
> v3
> - Base on pci/next.
> - Add `CapabilityId`/`ExtendedCapabilityId`, switch `find_*capability()`
> to use them.
> - Document the common ID constants.
> - Update the sample to use typed IDs and exercise the new helpers.
>
> v4
> - Minor doc/style nits.
> - Use early-return style in `find_*capability()`.
>
>
> v5 (current)
> - Fix sample build by using `pdev.as_ref()` for `dev_info!`.
> - Use `as _` in constant definitions.
>
> Zijing Zhang (2):
> rust: pci: add capability lookup helpers
> samples: rust: pci: exercise capability lookup
>
> rust/kernel/pci.rs | 150 ++++++++++++++++++++++++++++++++
> samples/rust/rust_driver_pci.rs | 31 +++++++
> 2 files changed, 181 insertions(+)
>
>
> base-commit: ff0e2f679ab0de50a2e9e88fabc1026bc3be04ba
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v5 0/2] rust: pci: add capability lookup helpers
2026-02-02 15:02 ` Gary Guo
@ 2026-02-02 15:41 ` Zijing Zhang
2026-02-02 19:57 ` Zhi Wang
0 siblings, 1 reply; 8+ messages in thread
From: Zijing Zhang @ 2026-02-02 15:41 UTC (permalink / raw)
To: Gary Guo, dakr, linux-pci, rust-for-linux
Cc: bhelgaas, kwilczynski, ojeda, dirk.behme, lianux.mm, zhiw
On 2/2/2026 11:02 PM, Gary Guo wrote:
> On Sun Feb 1, 2026 at 7:42 AM GMT, Zijing Zhang wrote:
>> It introduces `pci::Device::{find_capability, find_ext_capability}`, thin
>> wrappers around the PCI core helpers (`pci_find_capability()` and
>> `pci_find_ext_capability()`), returning the config-space offset when present.
>>
>> In `pci::CapabilityId` and `pci::ExtendedCapabilityId`, Capability IDs are
>> wrapped as newtypes with `from_raw()` plus a set of common constants.
>>
>> An in-tree user is added to Rust PCI driver sample to exercise the new API.
>>
>> Previous versions (v4)
>> https://lore.kernel.org/rust-for-linux/20260201071450.1614172-1-zijing.zhang@ry.rs/
>
> Also I'd like to mention that Zhi Wang already have a version adding the same
> feature on the list, sent before your v1:
>
> https://lore.kernel.org/rust-for-linux/20260126215957.541180-3-zhiw@nvidia.com/
>
> I'd recommend to work together for the feature rather than creating competing
> series.
>
> Thanks,
> Gary
>
>>
>> Testing
>> ---
>>
>> Build
>> - x86_64 defconfig-based kernel with Rust enabled (out-of-tree build)
>> - `CONFIG_SAMPLES_RUST=y`
>> - `CONFIG_SAMPLE_RUST_DRIVER_PCI=y`
>>
>> Runtime
>> - QEMU x86_64 (i440FX) with `-device pci-testdev`
>> - QEMU x86_64 (q35) with an NVMe device
>>
>> Changelog
>> ---
>>
>> v2
>> - Run rustfmt on samples/rust/rust_driver_pci.rs to fix rustfmtcheck.
>>
>> v3
>> - Base on pci/next.
>> - Add `CapabilityId`/`ExtendedCapabilityId`, switch `find_*capability()`
>> to use them.
>> - Document the common ID constants.
>> - Update the sample to use typed IDs and exercise the new helpers.
>>
>> v4
>> - Minor doc/style nits.
>> - Use early-return style in `find_*capability()`.
>>
>>
>> v5 (current)
>> - Fix sample build by using `pdev.as_ref()` for `dev_info!`.
>> - Use `as _` in constant definitions.
>>
>> Zijing Zhang (2):
>> rust: pci: add capability lookup helpers
>> samples: rust: pci: exercise capability lookup
>>
>> rust/kernel/pci.rs | 150 ++++++++++++++++++++++++++++++++
>> samples/rust/rust_driver_pci.rs | 31 +++++++
>> 2 files changed, 181 insertions(+)
>>
>>
>> base-commit: ff0e2f679ab0de50a2e9e88fabc1026bc3be04ba
>
On 2/2/2026 11:02 PM, Gary Guo wrote:
> On Sun Feb 1, 2026 at 7:42 AM GMT, Zijing Zhang wrote:
>> It introduces `pci::Device::{find_capability, find_ext_capability}`,
thin
>> wrappers around the PCI core helpers (`pci_find_capability()` and
>> `pci_find_ext_capability()`), returning the config-space offset when
present.
>>
>> In `pci::CapabilityId` and `pci::ExtendedCapabilityId`, Capability
IDs are
>> wrapped as newtypes with `from_raw()` plus a set of common constants.
>>
>> An in-tree user is added to Rust PCI driver sample to exercise the
new API.
>>
>> Previous versions (v4)
>>
https://lore.kernel.org/rust-for-linux/20260201071450.1614172-1-zijing.zhang@ry.rs/
>
> Also I'd like to mention that Zhi Wang already have a version adding
the same
> feature on the list, sent before your v1:
>
>
https://lore.kernel.org/rust-for-linux/20260126215957.541180-3-zhiw@nvidia.com/
>
> I'd recommend to work together for the feature rather than creating
competing
> series.
>
> Thanks,
> Gary
>
>>
>> Testing
>> ---
>>
>> Build
>> - x86_64 defconfig-based kernel with Rust enabled (out-of-tree build)
>> - `CONFIG_SAMPLES_RUST=y`
>> - `CONFIG_SAMPLE_RUST_DRIVER_PCI=y`
>>
>> Runtime
>> - QEMU x86_64 (i440FX) with `-device pci-testdev`
>> - QEMU x86_64 (q35) with an NVMe device
>>
>> Changelog
>> ---
>>
>> v2
>> - Run rustfmt on samples/rust/rust_driver_pci.rs to fix rustfmtcheck.
>>
>> v3
>> - Base on pci/next.
>> - Add `CapabilityId`/`ExtendedCapabilityId`, switch `find_*capability()`
>> to use them.
>> - Document the common ID constants.
>> - Update the sample to use typed IDs and exercise the new helpers.
>>
>> v4
>> - Minor doc/style nits.
>> - Use early-return style in `find_*capability()`.
>>
>>
>> v5 (current)
>> - Fix sample build by using `pdev.as_ref()` for `dev_info!`.
>> - Use `as _` in constant definitions.
>>
>> Zijing Zhang (2):
>> rust: pci: add capability lookup helpers
>> samples: rust: pci: exercise capability lookup
>>
>> rust/kernel/pci.rs | 150 ++++++++++++++++++++++++++++++++
>> samples/rust/rust_driver_pci.rs | 31 +++++++
>> 2 files changed, 181 insertions(+)
>>
>>
>> base-commit: ff0e2f679ab0de50a2e9e88fabc1026bc3be04ba
>
Hi Gary and all,
Thanks for the feedback.
Zhi's work on SR-IOV is excellent and provides a higher-level
abstraction. My series focuses on providing the fundamental lookup
infrastructure and typed IDs, which are intended to serve as a
general-purpose foundation for any PCI capability interaction.
These two series appear to be complementary. I am open to any
integration path the maintainers prefer and would welcome Zhi's thoughts
on how we might best align these efforts.
As a newcomer to the community, I am passionate about Rust PCI driver
development and appreciate Gary's diligence in maintaining the
subsystem's quality. I've taken note of the feedback regarding the patch
frequency and will ensure to allow more time for review in future
iterations.
Thanks,
Zijing
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v5 0/2] rust: pci: add capability lookup helpers
2026-02-02 15:41 ` Zijing Zhang
@ 2026-02-02 19:57 ` Zhi Wang
2026-02-03 5:42 ` Zijing Zhang
0 siblings, 1 reply; 8+ messages in thread
From: Zhi Wang @ 2026-02-02 19:57 UTC (permalink / raw)
To: Zijing Zhang
Cc: Gary Guo, dakr, linux-pci, rust-for-linux, bhelgaas, kwilczynski,
ojeda, dirk.behme, lianux.mm
On Mon, 2 Feb 2026 23:41:42 +0800
Zijing Zhang <zijing.zhang@ry.rs> wrote:
>
>
Hi Zijing,
Good to see you working on this too! Welcome to join the party!
I think "thin wrappers" were indeed the initial thought for many of us.
However, after several rounds of discussions with maintainers at the
summits, the requirement has shifted towards a stricter, OO-style Rust
abstraction rather than direct wrappers.
The key takeaways for the current direction are:
- Enforcing boundary checks via the Io trait backend.
- Using register! macros for definitions.
- Implementing proper Rust iterators for Cap discovery.
Since nova-core relies on these specific safety features, I'm pushing
forward with this high-level abstraction. For nova-core, our immediate
need is accessing and reading registers in the SR-IOV capability.
That said, there is plenty of room for collaboration to achieve a complete
framework! For example, support for normal configuration space
capabilities, the iterator implementation itself, and capabilities other
than SR-IOV are all areas that need work.
Currently, I am waiting for Alex's Io trait cleanup and refactor to settle
before deciding what should be included or changed in my next re-spin.
Also, any input on how to best organize the traits between normal
configuration space caps and extended caps would be much appreciated!
You are also welcome to reach out via Zulip for a quick discussion or
catch-up.
Z.
> On 2/2/2026 11:02 PM, Gary Guo wrote:
> > On Sun Feb 1, 2026 at 7:42 AM GMT, Zijing Zhang wrote:
> >> It introduces `pci::Device::{find_capability, find_ext_capability}`,
> >> thin wrappers around the PCI core helpers (`pci_find_capability()` and
> >> `pci_find_ext_capability()`), returning the config-space offset when
> >> present.
> >>
> >> In `pci::CapabilityId` and `pci::ExtendedCapabilityId`, Capability
> >> IDs are wrapped as newtypes with `from_raw()` plus a set of common
> >> constants.
> >>
> >> An in-tree user is added to Rust PCI driver sample to exercise the
> >> new API.
> >>
> >> Previous versions (v4)
> >> https://lore.kernel.org/rust-for-linux/20260201071450.1614172-1-zijing.zhang@ry.rs/
> >
> > Also I'd like to mention that Zhi Wang already have a version adding
> > the same feature on the list, sent before your v1:
> >
> > https://lore.kernel.org/rust-for-linux/20260126215957.541180-3-zhiw@nvidia.com/
> >
> > I'd recommend to work together for the feature rather than creating
> > competing series.
> >
> > Thanks,
> > Gary
> >
> >>
> >> Testing
> >> ---
> >>
> >> Build
> >> - x86_64 defconfig-based kernel with Rust enabled (out-of-tree build)
> >> - `CONFIG_SAMPLES_RUST=y`
> >> - `CONFIG_SAMPLE_RUST_DRIVER_PCI=y`
> >>
> >> Runtime
> >> - QEMU x86_64 (i440FX) with `-device pci-testdev`
> >> - QEMU x86_64 (q35) with an NVMe device
> >>
> >> Changelog
> >> ---
> >>
> >> v2
> >> - Run rustfmt on samples/rust/rust_driver_pci.rs to fix rustfmtcheck.
> >>
> >> v3
> >> - Base on pci/next.
> >> - Add `CapabilityId`/`ExtendedCapabilityId`, switch
> >> `find_*capability()` to use them.
> >> - Document the common ID constants.
> >> - Update the sample to use typed IDs and exercise the new helpers.
> >>
> >> v4
> >> - Minor doc/style nits.
> >> - Use early-return style in `find_*capability()`.
> >>
> >>
> >> v5 (current)
> >> - Fix sample build by using `pdev.as_ref()` for `dev_info!`.
> >> - Use `as _` in constant definitions.
> >>
> >> Zijing Zhang (2):
> >> rust: pci: add capability lookup helpers
> >> samples: rust: pci: exercise capability lookup
> >>
> >> rust/kernel/pci.rs | 150
> >> ++++++++++++++++++++++++++++++++ samples/rust/rust_driver_pci.rs |
> >> 31 +++++++ 2 files changed, 181 insertions(+)
> >>
> >>
> >> base-commit: ff0e2f679ab0de50a2e9e88fabc1026bc3be04ba
> >
>
>
> On 2/2/2026 11:02 PM, Gary Guo wrote:
> > On Sun Feb 1, 2026 at 7:42 AM GMT, Zijing Zhang wrote:
> >> It introduces `pci::Device::{find_capability, find_ext_capability}`,
> thin
> >> wrappers around the PCI core helpers (`pci_find_capability()` and
> >> `pci_find_ext_capability()`), returning the config-space offset when
> present.
> >>
> >> In `pci::CapabilityId` and `pci::ExtendedCapabilityId`, Capability
> IDs are
> >> wrapped as newtypes with `from_raw()` plus a set of common constants.
> >>
> >> An in-tree user is added to Rust PCI driver sample to exercise the
> new API.
> >>
> >> Previous versions (v4)
> >>
> https://lore.kernel.org/rust-for-linux/20260201071450.1614172-1-zijing.zhang@ry.rs/
> >
> > Also I'd like to mention that Zhi Wang already have a version adding
> the same
> > feature on the list, sent before your v1:
> >
> >
> https://lore.kernel.org/rust-for-linux/20260126215957.541180-3-zhiw@nvidia.com/
> >
> > I'd recommend to work together for the feature rather than creating
> competing
> > series.
> >
> > Thanks,
> > Gary
> >
> >>
> >> Testing
> >> ---
> >>
> >> Build
> >> - x86_64 defconfig-based kernel with Rust enabled (out-of-tree build)
> >> - `CONFIG_SAMPLES_RUST=y`
> >> - `CONFIG_SAMPLE_RUST_DRIVER_PCI=y`
> >>
> >> Runtime
> >> - QEMU x86_64 (i440FX) with `-device pci-testdev`
> >> - QEMU x86_64 (q35) with an NVMe device
> >>
> >> Changelog
> >> ---
> >>
> >> v2
> >> - Run rustfmt on samples/rust/rust_driver_pci.rs to fix rustfmtcheck.
> >>
> >> v3
> >> - Base on pci/next.
> >> - Add `CapabilityId`/`ExtendedCapabilityId`, switch
> >> `find_*capability()` to use them.
> >> - Document the common ID constants.
> >> - Update the sample to use typed IDs and exercise the new helpers.
> >>
> >> v4
> >> - Minor doc/style nits.
> >> - Use early-return style in `find_*capability()`.
> >>
> >>
> >> v5 (current)
> >> - Fix sample build by using `pdev.as_ref()` for `dev_info!`.
> >> - Use `as _` in constant definitions.
> >>
> >> Zijing Zhang (2):
> >> rust: pci: add capability lookup helpers
> >> samples: rust: pci: exercise capability lookup
> >>
> >> rust/kernel/pci.rs | 150
> >> ++++++++++++++++++++++++++++++++ samples/rust/rust_driver_pci.rs |
> >> 31 +++++++ 2 files changed, 181 insertions(+)
> >>
> >>
> >> base-commit: ff0e2f679ab0de50a2e9e88fabc1026bc3be04ba
> >
>
> Hi Gary and all,
>
> Thanks for the feedback.
>
> Zhi's work on SR-IOV is excellent and provides a higher-level
> abstraction. My series focuses on providing the fundamental lookup
> infrastructure and typed IDs, which are intended to serve as a
> general-purpose foundation for any PCI capability interaction.
>
> These two series appear to be complementary. I am open to any
> integration path the maintainers prefer and would welcome Zhi's thoughts
> on how we might best align these efforts.
>
> As a newcomer to the community, I am passionate about Rust PCI driver
> development and appreciate Gary's diligence in maintaining the
> subsystem's quality. I've taken note of the feedback regarding the patch
> frequency and will ensure to allow more time for review in future
> iterations.
>
> Thanks,
> Zijing
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v5 0/2] rust: pci: add capability lookup helpers
2026-02-02 19:57 ` Zhi Wang
@ 2026-02-03 5:42 ` Zijing Zhang
0 siblings, 0 replies; 8+ messages in thread
From: Zijing Zhang @ 2026-02-03 5:42 UTC (permalink / raw)
To: Zhi Wang
Cc: Gary Guo, dakr, linux-pci, rust-for-linux, bhelgaas, kwilczynski,
ojeda, dirk.behme, lianux.mm
Hi Zhi,
Thank you, Zhi, for the detailed explanation. The shift toward a
stricter OO-style abstraction with `Io` trait integration and
`register!` macros makes a lot of sense and probably you could fold my
`CapabilityId` definitions and lookup logic into your series at your
will and consequently, I could withdraw my patch set to avoid further
duplication.
I look forward to discussing how to best align our efforts. I'm also
interested in taking on additional tasks, such as the iterator
implementation, once the underlying `Io` trait refactor settles.
Best regards,
Zijing
On 2/3/2026 3:57 AM, Zhi Wang wrote:
> On Mon, 2 Feb 2026 23:41:42 +0800
> Zijing Zhang <zijing.zhang@ry.rs> wrote:
>
>>
>>
>
> Hi Zijing,
>
> Good to see you working on this too! Welcome to join the party!
>
> I think "thin wrappers" were indeed the initial thought for many of us.
> However, after several rounds of discussions with maintainers at the
> summits, the requirement has shifted towards a stricter, OO-style Rust
> abstraction rather than direct wrappers.
>
> The key takeaways for the current direction are:
> - Enforcing boundary checks via the Io trait backend.
> - Using register! macros for definitions.
> - Implementing proper Rust iterators for Cap discovery.
>
> Since nova-core relies on these specific safety features, I'm pushing
> forward with this high-level abstraction. For nova-core, our immediate
> need is accessing and reading registers in the SR-IOV capability.
>
> That said, there is plenty of room for collaboration to achieve a complete
> framework! For example, support for normal configuration space
> capabilities, the iterator implementation itself, and capabilities other
> than SR-IOV are all areas that need work.
>
> Currently, I am waiting for Alex's Io trait cleanup and refactor to settle
> before deciding what should be included or changed in my next re-spin.
> Also, any input on how to best organize the traits between normal
> configuration space caps and extended caps would be much appreciated!
>
> You are also welcome to reach out via Zulip for a quick discussion or
> catch-up.
>
> Z.
>
>> On 2/2/2026 11:02 PM, Gary Guo wrote:
>>> On Sun Feb 1, 2026 at 7:42 AM GMT, Zijing Zhang wrote:
>>>> It introduces `pci::Device::{find_capability, find_ext_capability}`,
>>>> thin wrappers around the PCI core helpers (`pci_find_capability()` and
>>>> `pci_find_ext_capability()`), returning the config-space offset when
>>>> present.
>>>>
>>>> In `pci::CapabilityId` and `pci::ExtendedCapabilityId`, Capability
>>>> IDs are wrapped as newtypes with `from_raw()` plus a set of common
>>>> constants.
>>>>
>>>> An in-tree user is added to Rust PCI driver sample to exercise the
>>>> new API.
>>>>
>>>> Previous versions (v4)
>>>> https://lore.kernel.org/rust-for-linux/20260201071450.1614172-1-zijing.zhang@ry.rs/
>>>
>>> Also I'd like to mention that Zhi Wang already have a version adding
>>> the same feature on the list, sent before your v1:
>>>
>>> https://lore.kernel.org/rust-for-linux/20260126215957.541180-3-zhiw@nvidia.com/
>>>
>>> I'd recommend to work together for the feature rather than creating
>>> competing series.
>>>
>>> Thanks,
>>> Gary
>>>
>>>>
>>>> Testing
>>>> ---
>>>>
>>>> Build
>>>> - x86_64 defconfig-based kernel with Rust enabled (out-of-tree build)
>>>> - `CONFIG_SAMPLES_RUST=y`
>>>> - `CONFIG_SAMPLE_RUST_DRIVER_PCI=y`
>>>>
>>>> Runtime
>>>> - QEMU x86_64 (i440FX) with `-device pci-testdev`
>>>> - QEMU x86_64 (q35) with an NVMe device
>>>>
>>>> Changelog
>>>> ---
>>>>
>>>> v2
>>>> - Run rustfmt on samples/rust/rust_driver_pci.rs to fix rustfmtcheck.
>>>>
>>>> v3
>>>> - Base on pci/next.
>>>> - Add `CapabilityId`/`ExtendedCapabilityId`, switch
>>>> `find_*capability()` to use them.
>>>> - Document the common ID constants.
>>>> - Update the sample to use typed IDs and exercise the new helpers.
>>>>
>>>> v4
>>>> - Minor doc/style nits.
>>>> - Use early-return style in `find_*capability()`.
>>>>
>>>>
>>>> v5 (current)
>>>> - Fix sample build by using `pdev.as_ref()` for `dev_info!`.
>>>> - Use `as _` in constant definitions.
>>>>
>>>> Zijing Zhang (2):
>>>> rust: pci: add capability lookup helpers
>>>> samples: rust: pci: exercise capability lookup
>>>>
>>>> rust/kernel/pci.rs | 150
>>>> ++++++++++++++++++++++++++++++++ samples/rust/rust_driver_pci.rs |
>>>> 31 +++++++ 2 files changed, 181 insertions(+)
>>>>
>>>>
>>>> base-commit: ff0e2f679ab0de50a2e9e88fabc1026bc3be04ba
>>>
>>
>>
>> On 2/2/2026 11:02 PM, Gary Guo wrote:
>> > On Sun Feb 1, 2026 at 7:42 AM GMT, Zijing Zhang wrote:
>> >> It introduces `pci::Device::{find_capability, find_ext_capability}`,
>> thin
>> >> wrappers around the PCI core helpers (`pci_find_capability()` and
>> >> `pci_find_ext_capability()`), returning the config-space offset when
>> present.
>> >>
>> >> In `pci::CapabilityId` and `pci::ExtendedCapabilityId`, Capability
>> IDs are
>> >> wrapped as newtypes with `from_raw()` plus a set of common constants.
>> >>
>> >> An in-tree user is added to Rust PCI driver sample to exercise the
>> new API.
>> >>
>> >> Previous versions (v4)
>> >>
>> https://lore.kernel.org/rust-for-linux/20260201071450.1614172-1-zijing.zhang@ry.rs/
>> >
>> > Also I'd like to mention that Zhi Wang already have a version adding
>> the same
>> > feature on the list, sent before your v1:
>> >
>> >
>> https://lore.kernel.org/rust-for-linux/20260126215957.541180-3-zhiw@nvidia.com/
>> >
>> > I'd recommend to work together for the feature rather than creating
>> competing
>> > series.
>> >
>> > Thanks,
>> > Gary
>> >
>> >>
>> >> Testing
>> >> ---
>> >>
>> >> Build
>> >> - x86_64 defconfig-based kernel with Rust enabled (out-of-tree build)
>> >> - `CONFIG_SAMPLES_RUST=y`
>> >> - `CONFIG_SAMPLE_RUST_DRIVER_PCI=y`
>> >>
>> >> Runtime
>> >> - QEMU x86_64 (i440FX) with `-device pci-testdev`
>> >> - QEMU x86_64 (q35) with an NVMe device
>> >>
>> >> Changelog
>> >> ---
>> >>
>> >> v2
>> >> - Run rustfmt on samples/rust/rust_driver_pci.rs to fix rustfmtcheck.
>> >>
>> >> v3
>> >> - Base on pci/next.
>> >> - Add `CapabilityId`/`ExtendedCapabilityId`, switch
>> >> `find_*capability()` to use them.
>> >> - Document the common ID constants.
>> >> - Update the sample to use typed IDs and exercise the new helpers.
>> >>
>> >> v4
>> >> - Minor doc/style nits.
>> >> - Use early-return style in `find_*capability()`.
>> >>
>> >>
>> >> v5 (current)
>> >> - Fix sample build by using `pdev.as_ref()` for `dev_info!`.
>> >> - Use `as _` in constant definitions.
>> >>
>> >> Zijing Zhang (2):
>> >> rust: pci: add capability lookup helpers
>> >> samples: rust: pci: exercise capability lookup
>> >>
>> >> rust/kernel/pci.rs | 150
>> >> ++++++++++++++++++++++++++++++++ samples/rust/rust_driver_pci.rs |
>> >> 31 +++++++ 2 files changed, 181 insertions(+)
>> >>
>> >>
>> >> base-commit: ff0e2f679ab0de50a2e9e88fabc1026bc3be04ba
>> >
>>
>> Hi Gary and all,
>>
>> Thanks for the feedback.
>>
>> Zhi's work on SR-IOV is excellent and provides a higher-level
>> abstraction. My series focuses on providing the fundamental lookup
>> infrastructure and typed IDs, which are intended to serve as a
>> general-purpose foundation for any PCI capability interaction.
>>
>> These two series appear to be complementary. I am open to any
>> integration path the maintainers prefer and would welcome Zhi's thoughts
>> on how we might best align these efforts.
>>
>> As a newcomer to the community, I am passionate about Rust PCI driver
>> development and appreciate Gary's diligence in maintaining the
>> subsystem's quality. I've taken note of the feedback regarding the patch
>> frequency and will ensure to allow more time for review in future
>> iterations.
>>
>> Thanks,
>> Zijing
>>
>
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2026-02-03 5:42 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-01 7:42 [PATCH v5 0/2] rust: pci: add capability lookup helpers Zijing Zhang
2026-02-01 7:42 ` [PATCH v5 1/2] " Zijing Zhang
2026-02-01 7:42 ` [PATCH v5 2/2] samples: rust: pci: exercise capability lookup Zijing Zhang
2026-02-02 14:13 ` [PATCH v5 0/2] rust: pci: add capability lookup helpers Gary Guo
2026-02-02 15:02 ` Gary Guo
2026-02-02 15:41 ` Zijing Zhang
2026-02-02 19:57 ` Zhi Wang
2026-02-03 5:42 ` Zijing Zhang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox