Skip to content

rust: time: keep Instant invariant when adding/subtracting Delta

Franklin-Qi rust-for-linux stable 3 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v3 Latest2 patches 1 replyIn review
  2. v21 patch 2 repliesSuperseded
  3. v11 patch 7 repliesSuperseded

Changes in v3 from the cover letter

- Rebased onto timekeeping-next (Instant is now Instant<C, Nsec>).
- Without overflow checks, also warn once when saturating to KTIME_MAX, not only when clamping a negative result (Tomonori).
- Add a second patch with KUnit tests for Instant +/- Delta clamping (Andreas, Miguel).

Patches in v3 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/2rust: time: keep Instant invariant when adding/subtracting Deltarust/kernel/time.rs+81 -200 replies
2/2rust: time: add KUnit tests for Instant Delta clampingrust/kernel/time.rs+52 -01 reply

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v3 yet.

Read the v3 thread

Cover letter [PATCH v3 0/2] rust: time: keep Instant invariant when adding/subtracting Delta

Instant documents that its inner value stays in 0..=KTIME_MAX, but Add/Sub<Delta> only enforced the lower bound under CONFIG_RUST_OVERFLOW_CHECKS. With checks disabled the result could leave that range, which later Instant-Instant subtraction assumes still holds.

This series keeps the existing panic behaviour with overflow checks enabled, and otherwise saturates/clamps into range with a one-shot warning. A follow-up patch adds KUnit coverage for the clamping paths.

Changes in v3:
- Rebased onto timekeeping-next (Instant is now Instant<C, Nsec>).
- Without overflow checks, also warn once when saturating to KTIME_MAX, not only when clamping a negative result (Tomonori).
- Add a second patch with KUnit tests for Instant +/- Delta clamping (Andreas, Miguel).

v2: https://lore.kernel.org/rust-for-linux/[email protected]/

Franklin-Qi (2):
rust: time: keep Instant invariant when adding/subtracting Delta
rust: time: add KUnit tests for Instant Delta clamping

 rust/kernel/time.rs | 153 ++++++++++++++++++++++++++++++++++++++------
 1 file changed, 133 insertions(+), 20 deletions(-)

base-commit: 8ecc26b396a2b587088e8ffd4d4b77d878f1eb33

Signature · 1 line
2.55.0