* [PATCH 0/2] drm/gpuvm: add debugfs utilities for GPU VA state dumping
@ 2026-03-17 12:03 Alvin Sun
2026-03-17 12:03 ` [PATCH 1/2] drm/gpuvm: add name(), RawGpuVa and kernel_alloc_va() for debugfs Alvin Sun
2026-03-17 12:03 ` [PATCH 2/2] drm/gpuvm: add GpuVaIter and va_mappings() " Alvin Sun
0 siblings, 2 replies; 3+ messages in thread
From: Alvin Sun @ 2026-03-17 12:03 UTC (permalink / raw)
To: Danilo Krummrich, Matthew Brost, Thomas Hellström,
Alice Ryhl, David Airlie, Simona Vetter, Miguel Ojeda, Boqun Feng,
Gary Guo, Björn Roy Baron, Benno Lossin, Andreas Hindborg,
Trevor Gross
Cc: dri-devel, rust-for-linux, Alvin Sun
This patch series adds helper APIs to enable GPU drivers to implement
debugfs interfaces [1] [2] that expose GPU VA mapping state for
inspection and debugging purposes.
Dependencies:
- [PATCH v12 0/1] rust: interop: Add list module for C linked list interface
https://lore.kernel.org/rust-for-linux/20260306203648.1136554-1-joelagnelf@nvidia.com/
- [PATCH v4 0/6] Rust GPUVM immediate mode
https://lore.kernel.org/rust-for-linux/20260130-gpuvm-rust-v4-0-8364d104ff40@google.com/
Link: https://gitlab.freedesktop.org/panfrost/linux/-/issues/11 [1]
Link: https://gitlab.freedesktop.org/panfrost/linux/-/merge_requests/59 [2]
Signed-off-by: Alvin Sun <alvin.sun@linux.dev>
---
Alvin Sun (2):
drm/gpuvm: add name(), RawGpuVa and kernel_alloc_va() for debugfs
drm/gpuvm: add GpuVaIter and va_mappings() for debugfs
rust/kernel/drm/gpuvm/mod.rs | 20 ++++++++++
rust/kernel/drm/gpuvm/va.rs | 90 ++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 110 insertions(+)
---
base-commit: 34cb4f916af10153c87fabaf6c34e4cafa170427
change-id: 20260317-gpuvm-helpers-28dbe2b303b2
prerequisite-change-id: 20251128-gpuvm-rust-b719cac27ad6:v4
prerequisite-patch-id: 94679c36e594a7d6fc9279dad5419f5558f2302b
prerequisite-patch-id: 03b672e1e2c07d677326d64de7fccc6092ea6812
prerequisite-patch-id: 3c1a4c6eec5faaa1a70de53581bd7ae5ab7bc324
prerequisite-patch-id: 3712380c7bfdf784b6aca146864576cd76bc9a72
prerequisite-patch-id: 3149e1016beefce815c860d4b64e7c1bb7589f15
prerequisite-patch-id: 23467ae9a31746a6c44678e0054f1442c6a5ac06
prerequisite-message-id: <<20260306203648.1136554-1-joelagnelf@nvidia.com>>
prerequisite-patch-id: 9bc17713af35e5f2744ac55157e2b5078eae77cc
Best regards,
--
Alvin Sun <alvin.sun@linux.dev>
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH 1/2] drm/gpuvm: add name(), RawGpuVa and kernel_alloc_va() for debugfs
2026-03-17 12:03 [PATCH 0/2] drm/gpuvm: add debugfs utilities for GPU VA state dumping Alvin Sun
@ 2026-03-17 12:03 ` Alvin Sun
2026-03-17 12:03 ` [PATCH 2/2] drm/gpuvm: add GpuVaIter and va_mappings() " Alvin Sun
1 sibling, 0 replies; 3+ messages in thread
From: Alvin Sun @ 2026-03-17 12:03 UTC (permalink / raw)
To: Danilo Krummrich, Matthew Brost, Thomas Hellström,
Alice Ryhl, David Airlie, Simona Vetter, Miguel Ojeda, Boqun Feng,
Gary Guo, Björn Roy Baron, Benno Lossin, Andreas Hindborg,
Trevor Gross
Cc: dri-devel, rust-for-linux, Alvin Sun
Expose GPU VM name and kernel-reserved VA so drivers can dump GPU VA
state in debugfs.
Signed-off-by: Alvin Sun <alvin.sun@linux.dev>
---
rust/kernel/drm/gpuvm/mod.rs | 14 ++++++++++++++
rust/kernel/drm/gpuvm/va.rs | 37 +++++++++++++++++++++++++++++++++++++
2 files changed, 51 insertions(+)
diff --git a/rust/kernel/drm/gpuvm/mod.rs b/rust/kernel/drm/gpuvm/mod.rs
index 20e512842dfc6..3186df9f740cf 100644
--- a/rust/kernel/drm/gpuvm/mod.rs
+++ b/rust/kernel/drm/gpuvm/mod.rs
@@ -165,6 +165,13 @@ pub fn as_raw(&self) -> *mut bindings::drm_gpuvm {
self.vm.get()
}
+ /// Returns the name of this GpuVm.
+ #[inline]
+ pub fn name(&self) -> &CStr {
+ // SAFETY: The `name` field is immutable and points to a NUL-terminated string.
+ unsafe { CStr::from_char_ptr((*self.as_raw()).name) }
+ }
+
/// The start of the VA space.
#[inline]
pub fn va_start(&self) -> u64 {
@@ -188,6 +195,13 @@ pub fn va_range(&self) -> Range<u64> {
Range { start, end }
}
+ /// Returns the kernel-allocated VA for this GpuVm.
+ #[inline]
+ pub fn kernel_alloc_va(&self) -> &RawGpuVa {
+ // SAFETY: The `self.as_raw()` is guaranteed to be a valid pointer to a drm_gpuvm.
+ unsafe { RawGpuVa::from_raw(&raw mut (*self.as_raw()).kernel_alloc_node) }
+ }
+
/// Get or create the [`GpuVmBo`] for this gem object.
#[inline]
pub fn obtain(
diff --git a/rust/kernel/drm/gpuvm/va.rs b/rust/kernel/drm/gpuvm/va.rs
index a31122ff22282..8b8fd500b3c5f 100644
--- a/rust/kernel/drm/gpuvm/va.rs
+++ b/rust/kernel/drm/gpuvm/va.rs
@@ -81,6 +81,43 @@ pub fn vm_bo(&self) -> &GpuVmBo<T> {
}
}
+/// Represents that a range of a GEM object is mapped in the kernel.
+#[repr(transparent)]
+pub struct RawGpuVa(Opaque<bindings::drm_gpuva>);
+
+impl RawGpuVa {
+ /// Access this [`RawGpuVa`] from a raw pointer.
+ ///
+ /// # Safety
+ ///
+ /// For the duration of `'a`, the pointer must reference a valid `drm_gpuva`.
+ #[inline]
+ pub unsafe fn from_raw<'a>(ptr: *mut bindings::drm_gpuva) -> &'a Self {
+ // SAFETY: `drm_gpuva` and `RawGpuVa` have the same layout.
+ unsafe { &*(ptr.cast()) }
+ }
+
+ /// Returns a raw pointer to underlying C value.
+ #[inline]
+ pub fn as_raw(&self) -> *mut bindings::drm_gpuva {
+ self.0.get()
+ }
+
+ /// Returns the address of this mapping in the GPU virtual address space.
+ #[inline]
+ pub fn addr(&self) -> u64 {
+ // SAFETY: `self.as_raw()` is guaranteed to be a valid pointer to a `drm_gpuva`.
+ unsafe { (*self.as_raw()).va.addr }
+ }
+
+ /// Returns the length of this mapping.
+ #[inline]
+ pub fn length(&self) -> u64 {
+ // SAFETY: `self.as_raw()` is guaranteed to be a valid pointer to a `drm_gpuva`.
+ unsafe { (*self.as_raw()).va.range }
+ }
+}
+
/// A pre-allocated [`GpuVa`] object.
///
/// # Invariants
--
2.43.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH 2/2] drm/gpuvm: add GpuVaIter and va_mappings() for debugfs
2026-03-17 12:03 [PATCH 0/2] drm/gpuvm: add debugfs utilities for GPU VA state dumping Alvin Sun
2026-03-17 12:03 ` [PATCH 1/2] drm/gpuvm: add name(), RawGpuVa and kernel_alloc_va() for debugfs Alvin Sun
@ 2026-03-17 12:03 ` Alvin Sun
1 sibling, 0 replies; 3+ messages in thread
From: Alvin Sun @ 2026-03-17 12:03 UTC (permalink / raw)
To: Danilo Krummrich, Matthew Brost, Thomas Hellström,
Alice Ryhl, David Airlie, Simona Vetter, Miguel Ojeda, Boqun Feng,
Gary Guo, Björn Roy Baron, Benno Lossin, Andreas Hindborg,
Trevor Gross
Cc: dri-devel, rust-for-linux, Alvin Sun
Add an iterator over VA mappings so drivers can walk and dump GPU VA
state in debugfs.
Signed-off-by: Alvin Sun <alvin.sun@linux.dev>
---
rust/kernel/drm/gpuvm/mod.rs | 6 +++++
rust/kernel/drm/gpuvm/va.rs | 53 ++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 59 insertions(+)
diff --git a/rust/kernel/drm/gpuvm/mod.rs b/rust/kernel/drm/gpuvm/mod.rs
index 3186df9f740cf..41b99d468f9d9 100644
--- a/rust/kernel/drm/gpuvm/mod.rs
+++ b/rust/kernel/drm/gpuvm/mod.rs
@@ -301,6 +301,12 @@ pub fn data(&mut self) -> &mut T {
// SAFETY: By the type invariants we may access `core`.
unsafe { &mut *self.0.data.get() }
}
+
+ /// Returns an iterator over the VA mappings in this GpuVm.
+ #[inline]
+ pub fn va_mappings(&self) -> GpuVaIter<'_, T> {
+ GpuVaIter::new(&self.0)
+ }
}
impl<T: DriverGpuVm> Deref for GpuVmCore<T> {
diff --git a/rust/kernel/drm/gpuvm/va.rs b/rust/kernel/drm/gpuvm/va.rs
index 8b8fd500b3c5f..3210047f880e3 100644
--- a/rust/kernel/drm/gpuvm/va.rs
+++ b/rust/kernel/drm/gpuvm/va.rs
@@ -1,6 +1,14 @@
// SPDX-License-Identifier: GPL-2.0 OR MIT
use super::*;
+use crate::interop::list::{
+ CList,
+ CListIter, //
+};
+use core::{
+ marker::PhantomData,
+ mem::offset_of, //
+};
/// Represents that a range of a GEM object is mapped in this [`GpuVm`] instance.
///
@@ -118,6 +126,51 @@ pub fn length(&self) -> u64 {
}
}
+const DRM_GPUVA_LIST_ENTRY_OFFSET: usize = offset_of!(bindings::drm_gpuva, rb.entry);
+type RawGpuVaIter<'a> = CListIter<'a, RawGpuVa, DRM_GPUVA_LIST_ENTRY_OFFSET>;
+
+/// An iterator over the VA mappings in a [`GpuVm`].
+pub struct GpuVaIter<'a, T: DriverGpuVm> {
+ raw_gpuva_iter: RawGpuVaIter<'a>,
+ kern_gpuva_ptr: *mut bindings::drm_gpuva,
+ _marker: PhantomData<&'a T>,
+}
+
+impl<'a, T: DriverGpuVm> GpuVaIter<'a, T> {
+ #[inline]
+ pub(crate) fn new(gpuvm: &'a GpuVm<T>) -> Self {
+ // SAFETY: `gpuvm` is valid.
+ let head = unsafe { &raw mut (*gpuvm.as_raw()).rb.list };
+ // SAFETY: `head` is a valid pointer to a drm_gpuva list head.
+ let clist = unsafe { CList::<RawGpuVa, DRM_GPUVA_LIST_ENTRY_OFFSET>::from_raw(head) };
+ let kern_gpuva_ptr = gpuvm.kernel_alloc_va().as_raw();
+
+ Self {
+ raw_gpuva_iter: clist.iter(),
+ kern_gpuva_ptr,
+ _marker: PhantomData,
+ }
+ }
+}
+
+impl<'a, T: DriverGpuVm> Iterator for GpuVaIter<'a, T> {
+ type Item = &'a GpuVa<T>;
+
+ #[inline]
+ fn next(&mut self) -> Option<Self::Item> {
+ let mut curr = self.raw_gpuva_iter.next()?;
+
+ if curr.as_raw() == self.kern_gpuva_ptr {
+ // Skip kernel reserved node.
+ curr = self.raw_gpuva_iter.next()?;
+ }
+
+ // SAFETY: We have skipped the kernel reserved node, all remaining
+ // entries are valid GpuVa<T> instances.
+ Some(unsafe { GpuVa::from_raw(curr.as_raw()) })
+ }
+}
+
/// A pre-allocated [`GpuVa`] object.
///
/// # Invariants
--
2.43.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-03-17 12:05 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-17 12:03 [PATCH 0/2] drm/gpuvm: add debugfs utilities for GPU VA state dumping Alvin Sun
2026-03-17 12:03 ` [PATCH 1/2] drm/gpuvm: add name(), RawGpuVa and kernel_alloc_va() for debugfs Alvin Sun
2026-03-17 12:03 ` [PATCH 2/2] drm/gpuvm: add GpuVaIter and va_mappings() " Alvin Sun
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox