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 2/5] xen/arm64: use LSE in the atomic_t operations
Date: Wed, 25 Nov 2026 18:55:49 +0100 [thread overview]
Message-ID: <20261125175555.2110163-3-luca@edera.dev> (raw)
In-Reply-To: <20261125175555.2110163-1-luca@edera.dev>
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
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 ` [PATCH 1/5] xen/arm64: detect the LSE atomic instructions Luca Di Maio
2026-11-26 7:58 ` Jan Beulich
2026-12-01 15:53 ` Luca Di Maio
2026-11-25 17:55 ` Luca Di Maio [this message]
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-3-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.