From patchwork Fri Apr 19 10:29:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marc Zyngier X-Patchwork-Id: 13636198 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 07193C4345F for ; Fri, 19 Apr 2024 10:30:41 +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=NElBJOtJli3UtJnlTo4Iv0vfgylaWs0wCbQvd/ltxww=; b=zoV26rcw9csq/V uVsGphuhXL3XO9UIDN7mzDc/ROMYkzyYIQaiTb4XeX76vZrtuUPkVQqnMlF+dNq/8zitLfr1XOUmM qi4GC+poDWlBZeGWFk38t1ouQj/UftpRymr/KOTowNnnUXVrf0UkShnwIJyeYr6SwSV8BFGHNUpRP NTg7GfggRZrJZU80lLaONBN3GVVnW1pY7BcCJIQTlibwGoMtzb3FtYwPEM9ie35AOCHvCrx2DpZCQ 5XeKIKuDgVP99MfjVSAFOfJBJr2AjNWMzH2is1l0G2F0GBZiAycEgsJOAzBFtAVOz3LF8oYcMG8Q6 dMPF8nUWqH5BmtIuYhtQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rxlVk-00000005JGt-2oLD; Fri, 19 Apr 2024 10:30:28 +0000 Received: from dfw.source.kernel.org ([2604:1380:4641:c500::1]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rxlVE-00000005Ir4-3EWD for linux-arm-kernel@lists.infradead.org; Fri, 19 Apr 2024 10:29:58 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 4C8E76198C; Fri, 19 Apr 2024 10:29:53 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1B53DC32783; Fri, 19 Apr 2024 10:29:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713522593; bh=Dg+Z7zG4VBF0sGpOvyZhMnvQ2Jf+rhquslT9NGMAOik=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=slKkS3pAX2xzK1+VjPrqoDAeYLJp4NHm9HxcI7GC/8htf4d3sGcyAIJs9iXudt7gQ v5FvzU/ommGyYo5pFO6OEE2mEB4+BHrFRtKNs3k0gyg+zVCGsPO8y/uJ2xFTpSmMzF EQJEgtCfpzVJPXkVEr6Mcqy0e38gz+EMroHnkDsW9h3G2CLD47UzxQbt+U6YMnE6zM gjNj1bODCrQBpz/SUZeeXiFDhnSr7zZgESNBUHaWC59TZEthIgwuB1tEJ+UxkYFPOs ryKEktzAWMruRX7oDx8WY63FBqDEaO7TBQ2iM3W5EGJpfXuKTey9h7ArJVAczjuV9b gBj22R7G2zS9w== 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 1rxlV9-00636W-DP; Fri, 19 Apr 2024 11:29:51 +0100 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 , Fuad Tabba , Mostafa Saleh , Will Deacon , Catalin Marinas Subject: [PATCH v4 11/15] KVM: arm64: nv: Add kvm_has_pauth() helper Date: Fri, 19 Apr 2024 11:29:31 +0100 Message-Id: <20240419102935.1935571-12-maz@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240419102935.1935571-1-maz@kernel.org> References: <20240419102935.1935571-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, tabba@google.com, smostafa@google.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-20240419_032957_074447_F2D75A8C X-CRM114-Status: GOOD ( 10.93 ) 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 5566191d646a..ed4d82017b87 100644 --- a/arch/arm64/include/asm/kvm_host.h +++ b/arch/arm64/include/asm/kvm_host.h @@ -1336,4 +1336,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__ */