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] [day] [month] [year] [list]
Message-Id: <20250820.080721.742789396303033039.fujita.tomonori@gmail.com>
Date: Wed, 20 Aug 2025 08:07:21 +0900 (JST)
From: FUJITA Tomonori <fujita.tomonori@...il.com>
To: lyude@...hat.com
Cc: rust-for-linux@...r.kernel.org, linux-kernel@...r.kernel.org,
 tglx@...utronix.de, a.hindborg@...nel.org, fujita.tomonori@...il.com,
 boqun.feng@...il.com, frederic@...nel.org, anna-maria@...utronix.de,
 jstultz@...gle.com, sboyd@...nel.org, ojeda@...nel.org,
 alex.gaynor@...il.com, gary@...yguo.net, bjorn3_gh@...tonmail.com,
 lossin@...nel.org, aliceryhl@...gle.com, tmgross@...ch.edu, dakr@...nel.org
Subject: Re: [PATCH v8 6/7] rust: time: Add Instant::from_ktime()

On Tue, 19 Aug 2025 16:05:57 -0400
Lyude Paul <lyude@...hat.com> wrote:

> For implementing Rust bindings which can return a point in time.
> 
> Signed-off-by: Lyude Paul <lyude@...hat.com>
> 
> ---
> V4:
> * Turn from_nanos() into an unsafe function in order to ensure that we
>   uphold the invariants of Instant
> V5:
> * Add debug_assert!() to from_nanos
> V8:
> * Change name of function from Instant::from_nanos() to
>   Instant::from_ktime()
> 
>  rust/kernel/time.rs | 23 +++++++++++++++++++++++
>  1 file changed, 23 insertions(+)

Thanks!


> diff --git a/rust/kernel/time.rs b/rust/kernel/time.rs
> index 64c8dcf548d63..5c40ebe096357 100644
> --- a/rust/kernel/time.rs
> +++ b/rust/kernel/time.rs
> @@ -200,6 +200,29 @@ pub fn elapsed(&self) -> Delta {
>      pub(crate) fn as_nanos(&self) -> i64 {
>          self.inner
>      }
> +
> +    /// Create an [`Instant`] from a `ktime_t` without checking if it is non-negative.
> +    ///
> +    /// # Panics
> +    ///
> +    /// On debug builds, this function will panic if `nanos` is not in the range from 0 to
> +    /// `KTIME_MAX`.
> +    ///
> +    /// # Safety
> +    ///
> +    /// The caller promises that `nanos` is in the range from 0 to `KTIME_MAX`.

The comment looks outdated. 'ktime'?


> +    #[expect(unused)]
> +    #[inline]
> +    pub(crate) unsafe fn from_ktime(ktime: bindings::ktime_t) -> Self {
> +        debug_assert!(ktime >= 0);
> +
> +        // INVARIANT: Our safety contract ensures that `nanos` is in the range from 0 to

Ditto.

> +        // `KTIME_MAX`.
> +        Self {
> +            inner: ktime,
> +            _c: PhantomData,
> +        }
> +    }
>  }
>  
>  impl<C: ClockSource> core::ops::Sub for Instant<C> {
> -- 
> 2.50.0
> 
> 

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ