|
|
Log in / Subscribe / Register

rust: add `bitfield!` macro

From:  Alexandre Courbot <acourbot-AT-nvidia.com>
To:  Yury Norov <yury.norov-AT-gmail.com>, Miguel Ojeda <ojeda-AT-kernel.org>, Boqun Feng <boqun-AT-kernel.org>, Gary Guo <gary-AT-garyguo.net>, Björn Roy Baron <bjorn3_gh-AT-protonmail.com>, Benno Lossin <lossin-AT-kernel.org>, Andreas Hindborg <a.hindborg-AT-kernel.org>, Alice Ryhl <aliceryhl-AT-google.com>, Trevor Gross <tmgross-AT-umich.edu>, Danilo Krummrich <dakr-AT-kernel.org>, Daniel Almeida <daniel.almeida-AT-collabora.com>, David Airlie <airlied-AT-gmail.com>, Simona Vetter <simona-AT-ffwll.ch>
Subject:  [PATCH v4 0/7] rust: add `bitfield!` macro
Date:  Wed, 27 May 2026 21:51:54 +0900
Message-ID:  <20260527-bitfield-v4-0-e8821d4efbde@nvidia.com>
Cc:  John Hubbard <jhubbard-AT-nvidia.com>, Alistair Popple <apopple-AT-nvidia.com>, Timur Tabi <ttabi-AT-nvidia.com>, Zhi Wang <zhiw-AT-nvidia.com>, Eliot Courtney <ecourtney-AT-nvidia.com>, linux-kernel-AT-vger.kernel.org, rust-for-linux-AT-vger.kernel.org, nova-gpu-AT-lists.linux.dev, driver-core-AT-lists.linux.dev, Alexandre Courbot <acourbot-AT-nvidia.com>, Yury Norov <ynorov-AT-nvidia.com>, Joel Fernandes <joelagnelf-AT-nvidia.com>
Archive-link:  Article

This is the continuation of the `bitfield!` macro which started
alongside the `register!` one before being temporarily integrated into
it [1].

Thanks for all the feedback on v2; I believe this version addresses all
of it, modulo Eliot's suggestion for more explicit range error messages.
Since this is not fundamentally broken, I'd like to address this in a
follow-up change to keep the series focused on the macro extraction from
`register!`.

This version is based on `rust-next`, with [2] applied. If review proves
satisfying, the merge path with the least friction seems to be patches
1-3 into the rust tree this cycle, followed by patch 4 through the I/O
tree, and patches 5-6 via the DRM tree during the next cycle. Patch 7
can be merged after [2].

A tree with this branch and its dependencies is available at [3].

[1] https://lore.kernel.org/all/20260120-register-v1-0-723a17...
[2] https://lore.kernel.org/all/20260417031531.315281-1-ynoro...
[3] https://github.com/Gnurou/linux/tree/b4/bitfield

Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
---
Changes in v4:
- Inline private bitfield accessor methods.
- Fully qualify types in `bitfield!` macro.
- Rename `RUST_KERNEL_BITFIELD_KUNIT_TEST` to `RUST_BITFIELD_KUNIT_TEST`.
- Link to v3: https://patch.msgid.link/20260501-bitfield-v3-0-aa1076c33...

Changes in v3:
- Split patch 1 into the addition of the `bitfield!` macro and its use
  in the `io` module.
- Mention reserved field names in `bitfield!`'s doccomment.
- Properly order fields in the KUnit test.
- Add a Kconfig option for building the KUnit tests.
- Document behavior on non-covered bits.
- Document support for signed fields and storage types (TL;DR: not
  supported).
- Move `nova-core`'s `bitfield` module deletion into its own patch.
- Link to v2: https://patch.msgid.link/20260409-bitfield-v2-0-23ac40007...

---
Alexandre Courbot (6):
      rust: extract `bitfield!` macro from `register!`
      rust: bitfield: inline private accessors
      rust: bitfield: fully qualify types in macro
      rust: io: use the `bitfield!` macro in `register!`
      gpu: nova-core: switch to kernel bitfield macro
      gpu: nova-core: remove the driver-local `bitfield!` macro

Joel Fernandes (1):
      rust: bitfield: Add KUnit tests for bitfield

 MAINTAINERS                        |   7 +
 drivers/gpu/nova-core/bitfield.rs  | 329 --------------
 drivers/gpu/nova-core/gsp/fw.rs    |  11 +-
 drivers/gpu/nova-core/nova_core.rs |   3 -
 rust/kernel/Kconfig.test           |  10 +
 rust/kernel/bitfield.rs            | 863 +++++++++++++++++++++++++++++++++++++
 rust/kernel/io/register.rs         | 246 +----------
 rust/kernel/lib.rs                 |   1 +
 8 files changed, 889 insertions(+), 581 deletions(-)
---
base-commit: 72d33b8bfeacbfdccf2cda4650e8e002def036f8
change-id: 20260408-bitfield-6e18254f4fdc
prerequisite-message-id: 20260417031531.315281-1-ynorov@nvidia.com
prerequisite-patch-id: 403e34bb92b42d3f31ed972e11896d18902585e3
prerequisite-patch-id: 42ae775aa6762a9e28ff31c5f69a0b65a7b40dcc
prerequisite-patch-id: 19b3e535962348f7627ede57ea829b34abda08c7

Best regards,
--  
Alexandre Courbot <acourbot@nvidia.com>




Copyright © 2026, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds