From patchwork Mon Apr 22 22:48:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marc Zyngier X-Patchwork-Id: 13639174 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 59FEBC4345F for ; Mon, 22 Apr 2024 22:49:19 +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:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=GNYvt2bw9/StX+UkdrIdCSPIjrnsLul2Vf3ktQGnyNo=; b=ThQBKZ9iABKzhD sWlKrMVudWA2m92nEws00xrugKSPlE172zijRinyZ/Lde8mHmktIsSBwf5lH2ajB7thoIvGy2urYK qQ9gpIcygNnyXEmJf9BcxaGk7h8wKARAG6j9muQc4xTrM3libjy42ML0js5+EI2uZUOTLzEcBsYuJ aXag4vJwh9sCBTJpNDhIzfQeUACmQuO8Rxx6IgaM7OaXWkzm1UDL/QnfQWEDK6rP//+a1ARFShm5Y iA/619Tms+DHpchyf/xIsgi3Oq0uepHMDyH7KEAU5nQqtWIJ0+TYosoD1sFzkdbuiqphQgwIfRFTw AiMp/mWA64mTPKeF3AGA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rz2T9-0000000FFvc-3pPc; Mon, 22 Apr 2024 22:49:03 +0000 Received: from dfw.source.kernel.org ([139.178.84.217]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rz2T7-0000000FFvB-0eYt for linux-arm-kernel@lists.infradead.org; Mon, 22 Apr 2024 22:49:02 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id D47DF611DA; Mon, 22 Apr 2024 22:48:59 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 76A74C113CC; Mon, 22 Apr 2024 22:48:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713826139; bh=fm2a+0xycqqxT06+SBw2+4DgyIhfefjKQ/8uOfWuuLg=; h=From:To:Cc:Subject:Date:From; b=WSUQWyv+Cu5v8pGzEk7LzEBVlG4c2pdAWwXAgfD+OEe8qB35toLs5QlAD+KGXau6F NeqYcDy1q8YROd7l0SwHCKsRQNoRiwKR92/N2PbXoM1nlDvI2N3RCZ1SVYay8F5ol5 8eiDROQAKbmSZhrMmleQejBjJuUjJNJzWKq+67KhKxlvgNkaZXxNUecxW5M1/D0Hhd owSOjGZSjpY+S9WOF9HPL40lKkkUEY+5T8RO8k/TWg27F+2e9fev6Y09FZtN4iB383 /3i6PSBc4ig046mTwUbMwmMFS+1+ixVAil288NqH8j/Cx0SFlJTUkOHeStrhl1ZEX0 pWD8y76NF9ttA== Received: from sofa.misterjones.org ([185.219.108.64] helo=valley-girl.lan) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1rz2T2-006xt0-QU; Mon, 22 Apr 2024 23:48:56 +0100 From: Marc Zyngier To: kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org Cc: James Morse , Suzuki K Poulose , Oliver Upton , Zenghui Yu , Arnd Bergmann , Mark Rutland , Joey Gouly , Will Deacon , Naresh Kamboju , Linaro Kernel Functional Testing Subject: [PATCH] KVM: arm64: nv: Work around lack of pauth support in old toolchains Date: Mon, 22 Apr 2024 23:48:49 +0100 Message-Id: <20240422224849.2238222-1-maz@kernel.org> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, james.morse@arm.com, suzuki.poulose@arm.com, oliver.upton@linux.dev, yuzenghui@huawei.com, arnd@arndb.de, mark.rutland@arm.com, joey.gouly@arm.com, will@kernel.org, naresh.kamboju@linaro.org, lkft@linaro.org X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240422_154901_305421_F8881F78 X-CRM114-Status: GOOD ( 14.83 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 Acked-by: Arnd Bergmann --- 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))) + 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);