KVM: arm64: Filter out HCR_EL2 bits when running in hypervisor context
authorMarc Zyngier <maz@kernel.org>
Mon, 21 Jul 2025 10:19:50 +0000 (11:19 +0100)
committerOliver Upton <oliver.upton@linux.dev>
Mon, 21 Jul 2025 16:35:57 +0000 (09:35 -0700)
commit303084ad12767db64c84ba8fcd0450aec38c8534
treea7330d850aa4e0bfb33af0dee2443f1acbb6d193
parentc6e35dff58d348c1a9489e9b3b62b3721e62631d
KVM: arm64: Filter out HCR_EL2 bits when running in hypervisor context

Most HCR_EL2 bits are not supposed to affect EL2 at all, but only
the guest. However, we gladly merge these bits with the host's
HCR_EL2 configuration, irrespective of entering L1 or L2.

This leads to some funky behaviour, such as L1 trying to inject
a virtual SError for L2, and getting a taste of its own medecine.
Not quite what the architecture anticipated.

In the end, the only bits that matter are those we have defined as
invariants, either because we've made them RESx (E2H, HCD...), or
that we actively refuse to merge because the mess with KVM's own
logic.

Use the sanitisation infrastructure to get the RES1 bits, and let
things rip in a safer way.

Fixes: 04ab519bb86df ("KVM: arm64: nv: Configure HCR_EL2 for FEAT_NV2")
Signed-off-by: Marc Zyngier <maz@kernel.org>
Cc: stable@vger.kernel.org
Link: https://lore.kernel.org/r/20250721101955.535159-3-maz@kernel.org
Signed-off-by: Oliver Upton <oliver.upton@linux.dev>
arch/arm64/kvm/hyp/vhe/switch.c