]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
KVM: arm64: nv: Work around lack of pauth support in old toolchains
authorMarc Zyngier <maz@kernel.org>
Mon, 22 Apr 2024 14:13:03 +0000 (15:13 +0100)
committerMarc Zyngier <maz@kernel.org>
Tue, 23 Apr 2024 18:27:11 +0000 (19:27 +0100)
We still support GCC 8.x, and it appears that this toolchain
usually comes with an assembler that does not understand "pauth"
as a valid architectural extension.

This results in the NV ERETAx code breaking the build, as it relies
on this extention to make use of the PACGA instruction (required
by assemblers such as LLVM's).

Work around it by hand-assembling the instruction, which removes the
requirement for any assembler directive.

Fixes: 6ccc971ee2c6 ("KVM: arm64: nv: Add emulation for ERETAx instructions")
Reported-by: Linaro Kernel Functional Testing <lkft@linaro.org>
Suggested-by: Mark Rutland <mark.rutland@arm.com>
Acked-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Marc Zyngier <maz@kernel.org>
arch/arm64/kvm/pauth.c

index a3a5c404375bc0d07b248b10de71ea7fc00bf78f..d5eb3ae876be4f58f99dda387d12c1a5b38dd53e 100644 (file)
 
 #include <linux/kvm_host.h>
 
+#include <asm/gpr-num.h>
 #include <asm/kvm_emulate.h>
 #include <asm/pointer_auth.h>
 
+/* PACGA Xd, Xn, Xm */
+#define PACGA(d,n,m)                                   \
+       asm volatile(__DEFINE_ASM_GPR_NUMS              \
+                    ".inst 0x9AC03000          |"      \
+                    "(.L__gpr_num_%[Rd] << 0)  |"      \
+                    "(.L__gpr_num_%[Rn] << 5)  |"      \
+                    "(.L__gpr_num_%[Rm] << 16)\n"      \
+                    : [Rd] "=r" ((d))                  \
+                    : [Rn] "r" ((n)), [Rm] "r" ((m)))
+
 static u64 compute_pac(struct kvm_vcpu *vcpu, u64 ptr,
                       struct ptrauth_key ikey)
 {
@@ -36,8 +47,7 @@ static u64 compute_pac(struct kvm_vcpu *vcpu, u64 ptr,
        __ptrauth_key_install_nosync(APGA, ikey);
        isb();
 
-       asm volatile(ARM64_ASM_PREAMBLE ".arch_extension pauth\n"
-                    "pacga %0, %1, %2" : "=r" (pac) : "r" (ptr), "r" (mod));
+       PACGA(pac, ptr, mod);
        isb();
 
        __ptrauth_key_install_nosync(APGA, gkey);