MAINTAINERS | 8 + drivers/gpu/nova-core/bitfield.rs | 366 +++++----- drivers/gpu/nova-core/falcon.rs | 145 ++-- drivers/gpu/nova-core/falcon/hal/ga102.rs | 5 +- drivers/gpu/nova-core/fb/hal/ga100.rs | 9 +- drivers/gpu/nova-core/gpu.rs | 9 +- drivers/gpu/nova-core/regs.rs | 139 ++-- rust/kernel/lib.rs | 1 + rust/kernel/num.rs | 79 +++ rust/kernel/num/bounded.rs | 1054 +++++++++++++++++++++++++++++ 10 files changed, 1507 insertions(+), 308 deletions(-)
Minor revision adding the feedback received on v3.
Patch 3 adds a MAINTAINERS entry in case the Rust core team would like
us to maintain this, but please ignore it if you prefer to take it under
the core umbrella.
This series provides `Bounded`, a wrapper type for primitive integers
that guarantees that only a given number of bits are used to represent
values. This is particularly useful when working with bitfields, as the
guarantee that a given value fits within the number of assigned bits can
be enforced by the type system, saving cumbersome runtime checks, or
(worse) stripping data when bits are silently dropped.
For a basic usage, please see the rustdoc of the `Bounded` type on the
second patch.
The first use of this will be to represent bitfields in Nova register
types to guarantee that no data is ever stripped when manipulating them.
This should eventually allow the `bitfield` and `register` macros to
move out of Nova and into the kernel crate.
The last patch is just here to illustrate the use of this module; it is
not intended to be merged this cycle as it would likely result in big
merge conflicts with the drm tree.
This series applies on top of drm-rust-next for the needs of the last
patch, but the first 2 patches should apply cleanly on rust-next. A
branch with this series and its dependencies is available here:
https://github.com/Gnurou/linux/tree/b4/bounded_ints
Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
---
Changes in v4:
- Change `Unsigned` and `Signed` to be empty enums so they can never be
instantiated (thanks Alice!).
- Add test at the limits of a `Bounded<i8, 4>` to confirm `fits_within`
is working as expected.
- Rebase on top of drm-rust-next for Nova patch.
- Link to v3: https://lore.kernel.org/r/20251106-bounded_ints-v3-0-47104986a5c3@nvidia.com
Changes in v3:
- Rename to `Bounded` to avoid confusion with C's `_BitInt`.
- Request all common integer features on `Integer` trait and remove
unneeded `Boundable`.
- Use `assert` instead of `build_assert` in const blocks. (thanks Alice!)
- Implement `Integer` for `u/isize` and `u/i128`.
- Support `usize`/`isize` as `Bounded` types.
- Implement arithmetic and logic ops between two `Bounded` of the same
backing type (but not necessarily same length).
- Move addition of `num` module to its own patch.
- Add MAINTAINERS entry for `num`.
- Link to v2: https://lore.kernel.org/r/20251102-bounded_ints-v2-0-7ef0c26b1d36@nvidia.com
Changes in v2:
- Move type invariants of `BitInt` to a centralizing private
constructor.
- Simplify `From` implementations to and from primitive types.
- Remove ability to convert between unsigned and signed types as it was
buggy, and its utility doubtful.
- Use macro to implement `Integer` and avoid repeating code.
- Fix a few typos.
- More doctests, and split them into different paragraphs in the
`BitInt` main doccomment.
- Fix build with Rust 1.78.
- Finish implementing relevant `core::ops` traits.
- Link to v1: https://lore.kernel.org/r/20251031-bounded_ints-v1-0-e2dbcd8fda71@nvidia.com
Changes in v1:
- Rebase on top of `drm-rust-next`.
- Rename `BoundedInt` to `BitInt` (thanks Yury!).
- Add lots of documentation.
- Use shifts to validate bounds, as it works with both unsigned and
signed types contrary to the mask method.
- Support signed types (albeit with some bugs).
- Use `new` for the const static constructor and make it the preferred
way to build values (thanks Alice and Joel!).
- Rename `LargerThanX` into `AtLeastX` (thanks Joel!).
- Support basic arithmetic operations (+, -, etc.) against the backing
type.
- Add `Deref` implementation as alternative to the `get` method.
- Write correct `Default` implementation for bitfields.
- Make the new bitfield accessors `inline(always)`.
- Update bitfield documentation to the new usage.
- Link to RFC v2: https://lore.kernel.org/r/20251009-bounded_ints-v2-0-ff3d7fee3ffd@nvidia.com
Changes in RFC v2:
- Thorough implementation of `BoundedInt`.
- nova-core fully adapted to use `BoundedInt`.
- Link to RFC v1: https://lore.kernel.org/r/20251002-bounded_ints-v1-0-dd60f5804ea4@nvidia.com
---
Alexandre Courbot (4):
rust: add num module and Integer trait
rust: num: add Bounded integer wrapping type
MAINTAINERS: add entry for the Rust `num` module
[FOR REFERENCE] gpu: nova-core: use BitInt for bitfields
MAINTAINERS | 8 +
drivers/gpu/nova-core/bitfield.rs | 366 +++++-----
drivers/gpu/nova-core/falcon.rs | 145 ++--
drivers/gpu/nova-core/falcon/hal/ga102.rs | 5 +-
drivers/gpu/nova-core/fb/hal/ga100.rs | 9 +-
drivers/gpu/nova-core/gpu.rs | 9 +-
drivers/gpu/nova-core/regs.rs | 139 ++--
rust/kernel/lib.rs | 1 +
rust/kernel/num.rs | 79 +++
rust/kernel/num/bounded.rs | 1054 +++++++++++++++++++++++++++++
10 files changed, 1507 insertions(+), 308 deletions(-)
---
base-commit: 80b3dc0a5a2e51fb2b8f3406f5ee20ad4a652316
change-id: 20251001-bounded_ints-1d0457d9ae26
Best regards,
--
Alexandre Courbot <acourbot@nvidia.com>
On Sat, Nov 08, 2025 at 11:23:46AM +0900, Alexandre Courbot wrote: > Minor revision adding the feedback received on v3. > > Patch 3 adds a MAINTAINERS entry in case the Rust core team would like > us to maintain this, but please ignore it if you prefer to take it under > the core umbrella. > > This series provides `Bounded`, a wrapper type for primitive integers > that guarantees that only a given number of bits are used to represent > values. This is particularly useful when working with bitfields, as the > guarantee that a given value fits within the number of assigned bits can > be enforced by the type system, saving cumbersome runtime checks, or > (worse) stripping data when bits are silently dropped. > > For a basic usage, please see the rustdoc of the `Bounded` type on the > second patch. > > The first use of this will be to represent bitfields in Nova register > types to guarantee that no data is ever stripped when manipulating them. > This should eventually allow the `bitfield` and `register` macros to > move out of Nova and into the kernel crate. > > The last patch is just here to illustrate the use of this module; it is > not intended to be merged this cycle as it would likely result in big > merge conflicts with the drm tree. > > This series applies on top of drm-rust-next for the needs of the last > patch, but the first 2 patches should apply cleanly on rust-next. A > branch with this series and its dependencies is available here: > > https://github.com/Gnurou/linux/tree/b4/bounded_ints > > Signed-off-by: Alexandre Courbot <acourbot@nvidia.com> Reviewed-by: Alice Ryhl <aliceryhl@google.com>
On Sat Nov 8, 2025 at 11:23 AM JST, Alexandre Courbot wrote: > Minor revision adding the feedback received on v3. > > Patch 3 adds a MAINTAINERS entry in case the Rust core team would like > us to maintain this, but please ignore it if you prefer to take it under > the core umbrella. > > This series provides `Bounded`, a wrapper type for primitive integers > that guarantees that only a given number of bits are used to represent > values. This is particularly useful when working with bitfields, as the > guarantee that a given value fits within the number of assigned bits can > be enforced by the type system, saving cumbersome runtime checks, or > (worse) stripping data when bits are silently dropped. > > For a basic usage, please see the rustdoc of the `Bounded` type on the > second patch. > > The first use of this will be to represent bitfields in Nova register > types to guarantee that no data is ever stripped when manipulating them. > This should eventually allow the `bitfield` and `register` macros to > move out of Nova and into the kernel crate. > > The last patch is just here to illustrate the use of this module; it is > not intended to be merged this cycle as it would likely result in big > merge conflicts with the drm tree. > > This series applies on top of drm-rust-next for the needs of the last > patch, but the first 2 patches should apply cleanly on rust-next. A > branch with this series and its dependencies is available here: > > https://github.com/Gnurou/linux/tree/b4/bounded_ints > > Signed-off-by: Alexandre Courbot <acourbot@nvidia.com> Hi Rust core team, With -rc6 approaching, may I enquire on the appetite to merge this for 6.19? This is the last hard dependency for moving the bitfield/register macros out of Nova, so we need it if we want to tackle this for the next cycle. Please let me know if there is more I can do to bring this to shape! :)
On Tue, Nov 11, 2025 at 9:12 AM Alexandre Courbot <acourbot@nvidia.com> wrote: > > Hi Rust core team, > > With -rc6 approaching, may I enquire on the appetite to merge this for > 6.19? This is the last hard dependency for moving the bitfield/register > macros out of Nova, so we need it if we want to tackle this for the next > cycle. > > Please let me know if there is more I can do to bring this to shape! :) Let's get some testing in linux-next :) Acked-by: Miguel Ojeda <ojeda@kernel.org> Thanks! Cheers, Miguel
On Wed Nov 12, 2025 at 5:46 AM JST, Miguel Ojeda wrote: > On Tue, Nov 11, 2025 at 9:12 AM Alexandre Courbot <acourbot@nvidia.com> wrote: >> >> Hi Rust core team, >> >> With -rc6 approaching, may I enquire on the appetite to merge this for >> 6.19? This is the last hard dependency for moving the bitfield/register >> macros out of Nova, so we need it if we want to tackle this for the next >> cycle. >> >> Please let me know if there is more I can do to bring this to shape! :) > > Let's get some testing in linux-next :) > > Acked-by: Miguel Ojeda <ojeda@kernel.org> Thanks! What is the path from this to linux-next? IIUC we wanted to merge this series (minus patch 4) through the Rust (not drm-rust) tree.
On Wed, Nov 12, 2025 at 1:55 AM Alexandre Courbot <acourbot@nvidia.com> wrote: > > Thanks! What is the path from this to linux-next? IIUC we wanted to > merge this series (minus patch 4) through the Rust (not drm-rust) tree. Sounds fine, I can take them. Thanks! Cheers, Miguel
On Sat, Nov 8, 2025 at 3:24 AM Alexandre Courbot <acourbot@nvidia.com> wrote:
>
> Minor revision adding the feedback received on v3.
>
> Patch 3 adds a MAINTAINERS entry in case the Rust core team would like
> us to maintain this, but please ignore it if you prefer to take it under
> the core umbrella.
>
> This series provides `Bounded`, a wrapper type for primitive integers
> that guarantees that only a given number of bits are used to represent
> values. This is particularly useful when working with bitfields, as the
> guarantee that a given value fits within the number of assigned bits can
> be enforced by the type system, saving cumbersome runtime checks, or
> (worse) stripping data when bits are silently dropped.
>
> For a basic usage, please see the rustdoc of the `Bounded` type on the
> second patch.
>
> The first use of this will be to represent bitfields in Nova register
> types to guarantee that no data is ever stripped when manipulating them.
> This should eventually allow the `bitfield` and `register` macros to
> move out of Nova and into the kernel crate.
>
> The last patch is just here to illustrate the use of this module; it is
> not intended to be merged this cycle as it would likely result in big
> merge conflicts with the drm tree.
>
> This series applies on top of drm-rust-next for the needs of the last
> patch, but the first 2 patches should apply cleanly on rust-next. A
> branch with this series and its dependencies is available here:
>
> https://github.com/Gnurou/linux/tree/b4/bounded_ints
>
> Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
Applied to `rust-next` -- thanks everyone!
[ Added intra-doc link. Fixed a few other nits. - Miguel ]
Cheers,
Miguel
© 2016 - 2025 Red Hat, Inc.