From patchwork Thu May 2 17:59:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marc Zyngier X-Patchwork-Id: 13651955 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 0BA95C4345F for ; Thu, 2 May 2024 18:00:31 +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=VbPal5fv5pY7R/GVKnzHgRd1npFUGT0Txl2sAAZRQWo=; b=IuCZdFvrKOFQdP 1Xgg2U5EjnUA9zq+zamcaDIGJNzaHzht/Pw8o5zFeg0CnLqztGmLYBdJCaVNv43eVZ70Wo421SuCd nRcGStByj/vNrK+kPNS4wA8pKBkwKj4Ua3Bvh8/UFG2suujFoRMTsiAT/CwjoPJ3keBJ3nKnNF7Y7 M2rJJ2NiLMrnfsPKNGvPb69SJM58rcpfq7yLGCR2s5bkhXdMNlb6PY7odICuIaXIjfj+9GS8FOurO IkEiFIH5/CR5+lWyQKjDrGOCE386SF6dr9PpGzlUusvtV6/P2t2RzbmESPjdtJJp5sPkpGLTnQw2x pwGxVcB7mL4rGibjALqA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1s2aj5-0000000DWoz-0a4q; Thu, 02 May 2024 18:00:11 +0000 Received: from sin.source.kernel.org ([2604:1380:40e1:4800::1]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1s2aiz-0000000DWmd-2jeq for linux-arm-kernel@lists.infradead.org; Thu, 02 May 2024 18:00:09 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id AAB9DCE176F; Thu, 2 May 2024 18:00:03 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B2C8EC113CC; Thu, 2 May 2024 18:00:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714672802; bh=Uztgc0jtuFiH+ctT5hhpEehjUN1LGFtTpk6OV22QByE=; h=From:To:Cc:Subject:Date:From; b=dJCM1CK64dicof8h9x/SWA1dySmkf96gTwGaxSzHUV0qLTRO/R1yGYnaP8PTABake 4KFOGLuNT/Tzj6XLKPoiXEcQ6s8TvHHusoiHXjWwTkKG+9dU5PC57UAlCYxuN6YHrJ ub7470/h1X5xYAgZMojufrfVsmAk3fXRWLmSM7uvjJBWM7lxGQtRYC7qwvi5rlZG+X 5R7z9+976H6IGUe+KuWnPjtf8Zv3Iau5o0KGkl7CBtN0SkHl6c2lAFbvUsPYVKWBPH rOYog1WugWsd6m9QBqPGYda4r4nrrDDnOt6MfAHFuOWFqE3w8hU32Mm7KKUgvivklK W+O3jZmroInug== 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 1s2ait-00A52w-S9; Thu, 02 May 2024 19:00:00 +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 Subject: [PATCH] KVM: arm64: AArch32: Fix spurious trapping of conditional instructions Date: Thu, 2 May 2024 18:59:56 +0100 Message-Id: <20240502175956.3215496-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, 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 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-20240502_110006_238399_858D5799 X-CRM114-Status: GOOD ( 14.08 ) 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 recently upgraded the view of ESR_EL2 to 64bit, in keeping with the requirements of the architecture. However, the AArch32 emulation code was left unaudited, and the (already dodgy) code that triages whether a trap is spurious or not (because the condition code failed) broke in a subtle way: If ESR_EL2.ISS2 is ever non-zero (unlikely, but hey, this is the ARM architecture we're talking about), the hack that tests the top bits of ESR_EL2.EC will break in an interesting way. Instead, use kvm_vcpu_trap_get_class() to obtain the EC, and list all the possible ECs that can fail a condition code check. While we're at it, add SMC32 to the list, as it is explicitly listed as being allowed to trap despite failing a condition code check (as described in the HCR_EL2.TSC documentation). Fixes: 0b12620fddb8 ("KVM: arm64: Treat ESR_EL2 as a 64-bit register") Signed-off-by: Marc Zyngier --- arch/arm64/kvm/hyp/aarch32.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/arch/arm64/kvm/hyp/aarch32.c b/arch/arm64/kvm/hyp/aarch32.c index 8d9670e6615d..449fa58cf3b6 100644 --- a/arch/arm64/kvm/hyp/aarch32.c +++ b/arch/arm64/kvm/hyp/aarch32.c @@ -50,9 +50,23 @@ bool kvm_condition_valid32(const struct kvm_vcpu *vcpu) u32 cpsr_cond; int cond; - /* Top two bits non-zero? Unconditional. */ - if (kvm_vcpu_get_esr(vcpu) >> 30) + /* + * These are the exception classes that could fire with a + * conditional instruction. + */ + switch (kvm_vcpu_trap_get_class(vcpu)) { + case ESR_ELx_EC_CP15_32: + case ESR_ELx_EC_CP15_64: + case ESR_ELx_EC_CP14_MR: + case ESR_ELx_EC_CP14_LS: + case ESR_ELx_EC_FP_ASIMD: + case ESR_ELx_EC_CP10_ID: + case ESR_ELx_EC_CP14_64: + case ESR_ELx_EC_SVC32: + break; + default: return true; + } /* Is condition field valid? */ cond = kvm_vcpu_get_condition(vcpu);