Skip to content

Commit 2785830

Browse files
author
Marc Zyngier
committed
KVM: arm64: Use shadow SPSR_EL1 when injecting exceptions on !VHE
Injecting an exception into a guest with non-VHE is risky business. Instead of writing in the shadow register for the switch code to restore it, we override the CPU register instead. Which gets overriden a few instructions later by said restore code. The result is that although the guest correctly gets the exception, it will return to the original context in some random state, depending on what was there the first place... Boo. Fix the issue by writing to the shadow register. The original code is absolutely fine on VHE, as the state is already loaded, and writing to the shadow register in that case would actually be a bug. Fixes: bb666c4 ("KVM: arm64: Inject AArch64 exceptions from HYP") Cc: [email protected] Signed-off-by: Marc Zyngier <[email protected]> Reviewed-by: Fuad Tabba <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent d11a327 commit 2785830

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

arch/arm64/kvm/hyp/exception.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ static inline void __vcpu_write_sys_reg(struct kvm_vcpu *vcpu, u64 val, int reg)
3838

3939
static void __vcpu_write_spsr(struct kvm_vcpu *vcpu, u64 val)
4040
{
41-
write_sysreg_el1(val, SYS_SPSR);
41+
if (has_vhe())
42+
write_sysreg_el1(val, SYS_SPSR);
43+
else
44+
__vcpu_sys_reg(vcpu, SPSR_EL1) = val;
4245
}
4346

4447
static void __vcpu_write_spsr_abt(struct kvm_vcpu *vcpu, u64 val)

0 commit comments

Comments
 (0)