Re: [PATCH 1/8] rust: pci: add is_virtfn(), to check for VFs

From: Peter Colberg

Date: Tue Dec 09 2025 - 13:23:11 EST


On Sun, Dec 07, 2025 at 01:28:19AM -0500, Joel Fernandes wrote:
> On Wed, Nov 19, 2025 at 05:19:05PM -0500, Peter Colberg wrote:
> > From: John Hubbard <jhubbard@xxxxxxxxxx>
> >
> > Add a method to check if a PCI device is a Virtual Function (VF) created
> > through Single Root I/O Virtualization (SR-IOV).
> >
> > Signed-off-by: John Hubbard <jhubbard@xxxxxxxxxx>
> > Reviewed-by: Alistair Popple <apopple@xxxxxxxxxx>
> > Signed-off-by: Peter Colberg <pcolberg@xxxxxxxxxx>
> > ---
> > This patch was originally part of the series "rust: pci: expose
> > is_virtfn() and reject VFs in nova-core" and modified as follows:
> > - Replace true -> `true` in doc comment.
> > - Shorten description and omit justification specific to nova-core.
> >
> > Link: https://lore.kernel.org/rust-for-linux/20250930220759.288528-2-jhubbard@xxxxxxxxxx/
> > ---
> > rust/kernel/pci.rs | 6 ++++++
> > 1 file changed, 6 insertions(+)
> >
> > diff --git a/rust/kernel/pci.rs b/rust/kernel/pci.rs
> > index 82e128431f080fde78a06dc5c284ab12739e747e..c20b8daeb7aadbef9f6ecfc48c972436efac9a08 100644
> > --- a/rust/kernel/pci.rs
> > +++ b/rust/kernel/pci.rs
> > @@ -409,6 +409,12 @@ pub fn resource_start(&self, bar: u32) -> Result<bindings::resource_size_t> {
> > Ok(unsafe { bindings::pci_resource_start(self.as_raw(), bar.try_into()?) })
> > }
> >
> > + /// Returns `true` if this device is a Virtual Function (VF).
> > + pub fn is_virtfn(&self) -> bool {
>
> Add #[inline] here and to `is_physfn()` similar to other methods in this struct?

Thanks for your review! Where should the line be drawn for #[inline]?

Should these be #[inline] as well and why (not)?

- Device::num_vf()
- Device<Core>::enable_sriov()
- Device<Core>::disable_sriov()

Why is Device<Core>::enable_device_mem() not #[inline], while
Device<Core>::set_master() is [1]? Is the former an oversight?

[1] https://git.kernel.org/pub/scm/linux/kernel/git/driver-core/driver-core.git/tree/rust/kernel/pci.rs?id=67a454e6b1c604555c04501c77b7fedc5d98a779#n433

Thanks,
Peter

>
> With that,
>
> Reviewed-by: Joel Fernandes <joelagnelf@xxxxxxxxxx>
>
> thanks,
>
> - Joel
>
>
> > + // SAFETY: `self.as_raw` is a valid pointer to a `struct pci_dev`.
> > + unsafe { (*self.as_raw()).is_virtfn() != 0 }
> > + }
> > +
> > /// Returns the size of the given PCI BAR resource.
> > pub fn resource_len(&self, bar: u32) -> Result<bindings::resource_size_t> {
> > if !Bar::index_is_valid(bar) {
> >
> > --
> > 2.51.1
> >
>