[PATCH v3 06/11] selftests: Fix arm64 IO barriers to match kernel
From: Jason Gunthorpe <jgg@nvidia.com>
Date: 2026-07-16 17:03:45
Also in:
kvm, linux-kselftest, linux-patches, linux-rdma, llvm
Subsystem:
kernel selftest framework, the rest · Maintainers:
Shuah Khan, Linus Torvalds
The tools/include readl/writel MMIO accessors on arm64 use inner-shareable barriers (dmb ish) while the kernel uses outer-shareable (dmb osh). Fix them to match. Add __io_bw() and __io_ar() definitions matching the kernel's arch/arm64/include/asm/io.h, including the dummy control dependency in __io_ar() that orders MMIO reads against all subsequent instructions. Assisted-by: Claude:claude-opus-4.6 Signed-off-by: Jason Gunthorpe <jgg@nvidia.com> --- tools/arch/arm64/include/asm/io.h | 20 ++++++++++++++++++++ tools/include/asm/io.h | 2 ++ tools/testing/selftests/lib.mk | 5 +++++ 3 files changed, 27 insertions(+) create mode 100644 tools/arch/arm64/include/asm/io.h
diff --git a/tools/arch/arm64/include/asm/io.h b/tools/arch/arm64/include/asm/io.h
new file mode 100644
index 00000000000000..0d38f75a477682
--- /dev/null
+++ b/tools/arch/arm64/include/asm/io.h@@ -0,0 +1,20 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _TOOLS_ASM_ARM64_IO_H +#define _TOOLS_ASM_ARM64_IO_H + +#define __io_bw() dma_wmb() +#define __io_ar(v) \ +({ \ + unsigned long tmp; \ + \ + dma_rmb(); \ + \ + asm volatile("eor %0, %1, %1\n" \ + "cbnz %0, ." \ + : "=r" (tmp) : "r" ((unsigned long)(v)) \ + : "memory"); \ +}) + +#include <asm-generic/io.h> + +#endif /* _TOOLS_ASM_ARM64_IO_H */
diff --git a/tools/include/asm/io.h b/tools/include/asm/io.h
index eed5066f25c450..1090a2c387f40d 100644
--- a/tools/include/asm/io.h
+++ b/tools/include/asm/io.h@@ -4,6 +4,8 @@ #if defined(__i386__) || defined(__x86_64__) #include "../../arch/x86/include/asm/io.h" +#elif defined(__aarch64__) +#include "../../arch/arm64/include/asm/io.h" #else #include <asm-generic/io.h> #endif
diff --git a/tools/testing/selftests/lib.mk b/tools/testing/selftests/lib.mk
index f02cc8a2e4ae32..fdd22df9174b88 100644
--- a/tools/testing/selftests/lib.mk
+++ b/tools/testing/selftests/lib.mk@@ -5,9 +5,14 @@ ifneq ($(filter %/,$(LLVM)),) LLVM_PREFIX := $(LLVM) else ifneq ($(filter -%,$(LLVM)),) LLVM_SUFFIX := $(LLVM) +else ifneq ($(LLVM),1) +$(error Invalid value for LLVM, see Documentation/kbuild/llvm.rst) endif CLANG := $(LLVM_PREFIX)clang$(LLVM_SUFFIX) +LD := $(LLVM_PREFIX)ld.lld$(LLVM_SUFFIX) +# Selftests link through $(CC), so point clang at the LLVM linker. +LDFLAGS += --ld-path=$(LD) CLANG_TARGET_FLAGS_arm := arm-linux-gnueabi CLANG_TARGET_FLAGS_arm64 := aarch64-linux-gnu
--
2.43.0