From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ua1-f44.google.com (mail-ua1-f44.google.com [209.85.222.44]) (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 ED04E3E8C48 for ; Tue, 20 Jan 2026 22:51:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.44 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768949499; cv=none; b=CWBIAXqPXuriIPWpnZ50mE/HyyQnF3MKegwH9ODEOe8HO4U7HRiCqseIKttxQB8x/c45LiMu+eybpHfdomv3u7EMTdUyCcEfX6P8BTsP3XyynUPuvaurbRM2vfNrhao6LC1pNyiWpSMOInJtFhX4MDDTO9oH3o5d6LrYAlxq18A= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768949499; c=relaxed/simple; bh=SCuvlNzEZ7UQ+2kx4IZoBg20PyTWVc8GwsruEBfjr9w=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=q79U3OLvv772JutP5vP8J8XuvMU/1Hchyl+T1dl4JRBan6GgUsToO4ayM50AHgQUfN4FVbS/+Nf2Oud0Za1qY+p3zjN9aPBwiiteuAwiiQjmAT+QdRbQZQPdsoFnCscFyWSI6ge1CZtxKmUBuO+3BwRu7I/Q7BiXnpCUXpHAeGk= 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=IzCQCuwo; arc=none smtp.client-ip=209.85.222.44 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="IzCQCuwo" Received: by mail-ua1-f44.google.com with SMTP id a1e0cc1a2514c-94803734b11so676663241.2 for ; Tue, 20 Jan 2026 14:51:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1768949496; x=1769554296; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:feedback-id:from:to:cc:subject:date :message-id:reply-to; bh=eaX7O8khQ4I4NV6eOiLSvzgbdQ/3C6pFK5pqXcxYMdw=; b=IzCQCuwoNOWRWqGLM/X3TtsLchRIZizKyVXSHzlDrbZvWnHsBv0cwzRgnlYDDzHpCt bCnub7ZbmDm//oiI83ygCKGOxOEbSsAQFo+uEnSBGffv90lcdC4QPFj8ZU82tXijheyB U07S6EQ+oGvcns1UKaoa4eYaTbA7yrtRZq1r59ypbFovoCFh6e6lqMPV3rR8oAkkbjpO PmqT+YwaxpPtVQqTdFbagYTzundoflkiqk1lE/q8FkSwMlpdlatE+DXqDWoIh3oTICMp 7BsUBoL5UTVWAhqmQTZNh89RHHg94t31j2u5MhmrR7aNr9075zEf7w2cAzS05p3reGfA Oc3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768949496; x=1769554296; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:feedback-id:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=eaX7O8khQ4I4NV6eOiLSvzgbdQ/3C6pFK5pqXcxYMdw=; b=ItQntM8m/KD8bFQzUdO1QxF1vL3cvknR7uoFUODtuyplanBwItuwp1QZCGsoUB2ngf KjG/08RPuDg+91xwTRBwqMFV+4ZJOafu+8hLAJdmR7sxN68tsq6M0q3Q4RBMAoObQ3R0 pTneZgUZrVkSD+bNYIuvCoz5z4cXBL5iU+VlnWQADwJ9Fb2Z7CzoVhe2m0zErQ7s/31J ooSSJvNM3OeBfQLUgjRqCJlWJDSV8S+2WYxrsC6UpT2996uyFklAiFLOo6MFc43raKga 6iFq0qXo2eL2N+GSVmd89upIZD9/dLQg/HkrUmktsMfXdStF6KfUyMXZa0W6dxU2EzAz /+yA== X-Forwarded-Encrypted: i=1; AJvYcCVU9asthEVZtNpkOs49kwaC0KQFG0r7AsZ5Foi/4wZwEc0j+JDip+gAds/a3r/mg2/xi0Dzzla0df5PwIc=@vger.kernel.org X-Gm-Message-State: AOJu0YxpRFz5sqSBPDtdSeVV/PPTcgtPNJedrll9NndA2lv04kQyD1VU JCNasAo5n41/k1TUlGK/II5FKMarl/kWexpP/29RgHeWmr4oCmwuljKT X-Gm-Gg: AZuq6aKgkX+3h2mqGgUZd4cTMlq6isn9NGRtBZ1MfIgXRG9PiORUc9Ib4n7hova6JTY QyOMYgqRUDA8O5W4BMgp3vNABY0YI5CE7aPBnzkezxOLMSQFAGhO1aIgMLCtHDgqod3pGz7pmby Obw5fwOqk8jFFAOEjXGX5JV8Z5H/0XoccdCgd4GJR7H7e+nELNdR4WO+lPif9mcwRQSFnQ3Nw3/ uRGZK2dCKsQ9K6gxtN8HJ+PNBM8oO/lOHHGs3Hs4a1CTMspw/hOV3zW1YMIEgY7czpzL1O1HYDJ Ec0h2nyUlilppjVZC2WgSkopZC/BEDBslngPTWFnIdiapSYqzdYEAYfe1lbWmQr27proZRZe9CM yTMbLXgtsk+c0hJeW76z5yBRdKgyEah13tILyBL4kAS7b/1boLBOrv65ILkpXvbnCGOMHGbA7mP I7RNAZpHSctBmytRQYRX5txpy52fKZOMxSrO0Sfqo6x4YM86eNTmK6Va3IotU75IsedhnILvfPJ Qn/kC1eBNEa76Zgv7O7NsekKg== X-Received: by 2002:a05:620a:178e:b0:8c6:ab8b:29cf with SMTP id af79cd13be357-8c6ccdab52amr397765885a.17.1768943033146; Tue, 20 Jan 2026 13:03:53 -0800 (PST) Received: from fauth-a1-smtp.messagingengine.com (fauth-a1-smtp.messagingengine.com. [103.168.172.200]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-8942e6043a6sm117196466d6.18.2026.01.20.13.03.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Jan 2026 13:03:52 -0800 (PST) Received: from phl-compute-08.internal (phl-compute-08.internal [10.202.2.48]) by mailfauth.phl.internal (Postfix) with ESMTP id 33A63F4006D; Tue, 20 Jan 2026 16:03:51 -0500 (EST) Received: from phl-frontend-03 ([10.202.2.162]) by phl-compute-08.internal (MEProxy); Tue, 20 Jan 2026 16:03:51 -0500 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefgedrtddtgddugedugeegucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu rghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujf gurhepfffhvfevuffkfhggtggujgesthdtredttddtvdenucfhrhhomhepuehoqhhunhcu hfgvnhhguceosghoqhhunhdrfhgvnhhgsehgmhgrihhlrdgtohhmqeenucggtffrrghtth gvrhhnpeejiefhtdeuvdegvddtudffgfegfeehgfdtiedvveevleevhfekhefftdekieeh vdenucffohhmrghinheprhhushhtqdhlrghnghdrohhrghenucevlhhushhtvghrufhiii gvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegsohhquhhnodhmvghsmhhtphgruhht hhhpvghrshhonhgrlhhithihqdeiledvgeehtdeigedqudejjeekheehhedvqdgsohhquh hnrdhfvghngheppehgmhgrihhlrdgtohhmsehfihigmhgvrdhnrghmvgdpnhgspghrtghp thhtohepvdekpdhmohguvgepshhmthhpohhuthdprhgtphhtthhopehgrghrhiesghgrrh ihghhuohdrnhgvthdprhgtphhtthhopehruhhsthdqfhhorhdqlhhinhhugiesvhhgvghr rdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehlihhnuhigqdhkvghrnhgvlhesvhhgvg hrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehrtghusehvghgvrhdrkhgvrhhnvghl rdhorhhgpdhrtghpthhtohepohhjvggurgeskhgvrhhnvghlrdhorhhgpdhrtghpthhtoh epsghjohhrnhefpghghhesphhrohhtohhnmhgrihhlrdgtohhmpdhrtghpthhtoheplhho shhsihhnsehkvghrnhgvlhdrohhrghdprhgtphhtthhopegrrdhhihhnuggsohhrgheskh gvrhhnvghlrdhorhhgpdhrtghpthhtoheprghlihgtvghrhihhlhesghhoohhglhgvrdgt ohhm X-ME-Proxy: Feedback-ID: iad51458e:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 20 Jan 2026 16:03:50 -0500 (EST) Date: Wed, 21 Jan 2026 05:03:48 +0800 From: Boqun Feng To: Gary Guo Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, rcu@vger.kernel.org, Miguel Ojeda , =?iso-8859-1?Q?Bj=F6rn?= Roy Baron , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich , Will Deacon , Peter Zijlstra , Mark Rutland , "Paul E. McKenney" , Frederic Weisbecker , Neeraj Upadhyay , Joel Fernandes , Josh Triplett , Uladzislau Rezki , Steven Rostedt , Mathieu Desnoyers , Lai Jiangshan , Zqiang , FUJITA Tomonori , Dirk Behme , Dirk Behme Subject: Re: [PATCH v2 1/2] rust: sync: atomic: Clarify the need of CONFIG_ARCH_SUPPORTS_ATOMIC_RMW Message-ID: References: <20260120140503.62804-1-boqun.feng@gmail.com> <20260120140503.62804-2-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-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Tue, Jan 20, 2026 at 04:54:51PM +0000, Gary Guo wrote: > On Tue Jan 20, 2026 at 2:05 PM GMT, Boqun Feng wrote: > > Currently, since all the architectures that support Rust all have > > CONFIG_ARCH_SUPPORTS_ATOMIC_RMW selected, the helpers of atomic > > load/store on i8 and i16 relies on CONFIG_ARCH_SUPPORTS_ATOMIC_RMW=y. > > It's generally fine since most of architectures support that. > > > > The plan for CONFIG_ARCH_SUPPORTS_ATOMIC_RMW=n architectures is adding > > their (probably lock-based) atomic load/store for i8 and i16 as their > > atomic_{read,set}() and atomic64_{read,set}() counterpart when they > > plans to support Rust. > > > > Hence use a statis_assert!() to check this and remind the future us the > > need of the helpers. This is more clear than the #[cfg] on impl blocks > > of i8 and i16. > > > > Suggested-by: Dirk Behme > > Suggested-by: Benno Lossin > > Signed-off-by: Boqun Feng > > Reviewed-by: Gary Guo > Thanks! > > --- > > rust/kernel/sync/atomic/internal.rs | 19 +++++++++++++------ > > 1 file changed, 13 insertions(+), 6 deletions(-) > > > > diff --git a/rust/kernel/sync/atomic/internal.rs b/rust/kernel/sync/atomic/internal.rs > > index 0dac58bca2b3..ef516bcb02ee 100644 > > --- a/rust/kernel/sync/atomic/internal.rs > > +++ b/rust/kernel/sync/atomic/internal.rs > > @@ -37,16 +37,23 @@ pub trait AtomicImpl: Sized + Send + Copy + private::Sealed { > > type Delta; > > } > > > > -// The current helpers of load/store uses `{WRITE,READ}_ONCE()` hence the atomicity is only > > -// guaranteed against read-modify-write operations if the architecture supports native atomic RmW. > > -#[cfg(CONFIG_ARCH_SUPPORTS_ATOMIC_RMW)] > > +// The current helpers of load/store of atomic `i8` and `i16` use `{WRITE,READ}_ONCE()` hence the > > +// atomicity is only guaranteed against read-modify-write operations if the architecture supports > > +// native atomic RmW. > > +// > > +// In the future when a CONFIG_ARCH_SUPPORTS_ATOMIC_RMW=n architecture plans to support Rust, the > > +// load/store helpers that guarantee atomicity against RmW operations (usually via a lock) need to > > +// be added. > > +crate::static_assert!( > > + cfg!(CONFIG_ARCH_SUPPORTS_ATOMIC_RMW), > > + "The current implementation of atomic i8/i16/ptr relies on the architecure being \ > > + ARCH_SUPPORTS_ATOMIC_RMW" > > The printed string when assertion fails will have 5 spaces between "being" and > "ARCH", although it probably doesn't matter.. > Are you sure? My test result shows: ERROR:root:error[E0080]: evaluation panicked: The current implementation of atomic i8/i16/ptr relies on the architecure being ARCH_SUPPORTS_ATOMIC_RMW similar is the following playground example: https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=5dd0098247503be792bc35cda8f2630f Regards, Boqun > Best, > Gary > > > +); > > + > > impl AtomicImpl for i8 { > > type Delta = Self; > > } > > > > -// The current helpers of load/store uses `{WRITE,READ}_ONCE()` hence the atomicity is only > > -// guaranteed against read-modify-write operations if the architecture supports native atomic RmW. > > -#[cfg(CONFIG_ARCH_SUPPORTS_ATOMIC_RMW)] > > impl AtomicImpl for i16 { > > type Delta = Self; > > } >