Commit c83fad65 authored by Sean Christopherson's avatar Sean Christopherson Committed by Paolo Bonzini

KVM: x86: Move #UD injection for failed emulation into emulation code

Immediately inject a #UD and return EMULATE done if emulation fails when
handling an intercepted #UD.  This helps pave the way for removing
EMULATE_FAIL altogether.
Signed-off-by: default avatarSean Christopherson <sean.j.christopherson@intel.com>
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent b4000606
...@@ -5440,7 +5440,6 @@ EXPORT_SYMBOL_GPL(kvm_write_guest_virt_system); ...@@ -5440,7 +5440,6 @@ EXPORT_SYMBOL_GPL(kvm_write_guest_virt_system);
int handle_ud(struct kvm_vcpu *vcpu) int handle_ud(struct kvm_vcpu *vcpu)
{ {
int emul_type = EMULTYPE_TRAP_UD; int emul_type = EMULTYPE_TRAP_UD;
enum emulation_result er;
char sig[5]; /* ud2; .ascii "kvm" */ char sig[5]; /* ud2; .ascii "kvm" */
struct x86_exception e; struct x86_exception e;
...@@ -5452,12 +5451,7 @@ int handle_ud(struct kvm_vcpu *vcpu) ...@@ -5452,12 +5451,7 @@ int handle_ud(struct kvm_vcpu *vcpu)
emul_type = EMULTYPE_TRAP_UD_FORCED; emul_type = EMULTYPE_TRAP_UD_FORCED;
} }
er = kvm_emulate_instruction(vcpu, emul_type); return kvm_emulate_instruction(vcpu, emul_type) != EMULATE_USER_EXIT;
if (er == EMULATE_USER_EXIT)
return 0;
if (er != EMULATE_DONE)
kvm_queue_exception(vcpu, UD_VECTOR);
return 1;
} }
EXPORT_SYMBOL_GPL(handle_ud); EXPORT_SYMBOL_GPL(handle_ud);
...@@ -6630,8 +6624,10 @@ int x86_emulate_instruction(struct kvm_vcpu *vcpu, ...@@ -6630,8 +6624,10 @@ int x86_emulate_instruction(struct kvm_vcpu *vcpu,
++vcpu->stat.insn_emulation; ++vcpu->stat.insn_emulation;
if (r != EMULATION_OK) { if (r != EMULATION_OK) {
if ((emulation_type & EMULTYPE_TRAP_UD) || if ((emulation_type & EMULTYPE_TRAP_UD) ||
(emulation_type & EMULTYPE_TRAP_UD_FORCED)) (emulation_type & EMULTYPE_TRAP_UD_FORCED)) {
return EMULATE_FAIL; kvm_queue_exception(vcpu, UD_VECTOR);
return EMULATE_DONE;
}
if (reexecute_instruction(vcpu, cr2, write_fault_to_spt, if (reexecute_instruction(vcpu, cr2, write_fault_to_spt,
emulation_type)) emulation_type))
return EMULATE_DONE; return EMULATE_DONE;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment