From: Alexandre Courbot <acourbot@nvidia.com>
To: "Miguel Ojeda" <ojeda@kernel.org>,
"Alex Gaynor" <alex.gaynor@gmail.com>,
"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>
Cc: linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org,
nouveau@lists.freedesktop.org,
Alexandre Courbot <acourbot@nvidia.com>
Subject: [PATCH 0/3] rust: add `num` module
Date: Fri, 20 Jun 2025 22:14:50 +0900 [thread overview]
Message-ID: <20250620-num-v1-0-7ec3d3fb06c9@nvidia.com> (raw)
This patchset was part of the Nova FWSEC-FRTS submission [1], but has
been extracted as it was not very visible there, and seems to require
more discussion that the Nova code. I hope that presenting it separately
will help make it converge towards something that can be merged.
The motivation for this new module is to provide numerical functions not
supported (or not optimally supported for the kernel use-cases) by Rust
core. One example is how kernel code often aligns addresses or length to
some power-of-two. While Rust has `next_multiple_of` that provides the
same result, it also supports non-power-of-two values and is thus not as
efficient as the simple substract-and-mask operation that can be done
with a power of two.
Another missing operation is `last_set_bit` (`fls` in the C code), which
is again commonly used in the kernel but has no equivalent yet in Rust
core.
This patchset introduces these two features available:
- A `PowerOfTwo` newtype for unsigned integers with `align_down` and
`align_up` operations optimized for the kernel. The newtype ensures
that these operations cannot be used with a non-power-of-two, which
would yield an incorrect result.
- A set of `last_set_bit` const functions for unsigned integers types.
The last patch makes use of these features in the Nova driver, as was
originally done in the patchset. It requires the v6 of the patch series
[2] to be applied.
[1] https://lore.kernel.org/rust-for-linux/DANP9ATT1T5W.1KP4992E26FTP@nvidia.com/
[2] https://lore.kernel.org/rust-for-linux/20250619-nova-frts-v6-0-ecf41ef99252@nvidia.com/
Changes since split from the nova-core series:
- Rename `fls` to `last_set_bit`,
- Generate per-type doctests,
- Add invariants section to `PowerOfTwo`.
- Do not use reference to `self` in `PowerOfTwo` methods since it
implements `Copy`,
- Use #[derive] where possible instead of implementing traits manually,
- Remove `Deref` and `Borrow` implementations.
Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
---
Alexandre Courbot (3):
rust: add `num` module with `PowerOfTwo` type
rust: num: add the `last_set_bit` operation
nova-core: use `num` module
Documentation/gpu/nova/core/todo.rst | 15 ---
drivers/gpu/nova-core/falcon/hal/ga102.rs | 4 +-
drivers/gpu/nova-core/fb.rs | 6 +-
drivers/gpu/nova-core/firmware/fwsec.rs | 7 +-
drivers/gpu/nova-core/vbios.rs | 4 +-
rust/kernel/lib.rs | 1 +
rust/kernel/num.rs | 201 ++++++++++++++++++++++++++++++
7 files changed, 211 insertions(+), 27 deletions(-)
---
base-commit: c7864f7ab73417e352d8d00e46d3e9e6a228c5ab
change-id: 20250620-num-9420281c02c7
Best regards,
--
Alexandre Courbot <acourbot@nvidia.com>
next reply other threads:[~2025-06-20 13:15 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-20 13:14 Alexandre Courbot [this message]
2025-06-20 13:14 ` [PATCH 1/3] rust: add `num` module with `PowerOfTwo` type Alexandre Courbot
2025-06-20 13:35 ` Miguel Ojeda
2025-06-20 13:59 ` Alexandre Courbot
2025-06-20 14:02 ` Alice Ryhl
2025-08-02 14:02 ` Alexandre Courbot
2025-08-02 14:18 ` Miguel Ojeda
2025-08-03 13:13 ` Alexandre Courbot
2025-08-03 15:15 ` Miguel Ojeda
2025-08-04 7:32 ` Alexandre Courbot
2025-08-06 5:02 ` Alexandre Courbot
2026-04-14 9:45 ` Miguel Ojeda
2025-06-20 17:06 ` Miguel Ojeda
2025-06-22 8:11 ` Benno Lossin
2025-07-25 3:38 ` Alexandre Courbot
2025-07-25 10:10 ` Benno Lossin
2025-06-20 13:14 ` [PATCH 2/3] rust: num: add the `last_set_bit` operation Alexandre Courbot
2025-06-22 8:12 ` Benno Lossin
2025-06-23 11:42 ` Alice Ryhl
2025-06-20 13:14 ` [PATCH 3/3] nova-core: use `num` module Alexandre Courbot
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=20250620-num-v1-0-7ec3d3fb06c9@nvidia.com \
--to=acourbot@nvidia.com \
--cc=a.hindborg@kernel.org \
--cc=alex.gaynor@gmail.com \
--cc=aliceryhl@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=dakr@kernel.org \
--cc=gary@garyguo.net \
--cc=linux-kernel@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=nouveau@lists.freedesktop.org \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=tmgross@umich.edu \
/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
Powered by JetHome