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: <DBDQASMSS32U.FJBYKS3LWEQ6@kernel.org>
Date: Wed, 16 Jul 2025 21:32:47 +0200
From: "Danilo Krummrich" <dakr@...nel.org>
To: "Daniel Almeida" <daniel.almeida@...labora.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" <lossin@...nel.org>, "Andreas
 Hindborg" <a.hindborg@...nel.org>, "Alice Ryhl" <aliceryhl@...gle.com>,
 "Trevor Gross" <tmgross@...ch.edu>, <linux-kernel@...r.kernel.org>,
 <rust-for-linux@...r.kernel.org>, "Alexandre Courbot" <acourbot@...dia.com>
Subject: Re: [PATCH v9] rust: kernel: add support for bits/genmask macros

On Wed Jul 16, 2025 at 9:11 PM CEST, Daniel Almeida wrote:
> Let’s transfer this discussion to this patch.
>
>> I also quickly tried genmask and I have a few questions:
>> 
>>  (1) Why does genmask not use a const generic? I think this makes it more
>>      obvious that it's only intended to be used from const context.
>
> I guess none of us thought about it, since the current version also works.

I think using a const generic would be a bit better for the mentioned reason.

>> 
>>  (2) Why is there no build_assert() when the range exceeds the number of bits
>>      of the target type? I would expect genmask_u64(0..100) to fail.
>
> Doesn’t it?
>
> There is a build_assert in the underlying bit implementation. It was redundant
> to have it both in bit_* and in genmask, because genmask calls bit().
>
> In your example, bit_u64(100) hits that assert, and so it shouldn't compile.

Indeed, and it also works, except from doc-tests for some reason, which is what
I tried real quick. :)

>>  (3) OOC, why did you choose u32 as argument type?
>
> No reason. i32 is the default integer type and signed integers don’t make
> sense here, so I chose u32.
>
> Also, we can trivially promote integers to wider types,  but the other way
> around is not true. So my reasoning was that if you had u8, or u16s you could
> trivially get u32s using into(), but if you had u32s and e.g. genmask_u16
> required u16s, you'd have to resort to try_into() or `as`, which is annoying.
>
> In any case, feel free to suggest anything else, I think.

I feel like usize would be a better fit, but not a strong opinion.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ