All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Alexandre Courbot" <acourbot@nvidia.com>
Cc: dri-devel@lists.freedesktop.org,
	"Danilo Krummrich" <dakr@kernel.org>,
	ojeda@kernel.org
Subject: Re: [PATCH v4 02/13] gpu: nova-core: gsp: sequencer: do not store sequence into GspSequencer
Date: Mon, 29 Jun 2026 14:19:27 +0000	[thread overview]
Message-ID: <20260629141928.6BF431F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260629-nova-bootcontext-v4-2-5539d8469590@nvidia.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

Pre-existing issues:
- [High] The sequencer iterator silently terminates upon encountering a command parsing error, causing the boot sequence to falsely report success.
- [High] Truncated commands at the end of the sequence buffer are silently executed with zero-padded payloads instead of failing.
--

commit ffd1618690514804f608d22ee8574e39be09904e
Author: Alexandre Courbot <acourbot@nvidia.com>

gpu: nova-core: gsp: sequencer: do not store sequence into GspSequencer

The sequence is currently stored in the `GspSequencer` even though its
lifetime is limited to `GspSequencer::run`. This object-oriented design
does not play well with the borrow-checker, as `GspSequencer::iter`
borrows a reference to the `GspSequencer`, which makes it difficult to
introduce mutable references in `GspBootContext`, as we want to do in
order to make the `Falcon` references mutable.

Thus, store the sequence locally in `GspSequencer::run`, and move
iterator creation to `GspSeqIter::new` so it no longer needs to borrow
the whole `GspSequencer`.

> diff --git a/drivers/gpu/nova-core/gsp/sequencer.rs b/drivers/gpu/nova-core/gsp/sequencer.rs
> index f55205bd61f35..ddce32cc4e308 100644
> --- a/drivers/gpu/nova-core/gsp/sequencer.rs
> +++ b/drivers/gpu/nova-core/gsp/sequencer.rs

[ ... ]

> @@ -281,6 +279,18 @@ pub(crate) struct GspSeqIter<'a> {
>      dev: &'a device::Device,
>  }
>  
> +impl<'a> GspSeqIter<'a> {
> +    fn new(seq: &'a GspSequence, dev: &'a device::Device) -> Self {
> +        Self {
> +            cmd_data: &seq.cmd_data,
> +            current_offset: 0,
> +            total_cmds: seq.cmd_index,
> +            cmds_processed: 0,
> +            dev,
> +        }
> +    }
> +}
> +
>  impl<'a> Iterator for GspSeqIter<'a> {
>      type Item = Result<GspSeqCmd>;
>  
> @@ -322,20 +332,6 @@ fn next(&mut self) -> Option<Self::Item> {
>      }
>  }
>  
> -impl<'a> GspSequencer<'a> {
> -    fn iter(&self) -> GspSeqIter<'_> {
> -        let cmd_data = &self.seq_info.cmd_data[..];
> -
> -        GspSeqIter {
> -            cmd_data,
> -            current_offset: 0,
> -            total_cmds: self.seq_info.cmd_index,
> -            cmds_processed: 0,
> -            dev: self.dev,
> -        }
> -    }
> -}
> -

[Severity: High]
This isn't a bug introduced by this patch, but while looking at
GspSeqIter::next() I noticed that it silently terminates on parsing errors:

drivers/gpu/nova-core/gsp/sequencer.rs:GspSeqIter::next() {
    ...
    let cmd_result = GspSeqCmd::new(&buffer, self.dev);

    cmd_result.map_or_else(
        |_err| {
            dev_err!(self.dev, "Error parsing command at offset {}\n", offset);
            None
        },
    ...
}

If firmware sends invalid data and GspSeqCmd::new() returns an error, the
iterator returns None instead of propagating the error. This silently stops
the iterator loop, causing the remaining hardware initialization commands
to be skipped while GspSequencer::run() falsely reports success.

Can this leave the GPU in an uninitialized state and cause system hangs or
memory corruption?

[Severity: High]
This is a pre-existing issue, but I also noticed a potential bounds checking
bypass when GspSeqIter::next() processes truncated commands at the end of the
sequence buffer:

drivers/gpu/nova-core/gsp/sequencer.rs:GspSeqIter::next() {
    ...
    let mut buffer = [0u8; CMD_SIZE];
    let copy_len = if offset + CMD_SIZE <= self.cmd_data.len() {
        CMD_SIZE
    } else {
        self.cmd_data.len() - offset
    };
    buffer[..copy_len].copy_from_slice(&self.cmd_data[offset..offset + copy_len]);
    let cmd_result = GspSeqCmd::new(&buffer, self.dev);
    ...
}

When copy_len is less than CMD_SIZE, the data is copied into the zero-padded
buffer and passed to GspSeqCmd::new() as a full CMD_SIZE slice.

Inside GspSeqCmd::new():

drivers/gpu/nova-core/gsp/sequencer.rs:GspSeqCmd::new() {
    ...
    if data.len() < size {
        dev_err!(dev, "Data is not enough for command\n");
        return Err(EINVAL);
    }
    ...
}

Since data.len() is always evaluated as the full buffer length (CMD_SIZE),
this check always passes, neutralizing the intended length validation.

Does this execute truncated firmware commands with zeroed payloads instead of
failing, potentially causing unintended hardware actions or state corruption?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260629-nova-bootcontext-v4-0-5539d8469590@nvidia.com?part=2

  reply	other threads:[~2026-06-29 14:19 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-29 14:09 [PATCH v4 00/13] gpu: nova-core: consolidate and streamline GSP boot process Alexandre Courbot
2026-06-29 14:09 ` [PATCH v4 01/13] gpu: nova-core: gsp: sequencer: use GspBootContext Alexandre Courbot
2026-06-29 14:22   ` sashiko-bot
2026-06-29 14:09 ` [PATCH v4 02/13] gpu: nova-core: gsp: sequencer: do not store sequence into GspSequencer Alexandre Courbot
2026-06-29 14:19   ` sashiko-bot [this message]
2026-06-29 14:09 ` [PATCH v4 03/13] gpu: nova-core: gsp: replace BootUnloadGuard with local handlers Alexandre Courbot
2026-06-29 14:21   ` sashiko-bot
2026-07-01  2:54   ` Eliot Courtney
2026-07-06 10:00     ` Alexandre Courbot
2026-06-29 14:09 ` [PATCH v4 04/13] gpu: nova-core: gsp: pass GspBootContext to unload methods Alexandre Courbot
2026-07-01  3:57   ` Eliot Courtney
2026-06-29 14:09 ` [PATCH v4 05/13] gpu: nova-core: gsp: centralize missing unload bundle warnings Alexandre Courbot
2026-06-29 14:20   ` sashiko-bot
2026-07-01  4:06   ` Eliot Courtney
2026-06-29 14:09 ` [PATCH v4 06/13] gpu: nova-core: gsp: fold TU102 unload bundle construction into HAL method Alexandre Courbot
2026-07-01  4:15   ` Eliot Courtney
2026-06-29 14:09 ` [PATCH v4 07/13] gpu: nova-core: gsp: turn FWSEC execution " Alexandre Courbot
2026-07-01  4:16   ` Eliot Courtney
2026-06-29 14:09 ` [PATCH v4 08/13] gpu: nova-core: gsp: make use of FWSEC bootloader a property of the TU102 HAL Alexandre Courbot
2026-06-29 14:09 ` [PATCH v4 09/13] gpu: nova-core: introduce GspBootMethod Alexandre Courbot
2026-07-02  2:28   ` Eliot Courtney
2026-06-29 14:09 ` [PATCH v4 10/13] gpu: nova-core: avoid repeated calls to pci::Device::as_ref Alexandre Courbot
2026-06-29 14:17   ` sashiko-bot
2026-07-01  6:38   ` Eliot Courtney
2026-06-29 14:09 ` [PATCH v4 11/13] gpu: nova-core: gsp: pass GspBootContext mutably Alexandre Courbot
2026-07-01  6:40   ` Eliot Courtney
2026-06-29 14:09 ` [PATCH v4 12/13] gpu: nova-core: gsp: separate context and GPU lifetimes in GspBootContext Alexandre Courbot
2026-06-29 14:22   ` sashiko-bot
2026-07-01  6:52   ` Eliot Courtney
2026-06-29 14:09 ` [PATCH v4 13/13] gpu: nova-core: store Fsp instance in Gpu Alexandre Courbot
2026-06-29 14:27   ` sashiko-bot
2026-07-01  6:46   ` Eliot Courtney

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=20260629141928.6BF431F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=acourbot@nvidia.com \
    --cc=dakr@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=ojeda@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.