From: Karl Mehltretter <kmehltretter@gmail.com>
To: Russell King <linux@armlinux.org.uk>, Miguel Ojeda <ojeda@kernel.org>
Cc: "Karl Mehltretter" <kmehltretter@gmail.com>,
"Boqun Feng" <boqun@kernel.org>, "Gary Guo" <gary@garyguo.net>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Benno Lossin" <lossin@kernel.org>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Alice Ryhl" <aliceryhl@google.com>,
"Trevor Gross" <tmgross@umich.edu>,
"Danilo Krummrich" <dakr@kernel.org>,
"Daniel Almeida" <daniel.almeida@collabora.com>,
"Tamir Duberstein" <tamird@kernel.org>,
"Alexandre Courbot" <acourbot@nvidia.com>,
"Onur Özkan" <work@onurozkan.dev>,
"Arnd Bergmann" <arnd@arndb.de>,
"Linus Walleij" <linusw@kernel.org>,
"Christian Schrefl" <chrisi.schrefl@gmail.com>,
"Bradley Morgan" <brads@mainlining.org>,
"Paul E . McKenney" <paulmck@kernel.org>,
"Nathan Chancellor" <nathan@kernel.org>,
"Nick Desaulniers" <ndesaulniers@google.com>,
"Bill Wendling" <morbo@google.com>,
"Justin Stitt" <justinstitt@google.com>,
linux-arm-kernel@lists.infradead.org,
rust-for-linux@vger.kernel.org, llvm@lists.linux.dev,
linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH v2 2/6] ARM: cmpxchg: support 2-byte xchg() on pre-ARMv6 CPUs
Date: Thu, 8 Oct 2026 07:37:42 +0200 [thread overview]
Message-ID: <20261008053746.49631-3-kmehltretter@gmail.com> (raw)
In-Reply-To: <20261008053746.49631-1-kmehltretter@gmail.com>
Pre-ARMv6 CPUs have no halfword swp, so __arch_xchg() only handles 1-
and 4-byte exchanges there and turns any other size into a link error
via __bad_xchg().
No C code needs a 16-bit xchg() on these CPUs, but the Rust atomic
helpers in rust/helpers/atomic_ext.c provide xchg() for Atomic<i16>
unconditionally, so building with CONFIG_RUST=y for ARMv5 fails:
ld.lld: error: undefined symbol: __bad_xchg
>>> referenced by helpers.c
>>> rust/helpers/helpers.o:(rust_helper_atomic_i16_xchg)
Implement the 2-byte case with interrupts disabled, as the pre-ARMv6
atomic_t operations already do. This is safe because a kernel built
for ARMv5 or older is never SMP.
ARMv6 before ARMv6K (ARM1136r0) has no 16-bit exclusive access either.
It is not handled here. Rust stays disabled for those kernels, and
they cannot be SMP since commit d70242427110 ("ARM: rework ARM11 CPU
selection logic").
Acked-by: Arnd Bergmann <arnd@arndb.de>
Reviewed-by: Linus Walleij <linusw@kernel.org>
Reviewed-by: Bradley Morgan <brads@mainlining.org>
Assisted-by: LLM
Signed-off-by: Karl Mehltretter <kmehltretter@gmail.com>
---
arch/arm/include/asm/cmpxchg.h | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)
diff --git a/arch/arm/include/asm/cmpxchg.h b/arch/arm/include/asm/cmpxchg.h
index 0ce5225af442..18555ae22893 100644
--- a/arch/arm/include/asm/cmpxchg.h
+++ b/arch/arm/include/asm/cmpxchg.h
@@ -31,11 +31,10 @@ __arch_xchg(unsigned long x, volatile void *ptr, int size)
{
extern void __bad_xchg(volatile void *, int);
unsigned long ret;
-#ifdef swp_is_buggy
- unsigned long flags;
-#endif
#if __LINUX_ARM_ARCH__ >= 6
unsigned int tmp;
+#else
+ unsigned long flags;
#endif
prefetchw((const void *)ptr);
@@ -106,6 +105,15 @@ __arch_xchg(unsigned long x, volatile void *ptr, int size)
: "r" (x), "r" (ptr)
: "memory", "cc");
break;
+#endif
+#if __LINUX_ARM_ARCH__ < 6
+ case 2:
+ /* swp has no halfword form. Pre-ARMv6 is never SMP. */
+ raw_local_irq_save(flags);
+ ret = *(volatile unsigned short *)ptr;
+ *(volatile unsigned short *)ptr = x;
+ raw_local_irq_restore(flags);
+ break;
#endif
default:
/* Cause a link-time error, the xchg() size is not supported */
--
2.39.5 (Apple Git-154)
next prev parent reply other threads:[~2026-10-08 6:27 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-08 5:37 [PATCH v2 0/6] ARM: rust: Enable Rust support for ARMv4T, ARMv5TE and ARMv6K Karl Mehltretter
2026-10-08 5:37 ` [PATCH v2 1/6] ARM: cmpxchg: always inline __arch_xchg() and __cmpxchg() Karl Mehltretter
2026-10-08 9:01 ` Gary Guo
2026-10-09 1:17 ` Karl Mehltretter
2026-10-09 9:50 ` Gary Guo
2026-10-08 5:37 ` Karl Mehltretter [this message]
2026-10-08 5:37 ` [PATCH v2 3/6] ARM: rust: Enable Rust support for ARMv6K-only kernels Karl Mehltretter
2026-10-08 5:37 ` [PATCH v2 4/6] ARM: rust: Enable Rust support for ARMv5TE Karl Mehltretter
2026-10-08 5:37 ` [PATCH v2 5/6] ARM: rust: Enable Rust support for ARMv4T Karl Mehltretter
2026-10-08 9:08 ` Gary Guo
2026-10-09 1:21 ` Karl Mehltretter
2026-10-08 5:37 ` [PATCH v2 6/6] ARM: rust: Build Rust code for ARMv7 on ARMv7 kernels Karl Mehltretter
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=20261008053746.49631-3-kmehltretter@gmail.com \
--to=kmehltretter@gmail.com \
--cc=a.hindborg@kernel.org \
--cc=acourbot@nvidia.com \
--cc=aliceryhl@google.com \
--cc=arnd@arndb.de \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun@kernel.org \
--cc=brads@mainlining.org \
--cc=chrisi.schrefl@gmail.com \
--cc=dakr@kernel.org \
--cc=daniel.almeida@collabora.com \
--cc=gary@garyguo.net \
--cc=justinstitt@google.com \
--cc=linusw@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=llvm@lists.linux.dev \
--cc=lossin@kernel.org \
--cc=morbo@google.com \
--cc=nathan@kernel.org \
--cc=ndesaulniers@google.com \
--cc=ojeda@kernel.org \
--cc=paulmck@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=tamird@kernel.org \
--cc=tmgross@umich.edu \
--cc=work@onurozkan.dev \
/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