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>
Cc: "David Airlie" <airlied@gmail.com>,
	"Simona Vetter" <simona@ffwll.ch>,
	"Miguel Ojeda" <ojeda@kernel.org>,
	nova-gpu@lists.linux.dev, dri-devel@lists.freedesktop.org,
	gary@garyguo.net
Subject: Re: [RFC PATCH v2] gpu: nova-core: gsp: retain debugfs logs on teardown and capture logpmu
Date: Wed, 02 Dec 2026 03:05:05 +0000	[thread overview]
Message-ID: <sashiko-outbox-244742@kernel.org> (raw)
In-Reply-To: <20261202025028.43497-1-agustin.pereira.ro@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] gpu: nova-core: skipped DebugfsRootGuard cleanup in
  NovaCoreModule::init()
--

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

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

This commit captures PMU UCODE_LIBOS_PRINT events into a debugfs logpmu
buffer and adds a keep_gsp_logging module parameter to retain snapshots
of non-empty GSP debugfs log buffers after probe failures or device
unbind.

> diff --git a/drivers/gpu/nova-core/nova_core.rs b/drivers/gpu/nova-core/nova_core.rs
> index a8f6dc22057be..f182ebb6b928f 100644
> --- a/drivers/gpu/nova-core/nova_core.rs
> +++ b/drivers/gpu/nova-core/nova_core.rs
> @@ -35,11 +35,53 @@
>  // TODO: Move this into per-module data once that exists.
>  static mut DEBUGFS_ROOT: Option<debugfs::Dir> = None;

[ ... ]

> +/// Guard that clears retained logs and `DEBUGFS_ROOT` when dropped.
>  struct DebugfsRootGuard;
>  
>  impl Drop for DebugfsRootGuard {
>      fn drop(&mut self) {
> +        // Drop retained `debugfs` scopes and free the `KVec` backing allocation
> +        // before removing `DEBUGFS_ROOT`.
> +        *RETAINED_LOGS.lock() = KVec::new();
> +
>          // 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 };
> @@ -49,7 +91,7 @@ fn drop(&mut self) {
>  #[pin_data]
>  struct NovaCoreModule {
>      // Fields are dropped in declaration order, so `_driver` is dropped first,
> -    // then `_debugfs_guard` clears `DEBUGFS_ROOT`.
> +    // then `_debugfs_guard` clears retained logs and `DEBUGFS_ROOT`.
>      #[pin]
>      _driver: Registration<pci::Adapter<driver::NovaCoreDriver>>,
>      _debugfs_guard: DebugfsRootGuard,
> @@ -59,6 +101,10 @@ impl InPlaceModule for NovaCoreModule {
>      fn init(module: &'static kernel::ThisModule) -> impl PinInit<Self, Error> {
>          let dir = debugfs::Dir::new(c"nova-core");
>  
> +        // SAFETY: We are the only driver code running during init, so `RETAINED_LOGS`
> +        // is initialized exactly once before any driver callback can access it.
> +        unsafe { RETAINED_LOGS.init() };
> +
>          // 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) };

[Severity: Medium]
Does this leak RETAINED_LOGS and DEBUGFS_ROOT if Registration::new() fails
in NovaCoreModule::init()?

try_pin_init! runs field initializers in the order they appear in the
initializer block and only drops fields that have already been
initialized:

drivers/gpu/nova-core/nova_core.rs:NovaCoreModule::init() {
    ...
        try_pin_init!(Self {
            _driver <- Registration::new(MODULE_NAME, module),
            _debugfs_guard: DebugfsRootGuard,
        })
}

Because _driver is initialized before _debugfs_guard, an error from
Registration::new() returns before DebugfsRootGuard is constructed, so
DebugfsRootGuard::drop() never runs.  Any RetainedLogEntry pushed into
RETAINED_LOGS during synchronous probing in bus_add_driver() before
registration fails (along with DEBUGFS_ROOT itself) will be leaked and its
debugfs entries will remain dangling under /sys/kernel/debug/nova-core.

Initializing _debugfs_guard before _driver inside try_pin_init! (while
keeping the struct field declaration order unchanged for module unload)
ensures DebugfsRootGuard::drop() runs if Registration::new() fails.

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

  parent reply	other threads:[~2026-12-02  3:05 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02  2:50 [RFC PATCH v2] gpu: nova-core: gsp: retain debugfs logs on teardown and capture logpmu Agustín Pereira
2026-12-02  2:50 ` [RFC PATCH v2] gpu: nova-core: gsp: add RM alloc/control/free RPCs and client/device API Agustín Pereira
2026-12-02  3:01   ` sashiko-bot
2026-12-02  3:05 ` sashiko-bot [this message]
2026-12-02  3:37 ` [RFC PATCH v2] gpu: nova-core: gsp: retain debugfs logs on teardown and capture logpmu John Hubbard

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-244742@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=acourbot@nvidia.com \
    --cc=agustin.pereira.ro@gmail.com \
    --cc=airlied@gmail.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