kvmarm.lists.cs.columbia.edu archive mirror
 help / color / mirror / Atom feed
* [PATCH] KVM: arm64: nv: Work around lack of pauth support in old toolchains
@ 2024-04-22 22:48 Marc Zyngier
  2024-04-23  8:24 ` Arnd Bergmann
  2024-04-23  8:37 ` Mark Rutland
  0 siblings, 2 replies; 9+ messages in thread
From: Marc Zyngier @ 2024-04-22 22:48 UTC (permalink / raw)
  To: kvmarm, linux-arm-kernel
  Cc: James Morse, Suzuki K Poulose, Oliver Upton, Zenghui Yu,
	Arnd Bergmann, Mark Rutland, Joey Gouly, Will Deacon,
	Naresh Kamboju, Linaro Kernel Functional Testing

We still support GCC 8.x, and it appears that this toolchain
does not understand "pauth" as a valid architectural extension.
After all, it's only been 8 years since ARMv8.3 was released...

This results in the NV ERETAx code breaking the build, as it relies
on this extention to make use of the PACGA instruction.

Work around it by hand-assembling the instruction using a mind-bending
trick lifted from an old patch by Will. Magic.

Fixes: e09faab353a6 ("KVM: arm64: nv: Add emulation for ERETAx instructions")
Reported-by: Linaro Kernel Functional Testing <lkft@linaro.org>
Signed-off-by: Marc Zyngier <maz@kernel.org>
---
 arch/arm64/kvm/pauth.c | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/arch/arm64/kvm/pauth.c b/arch/arm64/kvm/pauth.c
index a3a5c404375b..8baf2a2cbdd3 100644
--- a/arch/arm64/kvm/pauth.c
+++ b/arch/arm64/kvm/pauth.c
@@ -17,6 +17,22 @@
 #include <asm/kvm_emulate.h>
 #include <asm/pointer_auth.h>
 
+/*
+ * "// This is some of my finest work" (Will Deacon, 2019-02-12)
+ *
+ * The jury is still out on that one.
+ */
+#define REG(r)	"(0%x[" #r "] - ((0%x[" #r "] >> 4) * 6))"
+
+/* PACGA Xd, Xn, Xm */
+#define PACGA(d,n,m)						\
+	asm volatile(".inst 0x9AC03000   |"			\
+		     "(" REG(Rd) "<< 0)  |"			\
+		     "(" REG(Rn) "<< 5)  |"			\
+		     "(" REG(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 +52,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);
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2024-04-24  1:54 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-22 22:48 [PATCH] KVM: arm64: nv: Work around lack of pauth support in old toolchains Marc Zyngier
2024-04-23  8:24 ` Arnd Bergmann
2024-04-23 12:00   ` Aiqun Yu (Maria)
2024-04-23 12:06     ` Marc Zyngier
2024-04-23 12:37       ` Arnd Bergmann
2024-04-23 16:15         ` Marc Zyngier
2024-04-24  1:54           ` Aiqun Yu (Maria)
2024-04-23  8:37 ` Mark Rutland
2024-04-23 11:33   ` Marc Zyngier

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).