From: Boqun Feng <boqun.feng@gmail.com>
To: Alice Ryhl <aliceryhl@google.com>
Cc: "Marco Elver" <elver@google.com>, "Gary Guo" <gary@garyguo.net>,
linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org,
linux-fsdevel@vger.kernel.org, kasan-dev@googlegroups.com,
"Will Deacon" <will@kernel.org>,
"Peter Zijlstra" <peterz@infradead.org>,
"Mark Rutland" <mark.rutland@arm.com>,
"Miguel Ojeda" <ojeda@kernel.org>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Benno Lossin" <lossin@kernel.org>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Trevor Gross" <tmgross@umich.edu>,
"Danilo Krummrich" <dakr@kernel.org>,
"Elle Rhumsaa" <elle@weathered-steel.dev>,
"Paul E. McKenney" <paulmck@kernel.org>,
"FUJITA Tomonori" <fujita.tomonori@gmail.com>
Subject: Re: [PATCH 2/2] rust: sync: atomic: Add atomic operation helpers over raw pointers
Date: Wed, 21 Jan 2026 22:04:28 +0800 [thread overview]
Message-ID: <aXDc7KYgkD7g4HVd@tardis-2.local> (raw)
In-Reply-To: <aXDPliPQs8jU_wfz@google.com>
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
next prev parent reply other threads:[~2026-01-21 15:54 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-20 11:52 [PATCH 0/2] Provide Rust atomic " Boqun Feng
2026-01-20 11:52 ` [PATCH 1/2] rust: sync: atomic: Remove bound `T: Sync` for `Atomci::from_ptr()` Boqun Feng
2026-01-20 12:38 ` Alice Ryhl
2026-01-20 12:39 ` Alice Ryhl
2026-01-20 13:09 ` Gary Guo
2026-01-20 11:52 ` [PATCH 2/2] rust: sync: atomic: Add atomic operation helpers over raw pointers Boqun Feng
2026-01-20 12:40 ` Alice Ryhl
2026-01-20 13:25 ` Gary Guo
2026-01-20 13:46 ` Boqun Feng
2026-01-20 16:23 ` Marco Elver
2026-01-20 16:47 ` Gary Guo
2026-01-20 17:10 ` Marco Elver
2026-01-20 17:32 ` Gary Guo
2026-01-20 20:52 ` Boqun Feng
2026-01-21 12:13 ` Marco Elver
2026-01-21 12:58 ` Boqun Feng
2026-01-21 13:09 ` Alice Ryhl
2026-01-21 12:19 ` Alice Ryhl
2026-01-21 12:36 ` Marco Elver
2026-01-21 12:51 ` Boqun Feng
2026-01-21 13:07 ` Alice Ryhl
2026-01-21 14:04 ` Boqun Feng [this message]
2026-01-21 13:42 ` Gary Guo
2026-01-20 17:12 ` Gary Guo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aXDc7KYgkD7g4HVd@tardis-2.local \
--to=boqun.feng@gmail.com \
--cc=a.hindborg@kernel.org \
--cc=aliceryhl@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=dakr@kernel.org \
--cc=elle@weathered-steel.dev \
--cc=elver@google.com \
--cc=fujita.tomonori@gmail.com \
--cc=gary@garyguo.net \
--cc=kasan-dev@googlegroups.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=mark.rutland@arm.com \
--cc=ojeda@kernel.org \
--cc=paulmck@kernel.org \
--cc=peterz@infradead.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=tmgross@umich.edu \
--cc=will@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®