Skip to contentSkip to conversation

KVM: arm64: Filter out HCR_EL2.VSE when running in hypervisor context

PATCH In review Marc Zyngier 1 participant 2 messages Jul 20, 2025

Subsystems (4)
lore
Share & tools
lore

Marc Zyngier

author maintainer
#0 lore raw

PATCH 1/1 KVM: arm64: Filter out HCR_EL2.VSE when running in hypervisor context

HCR_EL2.VSE is delivering a virtual SError to the guest, and does not affect EL2 itself. However, when computing the host's HCR_EL2 value, we take the guest's view of HCR_EL2.VSE at face value, and apply it irrespective of the guest's exception level we are returning to.

The result is that a L1 hypervisor injecting a virtual SError to an L2 by setting its HCR_EL2.VSE to 1 results in itself getting the SError as if it was a physical one if it traps for any reason before returning to L2.

Fix it by filtering HCR_EL2.VSE out when entering the L1 host context.

Fixes 04ab519bb86df ("KVM: arm64: nv: Configure HCR_EL2 for FEAT_NV2")
---
 arch/arm64/kvm/hyp/vhe/switch.c | 3 +++
 1 file changed, 3 insertions(+)
arch/arm64/kvm/hyp/vhe/switch.c +3 -0
index 477f1580ffeaa..eddda649d9ee1 100644
@@ -68,6 +68,9 @@ static u64 __compute_hcr(struct kvm_vcpu *vcpu)
 		if (!vcpu_el2_e2h_is_set(vcpu))
 			hcr |= HCR_NV1;
 
+		/* Virtual SErrors only apply to L2, not L1 */
+		guest_hcr &= ~HCR_VSE;
+
 		write_sysreg_s(vcpu->arch.ctxt.vncr_array, SYS_VNCR_EL2);
 	} else {
 		host_data_clear_flag(VCPU_IN_HYP_CONTEXT);
Signature · 1 line
2.39.2
author maintainer
#1 lore raw
Quoted 24 lines · Marc Zyngier

HCR_EL2.VSE is delivering a virtual SError to the guest, and does not affect EL2 itself. However, when computing the host's HCR_EL2 value, we take the guest's view of HCR_EL2.VSE at face value, and apply it irrespective of the guest's exception level we are returning to.

The result is that a L1 hypervisor injecting a virtual SError to an L2 by setting its HCR_EL2.VSE to 1 results in itself getting the SError as if it was a physical one if it traps for any reason before returning to L2.

Fix it by filtering HCR_EL2.VSE out when entering the L1 host context.

Fixes 04ab519bb86df ("KVM: arm64: nv: Configure HCR_EL2 for FEAT_NV2")
---
 arch/arm64/kvm/hyp/vhe/switch.c | 3 +++
 1 file changed, 3 insertions(+)
arch/arm64/kvm/hyp/vhe/switch.c +0 -0
index 477f1580ffeaa..eddda649d9ee1 100644

arch/arm64/kvm/hyp/vhe/switch.c static u64 __compute_hcr(struct kvm_vcpu *vcpu) · line 76

Quoted 9 lines
arch/arm64/kvm/hyp/vhe/switch.c +3 -0
@@ -68,6 +68,9 @@ static u64 __compute_hcr(struct kvm_vcpu *vcpu)
 		if (!vcpu_el2_e2h_is_set(vcpu))
 			hcr |= HCR_NV1;
 
+		/* Virtual SErrors only apply to L2, not L1 */
+		guest_hcr &= ~HCR_VSE;
+
 		write_sysreg_s(vcpu->arch.ctxt.vncr_array, SYS_VNCR_EL2);
 	} else {
 		host_data_clear_flag(VCPU_IN_HYP_CONTEXT);

Actually, a better fix would be just nuke any bit that doesn't affect the HYP context. And that's almost all of them, bar the RES1 bits.

I'll repost something once I am done dealing with the rest of the RAS enabling stuff.

        M.
Signature · 1 line
Jazz is not dead. It just smells funny...