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: helpers: Add i8/i16 relaxed atomic helpers

Add READ_ONCE/WRITE_ONCE based helpers for i8 and i16 types to support
relaxed atomic operations in Rust.

While relaxed operations could be implemented purely in Rust using
read_volatile() and write_volatile(), using C's READ_ONCE() and
WRITE_ONCE() macros ensures complete consistency with the kernel
memory model.

These helpers expose different symbol names than their C counterparts
so they are split into atomic_ext.c instead of atomic.c. The symbol
names; the names make the interface Rust/C clear, consistent with
i32/i64.

[boqun: Rename the functions from {load,store} to {read,set} to avoid
future adjustment]

Signed-off-by: FUJITA Tomonori <fujita.tomonori@gmail.com>
Reviewed-by: Gary Guo <gary@garyguo.net>
Reviewed-by: Joel Fernandes <joelagnelf@nvidia.com>
Signed-off-by: Boqun Feng <boqun.feng@gmail.com>
Link: https://patch.msgid.link/20251211113826.1299077-3-fujita.tomonori@gmail.com

authored by

FUJITA Tomonori and committed by
Boqun Feng
300e53b3 2cc3d5d6

+21
+21
rust/helpers/atomic_ext.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0 2 2 3 3 #include <asm/barrier.h> 4 + #include <asm/rwonce.h> 5 + 6 + __rust_helper s8 rust_helper_atomic_i8_read(s8 *ptr) 7 + { 8 + return READ_ONCE(*ptr); 9 + } 4 10 5 11 __rust_helper s8 rust_helper_atomic_i8_read_acquire(s8 *ptr) 6 12 { 7 13 return smp_load_acquire(ptr); 14 + } 15 + 16 + __rust_helper s16 rust_helper_atomic_i16_read(s16 *ptr) 17 + { 18 + return READ_ONCE(*ptr); 8 19 } 9 20 10 21 __rust_helper s16 rust_helper_atomic_i16_read_acquire(s16 *ptr) ··· 23 12 return smp_load_acquire(ptr); 24 13 } 25 14 15 + __rust_helper void rust_helper_atomic_i8_set(s8 *ptr, s8 val) 16 + { 17 + WRITE_ONCE(*ptr, val); 18 + } 19 + 26 20 __rust_helper void rust_helper_atomic_i8_set_release(s8 *ptr, s8 val) 27 21 { 28 22 smp_store_release(ptr, val); 23 + } 24 + 25 + __rust_helper void rust_helper_atomic_i16_set(s16 *ptr, s16 val) 26 + { 27 + WRITE_ONCE(*ptr, val); 29 28 } 30 29 31 30 __rust_helper void rust_helper_atomic_i16_set_release(s16 *ptr, s16 val)