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 1/4] rust: helpers: Add i8/i16 atomic try_cmpxchg helpers
Date: Mon, 29 Dec 2025 20:06:25 +0800 [thread overview]
Message-ID: <aVJuwRCnyF7r5ygF@tardis-2.local> (raw)
In-Reply-To: <20251227115951.1424458-2-fujita.tomonori@gmail.com>
On Sat, Dec 27, 2025 at 08:59:48PM +0900, FUJITA Tomonori wrote:
> Add i8/i16 atomic try_cmpxchg helpers that call raw_try_cmpxchg()
> macro implementing atomic try_cmpxchg using architecture-specific
> instructions.
>
> x86_64 implements try_cmpxchg() with full ordering.
>
> On other architectures, try_cmpxchg() isn't implemented; so calling
> try_cmpxchg() ends up using cmpxchg() implementation.
>
> loongarch, arm64, and riscv implement cmpxchg with full ordering.
>
> arm v7 only supports relaxed-ordering cmpxchg; __atomic_op_fence()
> macro is used to add barriers before and after the relaxed cmpxchg.
>
> Signed-off-by: FUJITA Tomonori <fujita.tomonori@gmail.com>
> ---
One more thing, we should add this to comments in atomic_ext.c as well:
diff --git a/rust/helpers/atomic_ext.c b/rust/helpers/atomic_ext.c
index 10733bb4a75e..5ef81d2b47cf 100644
--- a/rust/helpers/atomic_ext.c
+++ b/rust/helpers/atomic_ext.c
@@ -91,6 +91,13 @@ __rust_helper s16 rust_helper_atomic_i16_xchg_relaxed(s16 *ptr, s16 new)
return raw_xchg_relaxed(ptr, new);
}
+/*
+ * try_cmpxchg helpers depend on ARCH_SUPPORTS_ATOMIC_RMW and on the
+ * architecture provding try_cmpxchg() support for i8 and i16.
+ *
+ * The architectures that currently support Rust (x86_64, armv7,
+ * arm64, riscv, and loongarch) satisfy these requirements.
+ */
__rust_helper bool rust_helper_atomic_i8_try_cmpxchg(s8 *ptr, s8 *old, s8 new)
{
return raw_try_cmpxchg(ptr, old, new);
I can add it myself if it works for you.
Regards,
Boqun
> rust/helpers/atomic_ext.c | 10 ++++++++++
> 1 file changed, 10 insertions(+)
>
> diff --git a/rust/helpers/atomic_ext.c b/rust/helpers/atomic_ext.c
> index 089f31bc8de8..9d62f659c8d2 100644
> --- a/rust/helpers/atomic_ext.c
> +++ b/rust/helpers/atomic_ext.c
> @@ -90,3 +90,13 @@ __rust_helper s16 rust_helper_atomic_i16_xchg_relaxed(s16 *ptr, s16 new)
> {
> return raw_xchg_relaxed(ptr, new);
> }
> +
> +__rust_helper bool rust_helper_atomic_i8_try_cmpxchg(s8 *ptr, s8 *old, s8 new)
> +{
> + return raw_try_cmpxchg(ptr, old, new);
> +}
> +
> +__rust_helper bool rust_helper_atomic_i16_try_cmpxchg(s16 *ptr, s16 *old, s16 new)
> +{
> + return raw_try_cmpxchg(ptr, old, new);
> +}
> --
> 2.43.0
>
next prev parent reply other threads:[~2025-12-29 12:06 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-27 11:59 [PATCH v1 0/4] rust: Add i8/i16 atomic try_cmpxchg helpers FUJITA Tomonori
2025-12-27 11:59 ` [PATCH v1 1/4] rust: helpers: " FUJITA Tomonori
2025-12-29 12:06 ` Boqun Feng [this message]
2025-12-29 12:57 ` FUJITA Tomonori
2025-12-27 11:59 ` [PATCH v1 2/4] rust: helpers: Add i8/i16 atomic try_cmpxchg_acquire helpers FUJITA Tomonori
2025-12-27 11:59 ` [PATCH v1 3/4] rust: helpers: Add i8/i16 atomic try_cmpxchg_release helpers FUJITA Tomonori
2025-12-27 11:59 ` [PATCH v1 4/4] rust: helpers: Add i8/i16 atomic try_cmpxchg_relaxed helpers FUJITA Tomonori
2025-12-29 11:27 ` [PATCH v1 0/4] rust: Add i8/i16 atomic try_cmpxchg helpers 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=aVJuwRCnyF7r5ygF@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