diff options
| author | John Hubbard <jhubbard@nvidia.com> | 2026-10-02 16:11:35 +0900 |
|---|---|---|
| committer | Alexandre Courbot <acourbot@nvidia.com> | 2026-10-02 21:49:40 +0900 |
| commit | 9cb3f5d56e81fd97a82ef361b210bc2322daaaa7 (patch) | |
| tree | 5a6e907c296299a520b6244ec89279a961936ce0 /drivers/gpu | |
| parent | 94ddc4b4843da8b1858535b13318346cb950800d (diff) | |
gpu: nova-core: add an interrupt delivery self-test
A GPU interrupt can be lost in the MSI or MSI-X allocation, in the GIN
tree's enables, or in the rearm, and every one of those failures looks
the same: no interrupt arrives, and no register or log line says which
one broke.
Add a probe-time self-test, built under NOVA_CORE_SELFTESTS, that
latches the CPU doorbell vector through the GIN software trigger and
waits for a registered handler to service it. One delivery would pass
with a broken rearm, because the first message-signaled interrupt
arrives whether or not the driver rearms, so the test triggers twice and
waits for the first handler to finish before the second trigger. It runs
after GFW boot and before GSP boot, on a quiesced tree, and fails probe
unless both deliveries arrive, each finds only the doorbell pending, and
the leaf ends clear.
The doorbell has the same vector on every supported GPU, so the test
names it without asking GSP-RM. It allocates the PCI vectors for the
doorbell's subtree and releases them before returning, so under MSI-X
the delivery also exercises that subtree's table entry.
Assisted-by: LLM
Co-developed-by: Joel Fernandes <joelagnelf@nvidia.com>
Signed-off-by: Joel Fernandes <joelagnelf@nvidia.com>
Signed-off-by: John Hubbard <jhubbard@nvidia.com>
Acked-by: Danilo Krummrich <dakr@kernel.org>
Link: https://patch.msgid.link/20260930034148.590687-9-jhubbard@nvidia.com
[acourbot: move relevant bits of previous patch into this one.]
[acourbot: remove reference to self-test section of documentation.]
[acourbot: replace completions with atomic polling code.]
Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
Diffstat (limited to 'drivers/gpu')
| -rw-r--r-- | drivers/gpu/nova-core/Kconfig | 5 | ||||
| -rw-r--r-- | drivers/gpu/nova-core/driver.rs | 19 | ||||
| -rw-r--r-- | drivers/gpu/nova-core/gpu.rs | 2 | ||||
| -rw-r--r-- | drivers/gpu/nova-core/irq.rs | 2 | ||||
| -rw-r--r-- | drivers/gpu/nova-core/irq/doorbell_test.rs | 251 | ||||
| -rw-r--r-- | drivers/gpu/nova-core/irq/interrupt_tree.rs | 15 | ||||
| -rw-r--r-- | drivers/gpu/nova-core/nova_core.rs | 2 |
7 files changed, 293 insertions, 3 deletions
diff --git a/drivers/gpu/nova-core/Kconfig b/drivers/gpu/nova-core/Kconfig index 1934f17baa8b..2e11e46c99c7 100644 --- a/drivers/gpu/nova-core/Kconfig +++ b/drivers/gpu/nova-core/Kconfig @@ -24,4 +24,9 @@ config NOVA_CORE_SELFTESTS help Build the driver self-tests and run them when the GPU is probed. + If the interrupt delivery test fails, the probe fails and the driver + does not bind to the GPU. A broken interrupt path would otherwise + show up later as a hang, far from its cause. Every other self-test + logs its failure and lets the probe continue. + If unsure, say N. diff --git a/drivers/gpu/nova-core/driver.rs b/drivers/gpu/nova-core/driver.rs index 623d59dcde6e..d195fd2bcf8c 100644 --- a/drivers/gpu/nova-core/driver.rs +++ b/drivers/gpu/nova-core/driver.rs @@ -24,7 +24,10 @@ use kernel::{ use crate::{ api::NovaCoreApi, - gpu::Gpu, // + gpu::{ + Gpu, + Spec, // + }, // }; /// Counter for generating unique auxiliary device IDs. @@ -115,6 +118,20 @@ impl pci::Driver for NovaCoreDriver { pdev.iomap_region(bar1_idx, c"nova-core/bar1")? }, + // Run self-tests that do not depend on the `Gpu` instance. + #[cfg(CONFIG_NOVA_CORE_SELFTESTS)] + _: { + let spec = Spec::new(pdev.as_ref(), bar)?; + + // We must wait for GFW_BOOT completion before doing any significant setup on + // the GPU. + Gpu::wait_gfw_boot_completion(pdev.as_ref(), bar, spec.chipset)?; + + // The self-test disables and drains the whole tree, so it has to run before + // `Gpu::new` boots the GSP. + crate::irq::doorbell_test::run_selftest(pdev, bar, spec.chipset)?; + }, + // TODO: Use self-referential pin-init syntax once available. gpu <- Gpu::new( pdev, diff --git a/drivers/gpu/nova-core/gpu.rs b/drivers/gpu/nova-core/gpu.rs index a7f6b1806f36..f91c7e22a303 100644 --- a/drivers/gpu/nova-core/gpu.rs +++ b/drivers/gpu/nova-core/gpu.rs @@ -251,7 +251,7 @@ pub struct Spec { } impl Spec { - fn new(dev: &device::Device, bar: Bar0<'_>) -> Result<Spec> { + pub(crate) fn new(dev: &device::Device, bar: Bar0<'_>) -> Result<Spec> { // Some brief notes about boot0 and boot42, in chronological order: // // NV04 through NV50: diff --git a/drivers/gpu/nova-core/irq.rs b/drivers/gpu/nova-core/irq.rs index b2cfe73af114..ff8b00a82442 100644 --- a/drivers/gpu/nova-core/irq.rs +++ b/drivers/gpu/nova-core/irq.rs @@ -9,6 +9,8 @@ //! //! See `Documentation/gpu/nova/core/interrupts.rst`. +#[cfg(CONFIG_NOVA_CORE_SELFTESTS)] +pub(crate) mod doorbell_test; mod hal; pub(crate) mod interrupt_tree; mod regs; diff --git a/drivers/gpu/nova-core/irq/doorbell_test.rs b/drivers/gpu/nova-core/irq/doorbell_test.rs new file mode 100644 index 000000000000..db6338e4dbde --- /dev/null +++ b/drivers/gpu/nova-core/irq/doorbell_test.rs @@ -0,0 +1,251 @@ +// SPDX-License-Identifier: GPL-2.0 +// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. + +//! Interrupt delivery self-test. +//! +//! The test triggers the CPU doorbell vector from software, twice, and checks that each trigger +//! reaches a registered handler. It runs during probe under `CONFIG_NOVA_CORE_SELFTESTS`. + +use core::pin::Pin; + +use kernel::{ + device::Bound, + io::poll::read_poll_timeout, + irq, + pci, + prelude::*, + sync::atomic::{ + Acquire, + Atomic, + Relaxed, + Release, // + }, + time::Delta, // +}; + +use super::interrupt_tree::{ + GinVector, + LeafEnableGuard, + LeafMask, + Subtree, + TopEnableGuard, + Tree, // +}; + +use crate::{ + driver::Bar0, + gpu::Chipset, + selftest_assert, + selftest_assert_eq, // +}; + +/// The CPU doorbell vector. Every supported GPU uses this number, so the test needs nothing from +/// GSP-RM, which is not running yet. +const DOORBELL_VECTOR: GinVector = GinVector::new::<129>(); + +/// The only subtree that this test services. +const DOORBELL_SUBTREE: Subtree = DOORBELL_VECTOR.subtree(); + +/// Time allowed for each delivery to arrive. +const DELIVERY_TIMEOUT: Delta = Delta::from_millis(1000); + +/// The self-test's interrupt handler. +/// +/// It clears only the doorbell's bit, rearms delivery, and never walks the tree. A missing rearm +/// shows up as a timeout on the second delivery. +#[pin_data] +struct DoorbellTestHandler<'a> { + tree: &'a Tree<'a>, + /// Deliveries that found the doorbell bit set. + irq_count: Atomic<u32>, + /// The doorbell leaf's pending bits, as read by the first delivery. + first_pending: Atomic<u32>, + /// The doorbell leaf's pending bits, as read by the second delivery. + second_pending: Atomic<u32>, +} + +impl irq::Handler for DoorbellTestHandler<'_> { + fn handle(&self) -> irq::IrqReturn { + let leaf = self.tree.read_pending(DOORBELL_VECTOR.leaf_index()); + let pending = leaf.vectors(); + if !pending.contains(DOORBELL_VECTOR.leaf_mask()) { + self.tree.rearm_pci_irq(DOORBELL_SUBTREE); + return irq::IrqReturn::None; + } + leaf.clear_vectors(DOORBELL_VECTOR.leaf_mask()); + // Rearm before counting the delivery, since the waiting thread triggers the next doorbell + // as soon as it observes the count. + self.tree.rearm_pci_irq(DOORBELL_SUBTREE); + + match self.irq_count.load(Relaxed) { + 0 => self.first_pending.store(pending.into_raw(), Relaxed), + 1 => self.second_pending.store(pending.into_raw(), Relaxed), + _ => (), + } + self.irq_count.fetch_add(1, Release); + + irq::IrqReturn::Handled + } +} + +/// The self-test's handler registration and the enables that deliver to it. +/// +/// Drops in the order that "Enabling the GSP event" in +/// `Documentation/gpu/nova/core/interrupts.rst` requires: the vector is disabled, then the +/// handler is freed, then the subtree is disabled. +struct SelftestResources<'a, 'r> { + _leaf_guard: LeafEnableGuard<'a>, + reg: Pin<KBox<irq::Registration<'r, DoorbellTestHandler<'a>>>>, + _top_guard: TopEnableGuard<'a>, +} + +impl<'a> SelftestResources<'a, '_> { + fn handler(&self) -> &DoorbellTestHandler<'a> { + self.reg.handler() + } + + /// Disables the doorbell vector and waits for a handler in flight on another CPU to finish. + /// + /// The handler's counters and the leaf's pending bits are final on return. + fn quiesce_source(&self) { + self.handler() + .tree + .disable_leaf(DOORBELL_VECTOR.leaf_index(), DOORBELL_VECTOR.leaf_mask()); + self.reg.synchronize(); + } +} + +/// Waits until `handler` has serviced `deliveries` interrupts, or [`DELIVERY_TIMEOUT`] elapses. +/// +/// Returns `false` on timeout. +fn wait_for_deliveries(handler: &DoorbellTestHandler<'_>, deliveries: u32) -> bool { + const DELIVERY_POLL_INTERVAL: Delta = Delta::from_micros(100); + + read_poll_timeout( + || Ok(handler.irq_count.load(Acquire)), + |count| *count >= deliveries, + DELIVERY_POLL_INTERVAL, + DELIVERY_TIMEOUT, + ) + .is_ok() +} + +/// Runs the interrupt delivery self-test. +/// +/// Call this only during probe, before GSP boot: it disables every vector in the tree and clears +/// every pending bit. On return, the doorbell's subtree is disabled at `TOP`, and the test's PCI +/// vectors and handler are released. +/// +/// # Errors +/// +/// `EINVAL` if `chipset` does not implement the doorbell's subtree. `ETIMEDOUT` if a delivery +/// does not arrive within [`DELIVERY_TIMEOUT`]. `EIO` if a self-test assertion fails. +/// Otherwise the error from allocating the PCI vectors or registering the handler. +pub(crate) fn run_selftest(pdev: &pci::Device<Bound>, bar: Bar0<'_>, chipset: Chipset) -> Result { + let tree = Tree::new(pdev, bar, chipset, DOORBELL_SUBTREE.into())?; + let tree_ref = &tree; + let request = tree.request_for(DOORBELL_SUBTREE)?; + let doorbell = DOORBELL_VECTOR.leaf_index(); + let doorbell_mask = DOORBELL_VECTOR.leaf_mask(); + + dev_info!( + pdev, + "interrupt self-test: starting on vector {}, subtree {}, with {:?}\n", + DOORBELL_VECTOR.into_raw(), + DOORBELL_SUBTREE.index(), + tree.msi_type, + ); + + // GFW boot can leave vectors enabled and pending. Registering a handler unmasks the PCI + // interrupt, and they would be delivered to a handler that services only the doorbell. + tree.reset(); + + // A delivery proves nothing unless the doorbell bit starts out clear. + let pre_pending = tree.read_pending(doorbell).vectors(); + selftest_assert!( + pdev, + !pre_pending.contains(doorbell_mask), + "vector {} already pending, leaf[{}] is {:#x}", + DOORBELL_VECTOR.into_raw(), + doorbell.get(), + pre_pending.into_raw() + ); + + let handler_init = try_pin_init!(DoorbellTestHandler { + tree: tree_ref, + irq_count: Atomic::new(0), + first_pending: Atomic::new(0), + second_pending: Atomic::new(0), + }? Error); + + // Registration must precede any enable, or a delivery reaches no handler. + let reg = KBox::pin_init( + // SAFETY: this registration is dropped before the enclosing function returns, so its + // `Drop`, which calls `free_irq()`, always runs. + unsafe { + irq::Registration::new( + request, + irq::Flags::TRIGGER_NONE, + c"nova-core-selftest", + handler_init, + ) + }, + GFP_KERNEL, + )?; + + let resources = SelftestResources { + _leaf_guard: tree.enable_leaf_guarded(doorbell, doorbell_mask), + _top_guard: tree.enable_top_guarded(), + reg, + }; + let handler = resources.handler(); + + tree.trigger(DOORBELL_VECTOR)?; + let mut completed = wait_for_deliveries(handler, 1); + + // The second trigger waits for the first delivery, or the two could coalesce. + if completed { + tree.trigger(DOORBELL_VECTOR)?; + completed = wait_for_deliveries(handler, 2); + } + + resources.quiesce_source(); + + let count = handler.irq_count.load(Relaxed); + let first_pending = LeafMask::from_raw(handler.first_pending.load(Relaxed)); + let second_pending = LeafMask::from_raw(handler.second_pending.load(Relaxed)); + let residual = tree.read_pending(doorbell).vectors(); + + if !completed { + dev_err!( + pdev, + "interrupt self-test: only {} of 2 deliveries arrived within {} ms\n", + count, + DELIVERY_TIMEOUT.as_millis(), + ); + return Err(ETIMEDOUT); + } + + selftest_assert_eq!(pdev, count, 2, "delivery count"); + + // Every other vector in the leaf is disabled and was drained, so require the exact mask. + selftest_assert_eq!(pdev, first_pending, doorbell_mask, "first delivery"); + selftest_assert_eq!(pdev, second_pending, doorbell_mask, "second delivery"); + selftest_assert!( + pdev, + !residual.contains(doorbell_mask), + "vector {} still pending, leaf[{}] is {:#x}", + DOORBELL_VECTOR.into_raw(), + doorbell.get(), + residual.into_raw() + ); + + dev_info!( + pdev, + "interrupt self-test: passed, subtree {}, {} deliveries\n", + DOORBELL_SUBTREE.index(), + count, + ); + + Ok(()) +} diff --git a/drivers/gpu/nova-core/irq/interrupt_tree.rs b/drivers/gpu/nova-core/irq/interrupt_tree.rs index da4203137bce..c1576ea3e61f 100644 --- a/drivers/gpu/nova-core/irq/interrupt_tree.rs +++ b/drivers/gpu/nova-core/irq/interrupt_tree.rs @@ -444,6 +444,21 @@ impl<'a> Tree<'a> { } } + /// Sets the pending bit of `vector` in its leaf, as if the vector's source had raised it. + /// + /// # Errors + /// + /// `EINVAL` if this tree does not implement `vector`. + #[cfg_attr(not(CONFIG_NOVA_CORE_SELFTESTS), expect(dead_code))] + pub(super) fn trigger(&self, vector: GinVector) -> Result { + vector.validate(self.hal.leaf_count())?; + self.bar.write_reg( + NV_VIRTUAL_FUNCTION_PRIV_CPU_INTR_LEAF_TRIGGER::zeroed().with_vector(vector), + ); + + Ok(()) + } + /// Disables every vector in every implemented leaf, including the subtrees that nova-core does /// not service. Call this only during probe. pub(super) fn disable_all_leaves(&self) { diff --git a/drivers/gpu/nova-core/nova_core.rs b/drivers/gpu/nova-core/nova_core.rs index 8202c4982efa..8c0761dedda4 100644 --- a/drivers/gpu/nova-core/nova_core.rs +++ b/drivers/gpu/nova-core/nova_core.rs @@ -18,7 +18,7 @@ mod firmware; mod fsp; mod gpu; mod gsp; -#[expect(dead_code)] +#[cfg_attr(not(CONFIG_NOVA_CORE_SELFTESTS), expect(dead_code))] mod irq; mod mctp; mod mm; |
