NVIDIA GPU driver infrastructure
 help / color / mirror / Atom feed
From: John Hubbard <jhubbard@nvidia.com>
To: Timur Tabi <ttabi@nvidia.com>,
	"nova-gpu@lists.linux.dev" <nova-gpu@lists.linux.dev>,
	Alexandre Courbot <acourbot@nvidia.com>,
	"dakr@kernel.org" <dakr@kernel.org>,
	Eliot Courtney <ecourtney@nvidia.com>
Subject: Re: [PATCH 1/5] gpu: nova-core: add Tlv.get_u64
Date: Tue, 10 Nov 2026 19:45:34 -0800	[thread overview]
Message-ID: <58c3cb46-d871-47ba-bb91-da6712b56c48@nvidia.com> (raw)
In-Reply-To: <8f6caca82e82f457a24984503ef8fe896e0afa32.camel@nvidia.com>

On 11/10/26 6:59 PM, Timur Tabi wrote:
> On Tue, 2026-11-10 at 16:20 -0800, John Hubbard wrote:
>> On 11/10/26 3:10 PM, Timur Tabi wrote:
>> ...
>> ...but then first_chunk() checks the length again, and also returns
>> an Option that is never None.
> 
> In an optimized build, that check is not actually done.  The only checks are for the match
> statement.

Nice. OK.

...
>> Instead, we could use try_from() to check the length and convert
>> the slice, in one step. Your TlvBlockHeader::parse() already uses
>> that approach, and I think it would also work here.
>>
>> Something like this:
>>
>>     pub(crate) fn get_u64(&self, tag: &[u8; 4]) -> Result<u64> {
>>         let value = self.get_bytes(tag)?;
>>
>>         if let Ok(bytes) = <[u8; 4]>::try_from(value) {
>>             Ok(u64::from(u32::from_le_bytes(bytes)))
>>         } else if let Ok(bytes) = <[u8; 8]>::try_from(value) {
>>             Ok(u64::from_le_bytes(bytes))
>>         } else {
>>             Err(EINVAL)
>>         }
>>     }
> 
> I'm more than happy to change it to whatever other people want.  I went through several
> iterations of this code, working with Cursor to evaluate each one.  IMHO, they are all ugly and
> hard to read, because of the from_le_bytes() constraint that I mentioned in the comment.

The reason I responded was that I think the try_from() is nicer
on-screen. I hadn't gone all the way to the asm code.

thanks,
-- 
John Hubbard


  reply	other threads:[~2026-11-11  3:47 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-10 23:10 [PATCH 0/5] Transition nova-core to use TLV variables for heap sizes Timur Tabi
2026-11-10 23:10 ` [PATCH 1/5] gpu: nova-core: add Tlv.get_u64 Timur Tabi
2026-11-11  0:20   ` John Hubbard
2026-11-11  2:59     ` Timur Tabi
2026-11-11  3:45       ` John Hubbard [this message]
2026-11-11  5:21         ` Eliot Courtney
2026-11-11  5:27   ` Eliot Courtney
2026-11-10 23:10 ` [PATCH 2/5] gpu: nova-core: merge LibosParams into GspFwHeapParams Timur Tabi
2026-11-11  6:30   ` Eliot Courtney
2026-11-10 23:10 ` [PATCH 3/5] gpu: nova-core: read GSP heap variables from TLV Timur Tabi
2026-11-10 23:10 ` [PATCH 4/5] gpu: nova-core: use the TLV heap sizes Timur Tabi
2026-11-10 23:10 ` [PATCH 5/5] gpu: nova-core: remove heap size related HAL functions Timur Tabi
2026-11-10 23:21 ` [PATCH 0/5] Transition nova-core to use TLV variables for heap sizes Timur Tabi

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=58c3cb46-d871-47ba-bb91-da6712b56c48@nvidia.com \
    --to=jhubbard@nvidia.com \
    --cc=acourbot@nvidia.com \
    --cc=dakr@kernel.org \
    --cc=ecourtney@nvidia.com \
    --cc=nova-gpu@lists.linux.dev \
    --cc=ttabi@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