Re: [PATCH v3 3/5] rust: pci: add a helper to query configuration space size

From: Zhi Wang

Date: Fri Oct 31 2025 - 08:16:33 EST


On Thu, 30 Oct 2025 11:51:15 -0500
Bjorn Helgaas <helgaas@xxxxxxxxxx> wrote:

> On Thu, Oct 30, 2025 at 03:48:40PM +0000, Zhi Wang wrote:
> > Expose a safe Rust wrapper for the `cfg_size` field of `struct
> > pci_dev`, allowing drivers to query the size of a device's
> > configuration space.
> >
> > This is useful for code that needs to know whether the device
> > supports extended configuration space (e.g. 256 vs 4096 bytes) when
> > accessing PCI configuration registers and apply runtime checks.
>
> What is the value of knowing the config space size, as opposed to just
> having config space accessors return PCIBIOS_BAD_REGISTER_NUMBER or
> similar when trying to read past the implemented size?
>

Per my understading, the Io trait aims to provide a generic I/O
validation that can be reused across different transports -
MMIO, PCI, SPI, and others - with each backend implementing its own
region boundaries while sharing the same pre-access validation logic.

By design, the framework needs to know the valid address range
before performing the actual access. Without exposing
cfg_size(), we would have to add PCI configuration-specific
handling inside the framework.

> Apart from pci-sysfs and vfio, I don't really see any drivers that use
> pdev->cfg_size today.

It is for the framework so far. If we believe that driver doesn't need
this in the near term, I can make it private in the next re-spin.

Z.