Skip to content

rust: add `bitfield!` macro

Alexandre Courbot driver-core lkml nova-gpu rust-for-linux 4 versions – Applied

Status from this message: Applied to `rust-next` -- thanks everyone!

Get series with b4
b4 am [email protected] change-id 20260408-bitfield-6e18254f4fdc

Versions newest first

  1. v5 Latest3 patches 4 repliesApplied
  2. v47 patches 6 repliesSuperseded
  3. v35 patches 8 repliesSuperseded
Earlier versions · 1
VersionPostedPatchesRepliesStatus
v23 patches28 repliesSuperseded

Changes in v5 from the cover letter

- Squash the fixup patches into the one extracting the bitfield! macro.
- Remove the nova-core patches to avoid a conflict/build breakage on -rc1.
- Improve the unit tests per Yury's feedback:
- Use a consistent test axis where each test focuses on a single thing.
- Rename members to generic name including range for readability.
- Add test exercising try_with.
- Add test checking that unallocated bits are left untouched.
- Link to v4: https://patch.msgid.link/[email protected]

Patches in v5 Applied

#Subject and filesSizeRepliesApplied
1/3rust: extract `bitfield!` macro from `register!`MAINTAINERS rust/kernel/bitfield.rs rust/kernel/lib.rs+556 -00 replies
2/3rust: bitfield: Add KUnit tests for bitfieldrust/kernel/Kconfig.test rust/kernel/bitfield.rs+324 -01 reply
3/3rust: io: use the `bitfield!` macro in `register!`rust/kernel/io/register.rs+2 -2440 replies

Reviews trailers per patch

All 3 patches have a Reviewed-by or Acked-by of their own; the series has one for all of them.

PatchYury NorovDanilo KrummrichEliot Courtney
SeriesR-b
1/3A-b A-b
2/3A-b R-b
3/3A-b A-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 3 reviewers.

Read the v5 thread

Cover letter [PATCH v5 0/3] rust: add `bitfield!` macro

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

This series extracts bitfield! from register!, adds unit tests for the new macro, and replaces the register! macro rules with the extracted version.

I have removed the nova-core patches, because the Blackwell support that has been added this cycle (and thus not visible from rust-next) introduces more uses of the Nova-local bitfield! macro that this series intended to remove. If these new uses are not updated, then nova-core won't build, thus to avoid conflicts and/or build breakages I think it is preferable to merge them during the next cycle.

This version is based on rust-next, with [2] applied.

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

[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/all/[email protected]/
[3] https://github.com/Gnurou/linux/tree/b4/bitfield

---
Changes in v5:
- Squash the fixup patches into the one extracting the bitfield! macro.
- Remove the nova-core patches to avoid a conflict/build breakage on -rc1.
- Improve the unit tests per Yury's feedback:
- Use a consistent test axis where each test focuses on a single thing.
- Rename members to generic name including range for readability.
- Add test exercising try_with.
- Add test checking that unallocated bits are left untouched.
- Link to v4: https://patch.msgid.link/[email protected]

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/[email protected]

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/[email protected]

---
Alexandre Courbot (2):
rust: extract bitfield! macro from register!
rust: io: use the bitfield! macro in register!

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

 MAINTAINERS                |   7 +
 rust/kernel/Kconfig.test   |  10 +
 rust/kernel/bitfield.rs    | 862 +++++++++++++++++++++++++++++++++++++++++++++
 rust/kernel/io/register.rs | 246 +------------
 rust/kernel/lib.rs         |   1 +
 5 files changed, 882 insertions(+), 244 deletions(-)

---
base-commit: 72d33b8bfeacbfdccf2cda4650e8e002def036f8
change-id: 20260408-bitfield-6e18254f4fdc
prerequisite-message-id: [email protected]
prerequisite-patch-id: 403e34bb92b42d3f31ed972e11896d18902585e3
prerequisite-patch-id: 42ae775aa6762a9e28ff31c5f69a0b65a7b40dcc
prerequisite-patch-id: 19b3e535962348f7627ede57ea829b34abda08c7

Best regards,

Signature · 1 line
Alexandre Courbot <[email protected]>