NVIDIA GPU driver infrastructure
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Agustín Pereira" <agustin.pereira.ro@gmail.com>,
	"Danilo Krummrich" <dakr@kernel.org>,
	"Alexandre Courbot" <acourbot@nvidia.com>,
	"Alice Ryhl" <aliceryhl@google.com>,
	"David Airlie" <airlied@gmail.com>,
	"Simona Vetter" <simona@ffwll.ch>
Cc: nova-gpu@lists.linux.dev, dri-devel@lists.freedesktop.org,
	ojeda@kernel.org, gary@garyguo.net
Subject: Re: [RFC PATCH] gpu: nova-core: gsp: retain debugfs logs on teardown and capture logpmu
Date: Wed, 02 Dec 2026 02:04:37 +0000	[thread overview]
Message-ID: <sashiko-outbox-244619@kernel.org> (raw)
In-Reply-To: <20261202015304.152927-1-agustin.pereira.ro@gmail.com>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] gpu: nova-core: unaligned stack slice in
  PmuLogBuffer::capture_event()
- [Medium] gpu: nova-core: RETAINED_LOGS KVec memory leak in
  DebugfsRootGuard::drop()
--

commit de98d34f69a2abc89f1f11708b2ef5d8075d83df
Author: Agustín Pereira <agustin.pereira.ro@gmail.com>

gpu: nova-core: gsp: retain debugfs logs on teardown and capture logpmu

This commit moves GSP-RM logging into a dedicated gsp::logs module, captures
PMU UCODE_LIBOS_PRINT events into a debugfs logpmu buffer, and adds a
keep_gsp_logging module parameter to snapshot and retain non-empty log
buffers in debugfs across probe failures or device unbind.

> diff --git a/drivers/gpu/nova-core/gsp/logs.rs b/drivers/gpu/nova-core/gsp/logs.rs
> new file mode 100644
> index 0000000000000..9044315f18db9
> --- /dev/null
> +++ b/drivers/gpu/nova-core/gsp/logs.rs
> @@ -0,0 +1,450 @@

[ ... ]

> +    pub(crate) fn capture_event(&self, contents: (&[u8], &[u8])) -> Result<usize> {
> +        let total_len = contents.0.len().saturating_add(contents.1.len());
> +        let header_len = size_of::<UcodeLibOsPrintHeader>();
> +        if total_len < header_len {
> +            return Err(EINVAL);
> +        }
> +
> +        let mut sbuf = SBufferIter::new_reader([contents.0, contents.1]);
> +        let mut hdr_bytes = [0u8; size_of::<UcodeLibOsPrintHeader>()];
> +        sbuf.read_exact(&mut hdr_bytes)?;
> +
> +        let hdr = UcodeLibOsPrintHeader::from_bytes(&hdr_bytes).ok_or(EIO)?;

[Severity: Medium]
Can UcodeLibOsPrintHeader::from_bytes(&hdr_bytes) fail with Err(EIO) on
valid events because hdr_bytes is only 1-byte aligned?

UcodeLibOsPrintHeader wraps rpc_ucode_libos_print_v1e_08, which contains
u32 fields and requires 4-byte alignment, while FromBytes::from_bytes()
returns None when slice_ptr.is_aligned() is false.  Whenever the compiler
places hdr_bytes on an address not divisible by 4, capture_event() rejects
valid PMU print events and fails the KUnit tests.  Using
UcodeLibOsPrintHeader::from_bytes_copy(&hdr_bytes) avoids the alignment
requirement.

> diff --git a/drivers/gpu/nova-core/nova_core.rs b/drivers/gpu/nova-core/nova_core.rs
> index a8f6dc22057be..028e368f1b831 100644
> --- a/drivers/gpu/nova-core/nova_core.rs
> +++ b/drivers/gpu/nova-core/nova_core.rs
> @@ -35,11 +35,52 @@
>  // TODO: Move this into per-module data once that exists.
>  static mut DEBUGFS_ROOT: Option<debugfs::Dir> = None;
>  
> -/// Guard that clears `DEBUGFS_ROOT` when dropped.
> +kernel::sync::global_lock! {
> +    // SAFETY: Initialized once in `NovaCoreModule::init` before driver registration
> +    // and cleared in `DebugfsRootGuard::drop` after driver unregistration.
> +    unsafe(uninit) static RETAINED_LOGS: Mutex<KVec<gsp::logs::RetainedLogEntry>> = KVec::new();
> +}

[ ... ]

> +/// Guard that clears retained logs and `DEBUGFS_ROOT` when dropped.
>  struct DebugfsRootGuard;
>  
>  impl Drop for DebugfsRootGuard {
>      fn drop(&mut self) {
> +        // Drop retained `debugfs` scopes before removing `DEBUGFS_ROOT`.
> +        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 };

[Severity: Medium]
Does RETAINED_LOGS.lock().clear() leak the KVec backing buffer on module
unload?

KVec::clear() truncates the vector to length 0 and drops its elements in
place, but keeps the Kmalloc capacity allocation.  Because RETAINED_LOGS is
a static item, its Drop implementation never runs when the module is
unloaded.  In addition, because NovaCoreModule drops _driver before
_debugfs_guard, unloading the module with keep_gsp_logging=true unbinds all
active devices and snapshots their logs into RETAINED_LOGS right before
DebugfsRootGuard::drop() clears them and leaks the vector buffer.
Replacing the vector with *RETAINED_LOGS.lock() = KVec::new() will drop the
old KVec and free its backing memory.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261202015304.152927-1-agustin.pereira.ro@gmail.com?part=1

      reply	other threads:[~2026-12-02  2:04 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02  1:53 [RFC PATCH] gpu: nova-core: gsp: retain debugfs logs on teardown and capture logpmu Agustín Pereira
2026-12-02  2:04 ` sashiko-bot [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-244619@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=acourbot@nvidia.com \
    --cc=agustin.pereira.ro@gmail.com \
    --cc=airlied@gmail.com \
    --cc=aliceryhl@google.com \
    --cc=dakr@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=gary@garyguo.net \
    --cc=nova-gpu@lists.linux.dev \
    --cc=ojeda@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=simona@ffwll.ch \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox