rust-for-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Rhys Lloyd <krakow20@gmail.com>
To: Alexandre Courbot <acourbot@nvidia.com>, dakr@kernel.org
Cc: airlied@gmail.com, simona@ffwll.ch,
	nouveau@lists.freedesktop.org, dri-devel@lists.freedesktop.org,
	linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org
Subject: Re: [PATCH] gpu: nova-core: define named constants for magic numbers
Date: Sun, 13 Jul 2025 23:10:37 -0700	[thread overview]
Message-ID: <cda61d51-ad85-4464-a637-426b960a83c6@gmail.com> (raw)
In-Reply-To: <DBBG6Q86XAAQ.43DPC0D210TI@nvidia.com>

On 7/13/25 8:11 PM, Alexandre Courbot wrote:
> On Sun Jul 13, 2025 at 11:51 AM JST, Rhys Lloyd wrote:
>> Introduce an associated constant `MIN_LEN` for each struct that checks
>> the length of the input data in its constructor against a magic number.
>>
>> Signed-off-by: Rhys Lloyd <krakow20@gmail.com>
> As I mentioned in [1], I think this would be better addressed by working
> in terms of `sizeof` upon the relevant structures, after making them
> `#[repr(C)]`. It might require splitting them a bit since some contain
> other data (or we can maybe turn them into DSTs).
>
> [1] https://lore.kernel.org/rust-for-linux/DB97X8JAJFI4.3G1I8ZPC1MWLS@nvidia.com/

As far as I can tell, only one of the five structs with `MIN_LEN` have 
the same layout in-memory as they do in the `data` byte slice, that 
being `BitHeader`.  Perhaps `#[repr(packed)]` could be used for 
`PmuLookupTableEntry`, sacrificing alignment, but that is undesirable as 
it comes with its own footguns such as unaligned loads.  The other 
structs include optional values and vectors which do not have the same 
encoding when reading from the `data` byte slice as they do in memory.  
I have worked with DSTs before, but I don't recommend them for 
non-library code since they are not first-class citizens in Rust.  
Notably the fat pointer is not resized when taking a reference to the 
unsized struct field, and constructing such objects is cumbersome.  
Also, in the current version of Rust (1.88), DSTs cannot yet live 
comfortably on the stack.

This patch can be dropped if it's not valuable enough to warrant the 
change, I only made it because of your comment here: 
https://gitlab.freedesktop.org/drm/nova/-/merge_requests/4#note_2999761


  reply	other threads:[~2025-07-14  6:10 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-13  2:51 [PATCH] gpu: nova-core: fix bounds check in PmuLookupTableEntry::new Rhys Lloyd
2025-07-13  2:51 ` [PATCH] gpu: nova-core: define named constants for magic numbers Rhys Lloyd
2025-07-14  3:11   ` Alexandre Courbot
2025-07-14  6:10     ` Rhys Lloyd [this message]
2025-07-14  3:06 ` [PATCH] gpu: nova-core: fix bounds check in PmuLookupTableEntry::new Alexandre Courbot
2025-07-17  5:15 ` Alexandre Courbot
  -- strict thread matches above, loose matches on Subject: below --
2025-07-11 14:29 Rhys Lloyd
2025-07-11 14:29 ` [PATCH] gpu: nova-core: define named constants for magic numbers Rhys Lloyd
2025-07-11 11:33 [PATCH] gpu: nova-core: fix bounds check In PmuLookupTableEntry::new, data is sliced from 2..6, but the bounds check data.len() < 5 does not satisfy those bounds Quaternions
2025-07-11 11:33 ` [PATCH] gpu: nova-core: define named constants for magic numbers Quaternions
2025-07-11 12:18   ` Alexandre Courbot
2025-07-14 15:26     ` Joel Fernandes

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=cda61d51-ad85-4464-a637-426b960a83c6@gmail.com \
    --to=krakow20@gmail.com \
    --cc=acourbot@nvidia.com \
    --cc=airlied@gmail.com \
    --cc=dakr@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nouveau@lists.freedesktop.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=simona@ffwll.ch \
    /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;
as well as URLs for NNTP newsgroup(s).