gpu: nova-core: retain the GSP-RM log buffers
Subsystems (6)
v2 cover gpu: nova-core: retain the GSP-RM log buffers
The GSP-RM log buffers are exposed through debugfs, but the entries are owned by the Gpu that probe() builds, and the buffers themselves are DMA allocations that cannot outlive the device. They are therefore gone as soon as the GPU is unbound, and in particular as soon as probe() fails - which is the case todo.rst singled out, and the one where a GSP log is worth having.
Patch 1 adds a gsp_keep_logs module parameter: when it is set, whatever the GSP wrote is copied into memory owned by the module and exposed under a "retained" directory until the module is unloaded. Patch 2 drops the now completed task from todo.rst.
Changes since v1:
- use a gsp_keep_logs module parameter instead of a Kconfig option, so that no kernel rebuild is needed
- use VVec rather than KVec for the copies
- move the log buffer code into gsp/logbuffer.rs
- create the "retained" directory in module_init(), which removes the additional unsafe block from the teardown path
- dev_dbg!() instead of dev_info!()
- take every allocation that can fail before dropping a previous copy of the same device, so that running out of memory cannot leave that device with no logs at all
Two things did not make it into this revision:
The parameter is a u8 taking 0 or 1 rather than a bool. bool is not available in this tree: the macro fails with "Unsupported parameter type bool", as rust/kernel/module_param.rs only instantiates param ops for i8..u64, isize and usize. There is a TODO in the code to switch over once it arrives.
The dma_rmb() discussed on v1 is likewise not here yet, as the barrier abstractions are still making their way in via the tip tree. I will send it as a separate patch once the backmerge has happened.
Testing was done on top of drm-rust-next with the TLV firmware images installed, which also settles the question left open on v1 about the older base. On a GB203:
- with gsp_keep_logs unset, no "retained" directory is created and the
entries disappear on unbind, as before;
- with gsp_keep_logs=1, retained/<BDF>/{loginit,logintr,logrm} hold
the contents the live entries had, all 64 KiB of each readable; - binding the GPU again recreates the live entries without disturbing the copies, and unbinding it a second time replaces them, leaving exactly one set behind;
- with a failure injected after the GSP has booted, probe() fails with -EINVAL, the driver stays unbound, and the logs of that attempt are still readable;
- the copies are released on module unload, and three load/unload cycles leave nothing behind.
No warnings, oopses or refcount complaints in dmesg throughout. Built and checked with CLIPPY=1 and rustfmtcheck. checkpatch --strict is clean apart from the MAINTAINERS note for the new file, which is already covered by the existing "F: drivers/gpu/nova-core/" pattern.
Vladislav Zaharov (2):
gpu: nova-core: gsp: retain the GSP-RM log buffers after unbind
Documentation: nova: remove completed GSP log buffer task
Documentation/gpu/nova/core/todo.rst | 12 -- drivers/gpu/nova-core/gsp.rs | 100 ++--------- drivers/gpu/nova-core/gsp/logbuffer.rs | 235 +++++++++++++++++++++++++ drivers/gpu/nova-core/nova_core.rs | 28 +++ 4 files changed, 282 insertions(+), 93 deletions(-) create mode 100644 drivers/gpu/nova-core/gsp/logbuffer.rs
Signature · 1 line
2.55.0
PATCH v2 1/2 gpu: nova-core: gsp: retain the GSP-RM log buffers after unbind
The GSP-RM log buffers are exposed through debugfs, but the Scope that owns them lives in Gsp, inside GspResources, inside the Gpu built by probe(). They are DMA allocations of the device and cannot outlive it, so the entries go away as soon as the GPU is unbound - and, more to the point, as soon as probe() fails, which is exactly when the log of a GSP that did not come up is the thing one wants to read.
Add a gsp_keep_logs module parameter. When it is set, dropping the log buffers copies whatever the GSP wrote into memory owned by the module and exposes the copies until the module is unloaded. A buffer whose "put" pointer is still zero was never written to and is skipped.
The copies live in a "retained" directory, created during module init rather than on first use, which keeps the teardown path from having to reach for DEBUGFS_ROOT. Keeping them out of the directory used by bound GPUs also means a device coming back does not find its debugfs name taken by its own history; nouveau, which recreates the entries under the name of the GPU that just went away, has that problem.
The parameter is a u8 taking 0 or 1 rather than a bool, as the module parameter abstraction has no bool in this tree yet.
While at it, move the log buffer code out of gsp.rs into gsp/logbuffer.rs.
--- drivers/gpu/nova-core/gsp.rs | 100 ++--------- drivers/gpu/nova-core/gsp/logbuffer.rs | 235 +++++++++++++++++++++++++ drivers/gpu/nova-core/nova_core.rs | 28 +++ 3 files changed, 282 insertions(+), 81 deletions(-) create mode 100644 drivers/gpu/nova-core/gsp/logbuffer.rs
drivers/gpu/nova-core/gsp.rs +19 -81
@@ -12,11 +12,7 @@ CoherentView, DmaAddress, // }, - io::{ - io_project, - io_write, - Io, // - }, + io::io_write, pci, prelude::*, // };
@@ -24,9 +20,13 @@pub (crate )mod cmdq;pub (crate )mod commands;mod fw; +mod logbuffer;mod regs;mod sequencer; +use logbuffer::LogBuffers ; +pub (crate )use logbuffer::RetainedLogs ; +pub (crate )use fw::{GspFmcBootParams ,GspFwWprMeta ,
@@ -77,10 +77,6 @@ pub(crate) fn dev(&self) -> &'gpu device::Device<device::Bound> { } } -/// Number of GSP pages to use in a RM log buffer. -const RM_LOG_BUFFER_NUM_PAGES :usize =0x10 ; -const LOG_BUFFER_SIZE :usize =RM_LOG_BUFFER_NUM_PAGES *GSP_PAGE_SIZE ; -/// Array of page table entries, as understood by the GSP bootloader. #[repr( C )] #[derive( FromBytes , IntoBytes )]
@@ -101,49 +97,6 @@ fn init(view: CoherentView<'_, Self>, start: DmaAddress) -> Result<()> { } } -/// The logging buffers are byte queues that contain encoded printf-like -/// messages from GSP-RM. They need to be decoded by a special application -/// that can parse the buffers. -/// -/// The 'loginit' buffer contains logs from early GSP-RM init and -/// exception dumps. The 'logrm' buffer contains the subsequent logs. Both are -/// written to directly by GSP-RM and can be any multiple of GSP_PAGE_SIZE. -/// -/// The physical address map for the log buffer is stored in the buffer -/// itself, starting with offset 1. Offset 0 contains the "put" pointer (pp). -/// Initially, pp is equal to 0. If the buffer has valid logging data in it, -/// then pp points to index into the buffer where the next logging entry will -/// be written. Therefore, the logging data is valid if: -/// 1 <= pp < sizeof(buffer)/sizeof(u64) -struct LogBuffer (Coherent <[u8 ;LOG_BUFFER_SIZE ]>); - -impl LogBuffer { -/// Creates a new `LogBuffer` mapped on `dev`. -fn new (dev: &device::Device <device::Bound >) ->Result <Self > { -let obj =Self (Coherent ::zeroed (dev,GFP_KERNEL )?); - -let start_addr = obj.0 .dma_address (); - -let pte_view =io_project! ( - obj.0 , - [build:size_of ::<u64 >()..][build: ..RM_LOG_BUFFER_NUM_PAGES *size_of ::<u64 >()] - ) - .try_cast ::<PteArray <RM_LOG_BUFFER_NUM_PAGES >>()?; -PteArray ::init (pte_view, start_addr)?; - -Ok (obj) - } -} - -struct LogBuffers { -/// Init log buffer. - loginit:LogBuffer , -/// Interrupts log buffer. - logintr:LogBuffer , -/// RM log buffer. - logrm:LogBuffer , -} -/// GSP runtime data. #[pin_data] pub (crate )struct Gsp {
@@ -165,9 +118,7 @@ pub(crate) fn new(pdev: &pci::Device<device::Bound>) -> impl PinInit<Self, Error pin_init::pin_init_scope (move || {let dev = pdev.as_ref (); -let loginit =LogBuffer ::new (dev)?; -let logintr =LogBuffer ::new (dev)?; -let logrm =LogBuffer ::new (dev)?; +let log_buffers =LogBuffers ::new (dev)?;// Initialise the logging structures. The OpenRM equivalents are in: // _kgspInitLibosLoggingStructures (allocates memory for buffers)
@@ -182,36 +133,23 @@ pub(crate) fn new(pdev: &pci::Device<device::Bound>) -> impl PinInit<Self, Error GFP_KERNEL, )?; - libos.init_at (0 ,LibosMemoryRegionInitArgument ::new ("LOGINIT" , &loginit.0 ))?; - libos.init_at (1 ,LibosMemoryRegionInitArgument ::new ("LOGINTR" , &logintr.0 ))?; - libos.init_at (2 ,LibosMemoryRegionInitArgument ::new ("LOGRM" , &logrm.0 ))?; + libos.init_at ( +0 , +LibosMemoryRegionInitArgument ::new ("LOGINIT" , &log_buffers.loginit.0 ), + )?; + libos.init_at ( +1 , +LibosMemoryRegionInitArgument ::new ("LOGINTR" , &log_buffers.logintr.0 ), + )?; + libos.init_at ( +2 , +LibosMemoryRegionInitArgument ::new ("LOGRM" , &log_buffers.logrm.0 ), + )?; libos.init_at (3 ,LibosMemoryRegionInitArgument ::new ("RMARGS" , rmargs))?; libos.into () }, - logs <- { -let log_buffers =LogBuffers { - loginit, - logintr, - logrm, - }; - -#[allow(static_mut_refs)] -// SAFETY: `DEBUGFS_ROOT` is created before driver registration and cleared -// after driver unregistration, so no probe() can race with its modification. -// -// PANIC: `DEBUGFS_ROOT` cannot be `None` here. It is set before driver -// registration and cleared after driver unregistration, so it is always -// `Some` for the entire lifetime that probe() can be called. -let log_parent: &debugfs::Dir =unsafe {crate ::DEBUGFS_ROOT .as_ref () } - .expect ("DEBUGFS_ROOT not initialized" ); - - log_parent.scope (log_buffers, dev.name (), |logs, dir| { - dir.read_binary_file (c"loginit" , &logs.loginit.0 ); - dir.read_binary_file (c"logintr" , &logs.logintr.0 ); - dir.read_binary_file (c"logrm" , &logs.logrm.0 ); - }) - }, + logs <- log_buffers.scope(dev), })) }) }
drivers/gpu/nova-core/gsp/logbuffer.rs new file +235 -0
235 lines not on this page · raw message
drivers/gpu/nova-core/nova_core.rs +28 -0
@@ -30,11 +30,21 @@// TODO: Move this into per-module data once that exists. static mut DEBUGFS_ROOT :Option <debugfs::Dir > =None ; +kernel::sync::global_lock! { +/// Log buffers of GPUs that are gone, kept around until the module is unloaded. +// TODO: Move this into per-module data once that exists. +unsafe (uninit)static RETAINED_LOGS :Mutex <gsp::RetainedLogs > = gsp::RetainedLogs ::new (); +} +/// Guard that clears `DEBUGFS_ROOT` when dropped. struct DebugfsRootGuard ;impl Drop for DebugfsRootGuard {fn drop (&mut self) { +// Retained log buffers own debugfs entries below `DEBUGFS_ROOT`, so they have to go away +// before it does. +RETAINED_LOGS .lock ().clear (); +// SAFETY: This guard is dropped after `_driver` (due to field order), // so the driver is unregistered and no probe() can be running. unsafe {DEBUGFS_ROOT =None };
@@ -54,6 +64,16 @@ impl InPlaceModule for NovaCoreModule {fn init (module: &'static kernel::ThisModule ) ->impl PinInit <Self ,Error > {let dir = debugfs::Dir ::new (c"nova-core" ); +// SAFETY: Module initialization runs exactly once, and before the driver is registered, +// so no probe can have touched `RETAINED_LOGS` yet. +unsafe {RETAINED_LOGS .init () }; + +// Creating the directory up front is what makes retaining possible without reaching for +// `DEBUGFS_ROOT` later, from the teardown path of a device. +if *module_parameters::gsp_keep_logs.value () !=0 { +RETAINED_LOGS .lock ().enable (&dir); + } +// SAFETY: We are the only driver code running during init, so there // cannot be any concurrent access to `DEBUGFS_ROOT`. unsafe {DEBUGFS_ROOT =Some (dir) };
@@ -72,6 +92,14 @@ fn init(module: &'static kernel::ThisModule) -> impl PinInit<Self, Error> { description: "Nova Core GPU driver", license: "GPL v2", firmware: [], + params: { + // TODO: Use `bool` once the module parameter abstraction supports it; until then this + // takes 0 or 1. + gsp_keep_logs: u8 { + default: 0, + description: "Keep the GSP-RM log buffers in debugfs after their GPU is gone (0|1)", + }, + }, } kernel::module_firmware!(firmware::ModInfoBuilder );
Signature · 1 line
2.55.0
PATCH v2 2/2 Documentation: nova: remove completed GSP log buffer task
In reply to Vladislav ZaharovExposing the GSP-RM log buffers through debugfs is implemented, and with the gsp_keep_logs module parameter they now also survive a failed probe, which was the part of the task that was still missing.
--- Documentation/gpu/nova/core/todo.rst | 12 ------------ 1 file changed, 12 deletions(-)
Documentation/gpu/nova/core/todo.rst +0 -12
@@ -141,18 +141,6 @@ Implement support for instmem (bar2) used to store page tables. GPU System Processor (GSP) ========================== -Export GSP log buffers ----------------------- - -Recent patches from Timur Tabi [1] added support to expose GSP-RM log buffers -(even after failure to probe the driver) through debugfs. - -This is also an interesting feature for nova-core, especially in the early days. - -| Link: https://lore.kernel.org/nouveau/[email protected]/ [1] -| Reference: Debugfs abstractions -| Complexity: Intermediate - GSP firmware abstraction ------------------------
Signature · 1 line
2.55.0