[PATCH v2 02/12] rust: pci: expose the VF index within its PF
From: Simon Song
Date: Fri Oct 23 2026 - 11:51:10 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.
Restrict vf_id() to Device<device::Bound>
Suggested-by: Danilo Krummrich <dakr@xxxxxxxxxx>
Suggested-by: Zhi Wang <zhiw@xxxxxxxxxx>
Signed-off-by: Danilo Krummrich <dakr@xxxxxxxxxx>
Signed-off-by: Zhi Wang <zhiw@xxxxxxxxxx>
Signed-off-by: Simon Song <xinmengs@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 9d9bd3ac702..76b2e395ca3 100644
--- a/rust/kernel/pci/iov.rs
+++ b/rust/kernel/pci/iov.rs
@@ -329,6 +329,14 @@ unsafe impl<F: ForLt> Send for VfRegistration<'_, F> where for<'a> F::Of<'a>: Se
unsafe impl<F: ForLt> Sync for VfRegistration<'_, F> where for<'a> F::Of<'a>: Send + Sync {}
impl Device<device::Bound> {
+ /// 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)
+ }
+
/// Internal helper: reads the `vf_registration_data_rust` pointer from the
/// PF, checks the `TypeId`, and returns a pinned reference.
///
--
2.43.7