Re: [PATCH v10 1/1] rust: pci: add extended capability and SR-IOV support

From: Danilo Krummrich

Date: Wed Sep 30 2026 - 20:00:51 EST


On Sun Sep 6, 2026 at 8:04 AM CEST, Zhi Wang wrote:
> + pub fn vf_bars(&self) -> Result<impl Iterator<Item = ExtSriovVfBar>> {
> + let slots: [u32; NUM_VF_BARS] =
> + core::array::from_fn(|slot| crate::io_read!(*self, .vf_bar[panic: slot]));
> + let mut slots = slots.into_iter();
> + let mut bars = [None; NUM_VF_BARS];
> + let mut count = 0;
> +
> + let mut decode = || {
> + while let Some(low) = slots.next().map(BarLow::from) {
> + // SR-IOV VF BARs describe memory-space apertures; an I/O-space encoding is not
> + // valid for these registers.
> + if low.io_space() {
> + return Err(EINVAL);
> + }
> +
> + let low_address = u64::from(low.address()) << BarLow::ADDRESS_SHIFT;
> + let bar = match low.memory_type()? {
> + BarMemoryType::Bits64 => ExtSriovVfBar {
> + address: (u64::from(slots.next().ok_or(EINVAL)?) << 32) | low_address,
> + is_64bit: true,
> + },
> + BarMemoryType::Bits32 => ExtSriovVfBar {
> + address: low_address,
> + is_64bit: false,
> + },
> + };
> +
> + bars[count] = Some(bar);
> + count += 1;
> + }
> +
> + Ok(())
> + };
> +
> + decode().inspect_err(|_| {
> + dev_err!(self.pdev, "invalid VF BAR encoding in SR-IOV capability\n");
> + })?;
> + Ok(bars.into_iter().flatten())
> + }

I don't mind too much, but can you please remind me why we decode the VF BAR
registers and can't use the PCI core's VF resource information instead?

(I gave it a very quick try and using pci_bus_address() and pci_resource_flags()
actually turned out worse, but that could be me spending less than 5 minutes on
it. :)