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 <[email protected]>

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/[email protected]?part=9

Reply via email to