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: <8734eij1bo.fsf@kernel.org>
Date: Tue, 08 Apr 2025 14:16:11 +0200
From: Andreas Hindborg <a.hindborg@...nel.org>
To: "Lyude Paul" <lyude@...hat.com>
Cc: <rust-for-linux@...r.kernel.org>,  <linux-kernel@...r.kernel.org>,
  "Boqun Feng" <boqun.feng@...il.com>,  "Frederic Weisbecker"
 <frederic@...nel.org>,  "Thomas Gleixner" <tglx@...utronix.de>,
  "Anna-Maria Behnsen" <anna-maria@...utronix.de>,  "Miguel Ojeda"
 <ojeda@...nel.org>,  "Alex Gaynor" <alex.gaynor@...il.com>,  "Gary Guo"
 <gary@...yguo.net>,  Björn Roy Baron
 <bjorn3_gh@...tonmail.com>,  "Benno
 Lossin" <benno.lossin@...ton.me>,  "Alice Ryhl" <aliceryhl@...gle.com>,
  "Trevor Gross" <tmgross@...ch.edu>
Subject: Re: [PATCH 6/6] rust: hrtimer: Add HrTimerCallback::expires()

"Lyude Paul" <lyude@...hat.com> writes:

> This adds the ability to read the expiry time of the current timer from the
> HrTimerCallbackContext.
>
> Signed-off-by: Lyude Paul <lyude@...hat.com>
> ---
>  rust/kernel/time/hrtimer.rs | 29 +++++++++++++++++++++++++++--
>  1 file changed, 27 insertions(+), 2 deletions(-)
>
> diff --git a/rust/kernel/time/hrtimer.rs b/rust/kernel/time/hrtimer.rs
> index d52cbb6cfc57f..e28b7895d8f37 100644
> --- a/rust/kernel/time/hrtimer.rs
> +++ b/rust/kernel/time/hrtimer.rs
> @@ -69,7 +69,7 @@
>
>  use super::ClockId;
>  use crate::{init::PinInit, prelude::*, time::Ktime, types::Opaque};
> -use core::{marker::PhantomData, ptr::NonNull};
> +use core::{marker::PhantomData, ptr::{NonNull, addr_of}};
>
>  /// A timer backed by a C `struct hrtimer`.
>  ///
> @@ -131,7 +131,7 @@ unsafe fn raw_get(this: *const Self) -> *mut bindings::hrtimer {
>          // SAFETY: The field projection to `timer` does not go out of bounds,
>          // because the caller of this function promises that `this` points to an
>          // allocation of at least the size of `Self`.
> -        unsafe { Opaque::raw_get(core::ptr::addr_of!((*this).timer)) }
> +        unsafe { Opaque::raw_get(addr_of!((*this).timer)) }
>      }
>
>      /// Cancel an initialized and potentially running timer.
> @@ -163,6 +163,31 @@ pub(crate) unsafe fn raw_cancel(this: *const Self) -> bool {
>          // handled on the C side.
>          unsafe { bindings::hrtimer_cancel(c_timer_ptr) != 0 }
>      }
> +
> +    /// Return the time expiry for the given timer pointer.
> +    ///
> +    /// This value should only be used as a snapshot, as the actual expiry time could change after
> +    /// this function is called.
> +    ///
> +    /// # Safety
> +    ///
> +    /// `self_ptr` must point to a valid `Self`.
> +    unsafe fn raw_expires(self_ptr: *const Self) -> Ktime {
> +        // SAFETY: self_ptr points to an allocation of at least `HrTimer` size.
> +        let c_timer_ptr = unsafe { HrTimer::raw_get(self_ptr) };
> +
> +        // SAFETY: There's no actual locking here, a racy read is fine and expected.
> +        Ktime::from_raw(unsafe { core::ptr::read(addr_of!((*c_timer_ptr).node.expires)) })

>From what I have picked up about racy reads lately, this should probably
be a `read_once` when we get that. For now you should use
`core::ptr::read_volatile` with a `FIXME(read_volatile)`.


Best regards,
Andreas Hindborg




Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ