From: sashiko-bot@kernel.org
To: "Alexandre Courbot" <acourbot@nvidia.com>
Cc: "Alexandre Courbot" <acourbot@nvidia.com>,
dri-devel@lists.freedesktop.org, ojeda@kernel.org,
"Danilo Krummrich" <dakr@kernel.org>
Subject: Re: [PATCH 2/2] gpu: nova-core: use FromSafeCast wherever possible
Date: Fri, 28 Aug 2026 05:49:17 +0000 [thread overview]
Message-ID: <20260828054917.936DD1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260828-nova_num-v1-2-e21f17ba4127@nvidia.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Pre-existing issues:
- [High] Missing DMA write memory barrier before updating the GSP command queue write pointer.
- [High] Missing DMA read memory barrier after reading the GSP message queue write pointer.
--
commit 899e3ba6af7f4cc7e2c28b0f4f3f73db18de1f16
Author: Alexandre Courbot <acourbot@nvidia.com>
gpu: nova-core: use FromSafeCast wherever possible
Replaces various *_as_* casting functions with FromSafeCast in
non-const contexts to simplify conversions.
> diff --git a/drivers/gpu/nova-core/gsp/cmdq.rs b/drivers/gpu/nova-core/gsp/cmdq.rs
> index f85fde09aa6e3..658d0a9b2cfb2 100644
> --- a/drivers/gpu/nova-core/gsp/cmdq.rs
> +++ b/drivers/gpu/nova-core/gsp/cmdq.rs
[ ... ]
> @@ -343,10 +346,10 @@ fn driver_write_area_size(&self) -> usize {
> unsafe {
> (
> core::slice::from_raw_parts(
> - data.add(casts::u32_as_usize(rx)),
> - casts::u32_as_usize(tail_end - rx),
> + data.add(usize::from_safe_cast(rx)),
> + usize::from_safe_cast(tail_end - rx),
> ),
> - core::slice::from_raw_parts(data, casts::u32_as_usize(wrap_end)),
> + core::slice::from_raw_parts(data, usize::from_safe_cast(wrap_end)),
> )
> }
> }
[Severity: High]
This isn't a bug introduced by this patch, but while reviewing this
file I noticed a potential memory barrier issue in advance_cpu_write_ptr():
> fn advance_cpu_write_ptr(&mut self, elem_count: u32) {
> let tx = io_project!(self.0, .cpuq.tx);
> let wptr = MsgqTxHeader::write_ptr(tx).wrapping_add(elem_count) % MSGQ_NUM_PAGES;
> MsgqTxHeader::set_write_ptr(tx, wptr);
>
> // Ensure all command data is visible before triggering the GSP read.
> fence(Ordering::SeqCst);
> }
Because there is no memory barrier between the payload writes (done prior
to calling this function) and the write pointer volatile write in
MsgqTxHeader::set_write_ptr(), the CPU can reorder them.
If the GSP observes the updated write pointer before the payload writes
are globally visible, could it read stale command data?
[Severity: High]
This is also a pre-existing issue, but is there a missing read memory
barrier after reading the message queue write pointer in wait_for_msg()?
> fn wait_for_msg(&self, timeout: Delta) -> Result<GspMessage<'_>> {
> // Wait for a message to arrive from the GSP.
> let (slice_1, slice_2) = read_poll_timeout(
> || Ok(self.gsp_mem.driver_read_area()),
> |driver_area| !driver_area.0.is_empty(),
> Delta::from_millis(1),
> timeout,
> )
> .map(|(slice_1, slice_2)| (slice_1.as_flattened(), slice_2.as_flattened()))?;
>
> // Extract the `GspMsgElement`.
> let (header, slice_1) = GspMsgElement::from_bytes_prefix(slice_1).ok_or(EIO)?;
When polling for a new message, read_poll_timeout repeatedly evaluates
driver_read_area(), which performs a volatile read of the GSP write
pointer.
Once a new message is indicated, the payload memory slices are immediately
accessed.
Since there is no read memory barrier between the volatile read of the
write pointer and the payload access, could modern CPUs speculatively
execute the data loads before the write pointer read completes, causing
the driver to read stale payload data?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260828-nova_num-v1-0-e21f17ba4127@nvidia.com?part=2
prev parent reply other threads:[~2026-08-28 5:49 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-28 5:33 [PATCH 0/2] gpu: nova-core: complete conversion to kernel `num` module Alexandre Courbot
2026-08-28 5:33 ` [PATCH 1/2] gpu: nova-core: use kernel lossless integer conversion module Alexandre Courbot
2026-08-28 5:43 ` sashiko-bot
2026-08-28 12:09 ` Danilo Krummrich
2026-08-28 12:16 ` Miguel Ojeda
2026-08-29 3:34 ` Alexandre Courbot
2026-08-29 19:14 ` Danilo Krummrich
2026-08-31 1:08 ` Alexandre Courbot
2026-08-31 12:50 ` Danilo Krummrich
2026-08-31 14:20 ` Alexandre Courbot
2026-08-28 5:33 ` [PATCH 2/2] gpu: nova-core: use FromSafeCast wherever possible Alexandre Courbot
2026-08-28 5:42 ` Eliot Courtney
2026-08-28 5:49 ` 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=20260828054917.936DD1F000E9@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox