Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

rust: sync: atomic: Clarify the need of CONFIG_ARCH_SUPPORTS_ATOMIC_RMW

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 <dirk.behme@gmail.com>
Suggested-by: Benno Lossin <lossin@kernel.org>
Signed-off-by: Boqun Feng <boqun.feng@gmail.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: Gary Guo <gary@garyguo.net>
Link: https://patch.msgid.link/20260120140503.62804-2-boqun.feng@gmail.com
Link: https://patch.msgid.link/20260303201701.12204-7-boqun@kernel.org

authored by

Boqun Feng and committed by
Peter Zijlstra
553c02fb a92236bf

+13 -6
+13 -6
rust/kernel/sync/atomic/internal.rs
··· 37 37 type Delta; 38 38 } 39 39 40 - // The current helpers of load/store uses `{WRITE,READ}_ONCE()` hence the atomicity is only 41 - // guaranteed against read-modify-write operations if the architecture supports native atomic RmW. 42 - #[cfg(CONFIG_ARCH_SUPPORTS_ATOMIC_RMW)] 40 + // The current helpers of load/store of atomic `i8` and `i16` use `{WRITE,READ}_ONCE()` hence the 41 + // atomicity is only guaranteed against read-modify-write operations if the architecture supports 42 + // native atomic RmW. 43 + // 44 + // In the future when a CONFIG_ARCH_SUPPORTS_ATOMIC_RMW=n architecture plans to support Rust, the 45 + // load/store helpers that guarantee atomicity against RmW operations (usually via a lock) need to 46 + // be added. 47 + crate::static_assert!( 48 + cfg!(CONFIG_ARCH_SUPPORTS_ATOMIC_RMW), 49 + "The current implementation of atomic i8/i16/ptr relies on the architecure being \ 50 + ARCH_SUPPORTS_ATOMIC_RMW" 51 + ); 52 + 43 53 impl AtomicImpl for i8 { 44 54 type Delta = Self; 45 55 } 46 56 47 - // The current helpers of load/store uses `{WRITE,READ}_ONCE()` hence the atomicity is only 48 - // guaranteed against read-modify-write operations if the architecture supports native atomic RmW. 49 - #[cfg(CONFIG_ARCH_SUPPORTS_ATOMIC_RMW)] 50 57 impl AtomicImpl for i16 { 51 58 type Delta = Self; 52 59 }