From: Luca Di Maio <luca@edera.dev>
To: xen-devel@lists.xenproject.org
Cc: Luca Di Maio <luca@edera.dev>,
Stefano Stabellini <sstabellini@kernel.org>,
Julien Grall <julien@xen.org>,
Bertrand Marquis <bertrand.marquis@arm.com>,
Michal Orzel <michal.orzel@amd.com>,
Volodymyr Babchuk <Volodymyr_Babchuk@epam.com>
Subject: [PATCH 1/5] xen/arm64: detect the LSE atomic instructions
Date: Wed, 25 Nov 2026 18:55:48 +0100 [thread overview]
Message-ID: <20261125175555.2110163-2-luca@edera.dev> (raw)
In-Reply-To: <20261125175555.2110163-1-luca@edera.dev>
Load/store exclusive loops give no forward-progress guarantee, so many
CPUs contending on one cache line can livelock. Add the
ARM64_HAS_LSE_ATOMICS capability and system_uses_lse_atomics(), patched
at boot like Linux's alternative_has_cap_likely(), for the next patches.
Assemblers older than binutils 2.26 lack .arch_extension, so Xen built
with one keeps the exclusive loops.
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Luca Di Maio <luca@edera.dev>
---
xen/arch/arm/arch.mk | 3 +++
xen/arch/arm/cpufeature.c | 10 +++++++++
xen/arch/arm/include/asm/arm64/lse.h | 31 +++++++++++++++++++++++++++
xen/arch/arm/include/asm/cpufeature.h | 3 ++-
4 files changed, 46 insertions(+), 1 deletion(-)
create mode 100644 xen/arch/arm/include/asm/arm64/lse.h
diff --git a/xen/arch/arm/arch.mk b/xen/arch/arm/arch.mk
index dea8dbd18a..fe8e02229f 100644
--- a/xen/arch/arm/arch.mk
+++ b/xen/arch/arm/arch.mk
@@ -19,6 +19,9 @@ endif
CFLAGS-$(CONFIG_ARM_64) += -mgeneral-regs-only # No fp registers etc
$(call cc-option-add,CFLAGS-$(CONFIG_ARM_64),CC,-mno-outline-atomics)
+# Binutils >= 2.26
+$(call as-option-add,CFLAGS-$(CONFIG_ARM_64),CC,".arch_extension lse",-DHAVE_AS_LSE)
+
ifneq ($(filter command line environment,$(origin CONFIG_EARLY_PRINTK)),)
$(error You must use 'make menuconfig' to enable/disable early printk now)
endif
diff --git a/xen/arch/arm/cpufeature.c b/xen/arch/arm/cpufeature.c
index 8d8cd19a96..144c3789a3 100644
--- a/xen/arch/arm/cpufeature.c
+++ b/xen/arch/arm/cpufeature.c
@@ -22,6 +22,11 @@ static bool has_sb_instruction(const struct arm_cpu_capabilities *entry)
{
return system_cpuinfo.isa64.sb;
}
+
+static bool has_lse_atomics(const struct arm_cpu_capabilities *entry)
+{
+ return system_cpuinfo.isa64.atomic >= 2;
+}
#endif
static const struct arm_cpu_capabilities arm_features[] = {
@@ -31,6 +36,11 @@ static const struct arm_cpu_capabilities arm_features[] = {
.capability = ARM_HAS_SB,
.matches = has_sb_instruction,
},
+ {
+ .desc = "LSE atomic instructions",
+ .capability = ARM64_HAS_LSE_ATOMICS,
+ .matches = has_lse_atomics,
+ },
#endif
{},
};
diff --git a/xen/arch/arm/include/asm/arm64/lse.h b/xen/arch/arm/include/asm/arm64/lse.h
new file mode 100644
index 0000000000..dbe75dfc59
--- /dev/null
+++ b/xen/arch/arm/include/asm/arm64/lse.h
@@ -0,0 +1,31 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * As Linux's asm/lse.h: LSE atomics always complete, where load/store
+ * exclusive loops can livelock under contention. Each atomic keeps the
+ * barriers of its load/store exclusive version.
+ */
+#ifndef __ASM_ARM64_LSE_H
+#define __ASM_ARM64_LSE_H
+
+#include <asm/alternative.h>
+
+#define __LSE_PREAMBLE ".arch_extension lse\n"
+
+/* Patched at boot, like Linux's alternative_has_cap_likely(). */
+static always_inline bool system_uses_lse_atomics(void)
+{
+#ifdef HAVE_AS_LSE
+ register_t ret;
+
+ asm_inline volatile ( ALTERNATIVE("mov %0, #0", "mov %0, #1",
+ ARM64_HAS_LSE_ATOMICS)
+ : "=r" (ret) );
+
+ return likely(ret);
+#else
+ /* The compiler drops the LSE blocks, which this assembler can't take. */
+ return false;
+#endif
+}
+
+#endif /* __ASM_ARM64_LSE_H */
diff --git a/xen/arch/arm/include/asm/cpufeature.h b/xen/arch/arm/include/asm/cpufeature.h
index c554686415..4d097a77ce 100644
--- a/xen/arch/arm/include/asm/cpufeature.h
+++ b/xen/arch/arm/include/asm/cpufeature.h
@@ -76,8 +76,9 @@
#define ARM_WORKAROUND_BHB_SMCC_3 15
#define ARM_HAS_SB 16
#define ARM64_WORKAROUND_1508412 17
+#define ARM64_HAS_LSE_ATOMICS 18
-#define ARM_NCAPS 18
+#define ARM_NCAPS 19
#ifndef __ASSEMBLER__
--
2.47.3
next prev parent reply other threads:[~2026-11-25 17:56 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-25 17:55 [PATCH 0/5] xen/arm64: use LSE atomics when the CPU has them Luca Di Maio
2026-11-25 17:55 ` Luca Di Maio [this message]
2026-11-26 7:58 ` [PATCH 1/5] xen/arm64: detect the LSE atomic instructions Jan Beulich
2026-12-01 15:53 ` Luca Di Maio
2026-11-25 17:55 ` [PATCH 2/5] xen/arm64: use LSE in the atomic_t operations Luca Di Maio
2026-11-25 17:55 ` [PATCH 3/5] xen/arm64: use LSE in xchg() and cmpxchg() Luca Di Maio
2026-11-25 17:55 ` [PATCH 4/5] xen/arm64: use LSE in the bitops Luca Di Maio
2026-11-25 17:55 ` [PATCH 5/5] xen/arm64: use LSE for arch_fetch_and_add() Luca Di Maio
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=20261125175555.2110163-2-luca@edera.dev \
--to=luca@edera.dev \
--cc=Volodymyr_Babchuk@epam.com \
--cc=bertrand.marquis@arm.com \
--cc=julien@xen.org \
--cc=michal.orzel@amd.com \
--cc=sstabellini@kernel.org \
--cc=xen-devel@lists.xenproject.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.