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: <20241109.133839.322803434056714560.fujita.tomonori@gmail.com>
Date: Sat, 09 Nov 2024 13:38:39 +0900 (JST)
From: FUJITA Tomonori <fujita.tomonori@...il.com>
To: boqun.feng@...il.com
Cc: fujita.tomonori@...il.com, anna-maria@...utronix.de,
 frederic@...nel.org, tglx@...utronix.de, jstultz@...gle.com,
 sboyd@...nel.org, linux-kernel@...r.kernel.org, netdev@...r.kernel.org,
 rust-for-linux@...r.kernel.org, andrew@...n.ch, hkallweit1@...il.com,
 tmgross@...ch.edu, ojeda@...nel.org, alex.gaynor@...il.com,
 gary@...yguo.net, bjorn3_gh@...tonmail.com, benno.lossin@...ton.me,
 a.hindborg@...sung.com, aliceryhl@...gle.com, arnd@...db.de
Subject: Re: [PATCH v5 4/7] rust: time: Add wrapper for fsleep function

On Wed, 6 Nov 2024 10:13:57 -0800
Boqun Feng <boqun.feng@...il.com> wrote:

>> diff --git a/rust/kernel/time/delay.rs b/rust/kernel/time/delay.rs
>> new file mode 100644
>> index 000000000000..c3c908b72a56
>> --- /dev/null
>> +++ b/rust/kernel/time/delay.rs
>> @@ -0,0 +1,43 @@
>> +// SPDX-License-Identifier: GPL-2.0
>> +
>> +//! Delay and sleep primitives.
>> +//!
>> +//! This module contains the kernel APIs related to delay and sleep that
>> +//! have been ported or wrapped for usage by Rust code in the kernel.
>> +//!
>> +//! C header: [`include/linux/delay.h`](srctree/include/linux/delay.h).
>> +
>> +use crate::time::Delta;
> 
> Nit: I think it's better to use:
> 
> use super::Delta;
> 
> here to refer a definition in the super mod.

Fixed.

>> +use core::ffi::c_ulong;
>> +
>> +/// Sleeps for a given duration at least.
>> +///
>> +/// Equivalent to the kernel's [`fsleep`], flexible sleep function,
>> +/// which automatically chooses the best sleep method based on a duration.
>> +///
>> +/// `delta` must be 0 or greater and no more than u32::MAX / 2 microseconds.
> 
> Adding backquotes on "u32::MAX / 2" would make it easier to read and
> generates better documentation. For example.
> 
> /// `delta` must be 0 or greater and no more than `u32::MAX / 2` microseconds.
>
>
>> +/// If a value outside the range is given, the function will sleep
>> +/// for u32::MAX / 2 microseconds at least.
> 
> Same here.

Updated both.

> I would also add the converted result in seconds of `u32::MAX / 2`
> microseconds to give doc readers some intuitions, like:
> 
> the function will sleep for `u32::MAX / 2` (= ~2147 seconds or ~36
> minutes) at least.

Yeah, looks good. Added.

>> +///
>> +/// This function can only be used in a nonatomic context.
>> +pub fn fsleep(delta: Delta) {
>> +    // The argument of fsleep is an unsigned long, 32-bit on 32-bit architectures.
>> +    // Considering that fsleep rounds up the duration to the nearest millisecond,
>> +    // set the maximum value to u32::MAX / 2 microseconds.
>> +    const MAX_DURATION: Delta = Delta::from_micros(u32::MAX as i64 >> 1);
>> +
>> +    let duration = if delta > MAX_DURATION || delta.as_nanos() < 0 {
> 
> I think it would be helpful if `Delta` has a `is_negative()` function.

Added.

Thanks a lot!

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ