Rust for Linux List
 help / color / mirror / Atom feed
From: Andreas Hindborg <a.hindborg@kernel.org>
To: Franklin-Qi <yusq77@gmail.com>, Lyude Paul <lyude@redhat.com>,
	Miguel Ojeda <ojeda@kernel.org>,
	Alice Ryhl <aliceryhl@google.com>
Cc: FUJITA Tomonori <fujita.tomonori@gmail.com>,
	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
Subject: Re: [PATCH] rust: time: keep Instant invariant when adding/subtracting Delta
Date: Tue, 01 Dec 2026 11:07:17 +0100	[thread overview]
Message-ID: <87mrqps4a2.fsf@t14s.mail-host-address-is-not-set> (raw)
In-Reply-To: <179610727734.137620.3884652165779521586@gmail.com>

"Franklin-Qi" <yusq77@gmail.com> writes:

> Instant documents inner in 0..=KTIME_MAX, but Add/Sub<Delta> only
> asserted non-negativity under CONFIG_RUST_OVERFLOW_CHECKS. With checks
> disabled, a negative result can be returned and later Instant-Instant
> subtraction may no longer be overflow-safe.
>
> Always assert the result is non-negative, and document the panic in the
> operators' rustdoc.
>
> Fixes: 22b65a40574e ("rust: time: Implement Add<Delta>/Sub<Delta> for Instant")
> Cc: stable@vger.kernel.org
> Reported-by: Georgios Androutsopoulos <georgeandrout13@gmail.com>
> Closes: https://github.com/Rust-for-Linux/linux/issues/1272
> Signed-off-by: Franklin-Qi <yusq77@gmail.com>
> ---
> Note: Per discussion on the GitHub issue with Miguel Ojeda, this uses an
> unconditional assert to preserve the Instant invariant (not clamp +
> warn_once), and documents the panic condition in the operators' rustdoc.

I agree that allowing the invariant to be broken is wrong, but could you
elaborate pros/cons wrt. clamping instead of panicking here?

I am more in favor of clamp + warn_once, since it does not crash the
kernel.

We could also consider panic if overflow checks enabled and clamp + warn
if not. But this may be too confusing?

Best regards,
Andreas Hindborg





  reply	other threads:[~2026-12-01 10:36 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <Mf9TNvNPTgERimoWnx-HXvSDdGaI4X1aH9iSG6qeVNn70w9dd_u0rKrIaSqNi8YN3O__uOmCDl8AWxrgV65JEg==@protonmail.internalid>
2026-12-01  6:41 ` [PATCH] rust: time: keep Instant invariant when adding/subtracting Delta Franklin-Qi
2026-12-01 10:07   ` Andreas Hindborg [this message]
2026-12-01 10:52     ` Miguel Ojeda
2026-12-02  8:03     ` Franklin-Qi
2026-12-02 10:43       ` Miguel Ojeda
2026-12-02 14:37       ` Andreas Hindborg
2026-12-02 15:30         ` Miguel Ojeda

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=87mrqps4a2.fsf@t14s.mail-host-address-is-not-set \
    --to=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=yusq77@gmail.com \
    /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