Re: [PATCH v11 4/5] rust: add find_bit_benchmark_rust module.
From: Burak Emir
Date: Wed Jun 11 2025 - 14:55:37 EST
On Thu, Jun 5, 2025 at 11:37 PM Pekka Ristola <pekkarr@xxxxxxxxxxxxxx> wrote:
>
> On Monday, June 2nd, 2025 at 16.53, Burak Emir <bqe@xxxxxxxxxx> wrote:
[...]
> > diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
> > index f9051ab610d5..3f826a73bdbf 100644
> > --- a/lib/Kconfig.debug
> > +++ b/lib/Kconfig.debug
> > @@ -2605,6 +2605,19 @@ config FIND_BIT_BENCHMARK
> >
> > If unsure, say N.
> >
> > +config FIND_BIT_BENCHMARK_RUST
> > + tristate "Test find_bit functions in Rust"
> > + depends on CONFIG_RUST
>
> The `CONFIG_` prefix should be removed.
Done.
[...]
> > diff --git a/rust/kernel/bitmap.rs b/rust/kernel/bitmap.rs
> > index 28c11e400d1e..9fefb2473099 100644
> > --- a/rust/kernel/bitmap.rs
> > +++ b/rust/kernel/bitmap.rs
> > @@ -252,6 +252,20 @@ pub fn new(nbits: usize, flags: Flags) -> Result<Self, AllocError> {
> > pub fn len(&self) -> usize {
> > self.nbits
> > }
> > +
> > + /// Fills this `Bitmap` with random bits.
> > + #[cfg(CONFIG_FIND_BIT_BENCHMARK_RUST)]
> > + pub fn fill_random(&mut self) {
> > + // SAFETY: `self.as_mut_ptr` points to either an array of the
> > + // appropriate length or one usize.
> > + unsafe {
> > + bindings::get_random_bytes(
> > + self.as_mut_ptr() as *mut ffi::c_void,
> > + usize::div_ceil(self.nbits, bindings::BITS_PER_LONG as usize)
> > + * bindings::BITS_PER_LONG as usize,
>
> I think the second argument to `get_random_bytes` should be in bytes, not
> bits. So it should be multiplied by "bytes per long", not "bits per long".
Thanks for catching this. At least I had memory safety in mind when I
overflowed the buffer (facepalm)!
Fixed.
Cheers,
-- Burak