From: "Alexandre Courbot" <acourbot@nvidia.com>
To: "Yury Norov" <ynorov@nvidia.com>
Cc: "Joel Fernandes" <joelagnelf@nvidia.com>,
"Yury Norov" <yury.norov@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>,
"Danilo Krummrich" <dakr@kernel.org>,
"Daniel Almeida" <daniel.almeida@collabora.com>,
"David Airlie" <airlied@gmail.com>,
"Simona Vetter" <simona@ffwll.ch>,
"John Hubbard" <jhubbard@nvidia.com>,
"Alistair Popple" <apopple@nvidia.com>,
"Timur Tabi" <ttabi@nvidia.com>, "Zhi Wang" <zhiw@nvidia.com>,
"Eliot Courtney" <ecourtney@nvidia.com>,
linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org,
driver-core@lists.linux.dev, dri-devel@lists.freedesktop.org
Subject: Re: [PATCH v2 1/3] rust: extract `bitfield!` macro from `register!`
Date: Fri, 01 May 2026 15:07:12 +0900 [thread overview]
Message-ID: <DI745FZNMA6V.CS7N0HL4L5IN@nvidia.com> (raw)
In-Reply-To: <aeA80WHkFBNTvQFz@yury>
On Thu Apr 16, 2026 at 10:35 AM JST, Yury Norov wrote:
> On Thu, Apr 09, 2026 at 11:58:47PM +0900, Alexandre Courbot wrote:
>> Extract the bitfield-defining part of the `register!` macro into an
>> independent macro used to define bitfield types with bounds-checked
>> accessors.
>>
>> Each field is represented as a `Bounded` of the appropriate bit width,
>> ensuring field values are never silently truncated.
>>
>> Fields can optionally be converted to/from custom types, either fallibly
>> or infallibly.
>>
>> Appropriate documentation is also added, and a MAINTAINERS entry created
>> for the new module.
>>
>> Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
>> ---
>> MAINTAINERS | 8 +
>> rust/kernel/bitfield.rs | 491 +++++++++++++++++++++++++++++++++++++++++++++
>> rust/kernel/io/register.rs | 246 +----------------------
>> rust/kernel/lib.rs | 1 +
>> 4 files changed, 502 insertions(+), 244 deletions(-)
>>
>> diff --git a/MAINTAINERS b/MAINTAINERS
>> index b01791963e25..77f2617ade5d 100644
>> --- a/MAINTAINERS
>> +++ b/MAINTAINERS
>> @@ -23186,6 +23186,14 @@ F: scripts/*rust*
>> F: tools/testing/selftests/rust/
>> K: \b(?i:rust)\b
>>
>> +RUST [BITFIELD]
>> +M: Alexandre Courbot <acourbot@nvidia.com>
>> +M: Joel Fernandes <joelagnelf@nvidia.com>
>> +R: Yury Norov <yury.norov@gmail.com>
>> +L: rust-for-linux@vger.kernel.org
>> +S: Maintained
>> +F: rust/kernel/bitfield.rs
>> +
>> RUST [ALLOC]
>> M: Danilo Krummrich <dakr@kernel.org>
>> R: Lorenzo Stoakes <ljs@kernel.org>
>> diff --git a/rust/kernel/bitfield.rs b/rust/kernel/bitfield.rs
>> new file mode 100644
>> index 000000000000..f5948eec8a76
>> --- /dev/null
>> +++ b/rust/kernel/bitfield.rs
>> @@ -0,0 +1,491 @@
>> +// SPDX-License-Identifier: GPL-2.0
>> +
>> +//! Support for defining bitfields as Rust structures.
>> +//!
>> +//! The [`bitfield!`](kernel::bitfield!) macro declares integer types that are split into distinct
>> +//! bit fields of arbitrary length. Each field is typed using [`Bounded`](kernel::num::Bounded) to
>> +//! ensure values are properly validated and to avoid implicit data loss.
>> +//!
>> +//! # Example
>> +//!
>> +//! ```rust
>> +//! use kernel::bitfield;
>> +//! use kernel::num::Bounded;
>> +//!
>> +//! bitfield! {
>> +//! pub struct Rgb(u16) {
>> +//! 15:11 blue;
>> +//! 10:5 green;
>> +//! 4:0 red;
>
> Hi Alex,
>
> Can you please describe those implied naming limitations we've
> discussed on the previous round, like with_blue, BLUE_SHIFT etc.
> in a separate top comment?
Yes, that was missing indeed. Added for v3.
next prev parent reply other threads:[~2026-05-01 6:07 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-09 14:58 [PATCH v2 0/3] rust: add `bitfield!` macro Alexandre Courbot
2026-04-09 14:58 ` [PATCH v2 1/3] rust: extract `bitfield!` macro from `register!` Alexandre Courbot
2026-04-13 2:29 ` Eliot Courtney
2026-04-15 23:18 ` John Hubbard
2026-05-01 6:08 ` Alexandre Courbot
2026-04-16 1:35 ` Yury Norov
2026-05-01 6:07 ` Alexandre Courbot [this message]
2026-04-09 14:58 ` [PATCH v2 2/3] rust: bitfield: Add KUNIT tests for bitfield Alexandre Courbot
2026-04-13 2:28 ` Eliot Courtney
2026-04-16 2:44 ` Yury Norov
2026-04-16 6:59 ` Alice Ryhl
2026-04-16 12:48 ` Yury Norov
2026-05-01 6:06 ` Alexandre Courbot
2026-04-09 14:58 ` [PATCH v2 3/3] gpu: nova-core: switch to kernel bitfield macro Alexandre Courbot
2026-04-13 2:01 ` Eliot Courtney
2026-04-15 23:20 ` John Hubbard
2026-05-01 6:07 ` Alexandre Courbot
2026-04-15 23:22 ` [PATCH v2 0/3] rust: add `bitfield!` macro John Hubbard
2026-04-16 1:08 ` Eliot Courtney
2026-04-16 22:18 ` Danilo Krummrich
2026-04-16 22:43 ` John Hubbard
2026-04-17 1:33 ` Alexandre Courbot
2026-04-17 3:11 ` Alexandre Courbot
2026-04-17 3:19 ` John Hubbard
2026-04-17 3:57 ` Alexandre Courbot
2026-04-17 4:15 ` John Hubbard
2026-04-17 5:55 ` Miguel Ojeda
2026-04-17 10:59 ` Mark Brown
2026-04-17 12:30 ` Danilo Krummrich
2026-04-17 12:00 ` Danilo Krummrich
2026-04-17 12:21 ` Miguel Ojeda
2026-04-17 14:59 ` Danilo Krummrich
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=DI745FZNMA6V.CS7N0HL4L5IN@nvidia.com \
--to=acourbot@nvidia.com \
--cc=a.hindborg@kernel.org \
--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=driver-core@lists.linux.dev \
--cc=ecourtney@nvidia.com \
--cc=gary@garyguo.net \
--cc=jhubbard@nvidia.com \
--cc=joelagnelf@nvidia.com \
--cc=linux-kernel@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=simona@ffwll.ch \
--cc=tmgross@umich.edu \
--cc=ttabi@nvidia.com \
--cc=ynorov@nvidia.com \
--cc=yury.norov@gmail.com \
--cc=zhiw@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