Skip to content

rust: add `Alignment` type

Alexandre Courbot lkml nouveau rust-for-linux 5 versions – Applied

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

Get series with b4
b4 am [email protected] change-id 20250620-num-9420281c02c7

Versions newest first

  1. v5 Latest2 patches 9 repliesApplied
  2. v42 patches 6 repliesSuperseded
  3. v32 patches 0 repliesSuperseded
Earlier versions · 2
VersionPostedPatchesRepliesStatus
v24 patches11 repliesSuperseded
v13 patches16 repliesSuperseded

Changes in v5 from the cover letter

- Update doccomments a bit.
- Use a const generic instead of a regular argument for the const constructor.
- Link to v4: https://lore.kernel.org/r/[email protected]

Patches in v5 Applied

#Subject and filesSizeRepliesApplied
1/2rust: add `Alignment` typerust/kernel/lib.rs rust/kernel/ptr.rs+228 -05 replies
2/2gpu: nova-core: use Alignment for alignment-related operationsDocumentation/gpu/nova/core/todo.rst drivers/gpu/nova-core/fb.rs drivers/gpu/nova-core/vbios.rs+5 -61 reply

Reviews trailers per patch

All 2 patches have a Reviewed-by or Acked-by.

PatchAlice RyhlDanilo KrummrichAlexandre Courbot
1/2R-b R-b A-b A-b
2/2R-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/2] rust: add `Alignment` type

The first patch makes two additions:

- Bring an equivalent of the nightly upstream Alignment type [1] with an near-identical public interface,
- Add a new Alignable extension trait that provides a way to align values up or down according to an Alignment, and implement it on unsigned integer types.

The second patch makes use of these in the Nova driver.

[1] https://doc.rust-lang.org/std/ptr/struct.Alignment.html

---
Changes in v5:
- Update doccomments a bit.
- Use a const generic instead of a regular argument for the const constructor.
- Link to v4: https://lore.kernel.org/r/[email protected]

Changes in v4:
- Add the generic_nonzero feature (stabilized in Rust 1.79) to fix build with Rust 1.78.
- Import core::mem::align_of for older Rust versions (as the patch adding it to the prelude is not attainable from nova-next yet).
- Link to v3: https://lore.kernel.org/r/[email protected]

Changes in v3:
- Move align_down and align_up into their own Alignable trait. (thanks Miguel!)
- Fix Alignment::mask implementation to match upstream's.
- Add missing SAFETY: comments.
- Improve grammar on a few hard-to-parse comments.
- Link to v2: https://lore.kernel.org/r/[email protected]

Changes in v2:
- Remove last_checked_bit (use Rust's checked_ilog2 instead).
- Port Rust nightly Alignment type and extend it with align_down and align_up methods.
- Link to v1: https://lore.kernel.org/r/[email protected]

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.

---
Alexandre Courbot (2):
rust: add Alignment type
gpu: nova-core: use Alignment for alignment-related operations

 Documentation/gpu/nova/core/todo.rst |   1 -
 drivers/gpu/nova-core/fb.rs          |   6 +-
 drivers/gpu/nova-core/vbios.rs       |   4 +-
 rust/kernel/lib.rs                   |   2 +
 rust/kernel/ptr.rs                   | 226 +++++++++++++++++++++++++++++++++++
 5 files changed, 233 insertions(+), 6 deletions(-)

---
base-commit: 062b3e4a1f880f104a8d4b90b767788786aa7b78
change-id: 20250620-num-9420281c02c7
prerequisite-message-id: <[email protected]>
prerequisite-patch-id: 2439f5f9b560ee4867716f0018b5326dcd72cda3

Best regards,

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