* [PATCH v3 1/8] PCI/IOV: Return unsigned int from pci_sriov_get_totalvfs() [not found] <20260701062622.3499033-1-zhiw@nvidia.com> @ 2026-07-01 6:26 ` Zhi Wang 2026-07-08 13:54 ` Alexandre Courbot 2026-07-01 6:26 ` [PATCH v3 2/8] rust: pci: add sriov_get_totalvfs() helper Zhi Wang 1 sibling, 1 reply; 8+ messages in thread From: Zhi Wang @ 2026-07-01 6:26 UTC (permalink / raw) To: dakr, acourbot Cc: airlied, simona, ojeda, alex.gaynor, boqun.feng, gary, bjorn3_gh, lossin, a.hindborg, aliceryhl, tmgross, jhubbard, ecourtney, joelagnelf, apopple, cjia, smitra, kjaju, alkumar, ankita, aniketa, kwankhede, targupta, nova-gpu, linux-kernel, zhiwang, Zhi Wang, Bjorn Helgaas, David Laight, linux-pci pci_sriov_get_totalvfs() reports a VF count, not an errno-style status. It returns 0 when SR-IOV is unavailable or the device is not a PF, and otherwise returns the PF's driver_max_VFs value. driver_max_VFs is stored as a u16 in struct pci_sriov. It is derived from the SR-IOV TotalVFs field or from a driver-provided limit, so the implementation cannot return a negative value. Change the declaration, CONFIG_PCI_IOV stub, and implementation to return unsigned int. Suggested-by: Alexandre Courbot <acourbot@nvidia.com> Cc: Bjorn Helgaas <bhelgaas@google.com> Cc: David Laight <david.laight.linux@gmail.com> Cc: Gary Guo <gary@garyguo.net> Cc: linux-pci@vger.kernel.org Link: https://lore.kernel.org/all/DJHPRE4TGGT8.BUTMYOF5YE05@nvidia.com/ Signed-off-by: Zhi Wang <zhiw@nvidia.com> --- drivers/pci/iov.c | 2 +- include/linux/pci.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c index b0d24839c084..9d408fb8ac25 100644 --- a/drivers/pci/iov.c +++ b/drivers/pci/iov.c @@ -1283,7 +1283,7 @@ EXPORT_SYMBOL_GPL(pci_sriov_set_totalvfs); * SRIOV capability value of TotalVFs or the value of driver_max_VFs * if the driver reduced it. Otherwise 0. */ -int pci_sriov_get_totalvfs(struct pci_dev *dev) +unsigned int pci_sriov_get_totalvfs(struct pci_dev *dev) { if (!dev->is_physfn) return 0; diff --git a/include/linux/pci.h b/include/linux/pci.h index ebb5b9d76360..2b9c61de5f67 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -2569,7 +2569,7 @@ void pci_iov_remove_virtfn(struct pci_dev *dev, int id); int pci_num_vf(struct pci_dev *dev); int pci_vfs_assigned(struct pci_dev *dev); int pci_sriov_set_totalvfs(struct pci_dev *dev, u16 numvfs); -int pci_sriov_get_totalvfs(struct pci_dev *dev); +unsigned int pci_sriov_get_totalvfs(struct pci_dev *dev); int pci_sriov_configure_simple(struct pci_dev *dev, int nr_virtfn); resource_size_t pci_iov_resource_size(const struct pci_dev *dev, int resno); int pci_iov_vf_bar_set_size(struct pci_dev *dev, int resno, int size); @@ -2622,7 +2622,7 @@ static inline int pci_vfs_assigned(struct pci_dev *dev) { return 0; } static inline int pci_sriov_set_totalvfs(struct pci_dev *dev, u16 numvfs) { return 0; } -static inline int pci_sriov_get_totalvfs(struct pci_dev *dev) +static inline unsigned int pci_sriov_get_totalvfs(struct pci_dev *dev) { return 0; } #define pci_sriov_configure_simple NULL static inline resource_size_t pci_iov_resource_size(const struct pci_dev *dev, -- 2.51.0 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH v3 1/8] PCI/IOV: Return unsigned int from pci_sriov_get_totalvfs() 2026-07-01 6:26 ` [PATCH v3 1/8] PCI/IOV: Return unsigned int from pci_sriov_get_totalvfs() Zhi Wang @ 2026-07-08 13:54 ` Alexandre Courbot 0 siblings, 0 replies; 8+ messages in thread From: Alexandre Courbot @ 2026-07-08 13:54 UTC (permalink / raw) To: Zhi Wang Cc: dakr, airlied, simona, ojeda, alex.gaynor, boqun.feng, gary, bjorn3_gh, lossin, a.hindborg, aliceryhl, tmgross, jhubbard, ecourtney, joelagnelf, apopple, cjia, smitra, kjaju, alkumar, ankita, aniketa, kwankhede, targupta, nova-gpu, linux-kernel, zhiwang, Bjorn Helgaas, David Laight, linux-pci On Wed Jul 1, 2026 at 3:26 PM JST, Zhi Wang wrote: > pci_sriov_get_totalvfs() reports a VF count, not an errno-style > status. It returns 0 when SR-IOV is unavailable or the device is not a > PF, and otherwise returns the PF's driver_max_VFs value. > > driver_max_VFs is stored as a u16 in struct pci_sriov. It is derived > from the SR-IOV TotalVFs field or from a driver-provided limit, so the > implementation cannot return a negative value. > > Change the declaration, CONFIG_PCI_IOV stub, and implementation to > return unsigned int. > > Suggested-by: Alexandre Courbot <acourbot@nvidia.com> > Cc: Bjorn Helgaas <bhelgaas@google.com> > Cc: David Laight <david.laight.linux@gmail.com> > Cc: Gary Guo <gary@garyguo.net> > Cc: linux-pci@vger.kernel.org > Link: https://lore.kernel.org/all/DJHPRE4TGGT8.BUTMYOF5YE05@nvidia.com/ > Signed-off-by: Zhi Wang <zhiw@nvidia.com> FWIW, Reviewed-by: Alexandre Courbot <acourbot@nvidia.com> ^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v3 2/8] rust: pci: add sriov_get_totalvfs() helper [not found] <20260701062622.3499033-1-zhiw@nvidia.com> 2026-07-01 6:26 ` [PATCH v3 1/8] PCI/IOV: Return unsigned int from pci_sriov_get_totalvfs() Zhi Wang @ 2026-07-01 6:26 ` Zhi Wang 2026-07-08 14:03 ` Alexandre Courbot 1 sibling, 1 reply; 8+ messages in thread From: Zhi Wang @ 2026-07-01 6:26 UTC (permalink / raw) To: dakr, acourbot Cc: airlied, simona, ojeda, alex.gaynor, boqun.feng, gary, bjorn3_gh, lossin, a.hindborg, aliceryhl, tmgross, jhubbard, ecourtney, joelagnelf, apopple, cjia, smitra, kjaju, alkumar, ankita, aniketa, kwankhede, targupta, nova-gpu, linux-kernel, zhiwang, Zhi Wang, Bjorn Helgaas, David Laight, linux-pci Expose pci_sriov_get_totalvfs() to Rust PCI drivers so they can query how many SR-IOV VFs a device supports. Cc: Alexandre Courbot <acourbot@nvidia.com> Cc: Bjorn Helgaas <bhelgaas@google.com> Cc: David Laight <david.laight.linux@gmail.com> Cc: Gary Guo <gary@garyguo.net> Cc: linux-pci@vger.kernel.org Link: https://lore.kernel.org/all/DJHPRE4TGGT8.BUTMYOF5YE05@nvidia.com/ Signed-off-by: Zhi Wang <zhiw@nvidia.com> --- rust/kernel/pci.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/rust/kernel/pci.rs b/rust/kernel/pci.rs index 5071cae6543f..21c51981c02e 100644 --- a/rust/kernel/pci.rs +++ b/rust/kernel/pci.rs @@ -450,6 +450,17 @@ pub fn pci_class(&self) -> Class { // SAFETY: `self.as_raw` is a valid pointer to a `struct pci_dev`. Class::from_raw(unsafe { (*self.as_raw()).class }) } + + /// Returns the total number of VFs, or 0 if SR-IOV is not available. + #[inline] + pub fn sriov_get_totalvfs(&self) -> u16 { + // SAFETY: `self.as_raw()` is a valid pointer to a `struct pci_dev`. + let total_vfs = unsafe { bindings::pci_sriov_get_totalvfs(self.as_raw()) }; + + // CAST: The C helper returns `unsigned int`, but the value originates + // from TotalVFs/driver_max_VFs, so this cast cannot truncate. + total_vfs as u16 + } } impl<'a> Device<device::Core<'a>> { -- 2.51.0 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH v3 2/8] rust: pci: add sriov_get_totalvfs() helper 2026-07-01 6:26 ` [PATCH v3 2/8] rust: pci: add sriov_get_totalvfs() helper Zhi Wang @ 2026-07-08 14:03 ` Alexandre Courbot 2026-07-08 14:13 ` Alexandre Courbot 2026-07-08 14:41 ` Alexandre Courbot 0 siblings, 2 replies; 8+ messages in thread From: Alexandre Courbot @ 2026-07-08 14:03 UTC (permalink / raw) To: Zhi Wang Cc: dakr, airlied, simona, ojeda, alex.gaynor, boqun.feng, gary, bjorn3_gh, lossin, a.hindborg, aliceryhl, tmgross, jhubbard, ecourtney, joelagnelf, apopple, cjia, smitra, kjaju, alkumar, ankita, aniketa, kwankhede, targupta, nova-gpu, linux-kernel, zhiwang, Bjorn Helgaas, David Laight, linux-pci On Wed Jul 1, 2026 at 3:26 PM JST, Zhi Wang wrote: > Expose pci_sriov_get_totalvfs() to Rust PCI drivers so they can query > how many SR-IOV VFs a device supports. > > Cc: Alexandre Courbot <acourbot@nvidia.com> > Cc: Bjorn Helgaas <bhelgaas@google.com> > Cc: David Laight <david.laight.linux@gmail.com> > Cc: Gary Guo <gary@garyguo.net> > Cc: linux-pci@vger.kernel.org > Link: https://lore.kernel.org/all/DJHPRE4TGGT8.BUTMYOF5YE05@nvidia.com/ > Signed-off-by: Zhi Wang <zhiw@nvidia.com> > --- > rust/kernel/pci.rs | 11 +++++++++++ > 1 file changed, 11 insertions(+) > > diff --git a/rust/kernel/pci.rs b/rust/kernel/pci.rs > index 5071cae6543f..21c51981c02e 100644 > --- a/rust/kernel/pci.rs > +++ b/rust/kernel/pci.rs > @@ -450,6 +450,17 @@ pub fn pci_class(&self) -> Class { > // SAFETY: `self.as_raw` is a valid pointer to a `struct pci_dev`. > Class::from_raw(unsafe { (*self.as_raw()).class }) > } > + > + /// Returns the total number of VFs, or 0 if SR-IOV is not available. > + #[inline] > + pub fn sriov_get_totalvfs(&self) -> u16 { > + // SAFETY: `self.as_raw()` is a valid pointer to a `struct pci_dev`. > + let total_vfs = unsafe { bindings::pci_sriov_get_totalvfs(self.as_raw()) }; > + > + // CAST: The C helper returns `unsigned int`, but the value originates > + // from TotalVFs/driver_max_VFs, so this cast cannot truncate. nit: "from TotalVFs/driver_max_VFs (which are defined as `u16`), ..." With that, Reviewed-by: Alexandre Courbot <acourbot@nvidia.com> ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v3 2/8] rust: pci: add sriov_get_totalvfs() helper 2026-07-08 14:03 ` Alexandre Courbot @ 2026-07-08 14:13 ` Alexandre Courbot 2026-07-09 14:24 ` Zhi Wang 2026-07-08 14:41 ` Alexandre Courbot 1 sibling, 1 reply; 8+ messages in thread From: Alexandre Courbot @ 2026-07-08 14:13 UTC (permalink / raw) To: Zhi Wang Cc: dakr, airlied, simona, ojeda, alex.gaynor, boqun.feng, gary, bjorn3_gh, lossin, a.hindborg, aliceryhl, tmgross, jhubbard, ecourtney, joelagnelf, apopple, cjia, smitra, kjaju, alkumar, ankita, aniketa, kwankhede, targupta, nova-gpu, linux-kernel, zhiwang, Bjorn Helgaas, David Laight, linux-pci On Wed Jul 8, 2026 at 11:03 PM JST, Alexandre Courbot wrote: > On Wed Jul 1, 2026 at 3:26 PM JST, Zhi Wang wrote: >> Expose pci_sriov_get_totalvfs() to Rust PCI drivers so they can query >> how many SR-IOV VFs a device supports. >> >> Cc: Alexandre Courbot <acourbot@nvidia.com> >> Cc: Bjorn Helgaas <bhelgaas@google.com> >> Cc: David Laight <david.laight.linux@gmail.com> >> Cc: Gary Guo <gary@garyguo.net> >> Cc: linux-pci@vger.kernel.org >> Link: https://lore.kernel.org/all/DJHPRE4TGGT8.BUTMYOF5YE05@nvidia.com/ >> Signed-off-by: Zhi Wang <zhiw@nvidia.com> >> --- >> rust/kernel/pci.rs | 11 +++++++++++ >> 1 file changed, 11 insertions(+) >> >> diff --git a/rust/kernel/pci.rs b/rust/kernel/pci.rs >> index 5071cae6543f..21c51981c02e 100644 >> --- a/rust/kernel/pci.rs >> +++ b/rust/kernel/pci.rs >> @@ -450,6 +450,17 @@ pub fn pci_class(&self) -> Class { >> // SAFETY: `self.as_raw` is a valid pointer to a `struct pci_dev`. >> Class::from_raw(unsafe { (*self.as_raw()).class }) >> } >> + >> + /// Returns the total number of VFs, or 0 if SR-IOV is not available. >> + #[inline] >> + pub fn sriov_get_totalvfs(&self) -> u16 { >> + // SAFETY: `self.as_raw()` is a valid pointer to a `struct pci_dev`. >> + let total_vfs = unsafe { bindings::pci_sriov_get_totalvfs(self.as_raw()) }; >> + >> + // CAST: The C helper returns `unsigned int`, but the value originates >> + // from TotalVFs/driver_max_VFs, so this cast cannot truncate. > > nit: "from TotalVFs/driver_max_VFs (which are defined as `u16`), ..." > > With that, > > Reviewed-by: Alexandre Courbot <acourbot@nvidia.com> ... with an additional item for thought: in a previous revision [1], I had raised the question of making the return type `Option<NonZero<u16>>`, as I think it better encodes "0 if SR-IOV is not available" - callers are then forced to consider the dichotomy of the result, and not interpret a particular value as having a special meaning. OTOH, for all practical purposes 0 VFs also seems to be strictly equivalent to "SR-IOV is not available", so please take this as a nit to consider, not a blocker. [1] https://lore.kernel.org/rust-for-linux/DETDILPA1GFY.27WND0TEC5352@nvidia.com/ ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v3 2/8] rust: pci: add sriov_get_totalvfs() helper 2026-07-08 14:13 ` Alexandre Courbot @ 2026-07-09 14:24 ` Zhi Wang 0 siblings, 0 replies; 8+ messages in thread From: Zhi Wang @ 2026-07-09 14:24 UTC (permalink / raw) To: Alexandre Courbot Cc: dakr, airlied, simona, ojeda, alex.gaynor, boqun.feng, gary, bjorn3_gh, lossin, a.hindborg, aliceryhl, tmgross, jhubbard, ecourtney, joelagnelf, apopple, cjia, smitra, kjaju, alkumar, ankita, aniketa, kwankhede, targupta, nova-gpu, linux-kernel, zhiwang, Bjorn Helgaas, David Laight, linux-pci On Wed, 08 Jul 2026 23:13:08 +0900 "Alexandre Courbot" <acourbot@nvidia.com> wrote: > On Wed Jul 8, 2026 at 11:03 PM JST, Alexandre Courbot wrote: > > On Wed Jul 1, 2026 at 3:26 PM JST, Zhi Wang wrote: > >> Expose pci_sriov_get_totalvfs() to Rust PCI drivers so they can > >> query how many SR-IOV VFs a device supports. > >> > >> Cc: Alexandre Courbot <acourbot@nvidia.com> > >> Cc: Bjorn Helgaas <bhelgaas@google.com> > >> Cc: David Laight <david.laight.linux@gmail.com> > >> Cc: Gary Guo <gary@garyguo.net> > >> Cc: linux-pci@vger.kernel.org > >> Link: > >> https://lore.kernel.org/all/DJHPRE4TGGT8.BUTMYOF5YE05@nvidia.com/ > >> Signed-off-by: Zhi Wang <zhiw@nvidia.com> --- > >> rust/kernel/pci.rs | 11 +++++++++++ > >> 1 file changed, 11 insertions(+) > >> > >> diff --git a/rust/kernel/pci.rs b/rust/kernel/pci.rs > >> index 5071cae6543f..21c51981c02e 100644 > >> --- a/rust/kernel/pci.rs > >> +++ b/rust/kernel/pci.rs > >> @@ -450,6 +450,17 @@ pub fn pci_class(&self) -> Class { > >> // SAFETY: `self.as_raw` is a valid pointer to a `struct > >> pci_dev`. Class::from_raw(unsafe { (*self.as_raw()).class }) > >> } > >> + > >> + /// Returns the total number of VFs, or 0 if SR-IOV is not > >> available. > >> + #[inline] > >> + pub fn sriov_get_totalvfs(&self) -> u16 { > >> + // SAFETY: `self.as_raw()` is a valid pointer to a > >> `struct pci_dev`. > >> + let total_vfs = unsafe { > >> bindings::pci_sriov_get_totalvfs(self.as_raw()) }; + > >> + // CAST: The C helper returns `unsigned int`, but the > >> value originates > >> + // from TotalVFs/driver_max_VFs, so this cast cannot > >> truncate. > > > > nit: "from TotalVFs/driver_max_VFs (which are defined as `u16`), > > ..." > > > > With that, > > > > Reviewed-by: Alexandre Courbot <acourbot@nvidia.com> > > ... with an additional item for thought: in a previous revision [1], I > had raised the question of making the return type > `Option<NonZero<u16>>`, as I think it better encodes "0 if SR-IOV is > not available" - callers are then forced to consider the dichotomy of > the result, and not interpret a particular value as having a special > meaning. > > OTOH, for all practical purposes 0 VFs also seems to be strictly > equivalent to "SR-IOV is not available", so please take this as a > nit to consider, not a blocker. > > [1] > https://lore.kernel.org/rust-for-linux/DETDILPA1GFY.27WND0TEC5352@nvidia.com/ Nice advice. I will address it in v4. :) ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v3 2/8] rust: pci: add sriov_get_totalvfs() helper 2026-07-08 14:03 ` Alexandre Courbot 2026-07-08 14:13 ` Alexandre Courbot @ 2026-07-08 14:41 ` Alexandre Courbot 2026-07-09 14:25 ` Zhi Wang 1 sibling, 1 reply; 8+ messages in thread From: Alexandre Courbot @ 2026-07-08 14:41 UTC (permalink / raw) To: Zhi Wang Cc: dakr, airlied, simona, ojeda, alex.gaynor, boqun.feng, gary, bjorn3_gh, lossin, a.hindborg, aliceryhl, tmgross, jhubbard, ecourtney, joelagnelf, apopple, cjia, smitra, kjaju, alkumar, ankita, aniketa, kwankhede, targupta, nova-gpu, linux-kernel, zhiwang, Bjorn Helgaas, David Laight, linux-pci On Wed Jul 8, 2026 at 11:03 PM JST, Alexandre Courbot wrote: > On Wed Jul 1, 2026 at 3:26 PM JST, Zhi Wang wrote: >> Expose pci_sriov_get_totalvfs() to Rust PCI drivers so they can query >> how many SR-IOV VFs a device supports. >> >> Cc: Alexandre Courbot <acourbot@nvidia.com> >> Cc: Bjorn Helgaas <bhelgaas@google.com> >> Cc: David Laight <david.laight.linux@gmail.com> >> Cc: Gary Guo <gary@garyguo.net> >> Cc: linux-pci@vger.kernel.org >> Link: https://lore.kernel.org/all/DJHPRE4TGGT8.BUTMYOF5YE05@nvidia.com/ >> Signed-off-by: Zhi Wang <zhiw@nvidia.com> >> --- >> rust/kernel/pci.rs | 11 +++++++++++ >> 1 file changed, 11 insertions(+) >> >> diff --git a/rust/kernel/pci.rs b/rust/kernel/pci.rs >> index 5071cae6543f..21c51981c02e 100644 >> --- a/rust/kernel/pci.rs >> +++ b/rust/kernel/pci.rs >> @@ -450,6 +450,17 @@ pub fn pci_class(&self) -> Class { >> // SAFETY: `self.as_raw` is a valid pointer to a `struct pci_dev`. >> Class::from_raw(unsafe { (*self.as_raw()).class }) >> } >> + >> + /// Returns the total number of VFs, or 0 if SR-IOV is not available. >> + #[inline] >> + pub fn sriov_get_totalvfs(&self) -> u16 { >> + // SAFETY: `self.as_raw()` is a valid pointer to a `struct pci_dev`. >> + let total_vfs = unsafe { bindings::pci_sriov_get_totalvfs(self.as_raw()) }; >> + >> + // CAST: The C helper returns `unsigned int`, but the value originates >> + // from TotalVFs/driver_max_VFs, so this cast cannot truncate. > > nit: "from TotalVFs/driver_max_VFs (which are defined as `u16`), ..." > > With that, > > Reviewed-by: Alexandre Courbot <acourbot@nvidia.com> Sorry, need to take my tag back. :( Build is failing if `CONFIG_PCI_IOV` is not set: error[E0425]: cannot find function `pci_sriov_get_totalvfs` in crate `bindings` --> ../rust/kernel/pci.rs:458:44 | 458 | let total_vfs = unsafe { bindings::pci_sriov_get_totalvfs(self.as_raw()) }; | ^^^^^^^^^^^^^^^^^^^^^^ not found in `bindings` Looks like you need to add a helper in `rust/helpers/pci.c` as the inline C function used when `CONFIG_PCI_IOV` is not set can not be invoked by Rust. ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v3 2/8] rust: pci: add sriov_get_totalvfs() helper 2026-07-08 14:41 ` Alexandre Courbot @ 2026-07-09 14:25 ` Zhi Wang 0 siblings, 0 replies; 8+ messages in thread From: Zhi Wang @ 2026-07-09 14:25 UTC (permalink / raw) To: Alexandre Courbot Cc: dakr, airlied, simona, ojeda, alex.gaynor, boqun.feng, gary, bjorn3_gh, lossin, a.hindborg, aliceryhl, tmgross, jhubbard, ecourtney, joelagnelf, apopple, cjia, smitra, kjaju, alkumar, ankita, aniketa, kwankhede, targupta, nova-gpu, linux-kernel, zhiwang, Bjorn Helgaas, David Laight, linux-pci On Wed, 08 Jul 2026 23:41:20 +0900 "Alexandre Courbot" <acourbot@nvidia.com> wrote: > On Wed Jul 8, 2026 at 11:03 PM JST, Alexandre Courbot wrote: > > On Wed Jul 1, 2026 at 3:26 PM JST, Zhi Wang wrote: > >> Expose pci_sriov_get_totalvfs() to Rust PCI drivers so they can > >> query how many SR-IOV VFs a device supports. > >> > >> Cc: Alexandre Courbot <acourbot@nvidia.com> > >> Cc: Bjorn Helgaas <bhelgaas@google.com> > >> Cc: David Laight <david.laight.linux@gmail.com> > >> Cc: Gary Guo <gary@garyguo.net> > >> Cc: linux-pci@vger.kernel.org > >> Link: > >> https://lore.kernel.org/all/DJHPRE4TGGT8.BUTMYOF5YE05@nvidia.com/ > >> Signed-off-by: Zhi Wang <zhiw@nvidia.com> --- > >> rust/kernel/pci.rs | 11 +++++++++++ > >> 1 file changed, 11 insertions(+) > >> > >> diff --git a/rust/kernel/pci.rs b/rust/kernel/pci.rs > >> index 5071cae6543f..21c51981c02e 100644 > >> --- a/rust/kernel/pci.rs > >> +++ b/rust/kernel/pci.rs > >> @@ -450,6 +450,17 @@ pub fn pci_class(&self) -> Class { > >> // SAFETY: `self.as_raw` is a valid pointer to a `struct > >> pci_dev`. Class::from_raw(unsafe { (*self.as_raw()).class }) > >> } > >> + > >> + /// Returns the total number of VFs, or 0 if SR-IOV is not > >> available. > >> + #[inline] > >> + pub fn sriov_get_totalvfs(&self) -> u16 { > >> + // SAFETY: `self.as_raw()` is a valid pointer to a > >> `struct pci_dev`. > >> + let total_vfs = unsafe { > >> bindings::pci_sriov_get_totalvfs(self.as_raw()) }; + > >> + // CAST: The C helper returns `unsigned int`, but the > >> value originates > >> + // from TotalVFs/driver_max_VFs, so this cast cannot > >> truncate. > > > > nit: "from TotalVFs/driver_max_VFs (which are defined as `u16`), > > ..." > > > > With that, > > > > Reviewed-by: Alexandre Courbot <acourbot@nvidia.com> > > Sorry, need to take my tag back. :( Build is failing if > `CONFIG_PCI_IOV` is not set: > > error[E0425]: cannot find function `pci_sriov_get_totalvfs` in > crate `bindings` --> ../rust/kernel/pci.rs:458:44 > | > 458 | let total_vfs = unsafe { > bindings::pci_sriov_get_totalvfs(self.as_raw()) }; | > ^^^^^^^^^^^^^^^^^^^^^^ not found in > `bindings` > > Looks like you need to add a helper in `rust/helpers/pci.c` as the > inline C function used when `CONFIG_PCI_IOV` is not set can not be > invoked by Rust. Add it in v4. ^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2026-07-09 14:26 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20260701062622.3499033-1-zhiw@nvidia.com>
2026-07-01 6:26 ` [PATCH v3 1/8] PCI/IOV: Return unsigned int from pci_sriov_get_totalvfs() Zhi Wang
2026-07-08 13:54 ` Alexandre Courbot
2026-07-01 6:26 ` [PATCH v3 2/8] rust: pci: add sriov_get_totalvfs() helper Zhi Wang
2026-07-08 14:03 ` Alexandre Courbot
2026-07-08 14:13 ` Alexandre Courbot
2026-07-09 14:24 ` Zhi Wang
2026-07-08 14:41 ` Alexandre Courbot
2026-07-09 14:25 ` Zhi Wang
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox