From patchwork Tue May 28 10:06: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: 13676420 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 98A33C25B7C for ; Tue, 28 May 2024 10:07:05 +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=dhsAm+It8+yWc9MTBUlUB+pV6mTvCKx+bfzh8lJQNtk=; b=TcCE9Pzlh8Aw++ 8HJpE4u727BoTZMH4rFDyTU8RWYeEvaLfqwtwz9GYLadtDPBPVp1pfEEGZ9mmY9qPwPf9PdlJBgHA Nv/XDaCRTl6bEF+uKQCI4uGHW6zC9vwl60Jz//1JruVXb70dOCB2iBx/MAoR1zSdzVNWX1Vwu1gDD x86sCnb1xVX+EVbNuj77Iscw9w05H2bYv0zc2dfbjeyppE3mm/4B3qjPC3/6PwZDuhVY7QdR9Y5vi xLIxpFsm5b8s0OkwS7eG8tbAzeIzPmmAhfrede8HdtupJyBMzbvpmqbXlSFN3HDSXliaqTBXAnR9l k1Oldot9f9U8kxOFi/DQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sBtjI-000000009Vs-1gUD; Tue, 28 May 2024 10:06:52 +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 1sBtjF-000000009Ur-3qqB for linux-arm-kernel@lists.infradead.org; Tue, 28 May 2024 10:06:51 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 2E59561E65; Tue, 28 May 2024 10:06:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D8EB3C32782; Tue, 28 May 2024 10:06:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1716890808; bh=RPq4l8wKvYlXeHYmhj8r/m8AdUmE1Arj5xOYZhuRmZo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Wq2ipwc0RcVwlSHuN/R9V0XSzZL9LOjJdhnNkrvQu1VtsHxAzTeYHc8+tpesitbR7 i05WiRJS1Oc7jHJ0fiXrZIttXU86S6iDTJDWox+CATL1erXY79b/61bidKCEm10H0U kMN1foTytXN62r82wdYa5X6WgFma8JzHU8LAlvS5rjC70an9t22toXt5JkCBhGp7rw EoGBWVRE1M1Tg2AfFzbk+xsqzdKdiNIwSrmBt38FK9hCqKccqseBZKivVUeVyThJsE 0gDT9kupOMXVianWuX86ku0V8fp8JdLCSkNdThsCSVQqVP58tUGt8UVPga/KUidSl1 kMHD9yCINPsTA== 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 1sBtjD-00GFdz-1O; Tue, 28 May 2024 11:06:47 +0100 From: Marc Zyngier To: kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org Cc: James Morse , Suzuki K Poulose , Oliver Upton , Zenghui Yu , Joey Gouly Subject: [PATCH 1/2] KVM: arm64: nv: Fix relative priorities of exceptions generated by ERETAx Date: Tue, 28 May 2024 11:06:31 +0100 Message-Id: <20240528100632.1831995-2-maz@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240528100632.1831995-1-maz@kernel.org> References: <20240528100632.1831995-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, linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org, james.morse@arm.com, suzuki.poulose@arm.com, oliver.upton@linux.dev, yuzenghui@huawei.com, joey.gouly@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-20240528_030650_210041_EBEED277 X-CRM114-Status: GOOD ( 17.11 ) 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 ERETAx can fail in multiple ways: (1) ELR_EL2 points lalaland (2) we get a PAC failure (3) SPSR_EL2 has the wrong mode (1) is easy, as we just let the CPU do its thing and deliver an Instruction Abort. However, (2) and (3) are interesting, because the PAC failure priority is way below that of the Illegal Execution State exception. Which means that if we have detected a PAC failure (and that we have FPACCOMBINE), we must be careful to give priority to the Illegal Execution State exception, should one be pending. Solving this involves hoisting the SPSR calculation earlier and testing for the IL bit before injecting the FPAC exception. In the extreme case of a ERETAx returning to an invalid mode *and* failing its PAC check, we end up with an Instruction Abort (due to the new PC being mangled by the failed Auth) *and* PSTATE.IL being set. Which matches the requirements of the architecture. Whilst we're at it, remove a stale comment that states the obvious and only confuses the reader. Fixes: 213b3d1ea161 ("KVM: arm64: nv: Handle ERETA[AB] instructions") Signed-off-by: Marc Zyngier Reviewed-by: Joey Gouly --- arch/arm64/kvm/emulate-nested.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/arch/arm64/kvm/emulate-nested.c b/arch/arm64/kvm/emulate-nested.c index 72d733c74a38..54090967a335 100644 --- a/arch/arm64/kvm/emulate-nested.c +++ b/arch/arm64/kvm/emulate-nested.c @@ -2181,16 +2181,23 @@ void kvm_emulate_nested_eret(struct kvm_vcpu *vcpu) if (forward_traps(vcpu, HCR_NV)) return; + spsr = vcpu_read_sys_reg(vcpu, SPSR_EL2); + spsr = kvm_check_illegal_exception_return(vcpu, spsr); + /* Check for an ERETAx */ esr = kvm_vcpu_get_esr(vcpu); if (esr_iss_is_eretax(esr) && !kvm_auth_eretax(vcpu, &elr)) { /* - * Oh no, ERETAx failed to authenticate. If we have - * FPACCOMBINE, deliver an exception right away. If we - * don't, then let the mangled ELR value trickle down the + * Oh no, ERETAx failed to authenticate. + * + * If we have FPACCOMBINE and we don't have a pending + * Illegal Execution State exception (which has priority + * over FPAC), deliver an exception right away. + * + * Otherwise, let the mangled ELR value trickle down the * ERET handling, and the guest will have a little surprise. */ - if (kvm_has_pauth(vcpu->kvm, FPACCOMBINE)) { + if (kvm_has_pauth(vcpu->kvm, FPACCOMBINE) && !(spsr & PSR_IL_BIT)) { esr &= ESR_ELx_ERET_ISS_ERETA; esr |= FIELD_PREP(ESR_ELx_EC_MASK, ESR_ELx_EC_FPAC); kvm_inject_nested_sync(vcpu, esr); @@ -2201,17 +2208,11 @@ void kvm_emulate_nested_eret(struct kvm_vcpu *vcpu) preempt_disable(); kvm_arch_vcpu_put(vcpu); - spsr = __vcpu_sys_reg(vcpu, SPSR_EL2); - spsr = kvm_check_illegal_exception_return(vcpu, spsr); if (!esr_iss_is_eretax(esr)) elr = __vcpu_sys_reg(vcpu, ELR_EL2); trace_kvm_nested_eret(vcpu, elr, spsr); - /* - * Note that the current exception level is always the virtual EL2, - * since we set HCR_EL2.NV bit only when entering the virtual EL2. - */ *vcpu_pc(vcpu) = elr; *vcpu_cpsr(vcpu) = spsr; From patchwork Tue May 28 10:06:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marc Zyngier X-Patchwork-Id: 13676422 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 F4026C25B78 for ; Tue, 28 May 2024 10:07:11 +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=OkqmGwp5DNN2LQR/gcJJSZB3CtkuXgAD0zzSPt38jiY=; b=lpn4Rvl9Ssio/d T3B+4DT48EhzlinH2gTfWYv4Yg2XiDh4VIJ+ApU9YxbaGVpvB53aKnPQtO0SWe/I6KFYTy08J/YNJ Q7byTYZApwwyNr57M19bzNsjthGBb7hW5PfN+ZfT3zGuiAOnfZVL7YRNEGph+FZjw2FJv2wbrSnHK vpIoyCZWSeGUWolr2Kk31Wb8T2N0GYWfG9DAAxlTMe6ghrFNC7pH1n/YHnVyY7z0qRNm+LuN+2IDf uNOyAu1AY0Oq3KSHFM4eMutZajFDV3E9BD0wo027TtbTG7GxLHB6EtLKYY3YJfUVvaYaHpiFzqt6s Efl558g16SIjoBsKNLwg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sBtjP-000000009YQ-3Xqi; Tue, 28 May 2024 10:06:59 +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 1sBtjG-000000009Us-1o6x for linux-arm-kernel@lists.infradead.org; Tue, 28 May 2024 10:06:51 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 9CB1461E43; Tue, 28 May 2024 10:06:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 53F59C32781; Tue, 28 May 2024 10:06:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1716890809; bh=yLKxPsfVUrnjvhtPXA7gFp6zdgd0T66pRYoAQcmZlfY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=t+FfRFRlmYNX3hiRUF2bFhYz9CLruH8MMvqdFJiTAxKxUz2pv0/6GcaBzGatxsOJ8 PQTeoEoqZZr9w0bJYNbOReZIOVwQOdfPQPM6oiZhdzbSkWY5HlrOHjoL/bgomblZRp NPUZP6o3KNQeKSssWxUBr5KSJcplwIYLs8o2oWrt7/bgA1R4BGMWMVZx0L6mrPiwsg RYkn6CaWY1j2IPuwkScUVMGN4P94U5IJcFTevsi8WiH5C9gJD7b92DqVws9IK1gSrZ XK8ElbzrrmPboh+gUyBHQt4QZCvke6JM2BSewNK/Ji5Dzy++U+Iw1obQyo1gJoe2O5 eJq5GaT0fiuWw== 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 1sBtjD-00GFdz-7C; Tue, 28 May 2024 11:06:47 +0100 From: Marc Zyngier To: kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org Cc: James Morse , Suzuki K Poulose , Oliver Upton , Zenghui Yu , Joey Gouly Subject: [PATCH 2/2] KVM: arm64: nv: Expose BTI and CSV_frac to a guest hypervisor Date: Tue, 28 May 2024 11:06:32 +0100 Message-Id: <20240528100632.1831995-3-maz@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240528100632.1831995-1-maz@kernel.org> References: <20240528100632.1831995-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, linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org, james.morse@arm.com, suzuki.poulose@arm.com, oliver.upton@linux.dev, yuzenghui@huawei.com, joey.gouly@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-20240528_030650_593996_84159C87 X-CRM114-Status: GOOD ( 11.51 ) 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 Now that we expose PAC to NV guests, we can also expose BTI (as the two as joined at the hip, due to some of the PAC instructions being landing pads). While we're at it, also propagate CSV_frac, which requires no particular emulation. Fixes: f4f6a95bac49 ("KVM: arm64: nv: Advertise support for PAuth") Signed-off-by: Marc Zyngier --- arch/arm64/kvm/nested.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/arch/arm64/kvm/nested.c b/arch/arm64/kvm/nested.c index 6813c7c7f00a..bae8536cbf00 100644 --- a/arch/arm64/kvm/nested.c +++ b/arch/arm64/kvm/nested.c @@ -58,8 +58,10 @@ static u64 limit_nv_id_reg(u32 id, u64 val) break; case SYS_ID_AA64PFR1_EL1: - /* Only support SSBS */ - val &= NV_FTR(PFR1, SSBS); + /* Only support BTI, SSBS, CSV2_frac */ + val &= (NV_FTR(PFR1, BT) | + NV_FTR(PFR1, SSBS) | + NV_FTR(PFR1, CSV2_frac)); break; case SYS_ID_AA64MMFR0_EL1: