lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <8e32c3e1-0b55-4809-92ad-f968252a05f8@proton.me>
Date: Thu, 20 Feb 2025 23:47:30 +0000
From: Benno Lossin <benno.lossin@...ton.me>
To: Andreas Hindborg <a.hindborg@...nel.org>, Miguel Ojeda <ojeda@...nel.org>, Anna-Maria Behnsen <anna-maria@...utronix.de>, Frederic Weisbecker <frederic@...nel.org>, Thomas Gleixner <tglx@...utronix.de>, Danilo Krummrich <dakr@...nel.org>
Cc: Alex Gaynor <alex.gaynor@...il.com>, Boqun Feng <boqun.feng@...il.com>, Gary Guo <gary@...yguo.net>, Björn Roy Baron <bjorn3_gh@...tonmail.com>, Alice Ryhl <aliceryhl@...gle.com>, Trevor Gross <tmgross@...ch.edu>, Lyude Paul <lyude@...hat.com>, Guangbo Cui <2407018371@...com>, Dirk Behme <dirk.behme@...il.com>, Daniel Almeida <daniel.almeida@...labora.com>, Tamir Duberstein <tamird@...il.com>, rust-for-linux@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH v8 05/14] rust: hrtimer: allow timer restart from timer handler

On 18.02.25 14:27, Andreas Hindborg wrote:
> This patch allows timer handlers to report that they want a timer to be
> restarted after the timer handler has finished executing.
> 
> Also update the `hrtimer` documentation to showcase the new feature.
> 
> Signed-off-by: Andreas Hindborg <a.hindborg@...nel.org>
> ---
>  rust/kernel/time/hrtimer.rs     | 28 +++++++++++++++++++++++++++-
>  rust/kernel/time/hrtimer/arc.rs |  4 +---
>  2 files changed, 28 insertions(+), 4 deletions(-)
> 
> diff --git a/rust/kernel/time/hrtimer.rs b/rust/kernel/time/hrtimer.rs
> index b2a3130bc21d7..e342193f985eb 100644
> --- a/rust/kernel/time/hrtimer.rs
> +++ b/rust/kernel/time/hrtimer.rs
> @@ -183,7 +183,7 @@ pub trait HrTimerCallback {
>      type CallbackTargetParameter<'a>;
> 
>      /// Called by the timer logic when the timer fires.
> -    fn run(this: Self::CallbackTargetParameter<'_>)
> +    fn run(this: Self::CallbackTargetParameter<'_>) -> HrTimerRestart
>      where
>          Self: Sized;
>  }
> @@ -278,6 +278,32 @@ unsafe fn start(self_ptr: *const Self, expires: Ktime) {
>      }
>  }
> 
> +/// Restart policy for timers.
> +pub enum HrTimerRestart {
> +    /// Timer should not be restarted.
> +    NoRestart,
> +    /// Timer should be restarted.
> +    Restart,
> +}
> +
> +impl From<bindings::hrtimer_restart> for HrTimerRestart {
> +    fn from(value: u32) -> Self {
> +        match value {
> +            bindings::hrtimer_restart_HRTIMER_NORESTART => Self::NoRestart,
> +            _ => Self::Restart,
> +        }
> +    }
> +}
> +
> +impl From<HrTimerRestart> for bindings::hrtimer_restart {
> +    fn from(value: HrTimerRestart) -> Self {
> +        match value {
> +            HrTimerRestart::NoRestart => bindings::hrtimer_restart_HRTIMER_NORESTART,
> +            HrTimerRestart::Restart => bindings::hrtimer_restart_HRTIMER_RESTART,
> +        }
> +    }
> +}

Do drivers need these impls? If no, I would prefer a private conversion
function just for the abstraction.

---
Cheers,
Benno

> +
>  /// Use to implement the [`HasHrTimer<T>`] trait.
>  ///
>  /// See [`module`] documentation for an example.
> diff --git a/rust/kernel/time/hrtimer/arc.rs b/rust/kernel/time/hrtimer/arc.rs
> index d1c90631d0036..109eded0e73be 100644
> --- a/rust/kernel/time/hrtimer/arc.rs
> +++ b/rust/kernel/time/hrtimer/arc.rs
> @@ -82,8 +82,6 @@ impl<T> RawHrTimerCallback for Arc<T>
>          // timer. This `T` is contained in an `Arc`.
>          let receiver = unsafe { ArcBorrow::from_raw(data_ptr) };
> 
> -        T::run(receiver);
> -
> -        bindings::hrtimer_restart_HRTIMER_NORESTART
> +        T::run(receiver).into()
>      }
>  }
> 
> --
> 2.47.0
> 
> 


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ