From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7CD0B606A322 for ; Fri, 4 Dec 2026 04:04:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=eT9Obv23 Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id ECB6010E41E; Fri, 4 Dec 2026 04:04:20 +0000 (UTC) Received: from tor.source.kernel.org (tor.source.kernel.org [172.105.4.254]) by gabe.freedesktop.org (Postfix) with ESMTPS id 8BE2110E80D for ; Fri, 4 Dec 2026 04:04:15 +0000 (UTC) Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id 8B0FF60F10; Fri, 4 Dec 2026 04:04:14 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 351EB1F000C2; Fri, 4 Dec 2026 04:04:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796357054; bh=M9AJ4g5Sa7W7ZtSYGovHgnAjMQ3uFZJF4E6B49qNndY=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=eT9Obv234R2FD9Lzsk61KxzqPcEWsiUYeKg0DVt/tSEbR5l+17wS6NVXz/LK73l0m YknIUc1usjUwBe3rn2smxW/3HQnR4m0jt38KBnB2WJnnaWGJJIGq9uZR1G2F16y7gP TNtublikOX0hjufG41CisaM522vXGtp/xunj734P8Y8N4kuZqrDjInvwh+UhFNKikw CZkV+GuvMSJxkxQfNAqJDce+Q/DS/o2JKJw3bQruD44OxQyd03Tj89+9QUdQLJkaJ4 MmBY4HxdYzeCaS9P6+V3ZcNtwNU6YnOHzXoRhmUpimrlk/jDIFbCkeRuC3GpRMcKv/ JzHLq14ggclpQ== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v2] rust: bitfield: implement compile-time bitfield! overlap check To: "Boming Kong" Cc: ojeda@kernel.org, "Alexandre Courbot" , gary@garyguo.net, "Danilo Krummrich" , "Alice Ryhl" , "David Airlie" , "Simona Vetter" , "Yury Norov" , "Boqun Feng" , =?utf-8?b?QmrDtnJuIFJveSBCYXJvbg==?= , "Benno Lossin" , "Andreas Hindborg" , "Trevor Gross" , "Daniel Almeida" , "Tamir Duberstein" , =?utf-8?b?T251ciDDlnprYW4=?= , "Greg Kroah-Hartman" , "Jakub Kicinski" , "Alex Deucher" , "Andrew Morton" , "Jens Axboe" , nova-gpu@lists.linux.dev, dri-devel@lists.freedesktop.org In-Reply-To: <20261204034830.117532-1-michaelkongboming@gmail.com> References: <20261204034830.117532-1-michaelkongboming@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 04:04:12 +0000 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: sashiko-reviews@lists.linux.dev Sender: "dri-devel" X-Spam-Status: No, score=-11.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 X-Archived-By: 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 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 =3D $doc:expr])* $hi:literal:$lo:literal $field:ident > + $($(#[$attr:ident $(=3D $doc:expr)?])* $hi:literal:$lo:literal $= field:ident > $(?=3D> $try_into_type:ty)? > $(=3D> $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 =3D $doc])* $vis $name $stor= age : $hi:$lo $field > + @public_field_accessors $($(#[doc =3D $doc])?)* $vis $name $= storage : $hi:$lo $field > $(?=3D> $try_into_type)? > $(=3D> $into_type)? > ); > @@ -379,6 +379,9 @@ impl $name { > } > =20 > $crate::bitfield!(@debug $name { $($field;)* }); > + $crate::bitfield!(@lohi_chk $name $storage { > + $($(#[$attr $(=3D $doc)?])* $field;)* > + }); > }; [Severity: Low] Should @fields match doc =3D $doc:expr and allow_overlap explicitly instead of rewriting any key-value attribute into #[doc =3D $doc]? A malformed #[allow_overlap =3D true] gets expanded as #[doc =3D 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>]( > ); > }; > =20 > + (@allow_overlap doc =3D $doc:expr) =3D> { false }; > + (@allow_overlap allow_overlap) =3D> { 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 $(=3D $doc:expr)?])* $field:ident;)* > + }) =3D> { > + ::kernel::macros::paste!( > + const _: () =3D { > + let masks: &[$storage] =3D &[ > + $(if false $(|| $crate::bitfield!(@allow_overlap $attr $= (=3D $doc)?))* { > + 0 > + } else { > + $name::[<$field:upper _MASK>] > + }),* > + ]; > + let err_msg: &[&str] =3D &[ > + $(concat!(stringify!($field), " overlaps a previous fiel= d")),* > + ]; > + let mut used: $storage =3D 0; > + let mut i =3D 0; > + while i < masks.len() { > + ::core::assert!(used & masks[i] =3D=3D 0, "{}", err_msg[= i]); > + used |=3D masks[i]; > + i +=3D 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. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261204034830.1175= 32-1-michaelkongboming@gmail.com?part=3D1