From: Mark Rutland <mark.rutland@arm.com>
To: Marc Zyngier <maz@kernel.org>
Cc: kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org,
James Morse <james.morse@arm.com>,
Suzuki K Poulose <suzuki.poulose@arm.com>,
Oliver Upton <oliver.upton@linux.dev>,
Zenghui Yu <yuzenghui@huawei.com>, Arnd Bergmann <arnd@arndb.de>,
Joey Gouly <joey.gouly@arm.com>, Will Deacon <will@kernel.org>,
Naresh Kamboju <naresh.kamboju@linaro.org>,
Linaro Kernel Functional Testing <lkft@linaro.org>
Subject: Re: [PATCH] KVM: arm64: nv: Work around lack of pauth support in old toolchains
Date: Tue, 23 Apr 2024 09:37:04 +0100 [thread overview]
Message-ID: <ZidzMO-tcsFUgL1r@FVFF77S0Q05N> (raw)
In-Reply-To: <20240422224849.2238222-1-maz@kernel.org>
On Mon, Apr 22, 2024 at 11:48:49PM +0100, Marc Zyngier wrote:
> 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)))
Can you please use <asm/gpr-num.h> rather than open-coding this new REG()
helper? That way this'll be consistent with the way we assemble MRS/MSR in
<asm/sysreg.h>, and it avoids the few seconds of confusion trying to figure out
the maths in the REG() helper (neat trick though!).
Fixlet for that below; I've build tested this and the resulting object file is
the same before and after (diff shows that only the name of the file changed):
| [mark@lakrids:~/src/linux]% usekorg 13.2.0 aarch64-linux-objdump -d pauth-maz.o | grep pacga
| 204: 9ac03335 pacga x21, x25, x0
| [mark@lakrids:~/src/linux]% usekorg 13.2.0 aarch64-linux-objdump -d pauth-rutland.o | grep pacga
| 204: 9ac03335 pacga x21, x25, x0
| [mark@lakrids:~/src/linux]% diff <(usekorg 13.2.0 aarch64-linux-objdump -d pauth-maz.o) <(usekorg 13.2.0 aarch64-linux-objdump -d pauth-rutland.o)
| 2c2
| < pauth-maz.o: file format elf64-littleaarch64
| ---
| > pauth-rutland.o: file format elf64-littleaarch64
If you'd prefer I can send this as a patch.
Otherwise, this looks good to me; thanks for the fix!
Mark.
---->8----
diff --git a/arch/arm64/kvm/pauth.c b/arch/arm64/kvm/pauth.c
index 8baf2a2cbdd32..e518baf570c86 100644
--- a/arch/arm64/kvm/pauth.c
+++ b/arch/arm64/kvm/pauth.c
@@ -14,24 +14,20 @@
#include <linux/kvm_host.h>
+#include <asm/gpr-num.h>
#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)))
+#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)
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next prev parent reply other threads:[~2024-04-23 8:37 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
2024-04-23 11:33 ` Marc Zyngier
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=ZidzMO-tcsFUgL1r@FVFF77S0Q05N \
--to=mark.rutland@arm.com \
--cc=arnd@arndb.de \
--cc=james.morse@arm.com \
--cc=joey.gouly@arm.com \
--cc=kvmarm@lists.linux.dev \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=lkft@linaro.org \
--cc=maz@kernel.org \
--cc=naresh.kamboju@linaro.org \
--cc=oliver.upton@linux.dev \
--cc=suzuki.poulose@arm.com \
--cc=will@kernel.org \
--cc=yuzenghui@huawei.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox