Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 51d8b661 authored by Andre Przywara's avatar Andre Przywara Committed by Avi Kivity
Browse files

KVM: cleanup emulate_instruction



emulate_instruction had many callers, but only one used all
parameters. One parameter was unused, another one is now
hidden by a wrapper function (required for a future addition
anyway), so most callers use now a shorter parameter list.

Signed-off-by: default avatarAndre Przywara <andre.przywara@amd.com>
Signed-off-by: default avatarMarcelo Tosatti <mtosatti@redhat.com>
parent db8fcefa
Loading
Loading
Loading
Loading
+9 −2
Original line number Diff line number Diff line
@@ -634,8 +634,15 @@ enum emulation_result {
#define EMULTYPE_NO_DECODE	    (1 << 0)
#define EMULTYPE_TRAP_UD	    (1 << 1)
#define EMULTYPE_SKIP		    (1 << 2)
int emulate_instruction(struct kvm_vcpu *vcpu,
			unsigned long cr2, u16 error_code, int emulation_type);
int x86_emulate_instruction(struct kvm_vcpu *vcpu,
			unsigned long cr2, int emulation_type);

static inline int emulate_instruction(struct kvm_vcpu *vcpu,
			int emulation_type)
{
	return x86_emulate_instruction(vcpu, 0, emulation_type);
}

void realmode_lgdt(struct kvm_vcpu *vcpu, u16 size, unsigned long address);
void realmode_lidt(struct kvm_vcpu *vcpu, u16 size, unsigned long address);

+1 −1
Original line number Diff line number Diff line
@@ -3348,7 +3348,7 @@ int kvm_mmu_page_fault(struct kvm_vcpu *vcpu, gva_t cr2, u32 error_code)
	if (r)
		goto out;

	er = emulate_instruction(vcpu, cr2, error_code, 0);
	er = x86_emulate_instruction(vcpu, cr2, 0);

	switch (er) {
	case EMULATE_DONE:
+7 −7
Original line number Diff line number Diff line
@@ -475,7 +475,7 @@ static void skip_emulated_instruction(struct kvm_vcpu *vcpu)
		svm->next_rip = svm->vmcb->control.next_rip;

	if (!svm->next_rip) {
		if (emulate_instruction(vcpu, 0, 0, EMULTYPE_SKIP) !=
		if (emulate_instruction(vcpu, EMULTYPE_SKIP) !=
				EMULATE_DONE)
			printk(KERN_DEBUG "%s: NOP\n", __func__);
		return;
@@ -1586,7 +1586,7 @@ static int ud_interception(struct vcpu_svm *svm)
{
	int er;

	er = emulate_instruction(&svm->vcpu, 0, 0, EMULTYPE_TRAP_UD);
	er = emulate_instruction(&svm->vcpu, EMULTYPE_TRAP_UD);
	if (er != EMULATE_DONE)
		kvm_queue_exception(&svm->vcpu, UD_VECTOR);
	return 1;
@@ -1703,7 +1703,7 @@ static int io_interception(struct vcpu_svm *svm)
	string = (io_info & SVM_IOIO_STR_MASK) != 0;
	in = (io_info & SVM_IOIO_TYPE_MASK) != 0;
	if (string || in)
		return emulate_instruction(vcpu, 0, 0, 0) == EMULATE_DONE;
		return emulate_instruction(vcpu, 0) == EMULATE_DONE;

	port = io_info >> 16;
	size = (io_info & SVM_IOIO_SIZE_MASK) >> SVM_IOIO_SIZE_SHIFT;
@@ -2648,12 +2648,12 @@ static int iret_interception(struct vcpu_svm *svm)

static int invlpg_interception(struct vcpu_svm *svm)
{
	return emulate_instruction(&svm->vcpu, 0, 0, 0) == EMULATE_DONE;
	return emulate_instruction(&svm->vcpu, 0) == EMULATE_DONE;
}

static int emulate_on_interception(struct vcpu_svm *svm)
{
	return emulate_instruction(&svm->vcpu, 0, 0, 0) == EMULATE_DONE;
	return emulate_instruction(&svm->vcpu, 0) == EMULATE_DONE;
}

static int cr0_write_interception(struct vcpu_svm *svm)
@@ -2661,7 +2661,7 @@ static int cr0_write_interception(struct vcpu_svm *svm)
	struct kvm_vcpu *vcpu = &svm->vcpu;
	int r;

	r = emulate_instruction(&svm->vcpu, 0, 0, 0);
	r = emulate_instruction(&svm->vcpu, 0);

	if (svm->nested.vmexit_rip) {
		kvm_register_write(vcpu, VCPU_REGS_RIP, svm->nested.vmexit_rip);
@@ -2680,7 +2680,7 @@ static int cr8_write_interception(struct vcpu_svm *svm)

	u8 cr8_prev = kvm_get_cr8(&svm->vcpu);
	/* instruction emulation calls kvm_set_cr8() */
	r = emulate_instruction(&svm->vcpu, 0, 0, 0);
	r = emulate_instruction(&svm->vcpu, 0);
	if (irqchip_in_kernel(svm->vcpu.kvm)) {
		clr_cr_intercept(svm, INTERCEPT_CR8_WRITE);
		return r == EMULATE_DONE;
+6 −6
Original line number Diff line number Diff line
@@ -2939,7 +2939,7 @@ static int handle_rmode_exception(struct kvm_vcpu *vcpu,
	 * Cause the #SS fault with 0 error code in VM86 mode.
	 */
	if (((vec == GP_VECTOR) || (vec == SS_VECTOR)) && err_code == 0)
		if (emulate_instruction(vcpu, 0, 0, 0) == EMULATE_DONE)
		if (emulate_instruction(vcpu, 0) == EMULATE_DONE)
			return 1;
	/*
	 * Forward all other exceptions that are valid in real mode.
@@ -3036,7 +3036,7 @@ static int handle_exception(struct kvm_vcpu *vcpu)
	}

	if (is_invalid_opcode(intr_info)) {
		er = emulate_instruction(vcpu, 0, 0, EMULTYPE_TRAP_UD);
		er = emulate_instruction(vcpu, EMULTYPE_TRAP_UD);
		if (er != EMULATE_DONE)
			kvm_queue_exception(vcpu, UD_VECTOR);
		return 1;
@@ -3127,7 +3127,7 @@ static int handle_io(struct kvm_vcpu *vcpu)
	++vcpu->stat.io_exits;

	if (string || in)
		return emulate_instruction(vcpu, 0, 0, 0) == EMULATE_DONE;
		return emulate_instruction(vcpu, 0) == EMULATE_DONE;

	port = exit_qualification >> 16;
	size = (exit_qualification & 7) + 1;
@@ -3372,7 +3372,7 @@ static int handle_vmx_insn(struct kvm_vcpu *vcpu)

static int handle_invd(struct kvm_vcpu *vcpu)
{
	return emulate_instruction(vcpu, 0, 0, 0) == EMULATE_DONE;
	return emulate_instruction(vcpu, 0) == EMULATE_DONE;
}

static int handle_invlpg(struct kvm_vcpu *vcpu)
@@ -3403,7 +3403,7 @@ static int handle_xsetbv(struct kvm_vcpu *vcpu)

static int handle_apic_access(struct kvm_vcpu *vcpu)
{
	return emulate_instruction(vcpu, 0, 0, 0) == EMULATE_DONE;
	return emulate_instruction(vcpu, 0) == EMULATE_DONE;
}

static int handle_task_switch(struct kvm_vcpu *vcpu)
@@ -3618,7 +3618,7 @@ static int handle_invalid_guest_state(struct kvm_vcpu *vcpu)
		    && (kvm_get_rflags(&vmx->vcpu) & X86_EFLAGS_IF))
			return handle_interrupt_window(&vmx->vcpu);

		err = emulate_instruction(vcpu, 0, 0, 0);
		err = emulate_instruction(vcpu, 0);

		if (err == EMULATE_DO_MMIO) {
			ret = 0;
+5 −6
Original line number Diff line number Diff line
@@ -4363,9 +4363,8 @@ static bool reexecute_instruction(struct kvm_vcpu *vcpu, gva_t gva)
	return false;
}

int emulate_instruction(struct kvm_vcpu *vcpu,
int x86_emulate_instruction(struct kvm_vcpu *vcpu,
			    unsigned long cr2,
			u16 error_code,
			    int emulation_type)
{
	int r;
@@ -4474,7 +4473,7 @@ done:

	return r;
}
EXPORT_SYMBOL_GPL(emulate_instruction);
EXPORT_SYMBOL_GPL(x86_emulate_instruction);

int kvm_fast_pio_out(struct kvm_vcpu *vcpu, int size, unsigned short port)
{
@@ -5398,7 +5397,7 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
			vcpu->mmio_needed = 0;
		}
		vcpu->srcu_idx = srcu_read_lock(&vcpu->kvm->srcu);
		r = emulate_instruction(vcpu, 0, 0, EMULTYPE_NO_DECODE);
		r = emulate_instruction(vcpu, EMULTYPE_NO_DECODE);
		srcu_read_unlock(&vcpu->kvm->srcu, vcpu->srcu_idx);
		if (r != EMULATE_DONE) {
			r = 0;