[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <aXDc7KYgkD7g4HVd@tardis-2.local>
Date: Wed, 21 Jan 2026 22:04:28 +0800
From: Boqun Feng <boqun.feng@...il.com>
To: Alice Ryhl <aliceryhl@...gle.com>
Cc: Marco Elver <elver@...gle.com>, Gary Guo <gary@...yguo.net>,
linux-kernel@...r.kernel.org, rust-for-linux@...r.kernel.org,
linux-fsdevel@...r.kernel.org, kasan-dev@...glegroups.com,
Will Deacon <will@...nel.org>,
Peter Zijlstra <peterz@...radead.org>,
Mark Rutland <mark.rutland@....com>,
Miguel Ojeda <ojeda@...nel.org>,
Björn Roy Baron <bjorn3_gh@...tonmail.com>,
Benno Lossin <lossin@...nel.org>,
Andreas Hindborg <a.hindborg@...nel.org>,
Trevor Gross <tmgross@...ch.edu>,
Danilo Krummrich <dakr@...nel.org>,
Elle Rhumsaa <elle@...thered-steel.dev>,
"Paul E. McKenney" <paulmck@...nel.org>,
FUJITA Tomonori <fujita.tomonori@...il.com>
Subject: Re: [PATCH 2/2] rust: sync: atomic: Add atomic operation helpers
over raw pointers
On Wed, Jan 21, 2026 at 01:07:34PM +0000, Alice Ryhl wrote:
> On Wed, Jan 21, 2026 at 08:51:48PM +0800, Boqun Feng wrote:
> > On Wed, Jan 21, 2026 at 01:36:04PM +0100, Marco Elver wrote:
> > [..]
[...]
> >
> > Note that it also applies to atomic_read() and atomic_set() as well.
>
> Just to be completely clear ... am I to understand this that READ_ONCE()
> and the LKMM's atomic_load() *are* the exact same thing? Because if so,
> then this was really confusing:
>
> > my argument was not about naming, it's
> > about READ_ONCE() being more powerful than atomic load (no, not because
> > of address dependency, they are the same on that, it's because of the
> > behaviors of them regarding a current access on the same memory
> > location)
> > https://lore.kernel.org/all/aWuV858wU3MeYeaX@tardis-2.local/
>
> Are they the *exact* same thing or not? Do you mean that they are the
> same under LKMM, but different under some other context?
Right, they are the same thing under LKMM when used for inter-thread
synchronization when they are atomic. But when READ_ONCE() (and
__READ_ONCE()) used on types that are larger than machine word size,
they are not guaranteed to be atomic, hence semantics-wise READ_ONCE()
firstly guarantees "once" (volatile and no data race with WRITE_ONCE())
and then on certain types, it's atomic as well.
* In the case that we need atomicity, we should just use atomic_load().
* In the case that we don't need atomicity and no data race, we can just
use read_volatile().
* In the case that there is a non-atomic concurrent write, that suggests
we have a bug in C code or we simply should have some other
synchronization. Or if we believe the conncurrent write has at last
per-byte atomicity, then we can have `READ_ONCE()`-like function that
returns a `MaybeUninit` to bear the possible tearing.
Regards,
Boqun
>
> Alice
Powered by blists - more mailing lists