[PATCH 0/5] Add READ_ONCE and WRITE_ONCE to Rust
Alice Ryhl
aliceryhl at google.com
Wed Dec 31 16:53:39 PST 2025
On Wed, Dec 31, 2025 at 03:12:16PM +0000, Gary Guo wrote:
> On Wed, 31 Dec 2025 12:22:24 +0000
> Alice Ryhl <aliceryhl at google.com> wrote:
>
> > There are currently a few places in the kernel where we use volatile
> > reads when we really should be using `READ_ONCE`. To make it possible to
> > replace these with proper `READ_ONCE` calls, introduce a Rust version of
> > `READ_ONCE`.
> >
> > A new config option CONFIG_ARCH_USE_CUSTOM_READ_ONCE is introduced so
> > that Rust is able to use conditional compilation to implement READ_ONCE
> > in terms of either a volatile read, or by calling into a C helper
> > function, depending on the architecture.
> >
> > This series is intended to be merged through ATOMIC INFRASTRUCTURE.
>
> Hi Alice,
>
> I would prefer not to expose the READ_ONCE/WRITE_ONCE functions, at
> least not with their atomic semantics.
>
> Both callsites that you have converted should be using
>
> Atomic::from_ptr().load(Relaxed)
>
> Please refer to the documentation of `Atomic` about this. Fujita has a
> series that expand the type to u8/u16 if you need narrower accesses.
Why? If we say that we're using the LKMM, then it seems confusing to not
have a READ_ONCE() for cases where we interact with C code, and that C
code documents that READ_ONCE() should be used.
Alice
More information about the linux-arm-kernel
mailing list