From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 45BFFC4345F for ; Tue, 23 Apr 2024 08:37:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=kRjjY+pGBwEN/7jnaeUfYCuzcY6NEwU+gEqcmfzN1bI=; b=i1u8EMUdQXZ7cx mxc+nLRcn7fBSzV/kke2oYnfWhJnMnSSPTBs9ESaVUegjZ2dCsIFMdM6OjamWIm0nTC7t6LGtiQhK kslpvxzK9p8LvWbX9jT9MO+EJUAkO/ydapccY/OfSadz23s/Sd8sqleOJrR5/pIl1IGlEpqRlv9WV bawY0MFW7OgPvpPHA3+vmjAtSHI3eNu58YVTwlY21vGIjaM1aW5EcuEfp468sbyYNBBPihoO4Lfxe khr2Bq9Pi3ye0uP9KBPaNoGinN0QadOtc6krVdISEfyVBLXz6kkFOFSJ1isbeDBRLo/cf/vjsR/iG 4yRvjqIzwVRHdgkKuWPg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rzBeU-0000000GTpx-2E9Z; Tue, 23 Apr 2024 08:37:22 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rzBeQ-0000000GTox-35XA for linux-arm-kernel@lists.infradead.org; Tue, 23 Apr 2024 08:37:20 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id EF947339; Tue, 23 Apr 2024 01:37:39 -0700 (PDT) Received: from FVFF77S0Q05N (unknown [10.57.21.210]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id DB9CA3F64C; Tue, 23 Apr 2024 01:37:09 -0700 (PDT) Date: Tue, 23 Apr 2024 09:37:04 +0100 From: Mark Rutland To: Marc Zyngier Cc: kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, James Morse , Suzuki K Poulose , Oliver Upton , Zenghui Yu , Arnd Bergmann , Joey Gouly , Will Deacon , Naresh Kamboju , Linaro Kernel Functional Testing Subject: Re: [PATCH] KVM: arm64: nv: Work around lack of pauth support in old toolchains Message-ID: References: <20240422224849.2238222-1-maz@kernel.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20240422224849.2238222-1-maz@kernel.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240423_013718_912622_A594AE8B X-CRM114-Status: GOOD ( 27.55 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.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 > Signed-off-by: Marc Zyngier > --- > 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 > #include > > +/* > + * "// 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 rather than open-coding this new REG() helper? That way this'll be consistent with the way we assemble MRS/MSR in , 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 +#include #include #include -/* - * "// 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