NVIDIA GPU driver infrastructure
 help / color / mirror / Atom feed
From: John Hubbard <jhubbard@nvidia.com>
To: sashiko-reviews@lists.linux.dev,
	"Eliot Courtney" <ecourtney@nvidia.com>,
	"Danilo Krummrich" <dakr@kernel.org>,
	"Lorenzo Stoakes" <ljs@kernel.org>,
	"Vlastimil Babka" <vbabka@kernel.org>,
	"Liam R. Howlett" <liam@infradead.org>,
	"Uladzislau Rezki" <urezki@gmail.com>,
	"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>,
	"Alice Ryhl" <aliceryhl@google.com>,
	"Trevor Gross" <tmgross@umich.edu>,
	"Daniel Almeida" <daniel.almeida@collabora.com>,
	"Tamir Duberstein" <tamird@kernel.org>,
	"Alexandre Courbot" <acourbot@nvidia.com>,
	"Onur Özkan" <work@onurozkan.dev>,
	"David Airlie" <airlied@gmail.com>,
	"Simona Vetter" <simona@ffwll.ch>
Cc: Alistair Popple <apopple@nvidia.com>,
	Timur Tabi <ttabi@nvidia.com>,
	nova-gpu@lists.linux.dev, dri-devel@lists.freedesktop.org,
	Roman Gushchin <roman.gushchin@linux.dev>
Subject: Re: [PATCH v4 4/7] gpu: nova-core: add NVKV decoder
Date: Thu, 15 Oct 2026 19:05:58 -0700	[thread overview]
Message-ID: <db71fe6b-bc96-4d02-a139-2bef73f568a2@nvidia.com> (raw)
In-Reply-To: <sashiko-outbox-173606@kernel.org>

On 10/15/26 7:00 PM, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
> - [High] gpu: nova-core: endianness bug when extracting u8/u32 arrays from native &[u64] stream
...
>> +++ b/drivers/gpu/nova-core/gsp/nvkv/decode.rs
> [ ... ]
>> +    /// Takes `count` bytes. If `count` is not a multiple of 8 (`u64` size), bytes are discarded up
>> +    /// to the next multiple.
>> +    fn take_u8s(&mut self, count: usize) -> Result<&'a [u8]> {
>> +        let values = self.take_u64s(count.div_ceil(size_of::<u64>()))?;
>> +        values.as_bytes().get(..count).ok_or(EINVAL)
>> +    }
> 
> [Severity: High]
> Does casting a native u64 slice to bytes extract the wrong payload on
> big-endian architectures?

Roman, or anyone who knows,

How do we update sashiko to make it stop reporting on this issue, which
we have decided is a non-issue (Nova is actually configured to only ever
be little-endian)?


thanks,
John Hubbard

> 
> Because Cursor::take_u64s() reads host-native 64-bit integers, using
> .as_bytes() reverses the byte layout on big-endian hosts compared to
> little-endian.
> 
> For example, if a 3-byte payload is stored inside a 64-bit word, a big-endian
> host will have the payload at the end of the word and zero-padding at the
> beginning, causing .get(..count) to extract the zeros instead of the actual
> data payload.
> 
>> +
>> +    /// Takes `count` 32-bit values. If `count` is not a multiple of 2 (`u32` values per `u64`),
>> +    /// bytes are discarded up to the next multiple.
>> +    fn take_u32s(&mut self, count: usize) -> Result<&'a [u32]> {
>> +        let values = self.take_u64s(count.div_ceil(size_of::<u64>() / size_of::<u32>()))?;
>> +        <[u32]>::ref_from_prefix_with_elems(values.as_bytes(), count)
>> +            .map(|(elems, _)| elems)
>> +            .map_err(|_| EINVAL)
>> +    }
> 
> [Severity: High]
> Can this result in swapped 32-bit words on big-endian systems?
> 
> Similar to the byte array extraction above, passing the native memory
> representation through .as_bytes() to recreate a [u32] slice will swap
> the order of the 32-bit halves on big-endian architectures compared to
> little-endian ones.
> 
> [ ... ]
>> +    /// Decodes every pair into `schema` and returns the result of [`Schema::finish`].
>> +    pub(crate) fn decode<'s, S: Schema + Visit<'a>>(
>> +        &self,
>> +        schema: &'s mut S,
>> +    ) -> Result<impl Init<S::Target, Error> + 's> {
>> +        let mut cursor = Cursor::new(self.data);
>> +        while !cursor.is_empty() {
>> +            let op: Op = cursor.take_u64()?.into();
> 
> [Severity: High]
> Does this misalign the operation bitfields on big-endian hosts?
> 
> The 64-bit operation word is read as a host-native integer via take_u64().
> If the NVKV stream comes from a little-endian GSP, parsing it directly as a
> native u64 on a big-endian host will misalign the key, index, and value
> fields inside Op.
> 
> Should this explicitly handle endianness (e.g., using little-endian read
> functions) instead of relying on native host integers?
> 



  reply	other threads:[~2026-10-16  2:06 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-16  1:53 [PATCH v4 0/7] gpu: nova-core: add NVKV codec Eliot Courtney
2026-10-16  1:53 ` [PATCH v4 1/7] rust: alloc: add Vec::try_push_init and Vec::push_init Eliot Courtney
2026-10-16  1:53 ` [PATCH v4 2/7] rust: alloc: add ArrayVec Eliot Courtney
2026-10-16  2:04   ` sashiko-bot
2026-10-16  1:53 ` [PATCH v4 3/7] gpu: nova-core: add NVKV encoder Eliot Courtney
2026-10-16  1:53 ` [PATCH v4 4/7] gpu: nova-core: add NVKV decoder Eliot Courtney
2026-10-16  2:00   ` sashiko-bot
2026-10-16  2:05     ` John Hubbard [this message]
2026-10-16  1:53 ` [PATCH v4 5/7] gpu: nova-core: add NVKV typed encoding Eliot Courtney
2026-10-16  1:53 ` [PATCH v4 6/7] gpu: nova-core: add NVKV typed decoding Eliot Courtney
2026-10-16  1:53 ` [PATCH v4 7/7] gpu: nova-core: add NVKV GSP_INIT schemas 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=db71fe6b-bc96-4d02-a139-2bef73f568a2@nvidia.com \
    --to=jhubbard@nvidia.com \
    --cc=a.hindborg@kernel.org \
    --cc=acourbot@nvidia.com \
    --cc=airlied@gmail.com \
    --cc=aliceryhl@google.com \
    --cc=apopple@nvidia.com \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun@kernel.org \
    --cc=dakr@kernel.org \
    --cc=daniel.almeida@collabora.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=ecourtney@nvidia.com \
    --cc=gary@garyguo.net \
    --cc=liam@infradead.org \
    --cc=ljs@kernel.org \
    --cc=lossin@kernel.org \
    --cc=nova-gpu@lists.linux.dev \
    --cc=ojeda@kernel.org \
    --cc=roman.gushchin@linux.dev \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=simona@ffwll.ch \
    --cc=tamird@kernel.org \
    --cc=tmgross@umich.edu \
    --cc=ttabi@nvidia.com \
    --cc=urezki@gmail.com \
    --cc=vbabka@kernel.org \
    --cc=work@onurozkan.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