lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <DD7TANT8PB1W.2SVA4TOU80BFN@kernel.org>
Date: Thu, 02 Oct 2025 13:49:37 +0200
From: "Danilo Krummrich" <dakr@...nel.org>
To: "John Hubbard" <jhubbard@...dia.com>
Cc: "Alexandre Courbot" <acourbot@...dia.com>, "Joel Fernandes"
 <joelagnelf@...dia.com>, "Timur Tabi" <ttabi@...dia.com>, "Alistair Popple"
 <apopple@...dia.com>, "Zhi Wang" <zhiw@...dia.com>, "Surath Mitra"
 <smitra@...dia.com>, "David Airlie" <airlied@...il.com>, "Simona Vetter"
 <simona@...ll.ch>, "Alex Williamson" <alex.williamson@...hat.com>, "Jason
 Gunthorpe" <jgg@...dia.com>, "Bjorn Helgaas" <bhelgaas@...gle.com>,
 Krzysztof Wilczyński <kwilczynski@...nel.org>, "Miguel
 Ojeda" <ojeda@...nel.org>, "Alex Gaynor" <alex.gaynor@...il.com>, "Boqun
 Feng" <boqun.feng@...il.com>, "Gary Guo" <gary@...yguo.net>,
 Björn Roy Baron <bjorn3_gh@...tonmail.com>, "Benno Lossin"
 <lossin@...nel.org>, "Andreas Hindborg" <a.hindborg@...nel.org>, "Alice
 Ryhl" <aliceryhl@...gle.com>, "Trevor Gross" <tmgross@...ch.edu>,
 <nouveau@...ts.freedesktop.org>, <linux-pci@...r.kernel.org>,
 <rust-for-linux@...r.kernel.org>, "LKML" <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH v2 1/2] rust: pci: skip probing VFs if driver doesn't
 support VFs

On Thu Oct 2, 2025 at 4:00 AM CEST, John Hubbard wrote:
> Add a "supports_vf" flag to struct pci_driver to let drivers declare
> Virtual Function (VF) support. If a driver does not support VFs, then
> the PCI driver core will not probe() any VFs for that driver's devices.
>
> On the Rust side, add a const "SUPPORTS_VF" Driver trait, defaulting to
> false: drivers must explicitly opt into VF support.
>
> Cc: Alexandre Courbot <acourbot@...dia.com>
> Cc: Alistair Popple <apopple@...dia.com>
> Cc: Joel Fernandes <joelagnelf@...dia.com>
> Cc: Zhi Wang <zhiw@...dia.com>
> Cc: Alex Williamson <alex.williamson@...hat.com>
> Cc: Jason Gunthorpe <jgg@...dia.com>
> Suggested-by: Danilo Krummrich <dakr@...nel.org>
> Signed-off-by: John Hubbard <jhubbard@...dia.com>
> ---
>  drivers/pci/pci-driver.c | 3 +++
>  include/linux/pci.h      | 1 +
>  rust/kernel/pci.rs       | 4 ++++
>  3 files changed, 8 insertions(+)
>
> diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c
> index 63665240ae87..588666cc7254 100644
> --- a/drivers/pci/pci-driver.c
> +++ b/drivers/pci/pci-driver.c
> @@ -412,6 +412,9 @@ static int __pci_device_probe(struct pci_driver *drv, struct pci_dev *pci_dev)
>  	if (drv->probe) {
>  		error = -ENODEV;
>  
> +		if (pci_dev->is_virtfn && !drv->supports_vf)
> +			return error;
> +
>  		id = pci_match_device(drv, pci_dev);
>  		if (id)
>  			error = pci_call_probe(drv, pci_dev, id);
> diff --git a/include/linux/pci.h b/include/linux/pci.h
> index 59876de13860..92510886a086 100644
> --- a/include/linux/pci.h
> +++ b/include/linux/pci.h
> @@ -983,6 +983,7 @@ struct pci_driver {
>  	struct device_driver	driver;
>  	struct pci_dynids	dynids;
>  	bool driver_managed_dma;
> +	bool supports_vf;	/* Will bind to Virtual Functions */

I don't see any driver changes in this patch, are we sure this doesn't break any
existing drivers given that this defaults to false?

Obviously, the safe call would be to invert the logic, such that it defaults to
VFs being supported, though I clearly do prefer the opt-in.

Also, in C this always defaults to false, whereas in Rust we have the choice to
make it true by default, hence in C we'd need to invert the semantics, which is
not desirable either.

>  };
>  
>  #define to_pci_driver(__drv)	\
> diff --git a/rust/kernel/pci.rs b/rust/kernel/pci.rs
> index 7fcc5f6022c1..c5d036770e65 100644
> --- a/rust/kernel/pci.rs
> +++ b/rust/kernel/pci.rs
> @@ -47,6 +47,7 @@ unsafe fn register(
>              (*pdrv.get()).probe = Some(Self::probe_callback);
>              (*pdrv.get()).remove = Some(Self::remove_callback);
>              (*pdrv.get()).id_table = T::ID_TABLE.as_ptr();
> +            (*pdrv.get()).supports_vf = T::SUPPORTS_VF;
>          }
>  
>          // SAFETY: `pdrv` is guaranteed to be a valid `RegType`.
> @@ -268,6 +269,9 @@ pub trait Driver: Send {
>      /// The table of device ids supported by the driver.
>      const ID_TABLE: IdTable<Self::IdInfo>;
>  
> +    /// Whether the driver supports Virtual Functions.
> +    const SUPPORTS_VF: bool = false;
> +
>      /// PCI driver probe.
>      ///
>      /// Called when a new pci device is added or discovered. Implementers should
> -- 
> 2.51.0


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ