From: sashiko-bot@kernel.org
To: "Andreas Hindborg" <a.hindborg@kernel.org>
Cc: intel-gfx@lists.freedesktop.org, ojeda@kernel.org,
dri-devel@lists.freedesktop.org
Subject: Re: [PATCH 3/6] rust: hrtimer: use the expiry injecting callback variant
Date: Tue, 25 Aug 2026 12:33:04 +0000 [thread overview]
Message-ID: <20260825123305.2DE741F00A3E@smtp.kernel.org> (raw)
In-Reply-To: <20260825-expires-v2-v1-3-90411c6217c7@kernel.org>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Safe Rust code can trigger a kernel WARN_ON_ONCE (and panic) by returning a zero interval in `HrTimerRestart::Forward`.
- [Low] Missing `#[inline]` attribute on small abstraction functions.
--
--- Patch [3]: [PATCH 3/6] rust: hrtimer: use the expiry injecting callback variant ---
commit 237e017d8140a6e80f2fd3f4c1d9d1b8d7532ab6
Author: Andreas Hindborg <a.hindborg@kernel.org>
rust: hrtimer: use the expiry injecting callback variant
A timer callback could modify the expiry of its timer with
HrTimerCallbackContext::forward(). This switches the abstraction to the expiry
injecting callback variant provided by hrtimer_setup_ext(). The callback
receives the expiry by value, snapshotted under the timer base lock, and
requests a restart by returning HrTimerRestart::Forward { now, interval }.
Link: https://lore.kernel.org/r/87h5kp88uy.fsf@kernel.org
> diff --git a/rust/kernel/time/hrtimer.rs b/rust/kernel/time/hrtimer.rs
> index 2d7f1131a8131..e6570a6162035 100644
> --- a/rust/kernel/time/hrtimer.rs
> +++ b/rust/kernel/time/hrtimer.rs
[ ... ]
> @@ -847,19 +847,62 @@ unsafe fn start(this: *const Self, expires: <Self::TimerMode as HrTimerMode>::Ex
[ ... ]
> +impl<T: HasHrTimer<T>> HrTimerRestart<T> {
> + /// Request that the timer be forwarded past the current time by `interval`
> + /// and restarted.
> + pub fn forward_now(interval: Delta) -> Self {
[Severity: Low]
This isn't a bug, but should this function be annotated with #[inline]?
The Rust subsystem coding guidelines mandate that small abstraction functions
should have this annotation.
> + Self::Forward {
> + now: HrTimerInstant::<T>::now(),
> + interval,
> + }
> + }
> +
> + /// Convert to the C representation, filling `fwd` with the forward
> + /// request.
> + ///
> + /// # Safety
> + ///
> + /// `fwd` must be valid for writing a `bindings::hrtimer_forward_args`.
> + pub(crate) unsafe fn into_c(
[Severity: Low]
This isn't a bug, but should this small conversion function also be annotated
with #[inline]?
> + self,
> + fwd: *mut bindings::hrtimer_forward_args,
> + ) -> bindings::hrtimer_restart {
> + match self {
> + Self::NoRestart => bindings::hrtimer_restart_HRTIMER_NORESTART,
> + Self::Forward { now, interval } => {
> + // SAFETY: By our safety contract, `fwd` is valid for writing.
> + unsafe {
> + *fwd = bindings::hrtimer_forward_args {
> + now: now.as_nanos(),
> + interval: interval.as_nanos(),
> + }
> + };
[Severity: High]
Does this code allow safe Rust to trigger a kernel panic?
If a safe Rust module constructs HrTimerRestart::Forward with a zero interval
(e.g., via HrTimerRestart::forward_now(Delta::ZERO)) and returns it from the
timer callback, the zero interval is blindly copied into fwd.interval here.
The C side execution in __run_hrtimer() will then trigger a WARN_ON_ONCE:
kernel/time/hrtimer.c:__run_hrtimer() {
/* An expiry injecting callback requesting a restart must forward. */
if (fn_ext && restart == HRTIMER_RESTART && WARN_ON_ONCE(!fwd.interval))
restart = HRTIMER_NORESTART;
...
}
If the kernel is configured with panic_on_warn, this could lead to a kernel
panic.
Should there be a check to validate that the interval is non-zero before
passing it to C, or should it be enforced when creating
HrTimerRestart::Forward?
> + bindings::hrtimer_restart_HRTIMER_RESTART
> + }
> + }
> + }
> +}
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260825-expires-v2-v1-0-90411c6217c7@kernel.org?part=3
next prev parent reply other threads:[~2026-08-25 12:33 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-25 12:16 [PATCH 0/6] hrtimer: add an expiry injecting callback variant Andreas Hindborg
2026-08-25 12:16 ` [PATCH 1/6] hrtimer: add " Andreas Hindborg
2026-08-25 12:16 ` [PATCH 2/6] drm/i915/pmu: use the expiry injecting hrtimer callback Andreas Hindborg
2026-08-25 12:29 ` sashiko-bot
2026-08-25 12:16 ` [PATCH 3/6] rust: hrtimer: use the expiry injecting callback variant Andreas Hindborg
2026-08-25 12:33 ` sashiko-bot [this message]
2026-08-25 12:16 ` [PATCH 4/6] rust: hrtimer: restrict expires() to exclusive access Andreas Hindborg
2026-08-25 12:25 ` sashiko-bot
2026-08-25 12:16 ` [PATCH 5/6] rust: hrtimer: document deadlock when starting a timer in its handler Andreas Hindborg
2026-08-25 12:26 ` sashiko-bot
2026-08-25 13:31 ` Gary Guo
2026-08-26 9:31 ` Andreas Hindborg
2026-08-25 12:16 ` [PATCH 6/6] rust: hrtimer: Make HrTimer repr(transparent) Andreas Hindborg
2026-08-25 12:30 ` sashiko-bot
2026-08-25 13:33 ` Gary Guo
2026-08-26 9:30 ` Andreas Hindborg
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=20260825123305.2DE741F00A3E@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=a.hindborg@kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=intel-gfx@lists.freedesktop.org \
--cc=ojeda@kernel.org \
--cc=sashiko-reviews@lists.linux.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