* [PATCH v2 0/5] xen/arm64: use LSE atomics when the CPU has them
@ 2026-12-01 16:08 Luca Di Maio
2026-12-01 16:08 ` [PATCH v2 1/5] xen/arm64: detect the LSE atomic instructions Luca Di Maio
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: Luca Di Maio @ 2026-12-01 16:08 UTC (permalink / raw)
To: xen-devel
Cc: Luca Di Maio, Stefano Stabellini, Julien Grall, Bertrand Marquis,
Michal Orzel, Volodymyr Babchuk, Alex Zenla, Alexander M. Merritt,
Andres Rodriguez, Simon Veith, Steven Noonan
On a two-socket Graviton4 (AWS c8g.metal-48xl, 192 Neoverse V2 cores),
dom0 hangs about two minutes into its boot. All 96 pCPUs of one socket
spin in the exclusive loop of atomic_add_return() on dom0's p2m rwlock:
nobody holds the lock, the increment itself never completes. The lock
is hot because every trapped-WFI block copies the vCPU's runstate to a
guest virtual address, and that translation takes the p2m read lock.
LSE atomics guarantee forward progress, and with them dom0 came up in
every boot I tried. Following Linux, the series detects LSE at boot and
puts a check patched by the alternatives in front of each existing
exclusive loop, so CPUs without LSE run the same code as today. Each
LSE sequence keeps the barriers of the loop it bypasses, so the
ordering is the same or stronger.
Tested on the 48xl with our 4.22-based tree, with guests running, and
on staging under QEMU with and without LSE (neoverse-n2, cortex-a57).
Changes in v2:
- Patch 1: check the assembler for LSE in Kconfig instead of arch.mk (Jan).
Luca Di Maio (5):
xen/arm64: detect the LSE atomic instructions
xen/arm64: use LSE in the atomic_t operations
xen/arm64: use LSE in xchg() and cmpxchg()
xen/arm64: use LSE in the bitops
xen/arm64: use LSE for arch_fetch_and_add()
xen/arch/arm/Kconfig | 4 ++
xen/arch/arm/arm64/lib/bitops.c | 47 ++++++++++++++++----
xen/arch/arm/cpufeature.c | 10 +++++
xen/arch/arm/include/asm/arm64/atomic.h | 55 ++++++++++++++++++++++++
xen/arch/arm/include/asm/arm64/cmpxchg.h | 41 ++++++++++++++++++
xen/arch/arm/include/asm/arm64/lse.h | 31 +++++++++++++
xen/arch/arm/include/asm/arm64/system.h | 20 +++++++++
xen/arch/arm/include/asm/cpufeature.h | 3 +-
xen/arch/arm/include/asm/system.h | 2 +
9 files changed, 204 insertions(+), 9 deletions(-)
create mode 100644 xen/arch/arm/include/asm/arm64/lse.h
base-commit: 091d3c200281ea44846ccdf1e5d39985321c643e
--
2.47.3
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v2 1/5] xen/arm64: detect the LSE atomic instructions
2026-12-01 16:08 [PATCH v2 0/5] xen/arm64: use LSE atomics when the CPU has them Luca Di Maio
@ 2026-12-01 16:08 ` Luca Di Maio
2026-12-01 16:08 ` [PATCH v2 2/5] xen/arm64: use LSE in the atomic_t operations Luca Di Maio
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Luca Di Maio @ 2026-12-01 16:08 UTC (permalink / raw)
To: xen-devel
Cc: Luca Di Maio, Stefano Stabellini, Julien Grall, Bertrand Marquis,
Michal Orzel, Volodymyr Babchuk
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>
---
v2: move the assembler check to Kconfig (Jan)
---
xen/arch/arm/Kconfig | 4 ++++
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, 47 insertions(+), 1 deletion(-)
create mode 100644 xen/arch/arm/include/asm/arm64/lse.h
diff --git a/xen/arch/arm/Kconfig b/xen/arch/arm/Kconfig
index b9c5c40678..b07c15e1cf 100644
--- a/xen/arch/arm/Kconfig
+++ b/xen/arch/arm/Kconfig
@@ -11,6 +11,10 @@ config ARM_64
select HAS_FAST_MULTIPLY
select HAS_VPCI_GUEST_SUPPORT if PCI_PASSTHROUGH
+config HAS_AS_LSE
+ def_bool $(as-instr,.arch_extension lse)
+ depends on ARM_64
+
config ARM
def_bool y
select DOMAIN_BUILD_HELPERS
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..3db2df3dfc
--- /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 CONFIG_HAS_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
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v2 2/5] xen/arm64: use LSE in the atomic_t operations
2026-12-01 16:08 [PATCH v2 0/5] xen/arm64: use LSE atomics when the CPU has them Luca Di Maio
2026-12-01 16:08 ` [PATCH v2 1/5] xen/arm64: detect the LSE atomic instructions Luca Di Maio
@ 2026-12-01 16:08 ` Luca Di Maio
2026-12-01 16:08 ` [PATCH v2 3/5] xen/arm64: use LSE in xchg() and cmpxchg() Luca Di Maio
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Luca Di Maio @ 2026-12-01 16:08 UTC (permalink / raw)
To: xen-devel
Cc: Luca Di Maio, Stefano Stabellini, Julien Grall, Bertrand Marquis,
Michal Orzel, Volodymyr Babchuk
On a two-socket Graviton4 every pCPU of a socket spun in the exclusive
loop of atomic_add_return() on dom0's p2m rwlock, and dom0 hung at boot.
Use the LSE instruction for each operation when the CPU has it, with the
same barriers; CPUs without LSE keep the exclusive loops.
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Luca Di Maio <luca@edera.dev>
---
xen/arch/arm/include/asm/arm64/atomic.h | 55 +++++++++++++++++++++++++
1 file changed, 55 insertions(+)
diff --git a/xen/arch/arm/include/asm/arm64/atomic.h b/xen/arch/arm/include/asm/arm64/atomic.h
index 4460165295..a113401db6 100644
--- a/xen/arch/arm/include/asm/arm64/atomic.h
+++ b/xen/arch/arm/include/asm/arm64/atomic.h
@@ -22,6 +22,8 @@
#ifndef __ARCH_ARM_ARM64_ATOMIC
#define __ARCH_ARM_ARM64_ATOMIC
+#include <asm/arm64/lse.h>
+
/*
* AArch64 UP and SMP safe atomic ops. We use load exclusive and
* store exclusive to ensure that these are atomic. We may loop
@@ -32,6 +34,14 @@ static inline void atomic_add(int i, atomic_t *v)
unsigned long tmp;
int result;
+ if (system_uses_lse_atomics()) {
+ asm volatile(__LSE_PREAMBLE
+" stadd %w1, %0"
+ : "+Q" (v->counter)
+ : "r" (i));
+ return;
+ }
+
asm volatile("// atomic_add\n"
"1: ldxr %w0, %2\n"
" add %w0, %w0, %w3\n"
@@ -46,6 +56,16 @@ static inline int atomic_add_return(int i, atomic_t *v)
unsigned long tmp;
int result;
+ if (system_uses_lse_atomics()) {
+ asm volatile(__LSE_PREAMBLE
+" ldaddal %w2, %w0, %1"
+ : "=&r" (result), "+Q" (v->counter)
+ : "r" (i)
+ : "memory");
+ smp_mb();
+ return (int)((unsigned int)result + i);
+ }
+
asm volatile("// atomic_add_return\n"
"1: ldxr %w0, %2\n"
" add %w0, %w0, %w3\n"
@@ -64,6 +84,14 @@ static inline void atomic_sub(int i, atomic_t *v)
unsigned long tmp;
int result;
+ if (system_uses_lse_atomics()) {
+ asm volatile(__LSE_PREAMBLE
+" stadd %w1, %0"
+ : "+Q" (v->counter)
+ : "r" (-(unsigned int)i));
+ return;
+ }
+
asm volatile("// atomic_sub\n"
"1: ldxr %w0, %2\n"
" sub %w0, %w0, %w3\n"
@@ -78,6 +106,16 @@ static inline int atomic_sub_return(int i, atomic_t *v)
unsigned long tmp;
int result;
+ if (system_uses_lse_atomics()) {
+ asm volatile(__LSE_PREAMBLE
+" ldaddal %w2, %w0, %1"
+ : "=&r" (result), "+Q" (v->counter)
+ : "r" (-(unsigned int)i)
+ : "memory");
+ smp_mb();
+ return (int)((unsigned int)result - i);
+ }
+
asm volatile("// atomic_sub_return\n"
"1: ldxr %w0, %2\n"
" sub %w0, %w0, %w3\n"
@@ -96,6 +134,14 @@ static inline void atomic_and(int m, atomic_t *v)
unsigned long tmp;
int result;
+ if (system_uses_lse_atomics()) {
+ asm volatile(__LSE_PREAMBLE
+" stclr %w1, %0"
+ : "+Q" (v->counter)
+ : "r" (~m));
+ return;
+ }
+
asm volatile("// atomic_and\n"
"1: ldxr %w0, %2\n"
" and %w0, %w0, %w3\n"
@@ -112,6 +158,15 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
smp_mb();
+ if (system_uses_lse_atomics()) {
+ asm volatile(__LSE_PREAMBLE
+" cas %w0, %w2, %1"
+ : "+r" (old), "+Q" (v->counter)
+ : "r" (new));
+ smp_mb();
+ return old;
+ }
+
asm volatile("// atomic_cmpxchg\n"
"1: ldxr %w1, %2\n"
" cmp %w1, %w3\n"
--
2.47.3
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v2 3/5] xen/arm64: use LSE in xchg() and cmpxchg()
2026-12-01 16:08 [PATCH v2 0/5] xen/arm64: use LSE atomics when the CPU has them Luca Di Maio
2026-12-01 16:08 ` [PATCH v2 1/5] xen/arm64: detect the LSE atomic instructions Luca Di Maio
2026-12-01 16:08 ` [PATCH v2 2/5] xen/arm64: use LSE in the atomic_t operations Luca Di Maio
@ 2026-12-01 16:08 ` Luca Di Maio
2026-12-01 16:08 ` [PATCH v2 4/5] xen/arm64: use LSE in the bitops Luca Di Maio
2026-12-01 16:08 ` [PATCH v2 5/5] xen/arm64: use LSE for arch_fetch_and_add() Luca Di Maio
4 siblings, 0 replies; 6+ messages in thread
From: Luca Di Maio @ 2026-12-01 16:08 UTC (permalink / raw)
To: xen-devel
Cc: Luca Di Maio, Stefano Stabellini, Julien Grall, Bertrand Marquis,
Michal Orzel, Volodymyr Babchuk
As for the atomic_t operations, use SWPAL and CAS when the CPU has LSE,
with the same barriers. A CAS cannot fail spuriously, so the _timeout
variants used by guest atomics succeed on their first try.
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Luca Di Maio <luca@edera.dev>
---
xen/arch/arm/include/asm/arm64/cmpxchg.h | 41 ++++++++++++++++++++++++
1 file changed, 41 insertions(+)
diff --git a/xen/arch/arm/include/asm/arm64/cmpxchg.h b/xen/arch/arm/include/asm/arm64/cmpxchg.h
index f160e8e7bc..442b6e1698 100644
--- a/xen/arch/arm/include/asm/arm64/cmpxchg.h
+++ b/xen/arch/arm/include/asm/arm64/cmpxchg.h
@@ -2,6 +2,7 @@
#define __ASM_ARM64_CMPXCHG_H
#include <xen/bug.h>
+#include <asm/arm64/lse.h>
extern void __bad_xchg(volatile void *ptr, int size);
@@ -11,6 +12,14 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size
switch (size) {
case 1:
+ if (system_uses_lse_atomics()) {
+ asm volatile(__LSE_PREAMBLE
+ " swpalb %w2, %w0, %1"
+ : "=&r" (ret), "+Q" (*(volatile u8 *)ptr)
+ : "r" (x)
+ : "memory");
+ break;
+ }
asm volatile("// __xchg1\n"
"1: ldxrb %w0, %2\n"
" stlxrb %w1, %w3, %2\n"
@@ -20,6 +29,14 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size
: "memory");
break;
case 2:
+ if (system_uses_lse_atomics()) {
+ asm volatile(__LSE_PREAMBLE
+ " swpalh %w2, %w0, %1"
+ : "=&r" (ret), "+Q" (*(volatile u16 *)ptr)
+ : "r" (x)
+ : "memory");
+ break;
+ }
asm volatile("// __xchg2\n"
"1: ldxrh %w0, %2\n"
" stlxrh %w1, %w3, %2\n"
@@ -29,6 +46,14 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size
: "memory");
break;
case 4:
+ if (system_uses_lse_atomics()) {
+ asm volatile(__LSE_PREAMBLE
+ " swpal %w2, %w0, %1"
+ : "=&r" (ret), "+Q" (*(volatile u32 *)ptr)
+ : "r" (x)
+ : "memory");
+ break;
+ }
asm volatile("// __xchg4\n"
"1: ldxr %w0, %2\n"
" stlxr %w1, %w3, %2\n"
@@ -38,6 +63,14 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size
: "memory");
break;
case 8:
+ if (system_uses_lse_atomics()) {
+ asm volatile(__LSE_PREAMBLE
+ " swpal %2, %0, %1"
+ : "=&r" (ret), "+Q" (*(volatile u64 *)ptr)
+ : "r" (x)
+ : "memory");
+ break;
+ }
asm volatile("// __xchg8\n"
"1: ldxr %0, %2\n"
" stlxr %w1, %3, %2\n"
@@ -75,6 +108,14 @@ static inline bool __cmpxchg_case_##name(volatile void *ptr, \
unsigned long oldval; \
unsigned long res; \
\
+ if (system_uses_lse_atomics()) { \
+ asm volatile(__LSE_PREAMBLE \
+ " cas" #sz " %" #w "0, %" #w "2, %1" \
+ : "+r" (*old), "+Q" (*(volatile unsigned long *)ptr) \
+ : "r" (new)); \
+ return true; \
+ } \
+ \
do { \
asm volatile("// __cmpxchg_case_" #name "\n" \
" ldxr" #sz " %" #w "1, %2\n" \
--
2.47.3
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v2 4/5] xen/arm64: use LSE in the bitops
2026-12-01 16:08 [PATCH v2 0/5] xen/arm64: use LSE atomics when the CPU has them Luca Di Maio
` (2 preceding siblings ...)
2026-12-01 16:08 ` [PATCH v2 3/5] xen/arm64: use LSE in xchg() and cmpxchg() Luca Di Maio
@ 2026-12-01 16:08 ` Luca Di Maio
2026-12-01 16:08 ` [PATCH v2 5/5] xen/arm64: use LSE for arch_fetch_and_add() Luca Di Maio
4 siblings, 0 replies; 6+ messages in thread
From: Luca Di Maio @ 2026-12-01 16:08 UTC (permalink / raw)
To: xen-devel
Cc: Luca Di Maio, Stefano Stabellini, Julien Grall, Bertrand Marquis,
Michal Orzel, Volodymyr Babchuk
As for the atomic_t operations, use ST{SET,CLR,EOR} and
LD{SET,CLR,EOR}AL when the CPU has LSE, with the same barriers; the
macros take the LSE operation as a new argument. The _timeout variants
now succeed on their first try.
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Luca Di Maio <luca@edera.dev>
---
xen/arch/arm/arm64/lib/bitops.c | 47 +++++++++++++++++++++++++++------
1 file changed, 39 insertions(+), 8 deletions(-)
diff --git a/xen/arch/arm/arm64/lib/bitops.c b/xen/arch/arm/arm64/lib/bitops.c
index 275a780329..0153e4f68b 100644
--- a/xen/arch/arm/arm64/lib/bitops.c
+++ b/xen/arch/arm/arm64/lib/bitops.c
@@ -15,6 +15,7 @@
*/
#include <xen/bitops.h>
+#include <asm/arm64/lse.h>
#include <asm/system.h>
/*
@@ -28,7 +29,7 @@
* XXX: Rework the interface to use unsigned int.
*/
-#define bitop(name, instr) \
+#define bitop(name, instr, lse_op) \
static always_inline bool int_##name(int nr, volatile void *p, bool timeout,\
unsigned int max_try) \
{ \
@@ -37,6 +38,15 @@ static always_inline bool int_##name(int nr, volatile void *p, bool timeout,\
const uint32_t mask = BITOP_MASK((unsigned int)nr); \
unsigned long res, tmp; \
\
+ if ( system_uses_lse_atomics() ) \
+ { \
+ asm volatile ( __LSE_PREAMBLE \
+ " st" #lse_op " %w1, %0\n" \
+ : "+Q" (*ptr) \
+ : "r" (mask) ); \
+ return true; \
+ } \
+ \
do \
{ \
asm volatile ("// " __stringify(name) "\n" \
@@ -64,7 +74,7 @@ bool name##_timeout(int nr, volatile void *p, unsigned int max_try) \
return int_##name(nr, p, true, max_try); \
}
-#define testop(name, instr) \
+#define testop(name, instr, lse_op) \
static always_inline bool int_##name(int nr, volatile void *p, int *oldbit, \
bool timeout, unsigned int max_try) \
{ \
@@ -74,6 +84,18 @@ static always_inline bool int_##name(int nr, volatile void *p, int *oldbit, \
const uint32_t mask = BITOP_MASK(bit); \
unsigned long res, tmp; \
\
+ if ( system_uses_lse_atomics() ) \
+ { \
+ asm volatile ( __LSE_PREAMBLE \
+ " ld" #lse_op "al %w2, %w0, %1\n" \
+ : "=&r" (tmp), "+Q" (*ptr) \
+ : "r" (mask) \
+ : "memory" ); \
+ dmb(ish); \
+ *oldbit = (tmp >> bit) & 1; \
+ return true; \
+ } \
+ \
do \
{ \
asm volatile ("// " __stringify(name) "\n" \
@@ -112,19 +134,28 @@ bool name##_timeout(int nr, volatile void *p, \
return int_##name(nr, p, oldbit, true, max_try); \
}
-bitop(change_bit, eor)
-bitop(clear_bit, bic)
-bitop(set_bit, orr)
+bitop(change_bit, eor, eor)
+bitop(clear_bit, bic, clr)
+bitop(set_bit, orr, set)
-testop(test_and_change_bit, eor)
-testop(test_and_clear_bit, bic)
-testop(test_and_set_bit, orr)
+testop(test_and_change_bit, eor, eor)
+testop(test_and_clear_bit, bic, clr)
+testop(test_and_set_bit, orr, set)
static always_inline bool int_clear_mask16(uint16_t mask, volatile uint16_t *p,
bool timeout, unsigned int max_try)
{
unsigned long res, tmp;
+ if ( system_uses_lse_atomics() )
+ {
+ asm volatile ( __LSE_PREAMBLE
+ " stclrh %w1, %0\n"
+ : "+Q" (*p)
+ : "r" (mask) );
+ return true;
+ }
+
do
{
asm volatile ("// int_clear_mask16\n"
--
2.47.3
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v2 5/5] xen/arm64: use LSE for arch_fetch_and_add()
2026-12-01 16:08 [PATCH v2 0/5] xen/arm64: use LSE atomics when the CPU has them Luca Di Maio
` (3 preceding siblings ...)
2026-12-01 16:08 ` [PATCH v2 4/5] xen/arm64: use LSE in the bitops Luca Di Maio
@ 2026-12-01 16:08 ` Luca Di Maio
4 siblings, 0 replies; 6+ messages in thread
From: Luca Di Maio @ 2026-12-01 16:08 UTC (permalink / raw)
To: xen-devel
Cc: Luca Di Maio, Stefano Stabellini, Julien Grall, Bertrand Marquis,
Michal Orzel, Volodymyr Babchuk
The spinlock tickets come from __sync_fetch_and_add(), which the
compiler builds from an exclusive loop for Armv8.0. On arm64, use
LDADDAL when the CPU has LSE and the builtin otherwise; the builtin
macro is now arm32 only, as it would replace the arm64 function.
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Luca Di Maio <luca@edera.dev>
---
xen/arch/arm/include/asm/arm64/system.h | 20 ++++++++++++++++++++
xen/arch/arm/include/asm/system.h | 2 ++
2 files changed, 22 insertions(+)
diff --git a/xen/arch/arm/include/asm/arm64/system.h b/xen/arch/arm/include/asm/arm64/system.h
index 2e2ee212a1..4cf3295b16 100644
--- a/xen/arch/arm/include/asm/arm64/system.h
+++ b/xen/arch/arm/include/asm/arm64/system.h
@@ -3,6 +3,7 @@
#define __ASM_ARM64_SYSTEM_H
#include <asm/arm64/cmpxchg.h>
+#include <asm/arm64/lse.h>
/* Uses uimm4 as a bitmask to select the clearing of one or more of
* the DAIF exception mask bits:
@@ -58,6 +59,25 @@ static inline int local_fiq_is_enabled(void)
return !(flags & PSR_FIQ_MASK);
}
+/* For Armv8.0 the compiler builds the builtin from an LL/SC loop. */
+static always_inline uint32_t arch_fetch_and_add(volatile uint32_t *ptr,
+ uint32_t v)
+{
+ if ( system_uses_lse_atomics() )
+ {
+ uint32_t old;
+
+ asm volatile ( __LSE_PREAMBLE
+ "ldaddal %w2, %w0, %1"
+ : "=&r" (old), "+Q" (*ptr)
+ : "r" (v)
+ : "memory" );
+ return old;
+ }
+
+ return __sync_fetch_and_add(ptr, v);
+}
+
#endif
/*
* Local variables:
diff --git a/xen/arch/arm/include/asm/system.h b/xen/arch/arm/include/asm/system.h
index 65d5c8e423..b988f79102 100644
--- a/xen/arch/arm/include/asm/system.h
+++ b/xen/arch/arm/include/asm/system.h
@@ -58,7 +58,9 @@ static inline int local_abort_is_enabled(void)
return !(flags & PSR_ABT_MASK);
}
+#ifdef CONFIG_ARM_32
#define arch_fetch_and_add(x, v) __sync_fetch_and_add(x, v)
+#endif
extern struct vcpu *__context_switch(struct vcpu *prev, struct vcpu *next);
--
2.47.3
^ permalink raw reply related [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-12-01 16:09 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-01 16:08 [PATCH v2 0/5] xen/arm64: use LSE atomics when the CPU has them Luca Di Maio
2026-12-01 16:08 ` [PATCH v2 1/5] xen/arm64: detect the LSE atomic instructions Luca Di Maio
2026-12-01 16:08 ` [PATCH v2 2/5] xen/arm64: use LSE in the atomic_t operations Luca Di Maio
2026-12-01 16:08 ` [PATCH v2 3/5] xen/arm64: use LSE in xchg() and cmpxchg() Luca Di Maio
2026-12-01 16:08 ` [PATCH v2 4/5] xen/arm64: use LSE in the bitops Luca Di Maio
2026-12-01 16:08 ` [PATCH v2 5/5] xen/arm64: use LSE for arch_fetch_and_add() Luca Di Maio
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.