public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Marc Zyngier <maz@kernel.org>, Fuad Tabba <tabba@google.com>,
	Sasha Levin <sashal@kernel.org>,
	catalin.marinas@arm.com, will@kernel.org, ardb@kernel.org,
	alexandru.elisei@arm.com, qperret@google.com, ascull@google.com,
	mark.rutland@arm.com, steven.price@arm.com,
	linux-arm-kernel@lists.infradead.org,
	kvmarm@lists.cs.columbia.edu
Subject: [PATCH AUTOSEL 5.10 02/15] KVM: arm64: Save PSTATE early on exit
Date: Mon,  6 Dec 2021 16:15:02 -0500	[thread overview]
Message-ID: <20211206211520.1660478-2-sashal@kernel.org> (raw)
In-Reply-To: <20211206211520.1660478-1-sashal@kernel.org>

From: Marc Zyngier <maz@kernel.org>

[ Upstream commit 83bb2c1a01d7127d5adc7d69d7aaa3f7072de2b4 ]

In order to be able to use primitives such as vcpu_mode_is_32bit(),
we need to synchronize the guest PSTATE. However, this is currently
done deep into the bowels of the world-switch code, and we do have
helpers evaluating this much earlier (__vgic_v3_perform_cpuif_access
and handle_aarch32_guest, for example).

Move the saving of the guest pstate into the early fixups, which
cures the first issue. The second one will be addressed separately.

Tested-by: Fuad Tabba <tabba@google.com>
Reviewed-by: Fuad Tabba <tabba@google.com>
Signed-off-by: Marc Zyngier <maz@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 arch/arm64/kvm/hyp/include/hyp/switch.h    | 6 ++++++
 arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h | 7 ++++++-
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/arch/arm64/kvm/hyp/include/hyp/switch.h b/arch/arm64/kvm/hyp/include/hyp/switch.h
index 1f875a8f20c47..8116ae1e636a2 100644
--- a/arch/arm64/kvm/hyp/include/hyp/switch.h
+++ b/arch/arm64/kvm/hyp/include/hyp/switch.h
@@ -406,6 +406,12 @@ static inline bool __hyp_handle_ptrauth(struct kvm_vcpu *vcpu)
  */
 static inline bool fixup_guest_exit(struct kvm_vcpu *vcpu, u64 *exit_code)
 {
+	/*
+	 * Save PSTATE early so that we can evaluate the vcpu mode
+	 * early on.
+	 */
+	vcpu->arch.ctxt.regs.pstate = read_sysreg_el2(SYS_SPSR);
+
 	if (ARM_EXCEPTION_CODE(*exit_code) != ARM_EXCEPTION_IRQ)
 		vcpu->arch.fault.esr_el2 = read_sysreg_el2(SYS_ESR);
 
diff --git a/arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h b/arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h
index cce43bfe158fa..0eacfb9d17b02 100644
--- a/arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h
+++ b/arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h
@@ -54,7 +54,12 @@ static inline void __sysreg_save_el1_state(struct kvm_cpu_context *ctxt)
 static inline void __sysreg_save_el2_return_state(struct kvm_cpu_context *ctxt)
 {
 	ctxt->regs.pc			= read_sysreg_el2(SYS_ELR);
-	ctxt->regs.pstate		= read_sysreg_el2(SYS_SPSR);
+	/*
+	 * Guest PSTATE gets saved at guest fixup time in all
+	 * cases. We still need to handle the nVHE host side here.
+	 */
+	if (!has_vhe() && ctxt->__hyp_running_vcpu)
+		ctxt->regs.pstate	= read_sysreg_el2(SYS_SPSR);
 
 	if (cpus_have_final_cap(ARM64_HAS_RAS_EXTN))
 		ctxt_sys_reg(ctxt, DISR_EL1) = read_sysreg_s(SYS_VDISR_EL2);
-- 
2.33.0


  reply	other threads:[~2021-12-06 21:16 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-06 21:15 [PATCH AUTOSEL 5.10 01/15] drm/msm/dsi: set default num_data_lanes Sasha Levin
2021-12-06 21:15 ` Sasha Levin [this message]
2021-12-06 21:15 ` [PATCH AUTOSEL 5.10 03/15] s390/test_unwind: use raw opcode instead of invalid instruction Sasha Levin
2021-12-06 21:15 ` [PATCH AUTOSEL 5.10 04/15] Revert "tty: serial: fsl_lpuart: drop earlycon entry for i.MX8QXP" Sasha Levin
2021-12-06 21:15 ` [PATCH AUTOSEL 5.10 05/15] USB: NO_LPM quirk Lenovo Powered USB-C Travel Hub Sasha Levin
2021-12-06 21:15 ` [PATCH AUTOSEL 5.10 06/15] net/mlx4_en: Update reported link modes for 1/10G Sasha Levin
2021-12-06 21:15 ` [PATCH AUTOSEL 5.10 07/15] ALSA: hda: Add Intel DG2 PCI ID and HDMI codec vid Sasha Levin
2021-12-06 21:15 ` [PATCH AUTOSEL 5.10 08/15] ALSA: hda/hdmi: fix HDA codec entry table order for ADL-P Sasha Levin
2021-12-06 21:15 ` [PATCH AUTOSEL 5.10 09/15] tools: Fix math.h breakage Sasha Levin
2021-12-06 21:15 ` [PATCH AUTOSEL 5.10 10/15] parisc/agp: Annotate parisc agp init functions with __init Sasha Levin
2021-12-06 21:15 ` [PATCH AUTOSEL 5.10 11/15] i2c: rk3x: Handle a spurious start completion interrupt flag Sasha Levin
2021-12-06 21:15 ` [PATCH AUTOSEL 5.10 12/15] net: netlink: af_netlink: Prevent empty skb by adding a check on len Sasha Levin
2021-12-06 21:15 ` [PATCH AUTOSEL 5.10 13/15] drm/amd/display: Fix for the no Audio bug with Tiled Displays Sasha Levin
2021-12-06 21:15 ` [PATCH AUTOSEL 5.10 14/15] drm/amd/display: add connector type check for CRC source set Sasha Levin
2021-12-06 21:15 ` [PATCH AUTOSEL 5.10 15/15] tracing: Fix a kmemleak false positive in tracing_map Sasha Levin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211206211520.1660478-2-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=alexandru.elisei@arm.com \
    --cc=ardb@kernel.org \
    --cc=ascull@google.com \
    --cc=catalin.marinas@arm.com \
    --cc=kvmarm@lists.cs.columbia.edu \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=maz@kernel.org \
    --cc=qperret@google.com \
    --cc=stable@vger.kernel.org \
    --cc=steven.price@arm.com \
    --cc=tabba@google.com \
    --cc=will@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox