Skip to contentSkip to conversation

gpu: nova-core: avoid probing non-display/compute PCI functions

PATCH In review John Hubbard 2 participants 3 messages Aug 13, 2025 – Aug 14, 2025

Subsystems (6)
DRM drivers PCI Rust DRM Rust +2 more subsystems
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 gpu: nova-core: avoid probing non-display/compute PCI functions

This avoids a kernel crash that reliably happens 100% of the time on my particular hardware (x86 with Ampere or Blackwell GPUs installed).

The problem is that NovaCore has so far been very sloppy about figuring out if probe() has found a supported PCI PF (Physical Function). By that I mean: probe() sets up BAR0 (which involves a lot of very careful devres and Device<Bound> details behind the scenes). And then if it is handling a non-supported device such as the .1 audio PF on many GPUs, it fails out due to an unexpected BAR0 size. We have been fortunate that the BAR0 sizes are different.

Really, we should be filtering on PCI class ID instead. These days I think we can confidently pick out Nova's supported PF's via PCI class ID. And if not, then we'll revisit.

There *might* also be a deeper problem involving devres_release_all() teardown, but on the other hand, it could also be a difference of opinion about how early it is supposed to be droppable. Because failing later in the probe() path works just fine.

So instead of digging into devres lifetimes that are already correct when used carefully, just stop stress-testing that subsystem via inaccurate behavior in the first place:

a) Expose the PCI Device class (available during probe()) to Rust.

b) Use the PCI Device class to filter out non-display, non-compute PFs.

Relevant excerpts of the crash are shown below.

...
NovaCore 0000:c1:00.0: GPU instance built
NovaCore 0000:c1:00.1: Probe Nova Core GPU driver.
NovaCore 0000:c1:00.1: enabling device (0000 -> 0002) NovaCore 0000:c1:00.1: probe with driver NovaCore failed with error -22
...
Bad IO access at port 0x0 ()

WARNING: CPU: 26 PID: 748 at lib/iomap.c:45 pci_iounmap+0x3f/0x50
...
<kernel::devres::Devres<kernel::pci::Bar<16777216>>>::devres_callback+0x2c/0x70 [nova_core]
devres_release_all+0xa8/0xf0
really_probe+0x30f/0x420
__driver_probe_device+0x77/0xf0
driver_probe_device+0x22/0x1b0
__driver_attach+0x118/0x250
bus_for_each_dev+0x105/0x130
bus_add_driver+0x163/0x2a0
driver_register+0x5d/0xf0
init_module+0x6d/0x1000 [nova_core]
do_one_initcall+0xde/0x380
do_init_module+0x60/0x250

...and then:

BUG: kernel NULL pointer dereference, address: 0000000000000538
RIP: 0010:pci_release_region+0x10/0x60
...
<kernel::devres::Devres<kernel::pci::Bar<16777216>>>::devres_callback+0x36/0x70 [nova_core]
devres_release_all+0xa8/0xf0
really_probe+0x30f/0x420
__driver_probe_device+0x77/0xf0
driver_probe_device+0x22/0x1b0
__driver_attach+0x118/0x250
bus_for_each_dev+0x105/0x130
bus_add_driver+0x163/0x2a0
driver_register+0x5d/0xf0
init_module+0x6d/0x1000 [nova_core]
do_one_initcall+0xde/0x380
do_init_module+0x60/0x250
---
 drivers/gpu/nova-core/driver.rs | 13 +++++++++++++
 rust/kernel/pci.rs              |  6 ++++++
 2 files changed, 19 insertions(+)
drivers/gpu/nova-core/driver.rs +13 -0
index 274989ea1fb4..4e0e6f5338e9 100644
@@ -31,6 +31,19 @@ impl pci::Driver for NovaCore {
     fn probe(pdev: &pci::Device<Core>, _info: &Self::IdInfo) -> Result<Pin<KBox<Self>>> {
         dev_dbg!(pdev.as_ref(), "Probe Nova Core GPU driver.\n");
 
+        let class_code = pdev.class();
+
+        if class_code != bindings::PCI_CLASS_DISPLAY_VGA
+            && class_code != bindings::PCI_CLASS_DISPLAY_3D
+        {
+            dev_dbg!(
+                pdev.as_ref(),
+                "Skipping non-display NVIDIA device with class 0x{:04x}\n",
+                class_code
+            );
+            return Err(kernel::error::code::ENODEV);
+        }
+
         pdev.enable_device_mem()?;
         pdev.set_master();
 
rust/kernel/pci.rs +6 -0
index 887ee611b553..b6416fe7bdfd 100644
@@ -399,6 +399,12 @@ pub fn device_id(&self) -> u16 {
         unsafe { (*self.as_raw()).device }
     }
 
+    /// Returns the PCI class code (class and subclass).
+    pub fn class(&self) -> u32 {
+        // SAFETY: `self.as_raw` is a valid pointer to a `struct pci_dev`.
+        unsafe { (*self.as_raw()).class >> 8 }
+    }
+
     /// Returns the size of the given PCI bar resource.
     pub fn resource_len(&self, bar: u32) -> Result<bindings::resource_size_t> {
         if !Bar::index_is_valid(bar) {

base-commit: dfc0f6373094dd88e1eaf76c44f2ff01b65db851

Signature · 1 line
2.50.1
maintainer
#1 lore raw
Quoted 22 lines · John Hubbard

NovaCore 0000:c1:00.0: GPU instance built
NovaCore 0000:c1:00.1: Probe Nova Core GPU driver.
NovaCore 0000:c1:00.1: enabling device (0000 -> 0002) NovaCore 0000:c1:00.1: probe with driver NovaCore failed with error -22
...
Bad IO access at port 0x0 ()

WARNING: CPU: 26 PID: 748 at lib/iomap.c:45 pci_iounmap+0x3f/0x50
...
<kernel::devres::Devres<kernel::pci::Bar<16777216>>>::devres_callback+0x2c/0x70 [nova_core]
devres_release_all+0xa8/0xf0
really_probe+0x30f/0x420
__driver_probe_device+0x77/0xf0
driver_probe_device+0x22/0x1b0
__driver_attach+0x118/0x250
bus_for_each_dev+0x105/0x130
bus_add_driver+0x163/0x2a0
driver_register+0x5d/0xf0
init_module+0x6d/0x1000 [nova_core]
do_one_initcall+0xde/0x380
do_init_module+0x60/0x250

...and then:

Quoted 15 lines
BUG: kernel NULL pointer dereference, address: 0000000000000538
RIP: 0010:pci_release_region+0x10/0x60
...
<kernel::devres::Devres<kernel::pci::Bar<16777216>>>::devres_callback+0x36/0x70 [nova_core]
devres_release_all+0xa8/0xf0
really_probe+0x30f/0x420
__driver_probe_device+0x77/0xf0
driver_probe_device+0x22/0x1b0
__driver_attach+0x118/0x250
bus_for_each_dev+0x105/0x130
bus_add_driver+0x163/0x2a0
driver_register+0x5d/0xf0
init_module+0x6d/0x1000 [nova_core]
do_one_initcall+0xde/0x380
do_init_module+0x60/0x250

This is caused by a bug in Devres, which I already fixed in [1].

With the patch in [1] nova-core should gracefully fail probing for the non-supported device classes as expected.

However, I think we still want to filter by PCI class, so the patch is fine in general. :)

Few comments below.

[1] https://lore.kernel.org/lkml/[email protected]/

Quoted 12 lines
---
 drivers/gpu/nova-core/driver.rs | 13 +++++++++++++
 rust/kernel/pci.rs              |  6 ++++++
 2 files changed, 19 insertions(+)
drivers/gpu/nova-core/driver.rs +0 -0
index 274989ea1fb4..4e0e6f5338e9 100644

drivers/gpu/nova-core/driver.rs impl pci::Driver for NovaCore { · line 37

Quoted 7 lines
drivers/gpu/nova-core/driver.rs +4 -0
@@ -31,6 +31,19 @@ impl pci::Driver for NovaCore {
     fn probe(pdev: &pci::Device<Core>, _info: &Self::IdInfo) -> Result<Pin<KBox<Self>>> {
         dev_dbg!(pdev.as_ref(), "Probe Nova Core GPU driver.\n");
 
+        let class_code = pdev.class();
+
+        if class_code != bindings::PCI_CLASS_DISPLAY_VGA
+            && class_code != bindings::PCI_CLASS_DISPLAY_3D

I think it would be nice if we could provide a Rust enum for PCI classes, such that this could be pci::Class::DISPLAY_VGA instead.

Of course the same is true for PCI (sub)vendor, (sub)device IDs.

drivers/gpu/nova-core/driver.rs impl pci::Driver for NovaCore { · line 44

Quoted 7 lines
drivers/gpu/nova-core/driver.rs +7 -0
+        {
+            dev_dbg!(
+                pdev.as_ref(),
+                "Skipping non-display NVIDIA device with class 0x{:04x}\n",
+                class_code
+            );
+            return Err(kernel::error::code::ENODEV);

With the prelude included you should be able to use ENODEV directly.

rust/kernel/pci.rs

Quoted 6 lines
drivers/gpu/nova-core/driver.rs +2 -0
+        }
+
         pdev.enable_device_mem()?;
         pdev.set_master();
 
rust/kernel/pci.rs +0 -0

Please split the PCI part up into a separate patch.

Quoted 20 lines

index 887ee611b553..b6416fe7bdfd 100644

rust/kernel/pci.rs +6 -0
@@ -399,6 +399,12 @@ pub fn device_id(&self) -> u16 {
         unsafe { (*self.as_raw()).device }
     }
 
+    /// Returns the PCI class code (class and subclass).
+    pub fn class(&self) -> u32 {
+        // SAFETY: `self.as_raw` is a valid pointer to a `struct pci_dev`.
+        unsafe { (*self.as_raw()).class >> 8 }
+    }
+
     /// Returns the size of the given PCI bar resource.
     pub fn resource_len(&self, bar: u32) -> Result<bindings::resource_size_t> {
         if !Bar::index_is_valid(bar) {

base-commit: dfc0f6373094dd88e1eaf76c44f2ff01b65db851

Signature · 1 line
2.50.1
#2 lore raw
Quoted 39 lines · Danilo Krummrich
Quoted 22 lines · John Hubbard

NovaCore 0000:c1:00.0: GPU instance built
NovaCore 0000:c1:00.1: Probe Nova Core GPU driver.
NovaCore 0000:c1:00.1: enabling device (0000 -> 0002) NovaCore 0000:c1:00.1: probe with driver NovaCore failed with error -22
...
Bad IO access at port 0x0 ()

WARNING: CPU: 26 PID: 748 at lib/iomap.c:45 pci_iounmap+0x3f/0x50
...
<kernel::devres::Devres<kernel::pci::Bar<16777216>>>::devres_callback+0x2c/0x70 [nova_core]
devres_release_all+0xa8/0xf0
really_probe+0x30f/0x420
__driver_probe_device+0x77/0xf0
driver_probe_device+0x22/0x1b0
__driver_attach+0x118/0x250
bus_for_each_dev+0x105/0x130
bus_add_driver+0x163/0x2a0
driver_register+0x5d/0xf0
init_module+0x6d/0x1000 [nova_core]
do_one_initcall+0xde/0x380
do_init_module+0x60/0x250

...and then:

Quoted 15 lines
BUG: kernel NULL pointer dereference, address: 0000000000000538
RIP: 0010:pci_release_region+0x10/0x60
...
<kernel::devres::Devres<kernel::pci::Bar<16777216>>>::devres_callback+0x36/0x70 [nova_core]
devres_release_all+0xa8/0xf0
really_probe+0x30f/0x420
__driver_probe_device+0x77/0xf0
driver_probe_device+0x22/0x1b0
__driver_attach+0x118/0x250
bus_for_each_dev+0x105/0x130
bus_add_driver+0x163/0x2a0
driver_register+0x5d/0xf0
init_module+0x6d/0x1000 [nova_core]
do_one_initcall+0xde/0x380
do_init_module+0x60/0x250
Quoted 1 line

This is caused by a bug in Devres, which I already fixed in [1].

Nice timing! btw, I scanned through rust-for-linux emails, and wasn't immediately able to connect it ("fix leak...") with this crash.

You might want to add a little note to that commit description, to mention that it also prevents a kernel crash in some cases?

Quoted 3 lines

With the patch in [1] nova-core should gracefully fail probing for the non-supported device classes as expected.

Beautiful.

Quoted 30 lines

However, I think we still want to filter by PCI class, so the patch is fine in general. :)

Few comments below.

[1] https://lore.kernel.org/lkml/[email protected]/

Quoted 12 lines
---
 drivers/gpu/nova-core/driver.rs | 13 +++++++++++++
 rust/kernel/pci.rs              |  6 ++++++
 2 files changed, 19 insertions(+)
drivers/gpu/nova-core/driver.rs +0 -0
index 274989ea1fb4..4e0e6f5338e9 100644

drivers/gpu/nova-core/driver.rs impl pci::Driver for NovaCore { · line 37

Quoted 7 lines
drivers/gpu/nova-core/driver.rs +4 -0
@@ -31,6 +31,19 @@ impl pci::Driver for NovaCore {
     fn probe(pdev: &pci::Device<Core>, _info: &Self::IdInfo) -> Result<Pin<KBox<Self>>> {
         dev_dbg!(pdev.as_ref(), "Probe Nova Core GPU driver.\n");
 
+        let class_code = pdev.class();
+
+        if class_code != bindings::PCI_CLASS_DISPLAY_VGA
+            && class_code != bindings::PCI_CLASS_DISPLAY_3D

I think it would be nice if we could provide a Rust enum for PCI classes, such that this could be pci::Class::DISPLAY_VGA instead.

Quoted 2 lines

Of course the same is true for PCI (sub)vendor, (sub)device IDs.

OK, will do.

Quoted 9 lines

drivers/gpu/nova-core/driver.rs impl pci::Driver for NovaCore { · line 44

Quoted 7 lines
drivers/gpu/nova-core/driver.rs +7 -0
+        {
+            dev_dbg!(
+                pdev.as_ref(),
+                "Skipping non-display NVIDIA device with class 0x{:04x}\n",
+                class_code
+            );
+            return Err(kernel::error::code::ENODEV);

With the prelude included you should be able to use ENODEV directly.

Yes. I should have noticed that, sorry.

Quoted 9 lines

rust/kernel/pci.rs

Quoted 7 lines
drivers/gpu/nova-core/driver.rs +2 -0
+        }
+
         pdev.enable_device_mem()?;
         pdev.set_master();
 
rust/kernel/pci.rs +0 -0

Please split the PCI part up into a separate patch.

OK, will do.

Thanks for the review!

thanks,

Signature · 1 line
John Hubbard
Quoted 22 lines
Quoted 21 lines

index 887ee611b553..b6416fe7bdfd 100644

rust/kernel/pci.rs +6 -0
@@ -399,6 +399,12 @@ pub fn device_id(&self) -> u16 {
         unsafe { (*self.as_raw()).device }
     }
 
+    /// Returns the PCI class code (class and subclass).
+    pub fn class(&self) -> u32 {
+        // SAFETY: `self.as_raw` is a valid pointer to a `struct pci_dev`.
+        unsafe { (*self.as_raw()).class >> 8 }
+    }
+
     /// Returns the size of the given PCI bar resource.
     pub fn resource_len(&self, bar: u32) -> Result<bindings::resource_size_t> {
         if !Bar::index_is_valid(bar) {

base-commit: dfc0f6373094dd88e1eaf76c44f2ff01b65db851

Signature · 1 line
2.50.1