mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: chenhan <chenhan0017.work@gmail.com>
To: Andreas Hindborg <a.hindborg@kernel.org>
Cc: rust-for-linux@vger.kernel.org, boqun@kernel.org,
	fujita.tomonori@gmail.com, frederic@kernel.org, lyude@redhat.com,
	tglx@kernel.org, anna-maria@linutronix.de, jstultz@google.com,
	sboyd@kernel.org, ojeda@kernel.org, gary@garyguo.net,
	bjorn3_gh@protonmail.com, lossin@kernel.org,
	aliceryhl@google.com, tmgross@umich.edu, dakr@kernel.org,
	daniel.almeida@collabora.com, tamird@kernel.org,
	acourbot@nvidia.com, work@onurozkan.dev,
	miguel.ojeda.sandonis@gmail.com, tomo@flapping.org,
	georgeandrout13@gmail.com, linux-kernel@vger.kernel.org,
	stable@vger.kernel.org
Subject: Re: [PATCH v4 2/3] rust: time: make Delta division and remainder fail consistently
Date: Sat, 31 Oct 2026 16:46:28 +0800	[thread overview]
Message-ID: <20261031084628.13273-1-chenhan0017.work@gmail.com> (raw)
In-Reply-To: <87bj8goc6x.fsf@t14s.mail-host-address-is-not-set>

Hi Andreas,

Thanks for asking. I should have distinguished the non-zero-divisor
requirement from the MIN/-1 check in those comments.

> Why change the safety comment here? If the function is always safe to
> call, the exclusion is not relevant. Was the old comment wrong?

The old "regardless of the input values" statement is too broad. In the
generic 32-bit implementation, div64_s64() goes through div64_u64() and
div_u64_rem() to do_div(). The latter contains C division and remainder
operations which require a non-zero divisor. The kernel's
-fno-strict-overflow does not define division by zero. An architecture's
divide-by-zero handling therefore does not establish that the C call is
safe for every input across implementations.

The zero-divisor check above the call supplies that precondition. I have
updated the local comments for the next revision to cite that check
explicitly, without grouping it with MIN/-1. For the division call:

    // SAFETY: `rhs.value` is non-zero due to the check above.

The MIN/-1 check preserves Rust's panic semantics; the generic
32-bit helpers use unsigned magnitude division and wrapping sign
arithmetic, so I should not present its rejection as a necessary safety
precondition of those implementations.

> Again, was the old safety comment wrong?

The old pointer explanation was correct: the local rem supplies valid
storage for the output. I expanded it to make the validity, alignment
and writability of &mut rem explicit. The signed remainder helper also
reaches the division path above, so the comment should explain both
the non-zero divisor, established by the check, and the valid output
pointer. The updated comments keep these separate from the MIN/-1
behavior check; both runtime checks are unchanged.

I have made the corresponding comment changes in the math helpers in
patch 3 as well, so the explanation remains consistent after extraction.

> Once kunit supports the `#[should_panic]` attribute, we can assert the
> behavior on all platforms.

Agreed; that would let us keep these panic cases as in-tree regression
tests when the support is available.

Best regards,
chenhan

  reply	other threads:[~2026-10-31  8:46 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-23 13:04 [PATCH v4 0/3] rust: time: fix Delta arithmetic and add math helpers chenhan
2026-10-23 13:04 ` [PATCH v4 1/3] rust: time: rename the rem_nanos() divisor chenhan
2026-10-23 13:04 ` [PATCH v4 2/3] rust: time: make Delta division and remainder fail consistently chenhan
2026-10-26 12:53   ` Andreas Hindborg
2026-10-31  8:46     ` chenhan [this message]
2026-10-23 13:04 ` [PATCH v4 3/3] rust: math: add signed division and remainder helpers chenhan

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=20261031084628.13273-1-chenhan0017.work@gmail.com \
    --to=chenhan0017.work@gmail.com \
    --cc=a.hindborg@kernel.org \
    --cc=acourbot@nvidia.com \
    --cc=aliceryhl@google.com \
    --cc=anna-maria@linutronix.de \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun@kernel.org \
    --cc=dakr@kernel.org \
    --cc=daniel.almeida@collabora.com \
    --cc=frederic@kernel.org \
    --cc=fujita.tomonori@gmail.com \
    --cc=gary@garyguo.net \
    --cc=georgeandrout13@gmail.com \
    --cc=jstultz@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lossin@kernel.org \
    --cc=lyude@redhat.com \
    --cc=miguel.ojeda.sandonis@gmail.com \
    --cc=ojeda@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=sboyd@kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=tamird@kernel.org \
    --cc=tglx@kernel.org \
    --cc=tmgross@umich.edu \
    --cc=tomo@flapping.org \
    --cc=work@onurozkan.dev \
    /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

all inboxes | Powered by JetHome®