Re: [PATCH] rust: hrtimer: document handle based design rationale

From: FUJITA Tomonori

Date: Fri Feb 27 2026 - 22:08:30 EST


On Sun, 15 Feb 2026 21:36:04 +0100
Andreas Hindborg <a.hindborg@xxxxxxxxxx> wrote:

> Add implementation notes explaining why the hrtimer abstraction uses a
> handle based approach.
>
> Signed-off-by: Andreas Hindborg <a.hindborg@xxxxxxxxxx>
> ---
> rust/kernel/time/hrtimer.rs | 12 ++++++++++++
> 1 file changed, 12 insertions(+)
>
> diff --git a/rust/kernel/time/hrtimer.rs b/rust/kernel/time/hrtimer.rs
> index 856d2d929a008..f92880b2cbdbd 100644
> --- a/rust/kernel/time/hrtimer.rs
> +++ b/rust/kernel/time/hrtimer.rs
> @@ -67,6 +67,18 @@
> //! A `restart` operation on a timer in the **stopped** state is equivalent to a
> //! `start` operation.
>
> +// Implementation details
> +//
> +// The reasoning for adopting a handle based approach:
> +// - If we explicitly drop the target of a timer callback in the timer callback, we
> +// may get a dangling reference.
> +// - If the callback owns the last reference to the target, target may be dropped
> +// in non-sleepable context when the callback is finished.
> +// - When dropping an object that is the target of an armed timer, we may drop
> +// fields accessed by the timer callback before we cancel the timer (drop order).
> +//
> +// By using a handle, we can make the handle own the callback target and avoid these problems.
> +

Reviewed-by: FUJITA Tomonori <fujita.tomonori@xxxxxxxxx>