From: Joel Fernandes <joelagnelf@nvidia.com>
To: John Hubbard <jhubbard@nvidia.com>
Cc: Yury Norov <yury.norov@gmail.com>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"dri-devel@lists.freedesktop.org"
<dri-devel@lists.freedesktop.org>,
"dakr@kernel.org" <dakr@kernel.org>,
Alexandre Courbot <acourbot@nvidia.com>,
Alistair Popple <apopple@nvidia.com>,
Miguel Ojeda <ojeda@kernel.org>,
Alex Gaynor <alex.gaynor@gmail.com>,
Boqun Feng <boqun.feng@gmail.com>, Gary Guo <gary@garyguo.net>,
"bjorn3_gh@protonmail.com" <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>,
David Airlie <airlied@gmail.com>, Simona Vetter <simona@ffwll.ch>,
Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
Maxime Ripard <mripard@kernel.org>,
Thomas Zimmermann <tzimmermann@suse.de>,
Timur Tabi <ttabi@nvidia.com>,
"joel@joelfernandes.org" <joel@joelfernandes.org>,
Elle Rhumsaa <elle@weathered-steel.dev>,
Daniel Almeida <daniel.almeida@collabora.com>,
"nouveau@lists.freedesktop.org" <nouveau@lists.freedesktop.org>
Subject: Re: [PATCH v3 5/5] rust: Add KUNIT tests for bitfield
Date: Sat, 20 Sep 2025 09:33:46 +0000 [thread overview]
Message-ID: <CC11C4AC-A37C-4BB7-820B-7AC257D719D2@nvidia.com> (raw)
In-Reply-To: <569b2f95-fa8d-4bd0-9e90-512b677435fe@nvidia.com>
Hello, John,
> On Sep 20, 2025, at 2:52 AM, John Hubbard <jhubbard@nvidia.com> wrote:
>
> On 9/19/25 5:39 PM, Joel Fernandes wrote:
>> On Tue, Sep 16, 2025 at 05:59:18AM -0400, Joel Fernandes wrote:
>> [...]
>>>>> In C also this is valid. If you passed a higher value than what the
>>>>> bitfield can hold, the compiler will still just use the bits that it
>>>>> needs and ignore the rest.
>>>>
>>>> In C we've got FIELD_{PREP,GET,MODIFY}, implementing the checks.
>>>> So those who want to stay on safe side have a choice.
>>>
>>> Ah ok. We can add these checks then for the accessors, I will do so in v4.
>>
>> The C checks use BUILD_BUG_ON, in rust-for-linux we have build_assert but it
>> is fragile and depends on the value being a constant. Since the setter API
>> accepts a run-time value and not a constant, we cannot use this.
>>
>> Or, we can fail at runtime, but that requires changing the set_* to try_set_*
>> and returning a Result instead of Self. Alternatively, we can have a debug
>> option that panics if the setter API is misued.
>
> Please no...
True, it requires significant complication.
>
>>
>> Thoughts?
>>
>> Or for the moment, we can keep it simple and filter out / ignore extra bits
>> of the larger value passed (which is what nova-core's register macro bitfield
>> implementation currently does anyway).
>>
>
> Yes. Assuming that I'm not completely lost here, you are proposing to
> simply truncate to the size of the bitfield--no panics, no warnings. And
> that's perfectly fine here IMHO.
Ok, thanks. Yeah truncate. This is what register macro also currently does for its bitfields. To the point Jury is making though, the C equivalents do have build checks. We could do that once he have a better build_assert in rust but until then.. hopefully this suffices.
I am currently also research better ways of implementing build_assert.
- Joel
>
> thanks,
> --
> John Hubbard
>
next prev parent reply other threads:[~2025-09-20 9:33 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-09 21:20 [PATCH v3 0/5] Introduce bitfield and move register macro to rust/kernel/ Joel Fernandes
2025-09-09 21:20 ` [PATCH v3 1/5] nova-core: bitfield: Move bitfield-specific code from register! into new macro Joel Fernandes
2025-09-09 21:20 ` [PATCH v3 2/5] nova-core: bitfield: Add support for different storage widths Joel Fernandes
2025-09-09 21:20 ` [PATCH v3 3/5] nova-core: bitfield: Add support for custom visiblity Joel Fernandes
2025-09-09 21:20 ` [PATCH v3 4/5] rust: Move register and bitfield macros out of Nova Joel Fernandes
2025-09-09 21:36 ` Miguel Ojeda
2025-09-10 0:15 ` Joel Fernandes
2025-09-09 21:20 ` [PATCH v3 5/5] rust: Add KUNIT tests for bitfield Joel Fernandes
2025-09-10 3:04 ` Yury Norov
2025-09-10 23:08 ` Joel Fernandes
2025-09-11 1:47 ` Yury Norov
2025-09-16 9:59 ` Joel Fernandes
2025-09-16 10:10 ` Joel Fernandes
2025-09-19 23:02 ` Joel Fernandes
2025-09-20 0:39 ` Joel Fernandes
2025-09-20 0:52 ` John Hubbard
2025-09-20 9:33 ` Joel Fernandes [this message]
2025-09-21 11:41 ` Miguel Ojeda
2025-09-10 23:22 ` 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=CC11C4AC-A37C-4BB7-820B-7AC257D719D2@nvidia.com \
--to=joelagnelf@nvidia.com \
--cc=a.hindborg@kernel.org \
--cc=acourbot@nvidia.com \
--cc=airlied@gmail.com \
--cc=alex.gaynor@gmail.com \
--cc=aliceryhl@google.com \
--cc=apopple@nvidia.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=dakr@kernel.org \
--cc=daniel.almeida@collabora.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=elle@weathered-steel.dev \
--cc=gary@garyguo.net \
--cc=jhubbard@nvidia.com \
--cc=joel@joelfernandes.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=maarten.lankhorst@linux.intel.com \
--cc=mripard@kernel.org \
--cc=nouveau@lists.freedesktop.org \
--cc=ojeda@kernel.org \
--cc=simona@ffwll.ch \
--cc=tmgross@umich.edu \
--cc=ttabi@nvidia.com \
--cc=tzimmermann@suse.de \
--cc=yury.norov@gmail.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
all inboxes | Powered by JetHome®