drm/tyr: add debugfs support
Subsystems (8)
v3 cover drm/tyr: add debugfs support
Add debugfs support for the Tyr DRM driver.
The series adds a SeqShow trait for seq_file-backed debugfs files, a debugfs_init callback on the DRM Driver trait, and a gpuvas debugfs file in Tyr exposing GPU VA space information.
This is based on drm-rust-next and depends on:
[PATCH v10 0/7] drm/tyr: firmware loading and MCU boot support
https://lore.kernel.org/r/[email protected]
See the full dependency and commit history at [1].
---
Changes in v3:
- Drop the DrmSeqShow adapter and use SeqShow directly, per Danilo's feedback. Simplify the debugfs_init callback signature accordingly.
- Redesign VmRegistry per Daniel's and Alice's feedback: move it to
vm.rs at the top level of the registration data, use Arc<VmRegistry>
for shared ownership, and separate register/unregister from Vm::new
and Vm::kill. Registration failure is non-fatal (dev_warn) since the registry is a debugfs convenience.
- Add VmRegistry::unregister to remove VMs on teardown, addressing
Alice's concern about the list going out of sync.
- Drop the "hold device reference for open files" patch; the debugfs
proxy fops already ensure file operations cannot outlive
debugfs_remove().
- Improve SAFETY comments and fix style issues identified during review.
- Link to v2: https://lore.kernel.org/r/[email protected]
Changes in v2:
- Reworked the debugfs implementation per feedback from Danilo on v1:
dropped the hazptr/revocable-based approach in favor of the DRM debugfs_init callback and generic seq_file abstractions.
- Fixed a UAF in drm_debugfs where a device could be unregistered while
a debugfs file remains open (drm_dev_get/put across file lifetime).
- Link to v1: https://lore.kernel.org/r/[email protected]
---
Alvin Sun (8):
rust: seq_file: add as_raw() method
rust: debugfs: add seq_file support
rust: debugfs: add ScopeRef for existing dentries
drm: move debugfs_init after dev->registered is set
rust: drm: add debugfs_init callback to Driver trait
rust: drm: gpuvm: add dump_gpuva_info to UniqueRefGpuVm drm/tyr: track VMs in a registry
drm/tyr: add gpuvas debugfs file
drivers/gpu/drm/drm_debugfs.c | 3 -- drivers/gpu/drm/drm_drv.c | 5 +++ drivers/gpu/drm/tyr/debugfs.rs | 20 ++++++++++ drivers/gpu/drm/tyr/driver.rs | 16 +++++++- drivers/gpu/drm/tyr/fw.rs | 18 +++++++-- drivers/gpu/drm/tyr/tyr.rs | 1 + drivers/gpu/drm/tyr/vm.rs | 33 ++++++++++++++++ rust/bindings/bindings_helper.h | 1 + rust/kernel/debugfs.rs | 84 ++++++++++++++++++++++++++++++++++++++++- rust/kernel/debugfs/entry.rs | 15 +++++++- rust/kernel/debugfs/file_ops.rs | 60 +++++++++++++++++++++++++++++ rust/kernel/debugfs/traits.rs | 11 ++++++ rust/kernel/drm/device.rs | 41 +++++++++++++++++++- rust/kernel/drm/driver.rs | 11 ++++++ rust/kernel/drm/gpuvm/mod.rs | 9 +++++ rust/kernel/seq_file.rs | 6 +++ 16 files changed, 323 insertions(+), 11 deletions(-)
---
base-commit: 0ffc014cb2abfc79d161662b125e085b3e7107e7
change-id: 20260730-tyr-debugfs-v2-608cef77d6e9
Best regards,
Signature · 1 line
Alvin Sun <[email protected]>
PATCH v3 1/8 rust: seq_file: add as_raw() method
Add a method to obtain a raw pointer to the underlying struct seq_file, needed for FFI calls into C (e.g. drm_debugfs_gpuva_info).
--- rust/kernel/seq_file.rs | 6 ++++++ 1 file changed, 6 insertions(+)
rust/kernel/seq_file.rs +6 -0
@@ -29,6 +29,12 @@ pub unsafe fn from_raw<'a>(ptr: *mut bindings::seq_file) -> &'a SeqFile {unsafe { &*ptr.cast () } } +/// Returns a raw pointer to the underlying `struct seq_file`. +#[inline] +pub fn as_raw (&self) -> *mut bindings::seq_file { + self.inner.get () + } +/// Used by the [`seq_print`] macro. #[inline] pub fn call_printf (&self, args: fmt::Arguments <'_>) {
Signature · 1 line
2.43.0
PATCH v3 2/8 rust: debugfs: add seq_file support
In reply to Alvin SunAdd SeqShow trait for seq_file-backed debugfs files. Needed by DRM and other subsystems to expose readable debugfs state via seq_file.
--- rust/kernel/debugfs/file_ops.rs | 60 +++++++++++++++++++++++++++++++++++++++++ rust/kernel/debugfs/traits.rs | 11 ++++++++ 2 files changed, 71 insertions(+)
rust/kernel/debugfs/file_ops.rs +60 -0
@@ -5,11 +5,13 @@ BinaryReader, BinaryWriter, Reader, + SeqShow, Writer, // };use crate ::{ debugfs::callback_adapters::Adapter , + error::from_result, fmt, fs::file, prelude::*,
@@ -123,6 +125,64 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {0 } +/// Show callback for `SeqShow` types. +/// +/// # Safety +/// +/// The seq_file core guarantees that `seq` points to a live `seq_file` +/// whose private data is a valid pointer to a `T` with no outstanding +/// mutable references. +unsafe extern "C" fn seq_file_show <S :SeqShow <T >,T :Sync >( + seq: *mut bindings::seq_file , + _: *mut c_void , +) ->c_int { +// SAFETY: `seq->private` is a valid `T` pointer with no outstanding +// mutable references. +let data =unsafe { &*((*seq).private.cast ::<T >()) }; +// SAFETY: `seq` points to a live `seq_file`. +let m =unsafe {SeqFile ::from_raw (seq) }; +from_result (||S ::show (data, m).map (|()|0 )) +} + +/// Open callback for `SeqShow` types. +/// +/// # Safety +/// +/// The VFS guarantees that `inode` is valid with `i_private` pointing to a +/// valid `T` that remains valid for the duration of the call, and that `file` +/// points to a live, uninitialized file object. +unsafe extern "C" fn seq_file_open <S :SeqShow <T >,T :Sync >( + inode: *mut bindings::inode , + file: *mut bindings::file , +) ->c_int { +// SAFETY: `inode` is valid per VFS. `i_private` points to a valid `T` +// (guaranteed by the `FileOps<T>` invariants). +let data =unsafe { (*inode).i_private.cast ::<T >() }; + +// SAFETY: `file` is valid per VFS; `data` matches `seq_file_show`'s contract. +unsafe { bindings::single_open (file,Some (seq_file_show ::<S ,T >), data.cast ()) } +} + +pub (crate )trait SeqReadFile <T > { +const FILE_OPS :FileOps <T >; +} + +impl <S :SeqShow <T >,T :Sync >SeqReadFile <T >for S { +const FILE_OPS :FileOps <T > = { +let operations = bindings::file_operations { + read:Some (bindings::seq_read), + llseek:Some (bindings::seq_lseek), + release:Some (bindings::single_release), + open:Some (seq_file_open ::<Self ,T >), + ..pin_init::zeroed () + }; +// SAFETY: `read` and `llseek` are stock `seq_file` implementations. +// `seq_file_open` treats `inode->i_private` as a valid `&T` reference, +// satisfying the `FileOps::new` contract. +unsafe {FileOps ::new (operations,0o400 ) } + }; +} +// Work around lack of generic const items. pub (crate )trait ReadFile <T > {const FILE_OPS :FileOps <T >;
rust/kernel/debugfs/traits.rs +11 -0
@@ -8,6 +8,7 @@ fmt, fs::file, prelude::*, + seq_file::SeqFile, sync::{ atomic::{Atomic ,
@@ -338,3 +339,13 @@ fn read_from_slice( self.deref ().read_from_slice (reader, offset) } } + +/// Renders `data` into a seq_file. +/// +/// `data` is the value stashed as the debugfs file's `i_private` at creation +/// time. `show` is invoked on each read to produce the file's contents. +/// `data` must remain valid while the debugfs file is registered. +pub trait SeqShow <T > { +/// Writes debugfs output for the file. +fn show (data: &T , m: &SeqFile ) ->Result ; +}
Signature · 1 line
2.43.0
PATCH v3 3/8 rust: debugfs: add ScopeRef for existing dentries
In reply to Alvin SunAdd methods to construct debugfs abstractions from raw C dentry pointers. Needed by DRM debugfs_init callback to create ScopedDir from an existing dentry.
Add ScopeRef<'a, T>, a debugfs directory handle that carries a reference to associated data of type T.
--- rust/kernel/debugfs.rs | 84 ++++++++++++++++++++++++++++++++++++++++++-- rust/kernel/debugfs/entry.rs | 15 +++++++- 2 files changed, 96 insertions(+), 3 deletions(-)
rust/kernel/debugfs.rs +82 -2
@@ -24,7 +24,7 @@ PhantomData, PhantomPinned, // }, - ops::Deref, + ops::Deref, // };mod traits;
@@ -33,6 +33,7 @@ BinaryReaderMut, BinaryWriter, Reader, + SeqShow, Writer, // };
@@ -51,6 +52,7 @@ FileOps, ReadFile, ReadWriteFile, + SeqReadFile, WriteFile, // };
@@ -538,7 +540,7 @@ pub fn dir<'dir2>(&'dir2 self, name: &CStr) -> ScopedDir<'data, 'dir2> { } } -fn create_file <T :Sync >(&self, name: &CStr , data: &'dataT , vtable: &'staticFileOps <T >) { +fn create_file <T :Sync >(&self, name: &CStr , data: &'dataT , vtable: &FileOps <T >) {#[cfg( CONFIG_DEBUG_FS )] core::mem::forget (Entry ::file (name, &self.entry, data, vtable)); }
@@ -588,6 +590,14 @@ pub fn read_callback_file<T, F>(&self, name: &CStr, data: &'data T, _f: &'static self.create_file (name, data, vtable) } +/// Creates a seq_file debugfs file in this directory. +/// +/// The file's contents are produced by invoking [`SeqShow::show`] with +/// `data` on each read. +pub fn seq_file <S :SeqShow <U >,U :Sync >(&self, name: &CStr , data: &'dataU ) { + self.create_file (name, data, &<S as SeqReadFile <U >>::FILE_OPS ) + } +/// Creates a read-write file in this directory. /// /// Reading the file uses the [`Writer`] implementation on `data`. Writing to the file uses
@@ -721,4 +731,74 @@ fn new(name: &CStr) -> ScopedDir<'data, 'static> { _phantom: PhantomData, } } + +/// Creates a [`ScopedDir`] wrapping an existing debugfs dentry. +/// +/// Files created under this directory are not automatically removed on drop; +/// their lifetime is tied to the dentry owner. +/// +/// # Safety +/// +/// The caller must ensure the dentry remains valid for the lifetime of the +/// returned `ScopedDir`. +pub unsafe fn from_dentry (dentry: *mut bindings::dentry ) ->Self { +let _ = dentry; +ScopedDir { +#[cfg( CONFIG_DEBUG_FS )] +// SAFETY: The caller guarantees the dentry is valid and outlives this `ScopedDir`. + entry:ManuallyDrop ::new (unsafe {Entry ::from_raw (dentry) }), + _phantom:PhantomData , + } + } +} + +/// A reference to a debugfs directory that also holds a reference to +/// associated data of type `T`. +/// +/// Created from an existing debugfs dentry (e.g. the DRM debugfs root). +/// `data` must remain valid while the debugfs files created under this +/// scope may be accessed. +pub struct ScopeRef <'a,T > { +#[cfg( CONFIG_DEBUG_FS )] + inner:ScopedDir <'a, 'a>, + data: &'aT , +} + +impl <'a,T >ScopeRef <'a,T > { +/// Creates a [`ScopeRef`] from an existing debugfs dentry and a data reference. +/// +/// # Safety +/// +/// The caller must ensure that `dentry` remains valid for the lifetime of +/// the returned [`ScopeRef`] and that `data` remains valid while the +/// debugfs files created under this scope may be accessed. +pub unsafe fn new (dentry: *mut bindings::dentry , data: &'aT ) ->Self { +let _ = dentry; +ScopeRef { +#[cfg( CONFIG_DEBUG_FS )] +// SAFETY: By the safety preconditions of `new`, `dentry` is valid +// and remains valid for the lifetime of the returned `ScopeRef`. + inner:unsafe {ScopedDir ::from_dentry (dentry) }, + data, + } + } + +/// Creates a seq_file debugfs file in this directory. +/// +/// The file's contents are produced by invoking [`SeqShow::show`] with +/// `data` on each read. +#[cfg( CONFIG_DEBUG_FS )] +pub fn seq_file <S :SeqShow <T >>(&self, name: &CStr ) +where +T :Sync , + { + self.inner.seq_file ::<S ,T >(name, self.data); + } + +#[cfg(not( CONFIG_DEBUG_FS ))] +pub fn seq_file <S :SeqShow <T >>(&self, _name: &CStr ) +where +T :Sync , + { + } }
rust/kernel/debugfs/entry.rs +14 -1
@@ -8,7 +8,7 @@ CStr, CStrExt as _, // }, - sync::Arc, + sync::Arc, // };use core::marker::PhantomData ;
@@ -87,6 +87,19 @@ pub(crate) unsafe fn dynamic_file<T>( }impl <'a>Entry <'a> { +/// Wraps a raw dentry pointer. +/// +/// # Safety +/// +/// The caller must ensure the dentry is valid and outlives this `Entry`. +pub (crate )unsafe fn from_raw (entry: *mut bindings::dentry ) ->Self { +Self { + entry, + _parent:None , + _phantom:PhantomData , + } + } +pub (crate )fn dir (name: &CStr , parent:Option <&'aEntry <'_>>) ->Self {let parent_ptr =match &parent { Some(entry) => entry.as_ptr(),
Signature · 1 line
2.43.0
PATCH v3 4/8 drm: move debugfs_init after dev->registered is set
In reply to Alvin SunThe debugfs_init callback is called from drm_debugfs_register during drm_minor_register, before dev->registered is set to true. Move it to drm_dev_register after dev->registered = true so that callbacks see a fully registered device.
--- drivers/gpu/drm/drm_debugfs.c | 3 --- drivers/gpu/drm/drm_drv.c | 5 +++++ 2 files changed, 5 insertions(+), 3 deletions(-)
drivers/gpu/drm/drm_debugfs.c +0 -3
@@ -442,9 +442,6 @@ int drm_debugfs_register(struct drm_minor *minor, int minor_id)/* TODO: Only for compatibility with drivers */ minor->debugfs_root = dev->debugfs_root; -if (dev->driver->debugfs_init && dev->render != minor) - dev->driver->debugfs_init (minor); -return 0 ; }
drivers/gpu/drm/drm_drv.c +5 -0
@@ -1101,6 +1101,11 @@ int drm_dev_register(struct drm_device *dev, unsigned long flags) dev->registered = true; dev->unplugged = false; +/* Call debugfs_init after the device is fully registered. */ +if (dev->driver->debugfs_init && dev->primary && + dev->render != dev->primary) + dev->driver->debugfs_init (dev->primary); +if (driver->load) { ret = driver->load (dev, flags);if (ret)
Signature · 1 line
2.43.0
PATCH v3 5/8 rust: drm: add debugfs_init callback to Driver trait
In reply to Alvin SunAdd debugfs_init method to the Driver trait, enabling Rust DRM drivers to populate debugfs entries during device registration.
--- rust/kernel/drm/device.rs | 41 ++++++++++++++++++++++++++++++++++++++++- rust/kernel/drm/driver.rs | 11 +++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-)
rust/kernel/drm/device.rs +40 -1
@@ -7,6 +7,7 @@use crate ::{ alloc::allocator::Kmalloc , bindings, + debugfs, device, drm::{ self,
@@ -170,7 +171,7 @@ const fn compute_features() -> u32 { release: Some(Device::<T>::release), master_set: None, master_drop: None, - debugfs_init: None, + debugfs_init: Some(Device::<T>::debugfs_init_callback), gem_create_object: T::Object::ALLOC_OPS.gem_create_object, prime_handle_to_fd: T::Object::ALLOC_OPS.prime_handle_to_fd,
@@ -353,6 +354,44 @@ extern "C" fn release(ptr: *mut bindings::drm_device) {unsafe { core::ptr::drop_in_place (this) }; } +/// C callback for `drm_driver.debugfs_init`. +/// +/// # Safety +/// +/// The DRM core guarantees that `minor` is valid and non-null, that +/// `minor->dev` is a valid `drm_device` embedded in a `Device<T>`. +unsafe extern "C" fn debugfs_init_callback (minor: *mut bindings::drm_minor ) { +// SAFETY: `minor` is valid and non-null per the function's safety +// precondition. +let dev_ptr =unsafe { (*minor).dev }; +// SAFETY: `minor` is valid per the function's safety precondition. +let debugfs_root =unsafe { (*minor).debugfs_root }; + +// Debugfs may be disabled. +if debugfs_root.is_null () { +return ; + } + +// SAFETY: `dev_ptr` points to a valid `drm_device` embedded in +// `Device<T>`. +let dev =unsafe {Self ::from_raw (dev_ptr) }; + +// SAFETY: The device is in the registered state per the function's +// safety precondition. +let dev =unsafe { dev.assume_ctx ::<Registered >() }; + + dev.registration_data_with (|reg_data| { +// SAFETY: `debugfs_root` is valid as long as the DRM device is +// registered. The debugfs proxy fops wait for in-progress file +// operations and block new ones during `debugfs_remove()`, so no +// access to `reg_data` can outlive it. `debugfs_remove()` runs +// before `Registration::drop` frees `reg_data`. +let dir =unsafe { debugfs::ScopeRef ::new (debugfs_root, reg_data) }; + +T ::debugfs_init (&dir); + }); + } +/// Change the [`DeviceContext`] for a [`Device`]. /// /// # Safety
rust/kernel/drm/driver.rs +11 -0
@@ -6,6 +6,7 @@use crate ::{ bindings, + debugfs, device, drm, error::to_result,
@@ -138,6 +139,16 @@ pub trait Driver {/// usable from the render node (i.e. marked DRM_RENDER_ALLOW), whereas /// userspace processes using the master node can invoke any ioctl. const FEAT_RENDER :bool =false ; + +/// Populates debugfs for this DRM device. +/// +/// Called by the DRM core during registration. The `ScopeRef` provides +/// access to the device's `RegistrationData` for creating debugfs files. +fn debugfs_init (_dir: &debugfs::ScopeRef <'_,Self ::RegistrationData <'_>>) +where +Self :Sized , + { + } }/// The registration type of a `drm::Device`.
Signature · 1 line
2.43.0
PATCH v3 6/8 rust: drm: gpuvm: add dump_gpuva_info to UniqueRefGpuVm
In reply to Alvin SunAdd method wrapping drm_debugfs_gpuva_info to dump GPU VA space mappings into a seq_file. Needed by the Tyr gpuvas debugfs file.
--- rust/bindings/bindings_helper.h | 1 + rust/kernel/drm/gpuvm/mod.rs | 9 +++++++++ 2 files changed, 10 insertions(+)
rust/bindings/bindings_helper.h +1 -0
@@ -30,6 +30,7 @@#include <linux/acpi.h> #include <linux/gpu_buddy.h> +#include <drm/drm_debugfs.h> #include <drm/drm_device.h> #include <drm/drm_drv.h> #include <drm/drm_file.h>
rust/kernel/drm/gpuvm/mod.rs +9 -0
@@ -312,6 +312,15 @@ pub fn data_ref(&self) -> &T {unsafe { &*self.0 .data.get () } } +/// Dumps GPU VA space info into a seq_file. +/// +/// Wraps the C `drm_debugfs_gpuva_info` function. +#[inline] +pub fn dump_gpuva_info (&self, m: &crate ::seq_file::SeqFile ) ->Result { +// SAFETY: `m.as_raw()` and `self.as_raw()` are valid by the type invariants. +to_result (unsafe { bindings::drm_debugfs_gpuva_info (m.as_raw (), self.as_raw ()) }) + } +/// Access the data owned by this `UniqueRefGpuVm` mutably. #[inline] pub fn data (&mut self) -> &mut T {
Signature · 1 line
2.43.0
PATCH v3 7/8 drm/tyr: track VMs in a registry
In reply to Alvin SunAdd VmRegistry to track all VMs for debugfs enumeration. VMs are explicitly registered and unregistered to keep the list in sync.
--- drivers/gpu/drm/tyr/driver.rs | 6 +++++- drivers/gpu/drm/tyr/fw.rs | 18 +++++++++++++++--- drivers/gpu/drm/tyr/vm.rs | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+), 4 deletions(-)
drivers/gpu/drm/tyr/driver.rs +5 -1
@@ -57,7 +57,8 @@ gpu, gpu::GpuInfo, mmu::Mmu, - regs::gpu_control::*, // + regs::gpu_control::*, + vm::VmRegistry, // };pub (crate )type IoMem <'a> = kernel::io::mem::IoMem <'a,SZ_2M >;
@@ -167,11 +168,14 @@ fn probe<'bound>(let mmu =Mmu ::new (pdev.as_ref (), iomem.as_arc_borrow (), &gpu_info)?; +let registry =Arc ::pin_init (VmRegistry ::new (),GFP_KERNEL )?; +let firmware =Firmware ::new ( pdev.as_ref (), iomem.clone (), &unreg_dev, mmu.as_arc_borrow (), + registry.clone (), &gpu_info, )?;
drivers/gpu/drm/tyr/fw.rs +15 -3
@@ -64,7 +64,6 @@ KernelBoVaAlloc, // }, gpu::GpuInfo, - mmu::Mmu, regs::{ gpu_control::{
@@ -76,7 +75,8 @@ }, // job_control::JOB_IRQ_CLEAR, }, - vm::Vm, // + vm::Vm, + vm::VmRegistry, // };mod interfaces;
@@ -174,6 +174,9 @@ pub(crate) struct Firmware<'drm> {/// MCU VM. vm: Arc<Vm<'drm>>, +/// VM registry, used to unregister `vm` on drop. + vm_registry: Arc<VmRegistry<'drm>>, +/// List of firmware sections. sections: KVec<Section<'drm>>,
@@ -195,6 +198,7 @@ fn drop(self: Pin<&mut Self>) {let _ = self.stop ();// AS slots retain a VM ref, we need to kill the circular ref manually. + self.vm_registry.unregister (&self.vm); self.vm.kill (); } }
@@ -251,12 +255,18 @@ pub(crate) fn new( iomem: Arc<IoMem<'drm>>, ddev: &TyrDrmDevice, mmu: ArcBorrow<'_, Mmu<'drm>>, + vm_registry: Arc<VmRegistry<'drm>>, gpu_info: &GpuInfo, ) -> Result<Arc<Firmware<'drm>>> {let vm =Vm ::new (dev, ddev, mmu, gpu_info)?; - vm.activate ()?; +if let Err (e) = vm_registry.register (vm.clone ()) { +dev_warn! (dev,"failed to register VM: {e:?}\n" ); + } +let registry = vm_registry.clone (); let result = (|| { + vm.activate()?; + let vm = &vm; let (fw, parsed_sections) = Self::load(dev, ddev, gpu_info)?; let mut sections = KVec::new();
@@ -291,6 +301,7 @@ pub(crate) fn new(try_pin_init! (Firmware { iomem, vm: vm.clone (), + vm_registry: registry, sections, global_iface <-new_mutex! (GlobalInterface ::new ()?), job_irq_wait:Arc ::pin_init (new_waitqueue! (),GFP_KERNEL )?,
@@ -301,6 +312,7 @@ pub(crate) fn new( })();if result.is_err () { + vm_registry.unregister (&vm); vm.kill (); }
drivers/gpu/drm/tyr/vm.rs +33 -0
@@ -311,6 +311,34 @@ pub(crate) struct GpuVmData<'drm> { _phantom: PhantomData<&'drm ()>, } +/// Tracks all VMs for this device. +#[pin_data] +pub (crate )struct VmRegistry <'drm> { +#[pin] + vms:Mutex <KVec <Arc <Vm <'drm>>>>, +} + +impl <'drm>VmRegistry <'drm> { +pub (crate )fn new () ->impl PinInit <Self > { +pin_init! (Self { vms <-new_mutex! (KVec ::new ()) }) + } + +pub (crate )fn register (&self, vm:Arc <Vm <'drm>>) ->Result { +Ok (self.vms.lock ().push (vm,GFP_KERNEL )?) + } + +pub (crate )fn unregister (&self, vm: &Vm <'drm>) { + self.vms.lock ().retain (|v| !core::ptr::eq (&**v, vm)); + } + +pub (crate )fn for_each (&self,mut f:impl FnMut (&Vm <'drm>) ->Result ) ->Result { +for vmin self.vms.lock ().iter () { +f (vm)?; + } +Ok (()) + } +} +/// GPU virtual address space. /// /// Each VM can be mapped into a hardware address space slot.
@@ -401,6 +429,11 @@ pub(crate) fn activate(&self) -> Result { }) } +/// Dumps GPU VA space info into a seq_file. +pub (crate )fn dump_gpuva_info (&self, m: &kernel::seq_file::SeqFile ) ->Result { + self.gpuvm_unique.lock ().dump_gpuva_info (m) + } +/// Deactivate the VM by evicting it from its address space slot. fn deactivate (&self) ->Result { self.mmu.deactivate_vm (&self.as_data).inspect_err (|e| {
Signature · 1 line
2.43.0
PATCH v3 8/8 drm/tyr: add gpuvas debugfs file
In reply to Alvin SunAdd a gpuvas debugfs file listing all GPU VAs for the Tyr DRM driver. Collects VMs into a shared list during firmware init and renders them via dump_gpuva_info on read.
--- drivers/gpu/drm/tyr/debugfs.rs | 20 ++++++++++++++++++++ drivers/gpu/drm/tyr/driver.rs | 10 ++++++++++ drivers/gpu/drm/tyr/tyr.rs | 1 + 3 files changed, 31 insertions(+)
drivers/gpu/drm/tyr/debugfs.rs new file +20 -0
@@ -0,0 +1,20 @@ +// SPDX-License-Identifier: GPL-2.0 or MIT + +//! Debugfs support for the Tyr DRM driver. + +use kernel::{ + debugfs::SeqShow , + prelude::*, + seq_file,// +}; + +use crate ::driver::TyrDrmRegistrationData ; + +/// `SeqShow` implementation for the `gpuvas` debugfs file. +pub (crate )struct GpuvasShow ; + +impl SeqShow <TyrDrmRegistrationData <'_>>for GpuvasShow { +fn show (reg_data: &TyrDrmRegistrationData <'_>, m: &seq_file::SeqFile ) ->Result { + reg_data.vm_registry.for_each (|vm| vm.dump_gpuva_info (m)) + } +}
drivers/gpu/drm/tyr/driver.rs +10 -0
@@ -7,6 +7,7 @@ Clk, OptionalClk, // }, + debugfs, device::{Bound ,Core ,
@@ -45,6 +46,7 @@ };use crate ::{ + debugfs::GpuvasShow , file::TyrDrmFileData , fw::{ irq::{
@@ -87,6 +89,9 @@ pub(crate) struct TyrDrmRegistrationData<'drm> {/// Firmware sections. pub(crate) fw: Arc<Firmware<'drm>>, +/// VM registry, used by debugfs to enumerate GPU VA spaces. + pub(crate) vm_registry: Arc<VmRegistry<'drm>>, +#[pin] clks: Mutex<Clocks>,
@@ -198,6 +203,7 @@ fn probe<'bound>( let reg_data = pin_init!(TyrDrmRegistrationData { pdev, fw: firmware, + vm_registry: registry, clks <- new_mutex!(Clocks { core: core_clk, stacks: stacks_clk,
@@ -252,6 +258,10 @@ impl drm::Driver for TyrDrmDriver { kernel::declare_drm_ioctls! { (PANTHOR_DEV_QUERY , drm_panthor_dev_query, ioctl::RENDER_ALLOW ,TyrDrmFileData ::dev_query), } + +fn debugfs_init (dir: &debugfs::ScopeRef <'_,TyrDrmRegistrationData <'_>>) { + dir.seq_file ::<GpuvasShow >(c"gpuvas" ); + } }struct Clocks {
drivers/gpu/drm/tyr/tyr.rs +1 -0
@@ -7,6 +7,7 @@use crate ::driver::TyrPlatformDriver ; +mod debugfs;mod driver;mod file;mod fw;
Signature · 1 line
2.43.0