From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f73.google.com (mail-wm1-f73.google.com [209.85.128.73]) (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 46DFA35C190 for ; Wed, 21 Jan 2026 12:19:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.73 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768997951; cv=none; b=pM+VRZkWAiNHVfYzWEWhH4o25D7sVPjcB+FQ3hyosgdED1mN4YVL9k4lMjkPfnOHNX55Dmc3ZmhHOK7ZBTx8hCwVYGpz/eYdZq5cwponxeUGAnkO2W0WMgCeLjcEgp6dUdU3bvBICbl+6wnt3uBNVbSDUnaFJ8C14EoyO04ItG8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768997951; c=relaxed/simple; bh=6Dcu8/bULslvO91L7SspBkSyK9LD8GT4ussbXNPXvLQ=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=U43q6mGfdifZPMZSMicH2N0bxbWzVUYT59Mn9xbXVnDpcOGOfdWzq6iHO2kdvBIYuScMzugBprM+9QmYn+VjhuaGNNPSRXFaA6AXYaP1Mzb54PlbG9RED0HagDcu4V7ay9GVpxBMScxORkzAjEDRgRskT2tBmc1oFXqB8eIFbXo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--aliceryhl.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=2ngn+bRU; arc=none smtp.client-ip=209.85.128.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--aliceryhl.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="2ngn+bRU" Received: by mail-wm1-f73.google.com with SMTP id 5b1f17b1804b1-4779ecc3cc8so47551145e9.3 for ; Wed, 21 Jan 2026 04:19:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1768997946; x=1769602746; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=tW692zqK7I63nrKQN1683F1Ixt/sQ4szIigR0l7y37E=; b=2ngn+bRUwxeDJmnW1ui4ycBm90U0fIRaM+5H0HhP/1KnryGObeXIOVGynEAonVpMcx NzUhynvPno6XOFx21Jy+yibP1glYYw0U0zvVF2f7pDVC7fGcCjHMVyEiSnjHNnMeKXVW cqaFMB1l6IAvAglNMM5SWbzVzVsB9FlUuzt3t5chdkXz2pIsuelMbx9wa6rAagaXxof9 iAncmp1EgIn3prq28td38N3lp7ZAlsho2Qlt1Ipf027zOkEdA11JualYvrmo2du/sHVf Ml4VCHlfEkSWBYdbj74y+bhHx029V9YnPOsSkEOL2/Hi6fT+8mY0FyKQq6silo57RGxY Q3Mw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768997946; x=1769602746; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=tW692zqK7I63nrKQN1683F1Ixt/sQ4szIigR0l7y37E=; b=lYXIQADIKqxPbuknMWy4uyTP0ROI+MyNkixBlzflYgZuojBBuMzJ5xLsnJpf16A/Di lOH9/sFsvckPaDu/4MEBzKCFkhFE9nZ303sqM94G38htHhv2iEJx9RYBP7C7ukwKlvz4 rPkHiEm/VNieJDcY09SOwErLQK0JBracUEW/ELJt7f+NOrBObWWuPs6Xb0kYtgGFsSvV z2YAdCQmt4JSp0Q9SiuZsCKlep+GYa01saoE54K5seXVODsNmxLQsnxa50+kb1lXksgA yIJNmDYyVbFWu1tmtSeDYLTmQe7C1Ez6h/FinhAIdzqwpg9eGR9/G/B+N/MXQuaWXYlf Aq2g== X-Forwarded-Encrypted: i=1; AJvYcCUK4gFdID9jGXkIWIV8C7r4Zc9CMmvkgvVGCVUISHGbVH51iqclK+1QZYRWB9lkfkZC4sIc87R6s/I0f2w=@vger.kernel.org X-Gm-Message-State: AOJu0YxfROISEnD0N0eEwdtcBAAj59Pkmzy+RI7KBBGpil/l+at7ZTE4 MxQlCGbCnY1KVfua1GOleq0U83v3TmAyUHiDhq+dtFLimuUeLGnfrkDq+sQW59gYOlJ47qaZVzJ 4Kw7B6bzMGADrCPYh5w== X-Received: from wmcu4.prod.google.com ([2002:a7b:c044:0:b0:47e:db03:6850]) (user=aliceryhl job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:45d1:b0:471:14b1:da13 with SMTP id 5b1f17b1804b1-4803e7a2c17mr77774955e9.14.1768997946591; Wed, 21 Jan 2026 04:19:06 -0800 (PST) Date: Wed, 21 Jan 2026 12:19:05 +0000 In-Reply-To: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260120115207.55318-1-boqun.feng@gmail.com> <20260120115207.55318-3-boqun.feng@gmail.com> Message-ID: Subject: Re: [PATCH 2/2] rust: sync: atomic: Add atomic operation helpers over raw pointers From: Alice Ryhl To: Gary Guo Cc: Marco Elver , Boqun Feng , linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-fsdevel@vger.kernel.org, kasan-dev@googlegroups.com, Will Deacon , Peter Zijlstra , Mark Rutland , Miguel Ojeda , "=?utf-8?B?QmrDtnJu?= Roy Baron" , Benno Lossin , Andreas Hindborg , Trevor Gross , Danilo Krummrich , Elle Rhumsaa , "Paul E. McKenney" , FUJITA Tomonori Content-Type: text/plain; charset="utf-8" On Tue, Jan 20, 2026 at 04:47:00PM +0000, Gary Guo wrote: > On Tue Jan 20, 2026 at 4:23 PM GMT, Marco Elver wrote: > > On Tue, Jan 20, 2026 at 07:52PM +0800, Boqun Feng wrote: > >> In order to synchronize with C or external, atomic operations over raw > >> pointers, althought previously there is always an `Atomic::from_ptr()` > >> to provide a `&Atomic`. However it's more convenient to have helpers > >> that directly perform atomic operations on raw pointers. Hence a few are > >> added, which are basically a `Atomic::from_ptr().op()` wrapper. > >> > >> Note: for naming, since `atomic_xchg()` and `atomic_cmpxchg()` has a > >> conflict naming to 32bit C atomic xchg/cmpxchg, hence they are just > >> named as `xchg()` and `cmpxchg()`. For `atomic_load()` and > >> `atomic_store()`, their 32bit C counterparts are `atomic_read()` and > >> `atomic_set()`, so keep the `atomic_` prefix. > >> > >> Signed-off-by: Boqun Feng > >> --- > >> rust/kernel/sync/atomic.rs | 104 +++++++++++++++++++++++++++ > >> rust/kernel/sync/atomic/predefine.rs | 46 ++++++++++++ > >> 2 files changed, 150 insertions(+) > >> > >> diff --git a/rust/kernel/sync/atomic.rs b/rust/kernel/sync/atomic.rs > >> index d49ee45c6eb7..6c46335bdb8c 100644 > >> --- a/rust/kernel/sync/atomic.rs > >> +++ b/rust/kernel/sync/atomic.rs > >> @@ -611,3 +611,107 @@ pub fn cmpxchg( > >> } > >> } > >> } > >> + > >> +/// Atomic load over raw pointers. > >> +/// > >> +/// This function provides a short-cut of `Atomic::from_ptr().load(..)`, and can be used to work > >> +/// with C side on synchronizations: > >> +/// > >> +/// - `atomic_load(.., Relaxed)` maps to `READ_ONCE()` when using for inter-thread communication. > >> +/// - `atomic_load(.., Acquire)` maps to `smp_load_acquire()`. > > > > I'm late to the party and may have missed some discussion, but it might > > want restating in the documentation and/or commit log: > > > > READ_ONCE is meant to be a dependency-ordering primitive, i.e. be more > > like memory_order_consume than it is memory_order_relaxed. This has, to > > the best of my knowledge, not changed; otherwise lots of kernel code > > would be broken. > > On the Rust-side documentation we mentioned that `Relaxed` always preserve > dependency ordering, so yes, it is closer to `consume` in the C11 model. Like in the other thread, I still think this is a mistake. Let's be explicit about intent and call things that they are. https://lore.kernel.org/all/aXDCTvyneWOeok2L@google.com/ > If the idea is to add an explicit `Consume` ordering on the Rust side to > document the intent clearly, then I am actually somewhat in favour. > > This way, we can for example, map it to a `READ_ONCE` in most cases, but we can > also provide an option to upgrade such calls to `smp_load_acquire` in certain > cases when needed, e.g. LTO arm64. It always maps to READ_ONCE(), no? It's just that on LTO arm64 the READ_ONCE() macro is implemented like smp_load_acquire(). > However this will mean that Rust code will have one more ordering than the C > API, so I am keen on knowing how Boqun, Paul, Peter and others think about this. On that point, my suggestion would be to use the standard LKMM naming such as rcu_dereference() or READ_ONCE(). I'm told that READ_ONCE() apparently has stronger guarantees than an atomic consume load, but I'm not clear on what they are. Alice