NVIDIA GPU driver infrastructure
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Alexandre Courbot" <acourbot@nvidia.com>,
	"Danilo Krummrich" <dakr@kernel.org>,
	"Alice Ryhl" <aliceryhl@google.com>,
	"David Airlie" <airlied@gmail.com>,
	"Simona Vetter" <simona@ffwll.ch>,
	"Miguel Ojeda" <ojeda@kernel.org>,
	"Boqun Feng" <boqun@kernel.org>, "Gary Guo" <gary@garyguo.net>,
	"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
	"Benno Lossin" <lossin@kernel.org>,
	"Andreas Hindborg" <a.hindborg@kernel.org>,
	"Trevor Gross" <tmgross@umich.edu>,
	"Daniel Almeida" <daniel.almeida@collabora.com>,
	"Tamir Duberstein" <tamird@kernel.org>,
	"Onur Özkan" <work@onurozkan.dev>,
	"Maarten Lankhorst" <maarten.lankhorst@linux.intel.com>,
	"Maxime Ripard" <mripard@kernel.org>,
	"Thomas Zimmermann" <tzimmermann@suse.de>,
	"Jonathan Corbet" <corbet@lwn.net>,
	"Shuah Khan" <skhan@linuxfoundation.org>,
	"Randy Dunlap" <rdunlap@infradead.org>
Cc: "John Hubbard" <jhubbard@nvidia.com>,
	"Alistair Popple" <apopple@nvidia.com>,
	"Timur Tabi" <ttabi@nvidia.com>,
	"Eliot Courtney" <ecourtney@nvidia.com>,
	"Zhi Wang" <zhiw@nvidia.com>, "Alok Kumar" <alkumar@nvidia.com>,
	nova-gpu@lists.linux.dev, dri-devel@lists.freedesktop.org
Subject: Re: [PATCH 09/15] gpu: nova-core: gsp: drain the message queue while waiting for GSP suspend
Date: Thu, 03 Dec 2026 12:56:01 +0000	[thread overview]
Message-ID: <sashiko-outbox-247803@kernel.org> (raw)
In-Reply-To: <20261203-b4-r000-switch-v1-9-b1463ec6dae2@nvidia.com>

Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] gpu: nova-core: cmdq.drain() error aborts GSP suspend wait in
  shutdown_gsp()
- [Medium] gpu: nova-core: unbounded cmdq.drain() bypasses
  shutdown_gsp() timeout
- [Low] gpu: nova-core: drain before suspend check in shutdown_gsp()
  misses events
--

commit 5a7f5b0b34f6ff35ede1c640685237ffd7e41f84
Author: John Hubbard <jhubbard@nvidia.com>

gpu: nova-core: gsp: drain the message queue while waiting for GSP suspend

This patch replaces wait_for_processor_suspend() in Gsp::shutdown_gsp() with
a read_poll_timeout() loop that calls cmdq.drain() on each poll iteration
while waiting for the GSP RISC-V core to suspend.

> diff --git a/drivers/gpu/nova-core/gsp/boot.rs b/drivers/gpu/nova-core/gsp/boot.rs
> index 2904f1ac74593..fb474e5984a80 100644
> --- a/drivers/gpu/nova-core/gsp/boot.rs
> +++ b/drivers/gpu/nova-core/gsp/boot.rs
> @@ -106,8 +106,19 @@ fn shutdown_gsp(
>          // Command to shut the GSP down.
>          cmdq.send_rpc_command(commands::rpc::UnloadingGuestDriver::new(mode))?;
>  
> -        // Wait until GSP signals it is suspended.
> -        gsp_falcon.wait_for_processor_suspend()
> +        // Wait until GSP signals it is suspended. GSP-RM posts messages while it suspends, and the
> +        // GSP event interrupt is already freed, so this poll drains them.
> +        read_poll_timeout(
> +            || {
> +                cmdq.drain()?;

[Severity: Medium]
Can an error from cmdq.drain() abort the suspend wait before the GSP stops?

read_poll_timeout() exits immediately when the closure returns Err.  If a
malformed message is stuck at the queue head (as left by
GspInterrupt::handle_threaded() after disabling the event IRQ), cmdq.drain()
returns Err(EIO) and skips waiting for is_processor_suspended().

Gsp::unload() then immediately runs unload_bundle to reset the falcon while
GSP-RM is still tearing down.  If unload_bundle is None, GspResources::drop()
frees the coherent DMA buffers while the GSP may still be performing DMA.

Logging the first drain error, skipping further drains, and continuing to
poll is_processor_suspended() until suspend or timeout would avoid this.

> +
> +                Ok(gsp_falcon.is_processor_suspended())

[Severity: Low]
Does draining before checking is_processor_suspended() miss trailing events
posted just before the GSP suspends?

CPU                               GSP-RM
cmdq.drain()  (queue empty)
                                  post final teardown message
                                  set processor_suspended
is_processor_suspended() == true
read_poll_timeout() returns       <-- final message never drained

Because Gsp::unload() resets the falcon right after without another drain,
final diagnostic messages logged by RpcMessage::log() can be lost.  Checking
is_processor_suspended() before cmdq.drain() (or draining once more after
read_poll_timeout() returns) closes this window.

> +            },
> +            |suspended| *suspended,
> +            Delta::from_millis(10),
> +            Delta::from_secs(5),
> +        )
> +        .map(|_| ())

[Severity: Medium]
Can cmdq.drain() spin indefinitely here and bypass the 5-second timeout?

CmdqInner::drain() loops with Delta::ZERO until the queue is empty,
advancing cpu_read_ptr on each message with no deadline, message cap, or
reschedule point.  read_poll_timeout() only checks the timeout after the
closure returns.

If malfunctioning GSP firmware keeps posting messages during suspend,
shutdown_gsp() hangs forever, preventing Gsp::unload() from running
unload_bundle and risking a CPU soft lockup on non-preemptible kernels.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261203-b4-r000-switch-v1-0-b1463ec6dae2@nvidia.com?part=9

  reply	other threads:[~2026-12-03 12:56 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03 12:09 [PATCH 00/15] gpu: nova-core: switch to the r000 GSP firmware Alexandre Courbot
2026-12-03 12:09 ` [PATCH 01/15] gpu: nova-core: gsp: nvkv: add const constructor for Key Alexandre Courbot
2026-12-03 12:09 ` [PATCH 02/15] gpu: nova-core: gsp: add the GSP_INIT command and its reply Alexandre Courbot
2026-12-03 12:26   ` sashiko-bot
2026-12-03 12:09 ` [PATCH 03/15] gpu: nova-core: gsp: populate VF information in GSP_INIT Alexandre Courbot
2026-12-03 14:03   ` Maxime Ripard
2026-12-03 14:32     ` Miguel Ojeda
2026-12-03 14:38       ` Maxime Ripard
2026-12-03 12:09 ` [PATCH 04/15] gpu: nova-core: gsp: re-export PowerStateLevel from gsp::commands Alexandre Courbot
2026-12-03 12:09 ` [PATCH 05/15] gpu: nova-core: gsp: add the GSP_SUSPEND request Alexandre Courbot
2026-12-03 12:09 ` [PATCH 06/15] gpu: nova-core: firmware: add the ucodes firmware loader Alexandre Courbot
2026-12-03 12:09 ` [PATCH 07/15] gpu: nova-core: gsp: define GSP_MSG_QUEUE_ELEMENT_SIZE_MAX without bindings Alexandre Courbot
2026-12-03 12:09 ` [PATCH 08/15] gpu: nova-core: fb: increase Blackwell reserved memory sizes for r000 Alexandre Courbot
2026-12-03 12:09 ` [PATCH 09/15] gpu: nova-core: gsp: drain the message queue while waiting for GSP suspend Alexandre Courbot
2026-12-03 12:56   ` sashiko-bot [this message]
2026-12-03 12:09 ` [PATCH 10/15] gpu: nova-core: gsp: zero-initialize FMC boot parameter structs Alexandre Courbot
2026-12-03 12:09 ` [PATCH 11/15] gpu: nova-core: firmware: add r000 GSP bindings Alexandre Courbot
2026-12-03 12:09 ` [PATCH 12/15] gpu: nova-core: switch to the r000 GSP firmware Alexandre Courbot
2026-12-03 13:23   ` sashiko-bot
2026-12-03 12:09 ` [PATCH 13/15] gpu: nova-core: gsp: delete the GSP sequencer Alexandre Courbot
2026-12-03 12:09 ` [PATCH 14/15] gpu: nova-core: gsp: delete the r570 RPC commands Alexandre Courbot
2026-12-03 12:09 ` [PATCH 15/15] gpu: nova-core: firmware: delete the r570 bindings Alexandre Courbot

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-247803@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=a.hindborg@kernel.org \
    --cc=acourbot@nvidia.com \
    --cc=airlied@gmail.com \
    --cc=aliceryhl@google.com \
    --cc=alkumar@nvidia.com \
    --cc=apopple@nvidia.com \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun@kernel.org \
    --cc=corbet@lwn.net \
    --cc=dakr@kernel.org \
    --cc=daniel.almeida@collabora.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=ecourtney@nvidia.com \
    --cc=gary@garyguo.net \
    --cc=jhubbard@nvidia.com \
    --cc=lossin@kernel.org \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=mripard@kernel.org \
    --cc=nova-gpu@lists.linux.dev \
    --cc=ojeda@kernel.org \
    --cc=rdunlap@infradead.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=simona@ffwll.ch \
    --cc=skhan@linuxfoundation.org \
    --cc=tamird@kernel.org \
    --cc=tmgross@umich.edu \
    --cc=ttabi@nvidia.com \
    --cc=tzimmermann@suse.de \
    --cc=work@onurozkan.dev \
    --cc=zhiw@nvidia.com \
    /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