From patchwork Thu Mar 21 15:53:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marc Zyngier X-Patchwork-Id: 13599054 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 DBC01CD11DC for ; Thu, 21 Mar 2024 15:55: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:References:In-Reply-To: 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: List-Owner; bh=jYmmemFxfYgYNwRmp7O1DRyQ5qPn7t4HTxRjYqC1yLw=; b=fziXcuh//SaApa 8mAHdjOTJ75N+4jLONAhcb6NKVSRoaJdH8vlPjLE8arND9SSViu/UKt771vOLcwoNIdNKUu6ZvggP pu+ixNStCiiIiz2B1ibHLZS1MkcjK4cJsrTsFMWP10FO6YE8w95Wq7RmVIw7EaFikGLm17UUmEITD Cr8TE1Y+9cDqvyg9TUUH682caLNmYqOatFvG86y8uh9u71VAF5wyyJt3L74rCz1+lyJrppVCfmFJ+ 1CCCwE9DtO0w/lKp4AOO07E+CzbNvlnqiV7ZPoIYddMsrZ54AptQsDtTI1ahPIfSE+sSmBFBy/+6v +yibVdoczrnaGiqN0xmA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rnKky-00000003eIS-0hom; Thu, 21 Mar 2024 15:55:04 +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 1rnKkW-00000003dwC-1LHc for linux-arm-kernel@lists.infradead.org; Thu, 21 Mar 2024 15:54:40 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 9221161207; Thu, 21 Mar 2024 15:54:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5B706C43330; Thu, 21 Mar 2024 15:54:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711036473; bh=rx2CXyS8Z2B7PlM560/Mg4cctxPW0BXZTrgvo90EaJw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SZnBJARKJl73lcaMHtHmRm4e1stVo2Gw0o5rg5xFXwPxs6sbCqJenaqBXSontmKFy fL7eY7MyXtcAIIU1ddGKjBOcfIIu25Qpwb5H4/IUr2HCEuIIO5I2oMleKxaTgatNCk wyjkEOkfJhjWdLgDkgvDz65nl07h8MpLieI5tFarNUpR3RwR2B1dWKOeHixHvnWFAv Q/D7iyEurk936SLwaPKudOGnaoq2m2Be2FulQWS2OVtAiaQpY85dS7KCxUEERfZuk3 34aFpACD7xmrcjtoeuRZmk+pdCSBpVz2eHXgN4xRXQEFxwknb1m9dcLZAJ/7IclACt aQWYRLlVYms2A== 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 1rnKkR-00EEqz-Ks; Thu, 21 Mar 2024 15:54:31 +0000 From: Marc Zyngier To: kvmarm@lists.linux.dev, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: James Morse , Suzuki K Poulose , Oliver Upton , Zenghui Yu , Joey Gouly , Will Deacon , Catalin Marinas Subject: [PATCH v3 11/15] KVM: arm64: nv: Add kvm_has_pauth() helper Date: Thu, 21 Mar 2024 15:53:52 +0000 Message-Id: <20240321155356.3236459-12-maz@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240321155356.3236459-1-maz@kernel.org> References: <20240321155356.3236459-1-maz@kernel.org> MIME-Version: 1.0 X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: kvmarm@lists.linux.dev, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, james.morse@arm.com, suzuki.poulose@arm.com, oliver.upton@linux.dev, yuzenghui@huawei.com, joey.gouly@arm.com, will@kernel.org, catalin.marinas@arm.com 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-20240321_085436_745284_4D195A80 X-CRM114-Status: GOOD ( 10.32 ) 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 Pointer Authentication comes in many flavors, and a faithful emulation relies on correctly handling the flavour implemented by the HW. For this, provide a new kvm_has_pauth() that checks whether we expose to the guest a particular level of support. This checks across all 3 possible authentication algorithms (Q5, Q3 and IMPDEF). Signed-off-by: Marc Zyngier --- arch/arm64/include/asm/kvm_host.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h index 3f1c3c91e5c2..a65701b95078 100644 --- a/arch/arm64/include/asm/kvm_host.h +++ b/arch/arm64/include/asm/kvm_host.h @@ -1335,4 +1335,19 @@ bool kvm_arm_vcpu_stopped(struct kvm_vcpu *vcpu); (get_idreg_field((kvm), id, fld) >= expand_field_sign(id, fld, min) && \ get_idreg_field((kvm), id, fld) <= expand_field_sign(id, fld, max)) +/* Check for a given level of PAuth support */ +#define kvm_has_pauth(k, l) \ + ({ \ + bool pa, pi, pa3; \ + \ + pa = kvm_has_feat((k), ID_AA64ISAR1_EL1, APA, l); \ + pa &= kvm_has_feat((k), ID_AA64ISAR1_EL1, GPA, IMP); \ + pi = kvm_has_feat((k), ID_AA64ISAR1_EL1, API, l); \ + pi &= kvm_has_feat((k), ID_AA64ISAR1_EL1, GPI, IMP); \ + pa3 = kvm_has_feat((k), ID_AA64ISAR2_EL1, APA3, l); \ + pa3 &= kvm_has_feat((k), ID_AA64ISAR2_EL1, GPA3, IMP); \ + \ + (pa + pi + pa3) == 1; \ + }) + #endif /* __ARM64_KVM_HOST_H__ */