From: Yury Norov <ynorov@nvidia.com>
To: Alexandre Courbot <acourbot@nvidia.com>
Cc: "Joel Fernandes" <joelagnelf@nvidia.com>,
"Miguel Ojeda" <ojeda@kernel.org>,
"Boqun Feng" <boqun.feng@gmail.com>,
"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>,
"Yury Norov" <yury.norov@gmail.com>,
"John Hubbard" <jhubbard@nvidia.com>,
"Alistair Popple" <apopple@nvidia.com>,
"Timur Tabi" <ttabi@nvidia.com>, "Edwin Peer" <epeer@nvidia.com>,
"Eliot Courtney" <ecourtney@nvidia.com>,
"Daniel Almeida" <daniel.almeida@collabora.com>,
"Dirk Behme" <dirk.behme@de.bosch.com>,
"Steven Price" <steven.price@arm.com>,
rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 3/6] rust: add `bitfield!` macro
Date: Wed, 28 Jan 2026 13:05:14 -0500 [thread overview]
Message-ID: <aXpP2l9Gr0XOfSEn@yury> (raw)
In-Reply-To: <DG0A8B4DUBDB.2NT25Q8SZOHT7@nvidia.com>
On Wed, Jan 28, 2026 at 11:12:27PM +0900, Alexandre Courbot wrote:
> On Wed Jan 28, 2026 at 2:27 PM JST, Yury Norov wrote:
<snip>
> >> > Then let's implement it better. Can you comment why the suggested API
> >> > doesn't work for you?
> >> >
> >> > color.set(blue, 10);
> >> > color.get(blue);
> >> >
> >> > I think it should solve the problem with name clashing.
> >>
> >> That syntax cannot be implemented as it is written. What type is `blue` here?
> >
> > 'blue' has no type because it is not a variable but keyword. We do
> > such things in C all the time:
> >
> > DEFINE_FREE(kfree, void *, if (_T) kfree(_T))
> > ^^^^^
> > keyword that becomes a part of cleanup function name
> >
> > And in another email I seemingly do similar thing for python_init!()
> > macro in rust to pick the right constructor.
>
> Yup, and we could do the same in Rust with a macro, but your example
> above was not macro code (macros are always ending with a `!`).
color.set!(blue, 10) is equally good, if it helps.
If someone will point to the excessive use of macros, you're safe to
ignore it. This is the very basic fundamental type, and I believe that
it brings enough attention and expertise to make it safe.
> >> The closest we could get would be a macro, that would look like
> >>
> >> bitfield_set!(color, blue, 10);
Or maybe bitfield_set!(color.blue, 10), but the above looks more natural.
Is it possible to make it color.blue = 10 by any chance?
Again (and again) - usability and readability is a king, and I'm glad
we're moving toward the right direction.
> >> And beyond the scenes it would call some more intricate (and unsightly)
> >> machinery. I'd rather define the constraints clearly for users - they
> >> are not so drastic.
> >
> > But that would not be chainable, I guess. I recall, Joel said it's an
> > important feature for some reason.
>
> We could make the macros return the modified bitfield, which would make
> them chainable. And the bitfield-englobing macro you proposed in your
> other email could also reduce the need to do so anyway.
>
> >
> >> > Can you share more about the other potential users?
> >>
> >> I know Joel is using bitfield for page table structures, but there are
> >> of course many others. Basically any structure with fields defined as a
> >> subset of its bits is a candidate. Registers just happen to be bitfields
> >> with extra properties for I/O.
> >
> > OK. Can I take a look at how bitfields are used there?
>
> Check out these patches:
>
> https://lore.kernel.org/all/20260120204303.3229303-10-joelagnelf@nvidia.com/
> https://lore.kernel.org/all/20260120204303.3229303-12-joelagnelf@nvidia.com/
> https://lore.kernel.org/all/20260120204303.3229303-13-joelagnelf@nvidia.com/
>
> But be aware that they use the `bitfield!` macro of nova-core, this one
> doesn't use `Bounded` yet.
next prev parent reply other threads:[~2026-01-28 18:05 UTC|newest]
Thread overview: 56+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-20 6:17 [PATCH 0/6] rust: add `bitfield!` and `register!` macros Alexandre Courbot
2026-01-20 6:17 ` [PATCH 1/6] rust: num: add `shr` and `shl` methods to `Bounded` Alexandre Courbot
2026-01-20 8:44 ` Alice Ryhl
2026-01-20 12:53 ` Alexandre Courbot
2026-01-20 16:12 ` kernel test robot
2026-01-21 8:15 ` Yury Norov
2026-01-21 10:10 ` Alice Ryhl
2026-01-20 6:17 ` [PATCH 2/6] rust: num: add `as_bool` method to `Bounded<_, 1>` Alexandre Courbot
2026-01-20 8:45 ` Alice Ryhl
2026-01-20 6:17 ` [PATCH 3/6] rust: add `bitfield!` macro Alexandre Courbot
2026-01-20 11:45 ` Dirk Behme
2026-01-20 12:37 ` Miguel Ojeda
2026-01-20 12:47 ` Dirk Behme
2026-01-20 13:08 ` Miguel Ojeda
2026-01-20 13:20 ` Alexandre Courbot
2026-01-20 21:02 ` Miguel Ojeda
2026-01-20 12:51 ` Alexandre Courbot
2026-01-21 9:16 ` Yury Norov
2026-01-26 13:35 ` Alexandre Courbot
2026-01-27 2:55 ` Yury Norov
2026-01-27 3:25 ` Joel Fernandes
2026-01-27 4:49 ` Yury Norov
2026-01-27 10:41 ` Alexandre Courbot
2026-01-27 10:55 ` Miguel Ojeda
2026-01-28 5:27 ` Yury Norov
2026-01-28 14:12 ` Alexandre Courbot
2026-01-28 18:05 ` Yury Norov [this message]
2026-01-29 13:40 ` Alexandre Courbot
2026-01-29 15:12 ` Miguel Ojeda
2026-01-27 11:00 ` Joel Fernandes
2026-01-27 15:02 ` Gary Guo
2026-01-28 1:23 ` Alexandre Courbot
2026-01-28 4:33 ` Yury Norov
2026-01-28 14:02 ` Alexandre Courbot
2026-01-28 18:12 ` Yury Norov
2026-01-27 9:57 ` Alexandre Courbot
2026-01-27 21:03 ` John Hubbard
2026-01-27 21:10 ` Gary Guo
2026-01-27 21:22 ` John Hubbard
2026-01-28 1:28 ` Alexandre Courbot
2026-01-28 1:41 ` John Hubbard
2026-01-20 6:17 ` [PATCH 4/6] rust: bitfield: Add KUNIT tests for bitfield Alexandre Courbot
2026-01-20 6:17 ` [PATCH 5/6] rust: io: add `register!` macro Alexandre Courbot
2026-01-20 6:17 ` [PATCH FOR REFERENCE 6/6] gpu: nova-core: use the kernel `register!` and `bitfield!` macros Alexandre Courbot
2026-01-20 13:14 ` [PATCH 0/6] rust: add `bitfield!` and `register!` macros Miguel Ojeda
2026-01-20 13:38 ` Danilo Krummrich
2026-01-20 13:50 ` Miguel Ojeda
2026-01-20 14:18 ` Danilo Krummrich
2026-01-20 14:57 ` Miguel Ojeda
2026-01-20 15:27 ` Danilo Krummrich
2026-01-20 15:48 ` Miguel Ojeda
2026-01-20 20:01 ` Danilo Krummrich
2026-01-20 20:31 ` Miguel Ojeda
2026-01-21 5:57 ` Yury Norov
2026-01-21 6:55 ` Alexandre Courbot
2026-01-26 14:03 ` 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=aXpP2l9Gr0XOfSEn@yury \
--to=ynorov@nvidia.com \
--cc=a.hindborg@kernel.org \
--cc=acourbot@nvidia.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=dirk.behme@de.bosch.com \
--cc=ecourtney@nvidia.com \
--cc=epeer@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=steven.price@arm.com \
--cc=tmgross@umich.edu \
--cc=ttabi@nvidia.com \
--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