Skip to content

Commit 6ea6e84

Browse files
committed
KVM: x86: inject exceptions produced by x86_decode_insn
Sometimes, a processor might execute an instruction while another processor is updating the page tables for that instruction's code page, but before the TLB shootdown completes. The interesting case happens if the page is in the TLB. In general, the processor will succeed in executing the instruction and nothing bad happens. However, what if the instruction is an MMIO access? If *that* happens, KVM invokes the emulator, and the emulator gets the updated page tables. If the update side had marked the code page as non present, the page table walk then will fail and so will x86_decode_insn. Unfortunately, even though kvm_fetch_guest_virt is correctly returning X86EMUL_PROPAGATE_FAULT, x86_decode_insn's caller treats the failure as a fatal error if the instruction cannot simply be reexecuted (as is the case for MMIO). And this in fact happened sometimes when rebooting Windows 2012r2 guests. Just checking ctxt->have_exception and injecting the exception if true is enough to fix the case. Thanks to Eduardo Habkost for helping in the debugging of this issue. Reported-by: Yanan Fu <[email protected]> Cc: Eduardo Habkost <[email protected]> Cc: [email protected] Signed-off-by: Paolo Bonzini <[email protected]> Signed-off-by: Radim Krčmář <[email protected]>
1 parent fab0aa3 commit 6ea6e84

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

arch/x86/kvm/x86.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5734,6 +5734,8 @@ int x86_emulate_instruction(struct kvm_vcpu *vcpu,
57345734
if (reexecute_instruction(vcpu, cr2, write_fault_to_spt,
57355735
emulation_type))
57365736
return EMULATE_DONE;
5737+
if (ctxt->have_exception && inject_emulated_exception(vcpu))
5738+
return EMULATE_DONE;
57375739
if (emulation_type & EMULTYPE_SKIP)
57385740
return EMULATE_FAIL;
57395741
return handle_emulation_failure(vcpu);

0 commit comments

Comments
 (0)