[PATCH v2 14/15] gpu: nova-core: add KUnit tests for the interrupt tree and HALs
From: John Hubbard
Date: Fri Aug 28 2026 - 21:36:50 EST
Neither the per-architecture interrupt policy nor the vector
arithmetic touches hardware, so KUnit can cover both without a GPU.
Add three suites:
* nova_core_gin_tree covers the leaf index bounds, what a leaf count
derives, the subtree-to-leaf mapping and its out-of-range filtering,
where a vector lands in the tree, the bound that rejects a vector
outside it, the subtree set operations, and that every supported
chipset implements the subtree carrying the GSP notification.
* nova_core_gin_hal covers the tree size on each family, and the
rearm method for each combination of family and interrupt type.
* nova_core_falcon_hal covers the falcon retrigger gate. It is keyed
on the architecture rather than the HAL, because GA100 shares the
Turing HAL but does have the register.
Assisted-by: Cursor:claude-opus-5
Reviewed-by: Will Pierce <wpierce@xxxxxxxxxx>
Signed-off-by: John Hubbard <jhubbard@xxxxxxxxxx>
---
drivers/gpu/nova-core/falcon/hal.rs | 24 +++++
drivers/gpu/nova-core/irq/hal.rs | 83 ++++++++++++++-
drivers/gpu/nova-core/irq/interrupt_tree.rs | 110 ++++++++++++++++++++
3 files changed, 216 insertions(+), 1 deletion(-)
diff --git a/drivers/gpu/nova-core/falcon/hal.rs b/drivers/gpu/nova-core/falcon/hal.rs
index f0828b32aebb..6bff9fea1a79 100644
--- a/drivers/gpu/nova-core/falcon/hal.rs
+++ b/drivers/gpu/nova-core/falcon/hal.rs
@@ -107,3 +107,27 @@ pub(super) fn falcon_hal<E: FalconEngine + 'static>(
Ok(hal)
}
+
+#[kunit_tests(nova_core_falcon_hal)]
+mod tests {
+ use super::*;
+
+ /// Only Turing falcons lack the interrupt retrigger register. GA100 has it even though
+ /// [`falcon_hal`] gives GA100 the Turing HAL, which is why the gate is keyed on the
+ /// architecture instead.
+ #[test]
+ fn intr_retrigger_gate_per_arch() {
+ assert!(!has_intr_retrigger(Chipset::TU102));
+
+ for chipset in [
+ Chipset::GA100,
+ Chipset::GA102,
+ Chipset::AD102,
+ Chipset::GH100,
+ Chipset::GB100,
+ Chipset::GB202,
+ ] {
+ assert!(has_intr_retrigger(chipset));
+ }
+ }
+}
diff --git a/drivers/gpu/nova-core/irq/hal.rs b/drivers/gpu/nova-core/irq/hal.rs
index ee354859b965..c7ecdc44144b 100644
--- a/drivers/gpu/nova-core/irq/hal.rs
+++ b/drivers/gpu/nova-core/irq/hal.rs
@@ -8,7 +8,8 @@
use kernel::{
io::Io,
- pci::IrqType, //
+ pci::IrqType,
+ prelude::*, //
};
use crate::{
@@ -109,3 +110,83 @@ pub(super) fn cpu_interrupt_hal(chipset: Chipset) -> &'static dyn CpuInterruptHa
}
}
}
+
+#[kunit_tests(nova_core_gin_hal)]
+mod tests {
+ use super::*;
+
+ use crate::gpu::Chipset;
+
+ /// Pre-Hopper parts have an 8-leaf tree.
+ #[test]
+ fn pre_hopper_tree_size() {
+ for chipset in [Chipset::TU102, Chipset::GA102, Chipset::AD102] {
+ assert_eq!(cpu_interrupt_hal(chipset).leaf_count(), LeafCount::Eight);
+ }
+ }
+
+ /// Hopper and later implement a 16-leaf tree.
+ #[test]
+ fn hopper_plus_tree_size() {
+ for chipset in [Chipset::GH100, Chipset::GB100, Chipset::GB202] {
+ assert_eq!(cpu_interrupt_hal(chipset).leaf_count(), LeafCount::Sixteen);
+ }
+ }
+
+ /// Only pre-Hopper MSI rearms through the configuration-space mirror. MSI on Hopper and later
+ /// cycles the `TOP` enables of every serviced subtree.
+ #[test]
+ fn msi_rearm_method_per_arch() {
+ for chipset in [Chipset::TU102, Chipset::GA102, Chipset::AD102] {
+ let hal = cpu_interrupt_hal(chipset);
+ assert_eq!(
+ hal.pci_irq_rearm_method(IrqType::Msi),
+ Some(PciIrqRearmMethod::ConfigMirrorEoi)
+ );
+ }
+
+ for chipset in [Chipset::GH100, Chipset::GB100, Chipset::GB202] {
+ let hal = cpu_interrupt_hal(chipset);
+ assert_eq!(
+ hal.pci_irq_rearm_method(IrqType::Msi),
+ Some(PciIrqRearmMethod::TopEnableCycleServiced)
+ );
+ }
+ }
+
+ /// MSI-X gives each subtree its own table entry, so on every architecture its rearm cycles
+ /// only the subtree the handler serves.
+ #[test]
+ fn msix_rearms_one_subtree_on_every_arch() {
+ for chipset in [
+ Chipset::TU102,
+ Chipset::GA102,
+ Chipset::AD102,
+ Chipset::GH100,
+ Chipset::GB100,
+ Chipset::GB202,
+ ] {
+ let hal = cpu_interrupt_hal(chipset);
+ assert_eq!(
+ hal.pci_irq_rearm_method(IrqType::MsiX),
+ Some(PciIrqRearmMethod::TopEnableCycleSubtree)
+ );
+ }
+ }
+
+ /// `INTx` is level-triggered and needs no rearm write on any architecture.
+ #[test]
+ fn intx_needs_no_rearm() {
+ for chipset in [
+ Chipset::TU102,
+ Chipset::GA102,
+ Chipset::AD102,
+ Chipset::GH100,
+ Chipset::GB100,
+ Chipset::GB202,
+ ] {
+ let hal = cpu_interrupt_hal(chipset);
+ assert_eq!(hal.pci_irq_rearm_method(IrqType::Intx), None);
+ }
+ }
+}
diff --git a/drivers/gpu/nova-core/irq/interrupt_tree.rs b/drivers/gpu/nova-core/irq/interrupt_tree.rs
index 02077184fd17..7277ffcb33a1 100644
--- a/drivers/gpu/nova-core/irq/interrupt_tree.rs
+++ b/drivers/gpu/nova-core/irq/interrupt_tree.rs
@@ -503,3 +503,113 @@ fn drop(&mut self) {
clear_top_enables(self.bar, self.serviced);
}
}
+
+#[kunit_tests(nova_core_gin_tree)]
+mod tests {
+ use super::*;
+
+ /// A leaf index is a `Bounded<usize, 4>`, so it accepts 0..=15 and rejects 16.
+ #[test]
+ fn leaf_index_bounds() {
+ assert!(LeafIndex::try_new(0).is_some());
+ assert!(LeafIndex::try_new(15).is_some());
+ assert!(LeafIndex::try_new(16).is_none());
+ }
+
+ /// A leaf count yields one subtree per pair of leaves, and 32 vectors per leaf.
+ #[test]
+ fn leaf_count_derives_subtrees_and_vectors() {
+ assert_eq!(LeafCount::Eight.subtree_count(), 4);
+ assert_eq!(LeafCount::Eight.subtree_set().into_raw(), 0x0f);
+ assert_eq!(LeafCount::Eight.vector_count(), 256);
+
+ assert_eq!(LeafCount::Sixteen.subtree_count(), 8);
+ assert_eq!(LeafCount::Sixteen.subtree_set().into_raw(), 0xff);
+ assert_eq!(LeafCount::Sixteen.vector_count(), 512);
+ }
+
+ /// Subtree `N` covers the two adjacent leaves `2N` and `2N + 1`, and an index past the leaf
+ /// register arrays yields nothing.
+ #[test]
+ fn subtree_covers_two_adjacent_leaves() {
+ for index in 0..8u32 {
+ let first = crate::num::u32_as_usize(index) * 2;
+ let mut leaves = subtree_leaves(index);
+
+ assert_eq!(leaves.next().map(LeafIndex::get), Some(first));
+ assert_eq!(leaves.next().map(LeafIndex::get), Some(first + 1));
+ assert!(leaves.next().is_none());
+ }
+
+ // Subtree 8 would cover leaves 16 and 17, both beyond the leaf index range.
+ assert!(subtree_leaves(8).next().is_none());
+ }
+
+ /// A vector maps to its leaf, its bit within that leaf, and its subtree. The fixed doorbell
+ /// (129) and GSP (155) vectors share a subtree, so one allocation and one enabled subtree
+ /// serve both.
+ #[test]
+ fn vector_maps_to_leaf_bit_and_subtree() {
+ let doorbell = GinVector::new::<129>();
+ let gsp = GinVector::new::<155>();
+
+ assert_eq!(doorbell.leaf_index().get(), 4);
+ assert_eq!(doorbell.leaf_mask().into_raw(), 1 << 1);
+ assert_eq!(doorbell.subtree().index(), 2);
+
+ assert_eq!(gsp.leaf_index().get(), 4);
+ assert_eq!(gsp.leaf_mask().into_raw(), 1 << 27);
+ assert_eq!(gsp.subtree().index(), 2);
+
+ assert_eq!(doorbell.subtree(), gsp.subtree());
+ }
+
+ /// Both fixed vectors lie within the 8-leaf tree, so every supported part carries them.
+ #[test]
+ fn fixed_vectors_fit_the_narrowest_tree() {
+ assert!(GinVector::new::<129>().validate(LeafCount::Eight).is_ok());
+ assert!(GinVector::new::<155>().validate(LeafCount::Eight).is_ok());
+
+ // The first vector beyond an 8-leaf tree.
+ assert!(GinVector::new::<256>().validate(LeafCount::Eight).is_err());
+ assert!(GinVector::new::<256>().validate(LeafCount::Sixteen).is_ok());
+ }
+
+ /// A subtree set reports membership, intersection, and how far it extends from subtree 0.
+ #[test]
+ fn subtree_set_operations() {
+ let gsp = GinVector::new::<155>().subtree();
+
+ assert!(LeafCount::Eight.subtree_set().contains(gsp));
+ assert!(!LeafCount::Eight.subtree_set().is_empty());
+
+ // Subtree 2 is the highest the GSP needs, so an MSI-X request covers entries 0 through 2.
+ assert_eq!(SubtreeSet::from(gsp).span(), 3);
+
+ // Hopper implements every subtree an 8-leaf tree does.
+ assert_eq!(
+ LeafCount::Sixteen
+ .subtree_set()
+ .intersection(LeafCount::Eight.subtree_set()),
+ LeafCount::Eight.subtree_set()
+ );
+ }
+
+ /// Every supported chipset implements the subtree that carries the GSP notification.
+ #[test]
+ fn gsp_subtree_is_implemented_everywhere() {
+ for chipset in [
+ Chipset::TU102,
+ Chipset::GA102,
+ Chipset::AD102,
+ Chipset::GH100,
+ Chipset::GB100,
+ Chipset::GB202,
+ ] {
+ assert!(cpu_interrupt_hal(chipset)
+ .leaf_count()
+ .subtree_set()
+ .contains(crate::irq::gsp::GSP_SUBTREE));
+ }
+ }
+}
--
2.55.0