]> Gentwo Git Trees - linux/.git/commit
rust: sync: Add basic atomic operation mapping framework
authorBoqun Feng <boqun.feng@gmail.com>
Fri, 5 Sep 2025 04:41:29 +0000 (21:41 -0700)
committerPeter Zijlstra <peterz@infradead.org>
Mon, 15 Sep 2025 07:38:32 +0000 (09:38 +0200)
commit2387fb2a9b84950dfe2eaa0b170f429e04b38168
tree470d39426abc6ee95eba5e55f603a39b6ec5c773
parentfdd7c7e0d2ab3987882c570612d4622f437292c7
rust: sync: Add basic atomic operation mapping framework

Preparation for generic atomic implementation. To unify the
implementation of a generic method over `i32` and `i64`, the C side
atomic methods need to be grouped so that in a generic method, they can
be referred as <type>::<method>, otherwise their parameters and return
value are different between `i32` and `i64`, which would require using
`transmute()` to unify the type into a `T`.

Introduce `AtomicImpl` to represent a basic type in Rust that has the
direct mapping to an atomic implementation from C. Use a sealed trait to
restrict `AtomicImpl` to only support `i32` and `i64` for now.

Further, different methods are put into different `*Ops` trait groups,
and this is for the future when smaller types like `i8`/`i16` are
supported but only with a limited set of API (e.g. only set(), load(),
xchg() and cmpxchg(), no add() or sub() etc).

While the atomic mod is introduced, documentation is also added for
memory models and data races.

Also bump my role to the maintainer of ATOMIC INFRASTRUCTURE to reflect
my responsibility on the Rust atomic mod.

Signed-off-by: Boqun Feng <boqun.feng@gmail.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Reviewed-by: Benno Lossin <lossin@kernel.org>
Reviewed-by: Elle Rhumsaa <elle@weathered-steel.dev>
Link: https://lore.kernel.org/all/20250719030827.61357-3-boqun.feng@gmail.com/
MAINTAINERS
rust/kernel/sync.rs
rust/kernel/sync/atomic.rs [new file with mode: 0644]
rust/kernel/sync/atomic/internal.rs [new file with mode: 0644]