John Hubbard
2025-Oct-02 02:00 UTC
[PATCH v2 0/2] rust: pci: don't probe() VFs in nova-core
Changes in v2: 1) Completely rewrote the series, using Danilo's suggested approach of "driver supports VF probing or not": the PCI driver core will skip probing any device's VFs if the driver has coded itself as "not supporting VFs". 2) Included Joel's clarification, as a comment in the code, about what happens if VFs are probed. As with v1 [1], I've based this on top of today's driver-core-next [2], because the first patch belongs there, and the second patch applies cleanly to either driver-core-next or drm-rust-next. So this seems like the easiest to work with. [1]] https://lore.kernel.org/20250930220759.288528-1-jhubbard at nvidia.com [2] https://git.kernel.org/pub/scm/linux/kernel/git/driver-core/driver-core.git/ Cc: Alexandre Courbot <acourbot at nvidia.com> Cc: Alistair Popple <apopple at nvidia.com> Cc: Joel Fernandes <joelagnelf at nvidia.com> Cc: Zhi Wang <zhiw at nvidia.com> Cc: Alex Williamson <alex.williamson at redhat.com> Cc: Jason Gunthorpe <jgg at nvidia.com> Cc: Danilo Krummrich <dakr at kernel.org> John Hubbard (2): rust: pci: skip probing VFs if driver doesn't support VFs gpu: nova-core: declare that VFs are not (yet) supported drivers/gpu/nova-core/driver.rs | 5 +++++ drivers/pci/pci-driver.c | 3 +++ include/linux/pci.h | 1 + rust/kernel/pci.rs | 4 ++++ 4 files changed, 13 insertions(+) base-commit: 6d97171ac6585de698df019b0bfea3f123fd8385 -- 2.51.0
John Hubbard
2025-Oct-02 02:00 UTC
[PATCH v2 1/2] rust: pci: skip probing VFs if driver doesn't support VFs
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 at nvidia.com>
Cc: Alistair Popple <apopple at nvidia.com>
Cc: Joel Fernandes <joelagnelf at nvidia.com>
Cc: Zhi Wang <zhiw at nvidia.com>
Cc: Alex Williamson <alex.williamson at redhat.com>
Cc: Jason Gunthorpe <jgg at nvidia.com>
Suggested-by: Danilo Krummrich <dakr at kernel.org>
Signed-off-by: John Hubbard <jhubbard at nvidia.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 */
};
#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
John Hubbard
2025-Oct-02 02:00 UTC
[PATCH v2 2/2] gpu: nova-core: declare that VFs are not (yet) supported
nova-core does not yet support PCIe Virtual Functions (VFs). Until it
does, declare to the Rust PCI driver core that VFs are not supported.
Because the Rust PCI driver core defaults to Driver::SUPPORTS_VF false, this
change is not strictly necessary for functionality. Its
purpose is to provide a self-documentating line of code that can be
easily changed, when VF support is being added.
Cc: Alexandre Courbot <acourbot at nvidia.com>
Cc: Alistair Popple <apopple at nvidia.com>
Cc: Joel Fernandes <joelagnelf at nvidia.com>
Cc: Zhi Wang <zhiw at nvidia.com>
Cc: Alex Williamson <alex.williamson at redhat.com>
Cc: Jason Gunthorpe <jgg at nvidia.com>
Suggested-by: Danilo Krummrich <dakr at kernel.org>
Signed-off-by: John Hubbard <jhubbard at nvidia.com>
---
drivers/gpu/nova-core/driver.rs | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/drivers/gpu/nova-core/driver.rs b/drivers/gpu/nova-core/driver.rs
index 5d23a91f51dd..4c19b0067862 100644
--- a/drivers/gpu/nova-core/driver.rs
+++ b/drivers/gpu/nova-core/driver.rs
@@ -51,6 +51,11 @@ impl pci::Driver for NovaCore {
type IdInfo = ();
const ID_TABLE: pci::IdTable<Self::IdInfo> = &PCI_TABLE;
+ // PCI probe() will report the same device ID for a PF and its associated
VFs. This will cause
+ // failures when trying to bind to the VFs, until NovaCore adds support to
handle that
+ // situation. Until then, tell the PCI driver core that we don't
support VFs.
+ const SUPPORTS_VF: bool = false;
+
fn probe(pdev: &pci::Device<Core>, _info: &Self::IdInfo)
-> Result<Pin<KBox<Self>>> {
dev_dbg!(pdev.as_ref(), "Probe Nova Core GPU driver.\n");
--
2.51.0