[PATCH 05/14] rust: pci: add is_virtfn(), to check for VFs

From: Zhi Wang

Date: Tue Sep 15 2026 - 17:00:26 EST


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>
Reviewed-by: Joel Fernandes <joelagnelf@xxxxxxxxxx>
Signed-off-by: Peter Colberg <pcolberg@xxxxxxxxxx>
Signed-off-by: Zhi Wang <zhiw@xxxxxxxxxx>
---
rust/kernel/pci.rs | 8 ++++++++
1 file changed, 8 insertions(+)

diff --git a/rust/kernel/pci.rs b/rust/kernel/pci.rs
index 7f50c1c96a4f..844d73a83670 100644
--- a/rust/kernel/pci.rs
+++ b/rust/kernel/pci.rs
@@ -507,6 +507,14 @@ 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).
+ #[inline]
+ #[expect(dead_code)]
+ pub(crate) fn is_virtfn(&self) -> bool {
+ // 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) {