Skip to content

Commit 8530a79

Browse files
Jan Dakinevichbonzini
authored andcommitted
KVM: x86: always stop emulation on page fault
inject_emulated_exception() returns true if and only if nested page fault happens. However, page fault can come from guest page tables walk, either nested or not nested. In both cases we should stop an attempt to read under RIP and give guest to step over its own page fault handler. This is also visible when an emulated instruction causes a #GP fault and the VMware backdoor is enabled. To handle the VMware backdoor, KVM intercepts #GP faults; with only the next patch applied, x86_emulate_instruction() injects a #GP but returns EMULATE_FAIL instead of EMULATE_DONE. EMULATE_FAIL causes handle_exception_nmi() (or gp_interception() for SVM) to re-inject the original #GP because it thinks emulation failed due to a non-VMware opcode. This patch prevents the issue as x86_emulate_instruction() will return EMULATE_DONE after injecting the #GP. Fixes: 6ea6e84 ("KVM: x86: inject exceptions produced by x86_decode_insn") Cc: [email protected] Cc: Denis Lunev <[email protected]> Cc: Roman Kagan <[email protected]> Cc: Denis Plotnikov <[email protected]> Signed-off-by: Jan Dakinevich <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 380e005 commit 8530a79

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

arch/x86/kvm/x86.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6576,8 +6576,10 @@ int x86_emulate_instruction(struct kvm_vcpu *vcpu,
65766576
if (reexecute_instruction(vcpu, cr2, write_fault_to_spt,
65776577
emulation_type))
65786578
return EMULATE_DONE;
6579-
if (ctxt->have_exception && inject_emulated_exception(vcpu))
6579+
if (ctxt->have_exception) {
6580+
inject_emulated_exception(vcpu);
65806581
return EMULATE_DONE;
6582+
}
65816583
if (emulation_type & EMULTYPE_SKIP)
65826584
return EMULATE_FAIL;
65836585
return handle_emulation_failure(vcpu, emulation_type);

0 commit comments

Comments
 (0)