[PATCH 2/7] rust: pci: expose the VF index within its PF
From: Zhi Wang
Date: Wed Sep 30 2026 - 07:12:56 EST
From: Danilo Krummrich <dakr@xxxxxxxxxx>
Nova identifies a vGPU instance by the VF's index within its PF. Expose
pci_iov_vf_id() through Device::vf_id() so a Rust VF driver can obtain
that index, with an error for devices that are not VFs.
Signed-off-by: Danilo Krummrich <dakr@xxxxxxxxxx>
Signed-off-by: Zhi Wang <zhiw@xxxxxxxxxx>
---
rust/kernel/pci/iov.rs | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/rust/kernel/pci/iov.rs b/rust/kernel/pci/iov.rs
index 9d9bd3ac7025..fac134d1ebab 100644
--- a/rust/kernel/pci/iov.rs
+++ b/rust/kernel/pci/iov.rs
@@ -40,6 +40,14 @@ pub 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 }
}
+
+ /// Return the zero-based VF index within its PF, or an error for a non-VF device.
+ pub fn vf_id(&self) -> Result<u32> {
+ // SAFETY: `self.as_raw()` points to a live PCI device; the helper checks VF membership.
+ let id = unsafe { bindings::pci_iov_vf_id(self.as_raw()) };
+ to_result(id)?;
+ Ok(id as u32)
+ }
}
impl Device<device::Core<'_>> {
--
2.53.0