public inbox for linux-arch@vger.kernel.org
 help / color / mirror / Atom feed
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 3/3] rust: sync: atomic: Add i8/i16 xchg and cmpxchg support
Date: Mon, 29 Dec 2025 20:27:01 +0800	[thread overview]
Message-ID: <aVJzlTWx4ybMi1ym@tardis-2.local> (raw)
In-Reply-To: <20251228120546.1602275-4-fujita.tomonori@gmail.com>

On Sun, Dec 28, 2025 at 09:05:46PM +0900, FUJITA Tomonori wrote:
> Add atomic xchg and cmpxchg operation support for i8 and i16 types
> with tests.
> 

I think we also needs the following, otherwise architectures may
accidentally enable Rust but don't have the correct atomic
implementation for i8 and i16.

diff --git a/rust/kernel/sync/atomic/predefine.rs b/rust/kernel/sync/atomic/predefine.rs
index 248d26555ccf..a4e5bbd45eb2 100644
--- a/rust/kernel/sync/atomic/predefine.rs
+++ b/rust/kernel/sync/atomic/predefine.rs
@@ -5,14 +5,22 @@
 use crate::static_assert;
 use core::mem::{align_of, size_of};

+// The current helpers of load/store uses `{WRITE,READ}_ONCE()` hence the atomicity is only
+// guaranteed against read-modify-write operations if the architecture supports native atomic RmW.
+//
 // SAFETY: `i8` has the same size and alignment with itself, and is round-trip transmutable to
 // itself.
+#[cfg(CONFIG_ARCH_SUPPORTS_ATOMIC_RMW)]
 unsafe impl super::AtomicType for i8 {
     type Repr = i8;
 }

+// The current helpers of load/store uses `{WRITE,READ}_ONCE()` hence the atomicity is only
+// guaranteed against read-modify-write operations if the architecture supports native atomic RmW.
+//
 // SAFETY: `i16` has the same size and alignment with itself, and is round-trip transmutable to
 // itself.
+#[cfg(CONFIG_ARCH_SUPPORTS_ATOMIC_RMW)]
 unsafe impl super::AtomicType for i16 {
     type Repr = i16;
 }

I can fold it into your patch if that works.

Regards,
Boqun

> Signed-off-by: FUJITA Tomonori <fujita.tomonori@gmail.com>
> ---
>  rust/kernel/sync/atomic/internal.rs  | 2 +-
>  rust/kernel/sync/atomic/predefine.rs | 4 ++--
>  2 files changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/rust/kernel/sync/atomic/internal.rs b/rust/kernel/sync/atomic/internal.rs
> index 1b2a7933bc14..55a80e22a7a0 100644
> --- a/rust/kernel/sync/atomic/internal.rs
> +++ b/rust/kernel/sync/atomic/internal.rs
> @@ -274,7 +274,7 @@ fn set[release](a: &AtomicRepr<Self>, v: Self) {
>  );
>  
>  declare_and_impl_atomic_methods!(
> -    [ i32 => atomic, i64 => atomic64 ]
> +    [ i8 => atomic_i8, i16 => atomic_i16, i32 => atomic, i64 => atomic64 ]
>      /// Exchange and compare-and-exchange atomic operations
>      pub trait AtomicExchangeOps {
>          /// Atomic exchange.
> diff --git a/rust/kernel/sync/atomic/predefine.rs b/rust/kernel/sync/atomic/predefine.rs
> index 51e9df0cf56e..248d26555ccf 100644
> --- a/rust/kernel/sync/atomic/predefine.rs
> +++ b/rust/kernel/sync/atomic/predefine.rs
> @@ -149,7 +149,7 @@ fn atomic_acquire_release_tests() {
>  
>      #[test]
>      fn atomic_xchg_tests() {
> -        for_each_type!(42 in [i32, i64, u32, u64, isize, usize] |v| {
> +        for_each_type!(42 in [i8, i16, i32, i64, u32, u64, isize, usize] |v| {
>              let x = Atomic::new(v);
>  
>              let old = v;
> @@ -162,7 +162,7 @@ fn atomic_xchg_tests() {
>  
>      #[test]
>      fn atomic_cmpxchg_tests() {
> -        for_each_type!(42 in [i32, i64, u32, u64, isize, usize] |v| {
> +        for_each_type!(42 in [i8, i16, i32, i64, u32, u64, isize, usize] |v| {
>              let x = Atomic::new(v);
>  
>              let old = v;
> -- 
> 2.43.0
> 

  reply	other threads:[~2025-12-29 12:27 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
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 [this message]
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=aVJzlTWx4ybMi1ym@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