From: Eliot Courtney <ecourtney@nvidia.com>
To: "Danilo Krummrich" <dakr@kernel.org>,
"Alice Ryhl" <aliceryhl@google.com>,
"Daniel Almeida" <daniel.almeida@collabora.com>,
"Miguel Ojeda" <ojeda@kernel.org>,
"Boqun Feng" <boqun@kernel.org>, "Gary Guo" <gary@garyguo.net>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Benno Lossin" <lossin@kernel.org>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Trevor Gross" <tmgross@umich.edu>,
"Tamir Duberstein" <tamird@kernel.org>,
"Alexandre Courbot" <acourbot@nvidia.com>,
"Onur Özkan" <work@onurozkan.dev>,
"Yury Norov" <yury.norov@gmail.com>,
"David Airlie" <airlied@gmail.com>,
"Simona Vetter" <simona@ffwll.ch>,
"Maarten Lankhorst" <maarten.lankhorst@linux.intel.com>,
"Maxime Ripard" <mripard@kernel.org>,
"Thomas Zimmermann" <tzimmermann@suse.de>,
"Jonathan Corbet" <corbet@lwn.net>,
"Shuah Khan" <skhan@linuxfoundation.org>
Cc: driver-core@lists.linux.dev, rust-for-linux@vger.kernel.org,
linux-kernel@vger.kernel.org, nova-gpu@lists.linux.dev,
dri-devel@lists.freedesktop.org, linux-doc@vger.kernel.org,
Eliot Courtney <ecourtney@nvidia.com>,
Joel Fernandes <joelagnelf@nvidia.com>
Subject: [PATCH 12/12] gpu: nova-core: mm: Add PRAMIN aperture self-tests
Date: Wed, 05 Aug 2026 14:44:59 +0900 [thread overview]
Message-ID: <20260805-pramin-split-v1-12-ff3e84a75dac@nvidia.com> (raw)
In-Reply-To: <20260805-pramin-split-v1-0-ff3e84a75dac@nvidia.com>
From: Joel Fernandes <joelagnelf@nvidia.com>
Add self-tests for the PRAMIN aperture mechanism to verify correct
operation during GPU probe. The tests validate various alignment
requirements and corner cases.
The tests are default disabled and behind CONFIG_NOVA_CORE_SELFTESTS.
When enabled, tests run after GSP boot during probe.
Signed-off-by: Joel Fernandes <joelagnelf@nvidia.com>
[ecourtney: convert the tests to window_at(), macros, and the new types]
[ecourtney: cfg-gate the tests and expect(dead_code), not a runtime no-op]
[ecourtney: run the self-tests on all architectures, drop the chipset arg]
[ecourtney: test within a usable FB region, skip when none is large enough]
[ecourtney: report failures without failing probe, start banner at dev_dbg]
[ecourtney: removed the mm-specific Kconfig option]
Signed-off-by: Eliot Courtney <ecourtney@nvidia.com>
---
drivers/gpu/nova-core/driver.rs | 3 +
drivers/gpu/nova-core/gpu.rs | 12 ++++
drivers/gpu/nova-core/mm.rs | 40 +++++++++++-
drivers/gpu/nova-core/mm/pramin.rs | 129 +++++++++++++++++++++++++++++++++++++
4 files changed, 183 insertions(+), 1 deletion(-)
diff --git a/drivers/gpu/nova-core/driver.rs b/drivers/gpu/nova-core/driver.rs
index 5738d4ac521b..2c11eeee92d2 100644
--- a/drivers/gpu/nova-core/driver.rs
+++ b/drivers/gpu/nova-core/driver.rs
@@ -86,6 +86,9 @@ fn probe<'bound>(
// (`try_pin_init!()` initializes fields in declaration order), lives at a pinned
// stable address, and is dropped after `gpu` (struct field drop order).
gpu <- Gpu::new(pdev, unsafe { &*core::ptr::from_ref(bar) }),
+ // Run optional GPU selftests.
+ #[cfg(CONFIG_NOVA_CORE_SELFTESTS)]
+ _: { gpu.run_selftests(pdev) },
_reg: auxiliary::Registration::new(
pdev.as_ref(),
c"nova-drm",
diff --git a/drivers/gpu/nova-core/gpu.rs b/drivers/gpu/nova-core/gpu.rs
index e29e07488e78..04e1e30eeed7 100644
--- a/drivers/gpu/nova-core/gpu.rs
+++ b/drivers/gpu/nova-core/gpu.rs
@@ -429,4 +429,16 @@ pub(crate) fn new(
)?,
})
}
+
+ /// Runs self-tests on the constructed [`Gpu`], logging failures without failing probe.
+ #[cfg(CONFIG_NOVA_CORE_SELFTESTS)]
+ pub(crate) fn run_selftests(self: Pin<&mut Self>, pdev: &pci::Device<device::Bound>) {
+ let this = self.project();
+ let dev = pdev.as_ref();
+ let regions = &this.gsp_static_info.usable_fb_regions;
+
+ if let Err(err) = crate::mm::selftest::run(dev, this.mm, regions) {
+ dev_err!(dev, "self-tests failed: {:?}\n", err);
+ }
+ }
}
diff --git a/drivers/gpu/nova-core/mm.rs b/drivers/gpu/nova-core/mm.rs
index 58dce211a337..9e4338c7c393 100644
--- a/drivers/gpu/nova-core/mm.rs
+++ b/drivers/gpu/nova-core/mm.rs
@@ -3,7 +3,7 @@
//! Memory management subsystems.
-#![expect(dead_code)]
+#![cfg_attr(not(CONFIG_NOVA_CORE_SELFTESTS), expect(dead_code))]
use core::{
fmt::LowerHex,
@@ -123,3 +123,41 @@ fn sub(self, rhs: Self) -> Self::Output {
self.into_raw() - rhs.into_raw()
}
}
+
+#[cfg(CONFIG_NOVA_CORE_SELFTESTS)]
+pub(crate) mod selftest {
+ use core::ops::Range;
+
+ use kernel::{
+ device,
+ sizes::SizeConstants, //
+ };
+
+ use super::*;
+
+ /// Run MM subsystem self-tests during probe.
+ pub(crate) fn run(
+ dev: &device::Device<device::Bound>,
+ mm: &mut GpuMm<'_>,
+ usable_fb_regions: &[Range<u64>],
+ ) -> Result {
+ // VRAM span the self-tests are free to overwrite, from the chosen test base.
+ const SELFTEST_SPAN: u64 = u64::SZ_64M;
+
+ let base = usable_fb_regions.iter().find_map(|region| {
+ // Tests rely on this being 8 byte aligned for checking misalignment handling.
+ let base = region.start.align_up(Alignment::new::<8>())?;
+ (base.checked_add(SELFTEST_SPAN)? <= region.end).then_some(base)
+ });
+ let Some(base) = base else {
+ dev_warn!(
+ dev,
+ "PRAMIN: skipping self-tests, no usable VRAM region of {:#x} bytes\n",
+ SELFTEST_SPAN
+ );
+ return Ok(());
+ };
+
+ pramin::selftest::run(dev, mm.pramin_mut(), VramAddress::from_raw(base))
+ }
+}
diff --git a/drivers/gpu/nova-core/mm/pramin.rs b/drivers/gpu/nova-core/mm/pramin.rs
index 2aa1bca22fa6..1019a6e57e26 100644
--- a/drivers/gpu/nova-core/mm/pramin.rs
+++ b/drivers/gpu/nova-core/mm/pramin.rs
@@ -154,3 +154,132 @@ pub(super) fn window_at<'a, T>(
})
}
}
+
+#[cfg(CONFIG_NOVA_CORE_SELFTESTS)]
+pub(super) mod selftest {
+ use kernel::{
+ device,
+ io::{
+ io_read,
+ io_write, //
+ },
+ sizes::SizeConstants, //
+ };
+
+ use super::*;
+ use crate::{
+ selftest_assert,
+ selftest_assert_eq, //
+ };
+
+ /// Test read/write at byte granularity.
+ fn test_byte_readwrite(
+ dev: &device::Device<device::Bound>,
+ pramin: &mut Pramin<'_>,
+ base: VramAddress,
+ ) -> Result {
+ {
+ let window = pramin.window_at::<[u8; 4]>(base)?;
+ for (i, val) in (0xA0u8..0xA4).enumerate() {
+ io_write!(window.view(), [build: i], val);
+ }
+ }
+
+ let window = pramin.window_at::<[u8; 4]>(base)?;
+ for (i, val) in (0xA0u8..0xA4).enumerate() {
+ selftest_assert_eq!(dev, io_read!(window.view(), [build: i]), val);
+ }
+ Ok(())
+ }
+
+ /// Test writing a `u32` and reading back as individual `u8`s.
+ fn test_u32_as_bytes(
+ dev: &device::Device<device::Bound>,
+ pramin: &mut Pramin<'_>,
+ base: VramAddress,
+ ) -> Result {
+ let addr = base + 0x10;
+ let val: u32 = 0xDEADBEEF;
+ pramin.window_at::<u32>(addr)?.view().write_val(val);
+
+ let window = pramin.window_at::<[u8; 4]>(addr)?;
+ for (i, &expected) in val.to_le_bytes().iter().enumerate() {
+ selftest_assert_eq!(dev, io_read!(window.view(), [build: i]), expected);
+ }
+ Ok(())
+ }
+
+ /// Test window repositioning across 1 MiB boundaries.
+ fn test_window_reposition(
+ dev: &device::Device<device::Bound>,
+ pramin: &mut Pramin<'_>,
+ base: VramAddress,
+ ) -> Result {
+ let addr_a = base;
+ let addr_b = base + u64::SZ_2M; // base + 2 MiB (different 1 MiB region).
+ let val_a: u32 = 0x11111111;
+ let val_b: u32 = 0x22222222;
+
+ pramin.window_at::<u32>(addr_a)?.view().write_val(val_a);
+ pramin.window_at::<u32>(addr_b)?.view().write_val(val_b);
+
+ selftest_assert_eq!(
+ dev,
+ pramin.window_at::<u32>(addr_a)?.view().read_val(),
+ val_a
+ );
+ selftest_assert_eq!(
+ dev,
+ pramin.window_at::<u32>(addr_b)?.view().read_val(),
+ val_b
+ );
+ Ok(())
+ }
+
+ /// Test that offsets outside the VRAM region are rejected.
+ fn test_invalid_offset(
+ dev: &device::Device<device::Bound>,
+ pramin: &mut Pramin<'_>,
+ vram_end: VramAddress,
+ ) -> Result {
+ selftest_assert!(dev, pramin.window_at::<u32>(vram_end).is_err());
+ Ok(())
+ }
+
+ /// Test that misaligned accesses are rejected.
+ fn test_misaligned_access(
+ dev: &device::Device<device::Bound>,
+ pramin: &mut Pramin<'_>,
+ base: VramAddress,
+ ) -> Result {
+ // Misaligned `window_at()` start (`Region` bases must be 4-byte aligned).
+ selftest_assert!(dev, pramin.window_at::<u32>(base + 2).is_err());
+
+ // `u64` at a 4-byte-aligned (not 8-byte-aligned) address.
+ selftest_assert!(dev, pramin.window_at::<u64>(base + 0x44).is_err());
+ Ok(())
+ }
+
+ /// Run PRAMIN self-tests during probe.
+ ///
+ /// `base` is the start of a driver-usable VRAM span that the tests are free to
+ /// overwrite.
+ pub(crate) fn run(
+ dev: &device::Device<device::Bound>,
+ pramin: &mut Pramin<'_>,
+ base: VramAddress,
+ ) -> Result {
+ dev_dbg!(dev, "PRAMIN: starting self-tests\n");
+
+ let vram_end = pramin.vram_range.end;
+
+ test_byte_readwrite(dev, pramin, base)?;
+ test_u32_as_bytes(dev, pramin, base)?;
+ test_window_reposition(dev, pramin, base)?;
+ test_invalid_offset(dev, pramin, vram_end)?;
+ test_misaligned_access(dev, pramin, base)?;
+
+ dev_info!(dev, "PRAMIN: self-tests passed\n");
+ Ok(())
+ }
+}
--
2.55.0
prev parent reply other threads:[~2026-08-05 5:46 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-05 5:44 [PATCH 00/12] gpu: nova-core: add PRAMIN window support Eliot Courtney
2026-08-05 5:44 ` [PATCH 01/12] rust: io: add Region::try_subregion Eliot Courtney
2026-08-05 10:43 ` Gary Guo
2026-08-07 5:39 ` Eliot Courtney
2026-08-05 5:44 ` [PATCH 02/12] rust: num: reject Bounded::shr overshifts at build time Eliot Courtney
2026-08-05 5:55 ` sashiko-bot
2026-08-05 5:44 ` [PATCH 03/12] rust: num: add Bounded::shr_exact Eliot Courtney
2026-08-05 5:51 ` sashiko-bot
2026-08-05 5:44 ` [PATCH 04/12] gpu: nova-core: mm: Add VramAddress type Eliot Courtney
2026-08-05 5:49 ` sashiko-bot
2026-08-05 5:44 ` [PATCH 05/12] gpu: nova-core: mm: Implement Alignable and Debug for VramAddress Eliot Courtney
2026-08-05 5:44 ` [PATCH 06/12] gpu: nova-core: mm: Add PRAMIN window registers Eliot Courtney
2026-08-05 5:44 ` [PATCH 07/12] gpu: nova-core: mm: Add the memory management HAL Eliot Courtney
2026-08-05 5:44 ` [PATCH 08/12] gpu: nova-core: mm: Add support to use PRAMIN windows to write to VRAM Eliot Courtney
2026-08-05 5:44 ` [PATCH 09/12] docs: gpu: nova-core: Document the PRAMIN aperture mechanism Eliot Courtney
2026-08-05 5:44 ` [PATCH 10/12] gpu: nova-core: mm: Add GpuMm centralized memory manager Eliot Courtney
2026-08-05 5:52 ` sashiko-bot
2026-08-05 5:44 ` [PATCH 11/12] gpu: nova-core: Add self-test assertion macros and config option Eliot Courtney
2026-08-05 5:44 ` Eliot Courtney [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260805-pramin-split-v1-12-ff3e84a75dac@nvidia.com \
--to=ecourtney@nvidia.com \
--cc=a.hindborg@kernel.org \
--cc=acourbot@nvidia.com \
--cc=airlied@gmail.com \
--cc=aliceryhl@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun@kernel.org \
--cc=corbet@lwn.net \
--cc=dakr@kernel.org \
--cc=daniel.almeida@collabora.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=driver-core@lists.linux.dev \
--cc=gary@garyguo.net \
--cc=joelagnelf@nvidia.com \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=maarten.lankhorst@linux.intel.com \
--cc=mripard@kernel.org \
--cc=nova-gpu@lists.linux.dev \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=simona@ffwll.ch \
--cc=skhan@linuxfoundation.org \
--cc=tamird@kernel.org \
--cc=tmgross@umich.edu \
--cc=tzimmermann@suse.de \
--cc=work@onurozkan.dev \
--cc=yury.norov@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox