Rust for Linux List
 help / color / mirror / Atom feed
From: Franklin-Qi <yusq77@gmail.com>
To: Andreas Hindborg <a.hindborg@kernel.org>,
	Lyude Paul <lyude@redhat.com>, Miguel Ojeda <ojeda@kernel.org>,
	Alice Ryhl <aliceryhl@google.com>
Cc: FUJITA Tomonori <fujita.tomonori@gmail.com>,
	FUJITA Tomonori <tomo@flapping.org>,
	Boqun Feng <boqun@kernel.org>, Danilo Krummrich <dakr@kernel.org>,
	rust-for-linux@vger.kernel.org, Thomas Gleixner <tglx@kernel.org>,
	John Stultz <jstultz@google.com>, Stephen Boyd <sboyd@kernel.org>,
	Frederic Weisbecker <frederic@kernel.org>,
	Anna-Maria Behnsen <anna-maria@linutronix.de>,
	Georgios Androutsopoulos <georgeandrout13@gmail.com>,
	stable@vger.kernel.org, Franklin-Qi <yusq77@gmail.com>
Subject: [PATCH v3 0/2] rust: time: keep Instant invariant when adding/subtracting Delta
Date: Thu,  3 Dec 2026 17:20:59 +0800	[thread overview]
Message-ID: <20261203092101.63850-1-yusq77@gmail.com> (raw)
In-Reply-To: <20261202080227.898512-1-yusq77@gmail.com>

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/20261202080227.898512-1-yusq77@gmail.com/

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
-- 
2.55.0

  parent reply	other threads:[~2026-12-03  9:21 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02  8:02 [PATCH v2] rust: time: keep Instant invariant when adding/subtracting Delta Franklin-Qi
2026-12-02 11:27 ` FUJITA Tomonori
2026-12-03  9:20   ` Franklin-Qi
2026-12-03  9:20 ` Franklin-Qi [this message]
2026-12-03  9:21   ` [PATCH v3 1/2] " Franklin-Qi
2026-12-03  9:21   ` [PATCH v3 2/2] rust: time: add KUnit tests for Instant Delta clamping Franklin-Qi

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=20261203092101.63850-1-yusq77@gmail.com \
    --to=yusq77@gmail.com \
    --cc=a.hindborg@kernel.org \
    --cc=aliceryhl@google.com \
    --cc=anna-maria@linutronix.de \
    --cc=boqun@kernel.org \
    --cc=dakr@kernel.org \
    --cc=frederic@kernel.org \
    --cc=fujita.tomonori@gmail.com \
    --cc=georgeandrout13@gmail.com \
    --cc=jstultz@google.com \
    --cc=lyude@redhat.com \
    --cc=ojeda@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=sboyd@kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=tglx@kernel.org \
    --cc=tomo@flapping.org \
    /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