[PATCH 2/8] rust: pci: add is_physfn(), to check for PFs

Peter Colberg posted 8 patches 2 months, 3 weeks ago
There is a newer version of this series
[PATCH 2/8] rust: pci: add is_physfn(), to check for PFs
Posted by Peter Colberg 2 months, 3 weeks ago
Add a method to check if a PCI device is a Physical Function (PF).

Signed-off-by: Peter Colberg <pcolberg@redhat.com>
---
 rust/kernel/pci.rs | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/rust/kernel/pci.rs b/rust/kernel/pci.rs
index c20b8daeb7aadbef9f6ecfc48c972436efac9a08..814990d386708fe2ac652ccaa674c10a6cf390cb 100644
--- a/rust/kernel/pci.rs
+++ b/rust/kernel/pci.rs
@@ -409,6 +409,12 @@ 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 Physical Function (VF).
+    pub fn is_physfn(&self) -> bool {
+        // SAFETY: `self.as_raw` is a valid pointer to a `struct pci_dev`.
+        unsafe { (*self.as_raw()).is_physfn() != 0 }
+    }
+
     /// Returns `true` if this device is a Virtual Function (VF).
     pub fn is_virtfn(&self) -> bool {
         // SAFETY: `self.as_raw` is a valid pointer to a `struct pci_dev`.

-- 
2.51.1
Re: [PATCH 2/8] rust: pci: add is_physfn(), to check for PFs
Posted by Joel Fernandes 2 months ago
On Wed, Nov 19, 2025 at 05:19:06PM -0500, Peter Colberg wrote:
> Add a method to check if a PCI device is a Physical Function (PF).
> 
> Signed-off-by: Peter Colberg <pcolberg@redhat.com>
> ---
>  rust/kernel/pci.rs | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/rust/kernel/pci.rs b/rust/kernel/pci.rs
> index c20b8daeb7aadbef9f6ecfc48c972436efac9a08..814990d386708fe2ac652ccaa674c10a6cf390cb 100644
> --- a/rust/kernel/pci.rs
> +++ b/rust/kernel/pci.rs
> @@ -409,6 +409,12 @@ 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 Physical Function (VF).

nit:  s/VF/PF/

also, add #[inline].

With that,

Reviewed-by: Joel Fernandes <joelagnelf@nvidia.com>

thanks,

 - Joel



> +    pub fn is_physfn(&self) -> bool {
> +        // SAFETY: `self.as_raw` is a valid pointer to a `struct pci_dev`.
> +        unsafe { (*self.as_raw()).is_physfn() != 0 }
> +    }
> +
>      /// Returns `true` if this device is a Virtual Function (VF).
>      pub fn is_virtfn(&self) -> bool {
>          // SAFETY: `self.as_raw` is a valid pointer to a `struct pci_dev`.
> 
> -- 
> 2.51.1
>
Re: [PATCH 2/8] rust: pci: add is_physfn(), to check for PFs
Posted by Peter Colberg 2 months ago
On Sun, Dec 07, 2025 at 01:35:29AM -0500, Joel Fernandes wrote:
> On Wed, Nov 19, 2025 at 05:19:06PM -0500, Peter Colberg wrote:
> > Add a method to check if a PCI device is a Physical Function (PF).
> > 
> > Signed-off-by: Peter Colberg <pcolberg@redhat.com>
> > ---
> >  rust/kernel/pci.rs | 6 ++++++
> >  1 file changed, 6 insertions(+)
> > 
> > diff --git a/rust/kernel/pci.rs b/rust/kernel/pci.rs
> > index c20b8daeb7aadbef9f6ecfc48c972436efac9a08..814990d386708fe2ac652ccaa674c10a6cf390cb 100644
> > --- a/rust/kernel/pci.rs
> > +++ b/rust/kernel/pci.rs
> > @@ -409,6 +409,12 @@ 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 Physical Function (VF).
> 
> nit:  s/VF/PF/
> 
> also, add #[inline].
> 
> With that,
> 
> Reviewed-by: Joel Fernandes <joelagnelf@nvidia.com>

Thanks, done.

Peter

> 
> thanks,
> 
>  - Joel
> 
> 
> 
> > +    pub fn is_physfn(&self) -> bool {
> > +        // SAFETY: `self.as_raw` is a valid pointer to a `struct pci_dev`.
> > +        unsafe { (*self.as_raw()).is_physfn() != 0 }
> > +    }
> > +
> >      /// Returns `true` if this device is a Virtual Function (VF).
> >      pub fn is_virtfn(&self) -> bool {
> >          // SAFETY: `self.as_raw` is a valid pointer to a `struct pci_dev`.
> > 
> > -- 
> > 2.51.1
> > 
>
Re: [PATCH 2/8] rust: pci: add is_physfn(), to check for PFs
Posted by kernel test robot 2 months, 2 weeks ago
Hi Peter,

kernel test robot noticed the following build errors:

[auto build test ERROR on e4addc7cc2dfcc19f1c8c8e47f3834b22cb21559]

url:    https://github.com/intel-lab-lkp/linux/commits/Peter-Colberg/rust-pci-add-is_virtfn-to-check-for-VFs/20251120-062302
base:   e4addc7cc2dfcc19f1c8c8e47f3834b22cb21559
patch link:    https://lore.kernel.org/r/20251119-rust-pci-sriov-v1-2-883a94599a97%40redhat.com
patch subject: [PATCH 2/8] rust: pci: add is_physfn(), to check for PFs
config: um-randconfig-001-20251121 (https://download.01.org/0day-ci/archive/20251121/202511211257.8KOIldMM-lkp@intel.com/config)
compiler: clang version 22.0.0git (https://github.com/llvm/llvm-project 9e9fe08b16ea2c4d9867fb4974edf2a3776d6ece)
rustc: rustc 1.88.0 (6b00bc388 2025-06-23)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251121/202511211257.8KOIldMM-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202511211257.8KOIldMM-lkp@intel.com/

All errors (new ones prefixed by >>):

>> error[E0599]: no method named `is_physfn` found for struct `bindings::pci_dev` in the current scope
   --> rust/kernel/pci.rs:415:35
   |
   415 |         unsafe { (*self.as_raw()).is_physfn() != 0 }
   |                                   ^^^^^^^^^ method not found in `pci_dev`

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki