Skip to content

Commit c92e8b9

Browse files
author
Marc Zyngier
committed
KVM: arm64: AArch32: Fix spurious trapping of conditional instructions
We recently upgraded the view of ESR_EL2 to 64bit, in keeping with the requirements of the architecture. However, the AArch32 emulation code was left unaudited, and the (already dodgy) code that triages whether a trap is spurious or not (because the condition code failed) broke in a subtle way: If ESR_EL2.ISS2 is ever non-zero (unlikely, but hey, this is the ARM architecture we're talking about), the hack that tests the top bits of ESR_EL2.EC will break in an interesting way. Instead, use kvm_vcpu_trap_get_class() to obtain the EC, and list all the possible ECs that can fail a condition code check. While we're at it, add SMC32 to the list, as it is explicitly listed as being allowed to trap despite failing a condition code check (as described in the HCR_EL2.TSC documentation). Fixes: 0b12620 ("KVM: arm64: Treat ESR_EL2 as a 64-bit register") Cc: [email protected] Acked-by: Oliver Upton <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Marc Zyngier <[email protected]>
1 parent dfe6d19 commit c92e8b9

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

arch/arm64/kvm/hyp/aarch32.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,23 @@ bool kvm_condition_valid32(const struct kvm_vcpu *vcpu)
5050
u32 cpsr_cond;
5151
int cond;
5252

53-
/* Top two bits non-zero? Unconditional. */
54-
if (kvm_vcpu_get_esr(vcpu) >> 30)
53+
/*
54+
* These are the exception classes that could fire with a
55+
* conditional instruction.
56+
*/
57+
switch (kvm_vcpu_trap_get_class(vcpu)) {
58+
case ESR_ELx_EC_CP15_32:
59+
case ESR_ELx_EC_CP15_64:
60+
case ESR_ELx_EC_CP14_MR:
61+
case ESR_ELx_EC_CP14_LS:
62+
case ESR_ELx_EC_FP_ASIMD:
63+
case ESR_ELx_EC_CP10_ID:
64+
case ESR_ELx_EC_CP14_64:
65+
case ESR_ELx_EC_SVC32:
66+
break;
67+
default:
5568
return true;
69+
}
5670

5771
/* Is condition field valid? */
5872
cond = kvm_vcpu_get_condition(vcpu);

0 commit comments

Comments
 (0)