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: <20250217.075029.1780115689208398996.fujita.tomonori@gmail.com>
Date: Mon, 17 Feb 2025 07:50:29 +0900 (JST)
From: FUJITA Tomonori <fujita.tomonori@...il.com>
To: daniel.almeida@...labora.com
Cc: fujita.tomonori@...il.com, linux-kernel@...r.kernel.org,
 rust-for-linux@...r.kernel.org, netdev@...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,
 anna-maria@...utronix.de, frederic@...nel.org, tglx@...utronix.de,
 arnd@...db.de, jstultz@...gle.com, sboyd@...nel.org, mingo@...hat.com,
 peterz@...radead.org, juri.lelli@...hat.com, vincent.guittot@...aro.org,
 dietmar.eggemann@....com, rostedt@...dmis.org, bsegall@...gle.com,
 mgorman@...e.de, vschneid@...hat.com, tgunders@...hat.com, me@...enk.dev
Subject: Re: [PATCH v10 7/8] rust: Add read_poll_timeout functions

On Sun, 16 Feb 2025 09:19:02 -0300
Daniel Almeida <daniel.almeida@...labora.com> wrote:

>>>> +/// Polls periodically until a condition is met or a timeout is reached.
>>>> +///
>>>> +/// ```rust
>>>> +/// use kernel::io::poll::read_poll_timeout;
>>>> +/// use kernel::time::Delta;
>>>> +/// use kernel::sync::{SpinLock, new_spinlock};
>>>> +///
>>>> +/// let lock = KBox::pin_init(new_spinlock!(()), kernel::alloc::flags::GFP_KERNEL)?;
>>>> +/// let g = lock.lock();
>>>> +/// read_poll_timeout(|| Ok(()), |()| true, Delta::from_micros(42), Some(Delta::from_micros(42)));
>>>> +/// drop(g);
>>>> +///
>>>> +/// # Ok::<(), Error>(())
>>> 
>>> IMHO, the example section here needs to be improved.
>> 
>> Do you have any specific ideas?
>> 
>> Generally, this function is used to wait for the hardware to be
>> ready. So I can't think of a nice example.
> 
> Just pretend that you’re polling some mmio address that indicates whether some hardware
> block is ready, for example.
> 
> You can use “ignore” if you want, the example just has to illustrate how this function works, really.

Ah, you use `ignore` comment. I was only considering examples that
would actually be tested.


> Something like
> 
> ```ignore
>  /* R is a fictional type that abstracts a memory-mapped register where `read()` returns Result<u32> */
>  fn wait_for_hardware(ready_register: R) {
>      let op = || ready_register.read()?
> 
>      // `READY` is some device-specific constant that we are waiting for.
>      let cond =  |value: &u32| { *value == READY }
> 
>      let res = io::poll::read_poll_timeout (/* fill this with the right arguments */);
> 
>      /* show how `res` works, is -ETIMEDOUT returned on Err? */
> 
>      match res {
>        Ok(<what is here?>) => { /* hardware is ready */}
>        Err(e) => { /* explain that *value != READY here? */ }
> 
>      /* sleep is Option<Delta>, how does this work? i.e.: show both None, and Some(…) with some comments. */
>  } 
> ```
> 
> That’s just a rough draft, but I think it's going to be helpful for users.

I'll add an example based on the code QT2025 PHY (8th patch). It's
similar to the above.

Thanks,

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ