drm/gpuvm: add debugfs utilities for GPU VA state dumping
Subsystems (4)
cover drm/gpuvm: add debugfs utilities for GPU VA state dumping
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/[email protected]/
- [PATCH v4 0/6] Rust GPUVM immediate mode
https://lore.kernel.org/rust-for-linux/[email protected]/
---
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: <<[email protected]>>
prerequisite-patch-id: 9bc17713af35e5f2744ac55157e2b5078eae77cc
Best regards,
Signature · 1 line
Alvin Sun <[email protected]>
PATCH 1/2 drm/gpuvm: add name(), RawGpuVa and kernel_alloc_va() for debugfs
Expose GPU VM name and kernel-reserved VA so drivers can dump GPU VA state in debugfs.
--- rust/kernel/drm/gpuvm/mod.rs | 14 ++++++++++++++ rust/kernel/drm/gpuvm/va.rs | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+)
rust/kernel/drm/gpuvm/mod.rs +14 -0
@@ -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(
rust/kernel/drm/gpuvm/va.rs +37 -0
@@ -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 ) -> &'aSelf { +// 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
Signature · 1 line
2.43.0
PATCH 2/2 drm/gpuvm: add GpuVaIter and va_mappings() for debugfs
In reply to Alvin SunAdd an iterator over VA mappings so drivers can walk and dump GPU VA state in debugfs.
--- rust/kernel/drm/gpuvm/mod.rs | 6 +++++ rust/kernel/drm/gpuvm/va.rs | 53 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+)
rust/kernel/drm/gpuvm/mod.rs +6 -0
@@ -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 > {
rust/kernel/drm/gpuvm/va.rs +53 -0
65 lines not on this page · raw message
Signature · 1 line
2.43.0