From mboxrd@z Thu Jan 1 00:00:00 1970 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 0FBC9C44509 for ; Tue, 14 Jul 2026 09:17:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=c+ZanZNTCeiK1eDDtdkdj8prMqqP83sRneyyFt5rg3k=; b=piaZMNDYSQTvjdLERWlSN5fvum 1nssWQjF4SfxQCWq1cNQz21PbwUlER4S1NcffZS3SLT/Uk5w9Gn2rZBIrWPEOS9LNvpQ16Gy23DxZ 9Hbj3obdoJQ22F2Xm2OVMgUC3hk5JFZPr0Q+1Rr6bL0cAxjJZvLDlPr4wYUtJMIYAmZtVUkg0q+U2 T6llhbZM2Y2q/9USKtJk2iIMqEkTeNqbIm0UeEnitHH9dkiNDTdDaaoiy+WJZJ/tXeQ+NYo0xu664 0yma7ZFhhQzVQwN9Aa3d9j8sSAuni48/gaTeFR5y8MieU8+KcBeW216TowX3t/X3wf3JD1Whsmc5h EfCVnTzA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1wjZGC-0000000BPGl-2yuB; Tue, 14 Jul 2026 09:17:04 +0000 Received: from sea.source.kernel.org ([2600:3c0a:e001:78e:0:1991:8:25]) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1wjZG0-0000000BP3g-1VPk for linux-arm-kernel@lists.infradead.org; Tue, 14 Jul 2026 09:16:52 +0000 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id 22CD043D68; Tue, 14 Jul 2026 09:16:52 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0915A1F0155F; Tue, 14 Jul 2026 09:16:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1784020612; bh=c+ZanZNTCeiK1eDDtdkdj8prMqqP83sRneyyFt5rg3k=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=KHxVGTsjcXDVv7ZwawJ57t4SLcMk9SbcLZVA9P1Jc+YO3CprEnThCl1ftXHPp+a4S BEiqCptLVi2IrZg/KirmAiBORdOFLO2FwclEKpjrYQukaktkQ+RkovLDaq1+r0C1fp fm4XqByVg9VNamCB2mXKtnXvEKVs35AI8JxmKSggQh8Dsk/Ra9r1+6oKxE9ZFmn12f W7+wCzo8OT93KdrdRJmNlOIW+8nPHe7Fd7N2mHhPsh14s4FQTWNC3DNA6c4O2cvUC4 wzmSNaN/HXFOOJ4nsLCGj7jnpnQgueFq6hMcHhCvOSLgRCtSnNYoOFlnpvShhx3GFX KcuX/ySuabCCQ== 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.98.2) (envelope-from ) id 1wjZFy-00000004ny1-1XO4; Tue, 14 Jul 2026 09:16:50 +0000 From: Marc Zyngier To: kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org Cc: Steffen Eiden , Joey Gouly , Suzuki K Poulose , Oliver Upton , Zenghui Yu Subject: [PATCH v2 16/28] KVM: arm64: Split NV-specific exit fixups from the non-NV handling Date: Tue, 14 Jul 2026 10:16:29 +0100 Message-ID: <20260714091641.1970822-17-maz@kernel.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260714091641.1970822-1-maz@kernel.org> References: <20260714091641.1970822-1-maz@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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, seiden@linux.ibm.com, joey.gouly@arm.com, suzuki.poulose@arm.com, oupton@kernel.org, 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-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 In order to facilitate further changes, move the NV handling of early fixups in its own helper. This also makes the code slightly simpler to parse. Signed-off-by: Marc Zyngier --- arch/arm64/kvm/hyp/vhe/switch.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/arch/arm64/kvm/hyp/vhe/switch.c b/arch/arm64/kvm/hyp/vhe/switch.c index 8460a8a6745b3..e26cc575e60e1 100644 --- a/arch/arm64/kvm/hyp/vhe/switch.c +++ b/arch/arm64/kvm/hyp/vhe/switch.c @@ -534,18 +534,15 @@ static const exit_handler_fn hyp_exit_handlers[] = { [0x3F] = kvm_hyp_handle_impdef, }; -static inline bool fixup_guest_exit(struct kvm_vcpu *vcpu, u64 *exit_code) +static void fixup_nv_guest_exit(struct kvm_vcpu *vcpu) { - synchronize_vcpu_pstate(vcpu); - /* * If we were in HYP context on entry, adjust the PSTATE view * so that the usual helpers work correctly. This enforces our * invariant that the guest's HYP context status is preserved * across a run. */ - if (vcpu_has_nv(vcpu) && - unlikely(host_data_test_flag(VCPU_IN_HYP_CONTEXT))) { + if (unlikely(host_data_test_flag(VCPU_IN_HYP_CONTEXT))) { u64 mode = *vcpu_cpsr(vcpu) & (PSR_MODE_MASK | PSR_MODE32_BIT); switch (mode) { @@ -562,8 +559,15 @@ static inline bool fixup_guest_exit(struct kvm_vcpu *vcpu, u64 *exit_code) } /* Apply extreme paranoia! */ - BUG_ON(vcpu_has_nv(vcpu) && - !!host_data_test_flag(VCPU_IN_HYP_CONTEXT) != is_hyp_ctxt(vcpu)); + BUG_ON(!!host_data_test_flag(VCPU_IN_HYP_CONTEXT) != is_hyp_ctxt(vcpu)); +} + +static bool fixup_guest_exit(struct kvm_vcpu *vcpu, u64 *exit_code) +{ + synchronize_vcpu_pstate(vcpu); + + if (vcpu_has_nv(vcpu)) + fixup_nv_guest_exit(vcpu); return __fixup_guest_exit(vcpu, exit_code, hyp_exit_handlers); } -- 2.47.3