* [PATCH] KVM: arm64: Filter out HCR_EL2.VSE when running in hypervisor context
@ 2025-07-20 11:33 Marc Zyngier
2025-07-20 17:39 ` Marc Zyngier
0 siblings, 1 reply; 2+ messages in thread
From: Marc Zyngier @ 2025-07-20 11:33 UTC (permalink / raw)
To: kvmarm, kvm, linux-arm-kernel
Cc: Joey Gouly, Suzuki K Poulose, Oliver Upton, Zenghui Yu, stable
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")
Signed-off-by: Marc Zyngier <maz@kernel.org>
Cc: stable@vger.kernel.org
---
arch/arm64/kvm/hyp/vhe/switch.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/arch/arm64/kvm/hyp/vhe/switch.c b/arch/arm64/kvm/hyp/vhe/switch.c
index 477f1580ffeaa..eddda649d9ee1 100644
--- a/arch/arm64/kvm/hyp/vhe/switch.c
+++ b/arch/arm64/kvm/hyp/vhe/switch.c
@@ -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);
--
2.39.2
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] KVM: arm64: Filter out HCR_EL2.VSE when running in hypervisor context
2025-07-20 11:33 [PATCH] KVM: arm64: Filter out HCR_EL2.VSE when running in hypervisor context Marc Zyngier
@ 2025-07-20 17:39 ` Marc Zyngier
0 siblings, 0 replies; 2+ messages in thread
From: Marc Zyngier @ 2025-07-20 17:39 UTC (permalink / raw)
To: kvmarm, kvm, linux-arm-kernel
Cc: Joey Gouly, Suzuki K Poulose, Oliver Upton, Zenghui Yu, stable
On 2025-07-20 12:33, Marc Zyngier wrote:
> 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")
> Signed-off-by: Marc Zyngier <maz@kernel.org>
> Cc: stable@vger.kernel.org
> ---
> arch/arm64/kvm/hyp/vhe/switch.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/arch/arm64/kvm/hyp/vhe/switch.c
> b/arch/arm64/kvm/hyp/vhe/switch.c
> index 477f1580ffeaa..eddda649d9ee1 100644
> --- a/arch/arm64/kvm/hyp/vhe/switch.c
> +++ b/arch/arm64/kvm/hyp/vhe/switch.c
> @@ -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.
--
Jazz is not dead. It just smells funny...
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-07-20 17:39 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-20 11:33 [PATCH] KVM: arm64: Filter out HCR_EL2.VSE when running in hypervisor context Marc Zyngier
2025-07-20 17:39 ` Marc Zyngier
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).