From: Danilo Krummrich 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 Suggested-by: Danilo Krummrich Suggested-by: Zhi Wang Signed-off-by: Danilo Krummrich Signed-off-by: Zhi Wang Signed-off-by: Simon Song --- 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 Send for VfRegistration<'_, F> where for<'a> F::Of<'a>: Se unsafe impl Sync for VfRegistration<'_, F> where for<'a> F::Of<'a>: Send + Sync {} impl Device { + /// Return the zero-based VF index within its PF, or an error for a non-VF device. + pub fn vf_id(&self) -> Result { + // 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