From: sashiko-bot@kernel.org
To: "Boming Kong" <michaelkongboming@gmail.com>
Cc: ojeda@kernel.org, "Alexandre Courbot" <acourbot@nvidia.com>,
gary@garyguo.net, "Danilo Krummrich" <dakr@kernel.org>,
"Alice Ryhl" <aliceryhl@google.com>,
"David Airlie" <airlied@gmail.com>,
"Simona Vetter" <simona@ffwll.ch>,
"Yury Norov" <yury.norov@gmail.com>,
"Boqun Feng" <boqun@kernel.org>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Benno Lossin" <lossin@kernel.org>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Trevor Gross" <tmgross@umich.edu>,
"Daniel Almeida" <daniel.almeida@collabora.com>,
"Tamir Duberstein" <tamird@kernel.org>,
"Onur Özkan" <work@onurozkan.dev>,
"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
"Jakub Kicinski" <kuba@kernel.org>,
"Alex Deucher" <alexander.deucher@amd.com>,
"Andrew Morton" <akpm@linux-foundation.org>,
"Jens Axboe" <axboe@kernel.dk>,
nova-gpu@lists.linux.dev, dri-devel@lists.freedesktop.org
Subject: Re: [PATCH v2] rust: bitfield: implement compile-time bitfield! overlap check
Date: Fri, 04 Dec 2026 04:04:12 +0000 [thread overview]
Message-ID: <sashiko-outbox-249075@kernel.org> (raw)
In-Reply-To: <20261204034830.117532-1-michaelkongboming@gmail.com>
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] rust: bitfield: allow_overlap zeroes mask and hides unrelated
overlaps
- [Low] rust: bitfield: missing docs for overlap check and allow_overlap
- [Low] rust: bitfield: unchecked field attr doc forwarding and misnamed
@lohi_chk
--
commit 4bf24af3cd86e778bdc829070073575d0ee69450
Author: Boming Kong <michaelkongboming@gmail.com>
rust: bitfield: implement compile-time bitfield! overlap check
This commit adds compile-time overlap checking to bitfield! (and register!
by inheritance), introduces a per-field #[allow_overlap] opt-out, and
updates nova-core MMU v2 page table definitions and bitfield tests.
> diff --git a/rust/kernel/bitfield.rs b/rust/kernel/bitfield.rs
> index 8d7d781753363..fe67cfe9a44ad 100644
> --- a/rust/kernel/bitfield.rs
> +++ b/rust/kernel/bitfield.rs
> @@ -359,7 +359,7 @@ unsafe impl $crate::mem::AsReprMut for $name {}
> // Definitions requiring knowledge of individual fields: private and public field accessors,
> // and `Debug` implementation.
> (@fields $vis:vis $name:ident $storage:ty {
> - $($(#[doc = $doc:expr])* $hi:literal:$lo:literal $field:ident
> + $($(#[$attr:ident $(= $doc:expr)?])* $hi:literal:$lo:literal $field:ident
> $(?=> $try_into_type:ty)?
> $(=> $into_type:ty)?
> ;
> @@ -371,7 +371,7 @@ impl $name {
> $(
> $crate::bitfield!(@private_field_accessors $vis $name $storage : $hi:$lo $field);
> $crate::bitfield!(
> - @public_field_accessors $(#[doc = $doc])* $vis $name $storage : $hi:$lo $field
> + @public_field_accessors $($(#[doc = $doc])?)* $vis $name $storage : $hi:$lo $field
> $(?=> $try_into_type)?
> $(=> $into_type)?
> );
> @@ -379,6 +379,9 @@ impl $name {
> }
>
> $crate::bitfield!(@debug $name { $($field;)* });
> + $crate::bitfield!(@lohi_chk $name $storage {
> + $($(#[$attr $(= $doc)?])* $field;)*
> + });
> };
[Severity: Low]
Should @fields match doc = $doc:expr and allow_overlap explicitly instead
of rewriting any key-value attribute into #[doc = $doc]? A malformed
#[allow_overlap = true] gets expanded as #[doc = true] on every public
accessor, causing spurious doc errors alongside the @allow_overlap error.
Also, @lohi_chk is a misleading name since it checks mask overlap rather
than lo/hi ordering, and both @allow_overlap and @lohi_chk omit the
descriptive comments present on the other helper arms in bitfield!.
[ ... ]
> @@ -540,6 +543,35 @@ const fn [<__with_ $field>](
> );
> };
>
> + (@allow_overlap doc = $doc:expr) => { false };
> + (@allow_overlap allow_overlap) => { true };
[Severity: Low]
Should the bitfield! syntax documentation in rust/kernel/bitfield.rs (and
rust/kernel/io/register.rs, which inherits this behavior) be updated to
describe the default compile-time overlap check and the #[allow_overlap]
field attribute?
> + (@lohi_chk $name:ident $storage:ty {
> + $($(#[$attr:ident $(= $doc:expr)?])* $field:ident;)*
> + }) => {
> + ::kernel::macros::paste!(
> + const _: () = {
> + let masks: &[$storage] = &[
> + $(if false $(|| $crate::bitfield!(@allow_overlap $attr $(= $doc)?))* {
> + 0
> + } else {
> + $name::[<$field:upper _MASK>]
> + }),*
> + ];
> + let err_msg: &[&str] = &[
> + $(concat!(stringify!($field), " overlaps a previous field")),*
> + ];
> + let mut used: $storage = 0;
> + let mut i = 0;
> + while i < masks.len() {
> + ::core::assert!(used & masks[i] == 0, "{}", err_msg[i]);
> + used |= masks[i];
> + i += 1;
> + }
> + };
> + );
> + };
[Severity: Medium]
Does zeroing the mask for #[allow_overlap] fields disable overlap checks
for unrelated fields in both directions?
Because the mask becomes 0, the annotated field is never checked against
earlier fields, and none of its bits are recorded in used for later
unannotated fields. In nova-core's Pde, table_frame_sys (53:8) carries
#[allow_overlap], so a typo colliding with no_ats (5:5) would compile.
In the same Pde, table_frame_vid (32:8) and peer_id (35:33) leave bits
53:36 unset in used, so a new unannotated field there would silently
overlap table_frame_sys. Scoping the opt-out to intended overlapping
partners or a mutually exclusive group would keep checking the other bits.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204034830.117532-1-michaelkongboming@gmail.com?part=1
prev parent reply other threads:[~2026-12-04 4:04 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-04 3:48 [PATCH v2] rust: bitfield: implement compile-time bitfield! overlap check Boming Kong
2026-12-04 4:04 ` sashiko-bot [this message]
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=sashiko-outbox-249075@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=a.hindborg@kernel.org \
--cc=acourbot@nvidia.com \
--cc=airlied@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=alexander.deucher@amd.com \
--cc=aliceryhl@google.com \
--cc=axboe@kernel.dk \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun@kernel.org \
--cc=dakr@kernel.org \
--cc=daniel.almeida@collabora.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=gary@garyguo.net \
--cc=gregkh@linuxfoundation.org \
--cc=kuba@kernel.org \
--cc=lossin@kernel.org \
--cc=michaelkongboming@gmail.com \
--cc=nova-gpu@lists.linux.dev \
--cc=ojeda@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=simona@ffwll.ch \
--cc=tamird@kernel.org \
--cc=tmgross@umich.edu \
--cc=work@onurozkan.dev \
--cc=yury.norov@gmail.com \
/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