|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [PATCH v2 1/5] xen/arm64: detect the LSE atomic instructions
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@xxxxxxxxx>
---
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
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |