From: sashiko-bot@kernel.org
To: "Eliot Courtney" <ecourtney@nvidia.com>
Cc: dri-devel@lists.freedesktop.org, ojeda@kernel.org,
"Alexandre Courbot" <acourbot@nvidia.com>,
"Danilo Krummrich" <dakr@kernel.org>
Subject: Re: [PATCH v4 2/5] rust: bitmap: restrict bitmap length to at most i32::MAX
Date: Mon, 10 Aug 2026 08:48:08 +0000 [thread overview]
Message-ID: <20260810084809.8B2471F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260810-chid-v4-2-c9f206fdcb97@nvidia.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but the safe Rust API for `Bitmap` allows data races (Undefined Behavior). The methods `set_bit_atomic` and `clear_bit_atomic` are marked as `safe` and take a shared reference `&self` to perform atomic mutations. However, `Bitmap` (and `BitmapVec` via `Deref`) implements `Sync`, meaning `&Bitmap` can be shared across multiple threads. Other safe methods like `next_bit`, `last_bit`, and `copy_and_extend` (via the `src` parameter) also take `&self` but perform non-atomic reads. This allows safe Rust code to execute concurrent atomic writes and non-atomic reads on the same memory, violating Rust's memory model and causing Undefined Behavior (a data race). The safety comment in `set_bit_atomic` incorrectly states 'the caller has ensured that there is no mix of non-atomic and atomic operations', but since the method is marked safe, the compiler cannot enforce this.
--
--- Patch [2]: [PATCH v4 2/5] rust: bitmap: restrict bitmap length to at most i32::MAX ---
commit d989729ee19564d93c5d59130c2e1ac3974ea804
Author: Eliot Courtney <ecourtney@nvidia.com>
rust: bitmap: restrict bitmap length to at most i32::MAX
This patch restricts the maximum size of a Bitmap to i32::MAX bits to match
BitmapVec. It updates the unsafe requirements for Bitmap::from_raw and
from_raw_mut to reflect this limit. It also corrects potential out-of-bounds
writes in copy_and_extend caused by u32 cast truncations.
Link: https://lore.kernel.org/DKG0U8RLO7LZ.2I1AIH0S38PAP@nvidia.com
> diff --git a/rust/kernel/bitmap.rs b/rust/kernel/bitmap.rs
> index a43bfe0ec3dc2..0d481d761f2ac 100644
> --- a/rust/kernel/bitmap.rs
> +++ b/rust/kernel/bitmap.rs
[ ... ]
> @@ -415,7 +420,8 @@ pub fn clear_bit_atomic(&self, index: usize) {
> #[inline]
> pub fn copy_and_extend(&mut self, src: &Bitmap) {
[Severity: High]
This isn't a bug introduced by this patch, but does the safe Rust API for
Bitmap allow data races?
The set_bit_atomic() and clear_bit_atomic() methods are marked as safe and
take a shared reference to perform atomic mutations. However, Bitmap
implements Sync, meaning it can be shared across multiple threads.
Other safe methods like next_bit(), last_bit(), and copy_and_extend() (via
the src parameter here) also take a shared reference but perform non-atomic
reads. This allows safe Rust code to execute concurrent atomic writes and
non-atomic reads on the same memory, violating the memory model.
The safety comment in set_bit_atomic() states the caller has ensured there is
no mix of non-atomic and atomic operations, but since the method is marked
safe, the compiler cannot enforce this.
Could the API be updated to prevent safe code from triggering a data race?
> let len = core::cmp::min(src.len(), self.len());
> - // SAFETY: access to `self` and `src` is within bounds.
> + // SAFETY: access to `self` and `src` is within bounds. Both lengths fit in `u32`
> + // because a `Bitmap` is at most `i32::MAX` bits, so the casts are lossless.
> unsafe {
> bindings::bitmap_copy_and_extend(
> self.as_mut_ptr(),
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260810-chid-v4-0-c9f206fdcb97@nvidia.com?part=2
next prev parent reply other threads:[~2026-08-10 8:48 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-10 8:34 [PATCH v4 0/5] rust: Add support for reserving of ranges of IDs Eliot Courtney
2026-08-10 8:34 ` [PATCH v4 1/5] rust: bitmap: use function-level cfg on kunit test Eliot Courtney
2026-08-10 8:34 ` [PATCH v4 2/5] rust: bitmap: restrict bitmap length to at most i32::MAX Eliot Courtney
2026-08-10 8:48 ` sashiko-bot [this message]
2026-08-11 2:20 ` Yury Norov
2026-08-10 8:34 ` [PATCH v4 3/5] rust: bitmap: add contiguous area operations Eliot Courtney
2026-08-10 8:55 ` sashiko-bot
2026-08-11 3:16 ` Yury Norov
2026-08-10 8:34 ` [PATCH v4 4/5] rust: id_pool: add contiguous area allocation Eliot Courtney
2026-08-10 8:34 ` [PATCH v4 5/5] gpu: nova-core: add ChannelIdPool Eliot Courtney
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260810084809.8B2471F00A3A@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=acourbot@nvidia.com \
--cc=dakr@kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=ecourtney@nvidia.com \
--cc=ojeda@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox