[PATCH] KVM: arm64: nv: Work around lack of pauth support in old toolchains

Marc Zyngier maz at kernel.org
Tue Apr 23 04:33:00 PDT 2024


On Tue, 23 Apr 2024 09:37:04 +0100,
Mark Rutland <mark.rutland at arm.com> wrote:
> 
> 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 at linaro.org>
> > Signed-off-by: Marc Zyngier <maz at 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!).

Ah, I had completely forgot about this guy. Good call. I'll fold that
patchlet in and re-push the result.

Thanks,

	M.

-- 
Without deviation from the norm, progress is not possible.



More information about the linux-arm-kernel mailing list