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

-- 
2.55.0

Reply via email to