Commit 22da61c9 authored by Sean Christopherson's avatar Sean Christopherson Committed by Paolo Bonzini
Browse files

KVM: x86: Clean up handle_emulation_failure()



When handling emulation failure, return the emulation result directly
instead of capturing it in a local variable.  Future patches will move
additional cases into handle_emulation_failure(), clean up the cruft
before so there isn't an ugly mix of setting a local variable and
returning directly.

Reviewed-by: default avatarVitaly Kuznetsov <vkuznets@redhat.com>
Reviewed-by: default avatarLiran Alon <liran.alon@oracle.com>
Signed-off-by: default avatarSean Christopherson <sean.j.christopherson@intel.com>
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent bc8a0aaf
Loading
Loading
Loading
Loading
+4 −6
Original line number Original line Diff line number Diff line
@@ -6304,24 +6304,22 @@ EXPORT_SYMBOL_GPL(kvm_inject_realmode_interrupt);


static int handle_emulation_failure(struct kvm_vcpu *vcpu, int emulation_type)
static int handle_emulation_failure(struct kvm_vcpu *vcpu, int emulation_type)
{
{
	int r = EMULATE_DONE;

	++vcpu->stat.insn_emulation_fail;
	++vcpu->stat.insn_emulation_fail;
	trace_kvm_emulate_insn_failed(vcpu);
	trace_kvm_emulate_insn_failed(vcpu);


	if (emulation_type & EMULTYPE_NO_UD_ON_FAIL)
	if (emulation_type & EMULTYPE_NO_UD_ON_FAIL)
		return EMULATE_FAIL;
		return EMULATE_FAIL;


	kvm_queue_exception(vcpu, UD_VECTOR);

	if (!is_guest_mode(vcpu) && kvm_x86_ops->get_cpl(vcpu) == 0) {
	if (!is_guest_mode(vcpu) && kvm_x86_ops->get_cpl(vcpu) == 0) {
		vcpu->run->exit_reason = KVM_EXIT_INTERNAL_ERROR;
		vcpu->run->exit_reason = KVM_EXIT_INTERNAL_ERROR;
		vcpu->run->internal.suberror = KVM_INTERNAL_ERROR_EMULATION;
		vcpu->run->internal.suberror = KVM_INTERNAL_ERROR_EMULATION;
		vcpu->run->internal.ndata = 0;
		vcpu->run->internal.ndata = 0;
		r = EMULATE_USER_EXIT;
		return EMULATE_USER_EXIT;
	}
	}


	kvm_queue_exception(vcpu, UD_VECTOR);
	return EMULATE_DONE;

	return r;
}
}


static bool reexecute_instruction(struct kvm_vcpu *vcpu, gva_t cr2,
static bool reexecute_instruction(struct kvm_vcpu *vcpu, gva_t cr2,