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: <8998B971-BB46-4624-8077-5C85FE5FA97A@collabora.com>
Date: Tue, 13 May 2025 15:52:12 -0300
From: Daniel Almeida <daniel.almeida@...labora.com>
To: Miguel Ojeda <miguel.ojeda.sandonis@...il.com>
Cc: Miguel Ojeda <ojeda@...nel.org>,
 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>,
 Benno Lossin <benno.lossin@...ton.me>,
 Andreas Hindborg <a.hindborg@...nel.org>,
 Alice Ryhl <aliceryhl@...gle.com>,
 Trevor Gross <tmgross@...ch.edu>,
 Danilo Krummrich <dakr@...nel.org>,
 linux-kernel@...r.kernel.org,
 rust-for-linux@...r.kernel.org,
 Fiona Behrens <me@...enk.dev>
Subject: Re: [PATCH v5] rust: kernel: add support for bits/genmask macros

Hi Miguel,

> On 27 Mar 2025, at 18:27, Miguel Ojeda <miguel.ojeda.sandonis@...il.com> wrote:
> 
> Hi Daniel,
> 
> My usual docs-only review... I hope that helps!
> 
> On Wed, Mar 26, 2025 at 3:07 PM Daniel Almeida
> <daniel.almeida@...labora.com> wrote:
>> 
>> +/// Equivalent to the kernel's `BIT` macro.
> 
> "To the C `BIT` macro" or "The C side ..." or similar -- these one
> would be also the kernel's :)
> 
>> +/// Create a contiguous bitmask starting at bit position `l` and ending at
>> +/// position `h`, where `h >= l`.
> 
> The first paragraph is a "short description" / title -- you may want
> to leave the details to a second sentence, i.e. in a second paragraph.
> Please check in any case how it looks in the rendered docs -- it may
> be fine to have all in the title.
> 
> In fact, given you `assert!`, we should probably mention that very
> prominently e.g. in a `# Panics` section. Or, better, avoid the panics
> to begin with if it makes sense.

I have been staring at this for a little while.

I wonder what is everyone's opinions on an extra set of:

// e.g.: for u32
const fn const_genmask_u32<const H: u32, const L: u32>() -> u32 {
  crate::build_assert!(H >= L);
  ...
}

..on top of the current genmask functions we already have?

This lets us move the checks to compile time for most cases, because for the
majority of users, h and l are simply integer literals.  

For the rest, we can probably modify the current functions:

fn genmask_u32(h: u32, l: u32) -> Result<u32> {
  if(h < l) {
    return Err(EINVAL);
  }
  ..
}

The implementation can probably be shared by using macros like kernel::io::Io,
for example, and the panics would be gone.

— Daniel

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ