From: Marc Zyngier <maz@kernel.org>
To: kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org,
kvm@vger.kernel.org
Cc: Joey Gouly <joey.gouly@arm.com>,
Suzuki K Poulose <suzuki.poulose@arm.com>,
Oliver Upton <oliver.upton@linux.dev>,
Zenghui Yu <yuzenghui@huawei.com>,
Andre Przywara <andre.przywara@arm.com>,
Eric Auger <eric.auger@redhat.com>
Subject: [PATCH v2 12/17] KVM: arm64: nv: Respect virtual HCR_EL2.TWx setting
Date: Sun, 12 Jan 2025 17:08:40 +0000 [thread overview]
Message-ID: <20250112170845.1181891-13-maz@kernel.org> (raw)
In-Reply-To: <20250112170845.1181891-1-maz@kernel.org>
From: Jintack Lim <jintack.lim@linaro.org>
Forward exceptions due to WFI or WFE instructions to the virtual EL2 if
they are not coming from the virtual EL2 and virtual HCR_EL2.TWx is set.
Signed-off-by: Jintack Lim <jintack.lim@linaro.org>
Signed-off-by: Marc Zyngier <maz@kernel.org>
---
arch/arm64/include/asm/kvm_emulate.h | 13 +++++++++++++
arch/arm64/kvm/handle_exit.c | 6 +++++-
2 files changed, 18 insertions(+), 1 deletion(-)
diff --git a/arch/arm64/include/asm/kvm_emulate.h b/arch/arm64/include/asm/kvm_emulate.h
index cf811009a33c9..5d2af20f75890 100644
--- a/arch/arm64/include/asm/kvm_emulate.h
+++ b/arch/arm64/include/asm/kvm_emulate.h
@@ -281,6 +281,19 @@ static __always_inline u64 kvm_vcpu_get_esr(const struct kvm_vcpu *vcpu)
return vcpu->arch.fault.esr_el2;
}
+static inline bool guest_hyp_wfx_traps_enabled(const struct kvm_vcpu *vcpu)
+{
+ u64 esr = kvm_vcpu_get_esr(vcpu);
+ bool is_wfe = !!(esr & ESR_ELx_WFx_ISS_WFE);
+ u64 hcr_el2 = __vcpu_sys_reg(vcpu, HCR_EL2);
+
+ if (!vcpu_has_nv(vcpu) || vcpu_is_el2(vcpu))
+ return false;
+
+ return ((is_wfe && (hcr_el2 & HCR_TWE)) ||
+ (!is_wfe && (hcr_el2 & HCR_TWI)));
+}
+
static __always_inline int kvm_vcpu_get_condition(const struct kvm_vcpu *vcpu)
{
u64 esr = kvm_vcpu_get_esr(vcpu);
diff --git a/arch/arm64/kvm/handle_exit.c b/arch/arm64/kvm/handle_exit.c
index d7c2990e7c9ed..206eb6698db70 100644
--- a/arch/arm64/kvm/handle_exit.c
+++ b/arch/arm64/kvm/handle_exit.c
@@ -129,8 +129,12 @@ static int kvm_handle_fpasimd(struct kvm_vcpu *vcpu)
static int kvm_handle_wfx(struct kvm_vcpu *vcpu)
{
u64 esr = kvm_vcpu_get_esr(vcpu);
+ bool is_wfe = !!(esr & ESR_ELx_WFx_ISS_WFE);
- if (esr & ESR_ELx_WFx_ISS_WFE) {
+ if (guest_hyp_wfx_traps_enabled(vcpu))
+ return kvm_inject_nested_sync(vcpu, kvm_vcpu_get_esr(vcpu));
+
+ if (is_wfe) {
trace_kvm_wfx_arm64(*vcpu_pc(vcpu), true);
vcpu->stat.wfe_exit_stat++;
} else {
--
2.39.2
next prev parent reply other threads:[~2025-01-12 17:08 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-12 17:08 [PATCH v2 00/17] KVM: arm64: Add NV GICv3 support Marc Zyngier
2025-01-12 17:08 ` [PATCH v2 01/17] arm64: sysreg: Add layout for ICH_HCR_EL2 Marc Zyngier
2025-01-15 18:39 ` Andre Przywara
2025-01-12 17:08 ` [PATCH v2 02/17] arm64: sysreg: Add layout for ICH_VTR_EL2 Marc Zyngier
2025-01-15 18:40 ` Andre Przywara
2025-01-12 17:08 ` [PATCH v2 03/17] arm64: sysreg: Add layout for ICH_MISR_EL2 Marc Zyngier
2025-01-15 18:41 ` Andre Przywara
2025-01-12 17:08 ` [PATCH v2 04/17] KVM: arm64: Move host SVE/SME state flags out of vCPU Marc Zyngier
2025-01-12 17:08 ` [PATCH v2 05/17] KVM: arm64: nv: Load timer before the GIC Marc Zyngier
2025-01-12 17:08 ` [PATCH v2 06/17] KVM: arm64: nv: Add ICH_*_EL2 registers to vpcu_sysreg Marc Zyngier
2025-01-12 17:08 ` [PATCH v2 07/17] KVM: arm64: nv: Plumb handling of GICv3 EL2 accesses Marc Zyngier
2025-01-12 17:08 ` [PATCH v2 08/17] KVM: arm64: nv: Sanitise ICH_HCR_EL2 accesses Marc Zyngier
2025-01-12 17:08 ` [PATCH v2 09/17] KVM: arm64: nv: Nested GICv3 emulation Marc Zyngier
2025-01-12 17:08 ` [PATCH v2 10/17] KVM: arm64: nv: Handle L2->L1 transition on interrupt injection Marc Zyngier
2025-01-12 17:08 ` [PATCH v2 11/17] KVM: arm64: nv: Add Maintenance Interrupt emulation Marc Zyngier
2025-01-12 17:08 ` Marc Zyngier [this message]
2025-01-12 17:08 ` [PATCH v2 13/17] KVM: arm64: nv: Request vPE doorbell upon nested ERET to L2 Marc Zyngier
2025-01-12 17:08 ` [PATCH v2 14/17] KVM: arm64: nv: Propagate used_lrs between L1 and L0 contexts Marc Zyngier
2025-01-12 17:08 ` [PATCH v2 15/17] KVM: arm64: nv: Fold GICv3 host trapping requirements into guest setup Marc Zyngier
2025-01-12 17:08 ` [PATCH v2 16/17] KVM: arm64: nv: Allow userland to set VGIC maintenance IRQ Marc Zyngier
2025-01-12 17:08 ` [PATCH v2 17/17] KVM: arm64: nv: Fail KVM init if asking for NV without GICv3 Marc Zyngier
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=20250112170845.1181891-13-maz@kernel.org \
--to=maz@kernel.org \
--cc=andre.przywara@arm.com \
--cc=eric.auger@redhat.com \
--cc=joey.gouly@arm.com \
--cc=kvm@vger.kernel.org \
--cc=kvmarm@lists.linux.dev \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=oliver.upton@linux.dev \
--cc=suzuki.poulose@arm.com \
--cc=yuzenghui@huawei.com \
/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