From: Boqun Feng <boqun.feng@gmail.com>
To: FUJITA Tomonori <fujita.tomonori@gmail.com>
Cc: ojeda@kernel.org, a.hindborg@kernel.org, aliceryhl@google.com,
bjorn3_gh@protonmail.com, dakr@kernel.org, gary@garyguo.net,
lossin@kernel.org, tmgross@umich.edu, acourbot@nvidia.com,
rust-for-linux@vger.kernel.org, linux-arch@vger.kernel.org
Subject: Re: [PATCH v1 2/3] rust: sync: atomic: Remove workaround macro for i8/i16 BasicOps
Date: Mon, 29 Dec 2025 19:58:48 +0800 [thread overview]
Message-ID: <aVJs-D4V1IpfzR7z@tardis-2.local> (raw)
In-Reply-To: <20251228120546.1602275-3-fujita.tomonori@gmail.com>
On Sun, Dec 28, 2025 at 09:05:45PM +0900, FUJITA Tomonori wrote:
> Remove workaround impl_atomic_only_load_and_store_ops macro and use
> declare_and_impl_atomic_methods to add AtomicBasicOps support for
> i8/i16.
>
I did the following so that we can drop this ;-)
1. Change function names of [1] and [2] from *{load,store}* to
*{read,set}*.
2. Reorder [3] before [4] to avoid introduction of
impl_atomic_only_load_and_store_ops!()
[1]: https://lore.kernel.org/all/20251211113826.1299077-3-fujita.tomonori@gmail.com/
[2]: https://lore.kernel.org/all/20251211113826.1299077-2-fujita.tomonori@gmail.com/
[3]: https://lore.kernel.org/all/20251228120546.1602275-2-fujita.tomonori@gmail.com/
[4]: https://lore.kernel.org/all/20251211113826.1299077-4-fujita.tomonori@gmail.com/
I also reorder a bit to make the introduction of helpers are grouped
together, please see at
https://git.kernel.org/pub/scm/linux/kernel/git/boqun/linux.git/log/?h=rust-sync.20251229
I feel this way we have a cleaner history of changes.
Thanks!
Regards,
Boqun
> Signed-off-by: FUJITA Tomonori <fujita.tomonori@gmail.com>
> ---
> rust/helpers/atomic_ext.c | 16 +++++-----
> rust/kernel/sync/atomic/internal.rs | 48 +----------------------------
> 2 files changed, 9 insertions(+), 55 deletions(-)
>
> diff --git a/rust/helpers/atomic_ext.c b/rust/helpers/atomic_ext.c
> index 3a5ef6bb2776..10733bb4a75e 100644
> --- a/rust/helpers/atomic_ext.c
> +++ b/rust/helpers/atomic_ext.c
> @@ -4,42 +4,42 @@
> #include <asm/rwonce.h>
> #include <linux/atomic.h>
>
> -__rust_helper s8 rust_helper_atomic_i8_load(s8 *ptr)
> +__rust_helper s8 rust_helper_atomic_i8_read(s8 *ptr)
> {
> return READ_ONCE(*ptr);
> }
>
> -__rust_helper s8 rust_helper_atomic_i8_load_acquire(s8 *ptr)
> +__rust_helper s8 rust_helper_atomic_i8_read_acquire(s8 *ptr)
> {
> return smp_load_acquire(ptr);
> }
>
> -__rust_helper s16 rust_helper_atomic_i16_load(s16 *ptr)
> +__rust_helper s16 rust_helper_atomic_i16_read(s16 *ptr)
> {
> return READ_ONCE(*ptr);
> }
>
> -__rust_helper s16 rust_helper_atomic_i16_load_acquire(s16 *ptr)
> +__rust_helper s16 rust_helper_atomic_i16_read_acquire(s16 *ptr)
> {
> return smp_load_acquire(ptr);
> }
>
> -__rust_helper void rust_helper_atomic_i8_store(s8 *ptr, s8 val)
> +__rust_helper void rust_helper_atomic_i8_set(s8 *ptr, s8 val)
> {
> WRITE_ONCE(*ptr, val);
> }
>
> -__rust_helper void rust_helper_atomic_i8_store_release(s8 *ptr, s8 val)
> +__rust_helper void rust_helper_atomic_i8_set_release(s8 *ptr, s8 val)
> {
> smp_store_release(ptr, val);
> }
>
> -__rust_helper void rust_helper_atomic_i16_store(s16 *ptr, s16 val)
> +__rust_helper void rust_helper_atomic_i16_set(s16 *ptr, s16 val)
> {
> WRITE_ONCE(*ptr, val);
> }
>
> -__rust_helper void rust_helper_atomic_i16_store_release(s16 *ptr, s16 val)
> +__rust_helper void rust_helper_atomic_i16_set_release(s16 *ptr, s16 val)
> {
> smp_store_release(ptr, val);
> }
> diff --git a/rust/kernel/sync/atomic/internal.rs b/rust/kernel/sync/atomic/internal.rs
> index 0634368d10d2..1b2a7933bc14 100644
> --- a/rust/kernel/sync/atomic/internal.rs
> +++ b/rust/kernel/sync/atomic/internal.rs
> @@ -256,7 +256,7 @@ macro_rules! declare_and_impl_atomic_methods {
> }
>
> declare_and_impl_atomic_methods!(
> - [ i32 => atomic, i64 => atomic64 ]
> + [ i8 => atomic_i8, i16 => atomic_i16, i32 => atomic, i64 => atomic64 ]
> /// Basic atomic operations
> pub trait AtomicBasicOps {
> /// Atomic read (load).
> @@ -273,15 +273,6 @@ fn set[release](a: &AtomicRepr<Self>, v: Self) {
> }
> );
>
> -// It is still unclear whether i8/i16 atomics will eventually support
> -// the same set of operations as i32/i64, because some architectures
> -// do not provide hardware support for the required atomic primitives.
> -// Furthermore, supporting Atomic<bool> will require even more
> -// significant structural changes.
> -//
> -// To avoid premature refactoring, a separate macro for i8 and i16 is
> -// used for now, leaving the existing macros untouched until the overall
> -// design requirements are settled.
> declare_and_impl_atomic_methods!(
> [ i32 => atomic, i64 => atomic64 ]
> /// Exchange and compare-and-exchange atomic operations
> @@ -332,40 +323,3 @@ fn fetch_add[acquire, release, relaxed](a: &AtomicRepr<Self>, v: Self::Delta) ->
> }
> }
> );
> -
> -macro_rules! impl_atomic_only_load_and_store_ops {
> - ($($ty:ty),* $(,)?) => {
> - $(
> - impl AtomicBasicOps for $ty {
> - paste! {
> - #[inline(always)]
> - fn atomic_read(a: &AtomicRepr<Self>) -> Self {
> - // SAFETY: `a.as_ptr()` is valid and properly aligned.
> - unsafe { bindings::[< atomic_ $ty _load >](a.as_ptr().cast()) }
> - }
> -
> - #[inline(always)]
> - fn atomic_read_acquire(a: &AtomicRepr<Self>) -> Self {
> - // SAFETY: `a.as_ptr()` is valid and properly aligned.
> - unsafe { bindings::[< atomic_ $ty _load_acquire >](a.as_ptr().cast()) }
> - }
> -
> - // Generate atomic_set and atomic_set_release
> - #[inline(always)]
> - fn atomic_set(a: &AtomicRepr<Self>, v: Self) {
> - // SAFETY: `a.as_ptr()` is valid and properly aligned.
> - unsafe { bindings::[< atomic_ $ty _store >](a.as_ptr().cast(), v) }
> - }
> -
> - #[inline(always)]
> - fn atomic_set_release(a: &AtomicRepr<Self>, v: Self) {
> - // SAFETY: `a.as_ptr()` is valid and properly aligned.
> - unsafe { bindings::[< atomic_ $ty _store_release >](a.as_ptr().cast(), v) }
> - }
> - }
> - }
> - )*
> - };
> -}
> -
> -impl_atomic_only_load_and_store_ops!(i8, i16);
> --
> 2.43.0
>
next prev parent reply other threads:[~2025-12-29 11:58 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-28 12:05 [PATCH v1 0/3] rust: Add xchg and cmpxchg support on i8/i16 FUJITA Tomonori
2025-12-28 12:05 ` [PATCH v1 1/3] rust: sync: atomic: Prepare AtomicOps macros for i8/i16 support FUJITA Tomonori
2025-12-29 11:13 ` Boqun Feng
2025-12-29 11:54 ` FUJITA Tomonori
2025-12-29 16:36 ` Gary Guo
2025-12-30 0:17 ` Boqun Feng
2026-01-02 11:25 ` Gary Guo
2025-12-28 12:05 ` [PATCH v1 2/3] rust: sync: atomic: Remove workaround macro for i8/i16 BasicOps FUJITA Tomonori
2025-12-29 11:58 ` Boqun Feng [this message]
2025-12-29 12:55 ` FUJITA Tomonori
2025-12-29 13:19 ` Boqun Feng
2025-12-28 12:05 ` [PATCH v1 3/3] rust: sync: atomic: Add i8/i16 xchg and cmpxchg support FUJITA Tomonori
2025-12-29 12:27 ` Boqun Feng
2025-12-29 12:30 ` Boqun Feng
2025-12-29 13:04 ` FUJITA Tomonori
2025-12-29 13:13 ` Boqun Feng
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=aVJs-D4V1IpfzR7z@tardis-2.local \
--to=boqun.feng@gmail.com \
--cc=a.hindborg@kernel.org \
--cc=acourbot@nvidia.com \
--cc=aliceryhl@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=dakr@kernel.org \
--cc=fujita.tomonori@gmail.com \
--cc=gary@garyguo.net \
--cc=linux-arch@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=tmgross@umich.edu \
/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