From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qv1-f47.google.com (mail-qv1-f47.google.com [209.85.219.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 167AA318BAB for ; Sun, 11 Jan 2026 12:02:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.47 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768132980; cv=none; b=Npox6rSC2KE5b8lqtl9xiv/X7TG7SELWpLXPt6EX11qvuKw1dKIz5OJ6ai5k/Fx+yFtCr99UqQDL2EBCgpJJ9ttHck8mSK1mD+Gg+wMS0TG5f4srrNYWUmzFk9V1047sfQpqGcemu0Z7Zi/FgzQ0ps1WkQPHjz4VyJjqhUs+kco= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768132980; c=relaxed/simple; bh=am9QCZcRcf2AAMBjS1CyDB4YX26g4rNaBgRNhi+yglM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ktnpqxIz3hf0BIyKrh5NKJBXnDsJVbVhVU26Xh1KO8+fHtJ26czj6GANfCJurODBo+beDLo4Ad0hHLJSfADADK9cW6+qyNJSV9oq+zeEdxa03P3lx1jWWgCh95Jc/jRnn3ukTChdUkd2IROyhjPeBulY0x664MBYHewzE3s4EoA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=dOkS4xED; arc=none smtp.client-ip=209.85.219.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="dOkS4xED" Received: by mail-qv1-f47.google.com with SMTP id 6a1803df08f44-8888a444300so54195206d6.1 for ; Sun, 11 Jan 2026 04:02:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1768132973; x=1768737773; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:feedback-id:from:to:cc:subject :date:message-id:reply-to; bh=n+VR8d+xDtsCoPiRu/UfANhgJIbLDtAMf28K6zfVKpQ=; b=dOkS4xEDz0nlXFF4kUc/4CFZevAnhig8Yu84glKJM2okNrI/roRSnh+D7AkJs35UcY kM1wG9FdUmLtdfdWlgXxDyX5A0lgCpR1nki8LDJuZI/jV6gNcpCeBPJYpGoFYpzL6rch fowOsEy/p+tocs0hV51DC4faQYitq0MHz+J2NaB6X/xrh8ste0We6TGdHwII8vxuhAhL 1Oa8c5r/e1egOAmMUT6OoFrVgrQatWxQSFLJ2AA60oqX9HhYfv7H0KDM3241hrqkOtYp ImBbFxz6TiGx5fMJN+e9kRqEO2j6MMYTntDHFcg2yBocigD1kkFnLIBE7WqjTzy9rl36 Lr/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768132973; x=1768737773; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:feedback-id:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=n+VR8d+xDtsCoPiRu/UfANhgJIbLDtAMf28K6zfVKpQ=; b=QGd9SAxMVZOHuN3vv0JEnloAkCFax81wSayuouyhiOnxsOMnWZT3ErzbtPoWTJBQbU 9Q1/lMxvajjS+Ah/AVjZ2BmPWSnXlf0vNtruaXeXGbOwQbOHxmbQfRTqZm8ieq8Z2j/T W8GJuIS59JnzFb+uy0/DTS2bh3EotV0XchnQr+NKmxVVhTKqZG4/7AUdcgxqYhlPvSZw GfCd3ZX3QNEZWp3iOUslhqANhzZuVGpgkVKoEI9EACc31zDyWXOhtHsui0zkQIXuj3eA awOEEtQfqLyLXsb1X/50ttvafO6GwiC4DssGkwNnarpmufzZqfgNUuexn50t3S6++97W cOiw== X-Forwarded-Encrypted: i=1; AJvYcCWD+G2IU/HCTnbh2G8sdAkHILIr360Oosh70jWZYGp45fM9o1GN/bl5HPZUSvSIH/NYPAn3+YieItKTPN8=@vger.kernel.org X-Gm-Message-State: AOJu0YycHqzxTTYXST2op+cgKW5bAXNc2GaaG9KjnnSNEVuY9wCqyVIh blCMfPDiVyhajWG+kfLy8B4g644rb33MNpdTIX7KhZMR6bkkla5qDW76 X-Gm-Gg: AY/fxX6Xdy8+V7PNgXvxJ26MT1HAKXHFflw/8KChsdPHEpikEpmoOl8wDhjsPSE2jTo /gQKgTH0GG5ZVXrKJggUVFJAsyxgGufZfK9TPr07avn2PySBHix1SyH+ZTbgU+5X1oDCPHYTcTC vT4Dmyae9Hc+tixLu/U2Qw9EOjyZ22GMcSVtmxXvY4WtDEs6jC7LVW6oeUyKnf5hXfeQtH++13T F19mdZgyGxmU1K2VpYVYPcqPVx8ZscIOsOcs2kHLTtlHSF5Q4/ZqXCzZ23XswiIWrsswNTWLqb4 Kj+XJlt5BAWleL+gqlcjKcE/KdpAb7tsTd2fd7e29iRuC5BMqzo7jrJ72/nG4bl8DLBcbumaySK W782O8SlHZGpXLSwfVw3ia2HrobcwwaEK6K3ttqDqO3abA7Glg/xV3qeH8SeFaG173ilSOn+tf4 rc0LTLa66SQGwW2t4ewGMreq36N6PXFtt19XEeebRbJ4YocgpY+vYRA/sxlJbjcamiZC0i4cVEd gspt43kGF2P/cWBH3Bm9dMfgQ== X-Google-Smtp-Source: AGHT+IGGgbGTyoxACaBF+0HtJRQ61/DF/nUsWZtrN72Gl/g3cg5v/faOWA6GQtenNrE7SzpLNmqDlA== X-Received: by 2002:a05:6214:4613:b0:888:57f3:ac07 with SMTP id 6a1803df08f44-890842552c3mr231905276d6.54.1768132972783; Sun, 11 Jan 2026 04:02:52 -0800 (PST) Received: from fauth-a2-smtp.messagingengine.com (fauth-a2-smtp.messagingengine.com. [103.168.172.201]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-890770ce99dsm118428406d6.3.2026.01.11.04.02.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 11 Jan 2026 04:02:52 -0800 (PST) Received: from phl-compute-03.internal (phl-compute-03.internal [10.202.2.43]) by mailfauth.phl.internal (Postfix) with ESMTP id EFF21F40068; Sun, 11 Jan 2026 07:02:51 -0500 (EST) Received: from phl-frontend-03 ([10.202.2.162]) by phl-compute-03.internal (MEProxy); Sun, 11 Jan 2026 07:02:51 -0500 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefgedrtddtgdduudeghedvucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu rghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujf gurhephffvvefufffkofgjfhgggfestdekredtredttdenucfhrhhomhepuehoqhhunhcu hfgvnhhguceosghoqhhunhdrfhgvnhhgsehgmhgrihhlrdgtohhmqeenucggtffrrghtth gvrhhnpedvveekvddtffelffelfedvudefffeuheejgeeivedufffgledvgeduveffueeh leenucffohhmrghinhepmhhsghhiugdrlhhinhhknecuvehluhhsthgvrhfuihiivgepud enucfrrghrrghmpehmrghilhhfrhhomhepsghoqhhunhdomhgvshhmthhprghuthhhphgv rhhsohhnrghlihhthidqieelvdeghedtieegqddujeejkeehheehvddqsghoqhhunhdrfh gvnhhgpeepghhmrghilhdrtghomhesfhhigihmvgdrnhgrmhgvpdhnsggprhgtphhtthho peduhedpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepphgvthgvrhiisehinhhfrh gruggvrggurdhorhhgpdhrtghpthhtohepmhhinhhgoheskhgvrhhnvghlrdhorhhgpdhr tghpthhtoheprhhushhtqdhfohhrqdhlihhnuhigsehvghgvrhdrkhgvrhhnvghlrdhorh hgpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdho rhhgpdhrtghpthhtohepfihilhhlsehkvghrnhgvlhdrohhrghdprhgtphhtthhopehmrg hrkhdrrhhuthhlrghnugesrghrmhdrtghomhdprhgtphhtthhopehtghhlgieslhhinhhu thhrohhnihigrdguvgdprhgtphhtthhopehojhgvuggrsehkvghrnhgvlhdrohhrghdprh gtphhtthhopehgrghrhiesghgrrhihghhuohdrnhgvth X-ME-Proxy: Feedback-ID: iad51458e:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 11 Jan 2026 07:02:51 -0500 (EST) From: Boqun Feng To: "Peter Zijlstra" , "Ingo Molnar" Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, "Will Deacon" , "Mark Rutland" , "Thomas Gleixner" , "Miguel Ojeda" , "Gary Guo" , "Alice Ryhl" , "Andreas Hindborg" , "Benno Lossin" , "Danilo Krummrich" , FUJITA Tomonori , Boqun Feng Subject: [PATCH 15/36] rust: sync: atomic: Prepare AtomicOps macros for i8/i16 support Date: Sun, 11 Jan 2026 20:01:48 +0800 Message-ID: <20260111120209.6133-13-boqun.feng@gmail.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260111120209.6133-1-boqun.feng@gmail.com> References: <20260111115808.5702-1-boqun.feng@gmail.com> <20260111120209.6133-1-boqun.feng@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: FUJITA Tomonori Rework the internal AtomicOps macro plumbing to generate per-type implementations from a mapping list. Capture the trait definition once and reuse it for both declaration and per-type impl expansion to reduce duplication and keep future extensions simple. This is a preparatory refactor for enabling i8/i16 atomics cleanly. Signed-off-by: FUJITA Tomonori Signed-off-by: Boqun Feng Link: https://patch.msgid.link/20251228120546.1602275-2-fujita.tomonori@gmail.com --- rust/kernel/sync/atomic/internal.rs | 85 ++++++++++++++++++++++------- 1 file changed, 66 insertions(+), 19 deletions(-) diff --git a/rust/kernel/sync/atomic/internal.rs b/rust/kernel/sync/atomic/internal.rs index 6fdd8e59f45b..41b4ce2935e3 100644 --- a/rust/kernel/sync/atomic/internal.rs +++ b/rust/kernel/sync/atomic/internal.rs @@ -156,16 +156,17 @@ fn [< atomic_ $func >]($($arg: $arg_type,)*) $(-> $ret)? { } } -// Delcares $ops trait with methods and implements the trait for `i32` and `i64`. -macro_rules! declare_and_impl_atomic_methods { - ($(#[$attr:meta])* $pub:vis trait $ops:ident { - $( - $(#[doc=$doc:expr])* - fn $func:ident [$($variant:ident),*]($($arg_sig:tt)*) $( -> $ret:ty)? { - $unsafe:tt { bindings::#call($($arg:tt)*) } - } - )* - }) => { +macro_rules! declare_atomic_ops_trait { + ( + $(#[$attr:meta])* $pub:vis trait $ops:ident { + $( + $(#[doc=$doc:expr])* + fn $func:ident [$($variant:ident),*]($($arg_sig:tt)*) $( -> $ret:ty)? { + $unsafe:tt { bindings::#call($($arg:tt)*) } + } + )* + } + ) => { $(#[$attr])* $pub trait $ops: AtomicImpl { $( @@ -175,21 +176,25 @@ fn $func:ident [$($variant:ident),*]($($arg_sig:tt)*) $( -> $ret:ty)? { ); )* } + } +} - impl $ops for i32 { +macro_rules! impl_atomic_ops_for_one { + ( + $ty:ty => $ctype:ident, + $(#[$attr:meta])* $pub:vis trait $ops:ident { $( - impl_atomic_method!( - (atomic) $func[$($variant)*]($($arg_sig)*) $(-> $ret)? { - $unsafe { call($($arg)*) } - } - ); + $(#[doc=$doc:expr])* + fn $func:ident [$($variant:ident),*]($($arg_sig:tt)*) $( -> $ret:ty)? { + $unsafe:tt { bindings::#call($($arg:tt)*) } + } )* } - - impl $ops for i64 { + ) => { + impl $ops for $ty { $( impl_atomic_method!( - (atomic64) $func[$($variant)*]($($arg_sig)*) $(-> $ret)? { + ($ctype) $func[$($variant)*]($($arg_sig)*) $(-> $ret)? { $unsafe { call($($arg)*) } } ); @@ -198,7 +203,47 @@ impl $ops for i64 { } } +// Declares $ops trait with methods and implements the trait. +macro_rules! declare_and_impl_atomic_methods { + ( + [ $($map:tt)* ] + $(#[$attr:meta])* $pub:vis trait $ops:ident { $($body:tt)* } + ) => { + declare_and_impl_atomic_methods!( + @with_ops_def + [ $($map)* ] + ( $(#[$attr])* $pub trait $ops { $($body)* } ) + ); + }; + + (@with_ops_def [ $($map:tt)* ] ( $($ops_def:tt)* )) => { + declare_atomic_ops_trait!( $($ops_def)* ); + + declare_and_impl_atomic_methods!( + @munch + [ $($map)* ] + ( $($ops_def)* ) + ); + }; + + (@munch [] ( $($ops_def:tt)* )) => {}; + + (@munch [ $ty:ty => $ctype:ident $(, $($rest:tt)*)? ] ( $($ops_def:tt)* )) => { + impl_atomic_ops_for_one!( + $ty => $ctype, + $($ops_def)* + ); + + declare_and_impl_atomic_methods!( + @munch + [ $($($rest)*)? ] + ( $($ops_def)* ) + ); + }; +} + declare_and_impl_atomic_methods!( + [ i32 => atomic, i64 => atomic64 ] /// Basic atomic operations pub trait AtomicBasicOps { /// Atomic read (load). @@ -216,6 +261,7 @@ fn set[release](a: &AtomicRepr, v: Self) { ); declare_and_impl_atomic_methods!( + [ i32 => atomic, i64 => atomic64 ] /// Exchange and compare-and-exchange atomic operations pub trait AtomicExchangeOps { /// Atomic exchange. @@ -243,6 +289,7 @@ fn try_cmpxchg[acquire, release, relaxed]( ); declare_and_impl_atomic_methods!( + [ i32 => atomic, i64 => atomic64 ] /// Atomic arithmetic operations pub trait AtomicArithmeticOps { /// Atomic add (wrapping). -- 2.51.0