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

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
...@@ -634,8 +634,15 @@ enum emulation_result { ...@@ -634,8 +634,15 @@ enum emulation_result {
#define EMULTYPE_NO_DECODE (1 << 0) #define EMULTYPE_NO_DECODE (1 << 0)
#define EMULTYPE_TRAP_UD (1 << 1) #define EMULTYPE_TRAP_UD (1 << 1)
#define EMULTYPE_SKIP (1 << 2) #define EMULTYPE_SKIP (1 << 2)
int emulate_instruction(struct kvm_vcpu *vcpu, int x86_emulate_instruction(struct kvm_vcpu *vcpu,
unsigned long cr2, u16 error_code, int emulation_type); 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_lgdt(struct kvm_vcpu *vcpu, u16 size, unsigned long address);
void realmode_lidt(struct kvm_vcpu *vcpu, u16 size, unsigned long address); void realmode_lidt(struct kvm_vcpu *vcpu, u16 size, unsigned long address);
......
...@@ -3348,7 +3348,7 @@ int kvm_mmu_page_fault(struct kvm_vcpu *vcpu, gva_t cr2, u32 error_code) ...@@ -3348,7 +3348,7 @@ int kvm_mmu_page_fault(struct kvm_vcpu *vcpu, gva_t cr2, u32 error_code)
if (r) if (r)
goto out; goto out;
er = emulate_instruction(vcpu, cr2, error_code, 0); er = x86_emulate_instruction(vcpu, cr2, 0);
switch (er) { switch (er) {
case EMULATE_DONE: case EMULATE_DONE:
......
...@@ -475,7 +475,7 @@ static void skip_emulated_instruction(struct kvm_vcpu *vcpu) ...@@ -475,7 +475,7 @@ static void skip_emulated_instruction(struct kvm_vcpu *vcpu)
svm->next_rip = svm->vmcb->control.next_rip; svm->next_rip = svm->vmcb->control.next_rip;
if (!svm->next_rip) { if (!svm->next_rip) {
if (emulate_instruction(vcpu, 0, 0, EMULTYPE_SKIP) != if (emulate_instruction(vcpu, EMULTYPE_SKIP) !=
EMULATE_DONE) EMULATE_DONE)
printk(KERN_DEBUG "%s: NOP\n", __func__); printk(KERN_DEBUG "%s: NOP\n", __func__);
return; return;
...@@ -1586,7 +1586,7 @@ static int ud_interception(struct vcpu_svm *svm) ...@@ -1586,7 +1586,7 @@ static int ud_interception(struct vcpu_svm *svm)
{ {
int er; int er;
er = emulate_instruction(&svm->vcpu, 0, 0, EMULTYPE_TRAP_UD); er = emulate_instruction(&svm->vcpu, EMULTYPE_TRAP_UD);
if (er != EMULATE_DONE) if (er != EMULATE_DONE)
kvm_queue_exception(&svm->vcpu, UD_VECTOR); kvm_queue_exception(&svm->vcpu, UD_VECTOR);
return 1; return 1;
...@@ -1703,7 +1703,7 @@ static int io_interception(struct vcpu_svm *svm) ...@@ -1703,7 +1703,7 @@ static int io_interception(struct vcpu_svm *svm)
string = (io_info & SVM_IOIO_STR_MASK) != 0; string = (io_info & SVM_IOIO_STR_MASK) != 0;
in = (io_info & SVM_IOIO_TYPE_MASK) != 0; in = (io_info & SVM_IOIO_TYPE_MASK) != 0;
if (string || in) if (string || in)
return emulate_instruction(vcpu, 0, 0, 0) == EMULATE_DONE; return emulate_instruction(vcpu, 0) == EMULATE_DONE;
port = io_info >> 16; port = io_info >> 16;
size = (io_info & SVM_IOIO_SIZE_MASK) >> SVM_IOIO_SIZE_SHIFT; size = (io_info & SVM_IOIO_SIZE_MASK) >> SVM_IOIO_SIZE_SHIFT;
...@@ -2648,12 +2648,12 @@ static int iret_interception(struct vcpu_svm *svm) ...@@ -2648,12 +2648,12 @@ static int iret_interception(struct vcpu_svm *svm)
static int invlpg_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) 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) static int cr0_write_interception(struct vcpu_svm *svm)
...@@ -2661,7 +2661,7 @@ 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; struct kvm_vcpu *vcpu = &svm->vcpu;
int r; int r;
r = emulate_instruction(&svm->vcpu, 0, 0, 0); r = emulate_instruction(&svm->vcpu, 0);
if (svm->nested.vmexit_rip) { if (svm->nested.vmexit_rip) {
kvm_register_write(vcpu, VCPU_REGS_RIP, 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) ...@@ -2680,7 +2680,7 @@ static int cr8_write_interception(struct vcpu_svm *svm)
u8 cr8_prev = kvm_get_cr8(&svm->vcpu); u8 cr8_prev = kvm_get_cr8(&svm->vcpu);
/* instruction emulation calls kvm_set_cr8() */ /* 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)) { if (irqchip_in_kernel(svm->vcpu.kvm)) {
clr_cr_intercept(svm, INTERCEPT_CR8_WRITE); clr_cr_intercept(svm, INTERCEPT_CR8_WRITE);
return r == EMULATE_DONE; return r == EMULATE_DONE;
......
...@@ -2939,7 +2939,7 @@ static int handle_rmode_exception(struct kvm_vcpu *vcpu, ...@@ -2939,7 +2939,7 @@ static int handle_rmode_exception(struct kvm_vcpu *vcpu,
* Cause the #SS fault with 0 error code in VM86 mode. * Cause the #SS fault with 0 error code in VM86 mode.
*/ */
if (((vec == GP_VECTOR) || (vec == SS_VECTOR)) && err_code == 0) 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; return 1;
/* /*
* Forward all other exceptions that are valid in real mode. * Forward all other exceptions that are valid in real mode.
...@@ -3036,7 +3036,7 @@ static int handle_exception(struct kvm_vcpu *vcpu) ...@@ -3036,7 +3036,7 @@ static int handle_exception(struct kvm_vcpu *vcpu)
} }
if (is_invalid_opcode(intr_info)) { 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) if (er != EMULATE_DONE)
kvm_queue_exception(vcpu, UD_VECTOR); kvm_queue_exception(vcpu, UD_VECTOR);
return 1; return 1;
...@@ -3127,7 +3127,7 @@ static int handle_io(struct kvm_vcpu *vcpu) ...@@ -3127,7 +3127,7 @@ static int handle_io(struct kvm_vcpu *vcpu)
++vcpu->stat.io_exits; ++vcpu->stat.io_exits;
if (string || in) if (string || in)
return emulate_instruction(vcpu, 0, 0, 0) == EMULATE_DONE; return emulate_instruction(vcpu, 0) == EMULATE_DONE;
port = exit_qualification >> 16; port = exit_qualification >> 16;
size = (exit_qualification & 7) + 1; size = (exit_qualification & 7) + 1;
...@@ -3372,7 +3372,7 @@ static int handle_vmx_insn(struct kvm_vcpu *vcpu) ...@@ -3372,7 +3372,7 @@ static int handle_vmx_insn(struct kvm_vcpu *vcpu)
static int handle_invd(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) static int handle_invlpg(struct kvm_vcpu *vcpu)
...@@ -3403,7 +3403,7 @@ static int handle_xsetbv(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) 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) static int handle_task_switch(struct kvm_vcpu *vcpu)
...@@ -3618,7 +3618,7 @@ static int handle_invalid_guest_state(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)) && (kvm_get_rflags(&vmx->vcpu) & X86_EFLAGS_IF))
return handle_interrupt_window(&vmx->vcpu); return handle_interrupt_window(&vmx->vcpu);
err = emulate_instruction(vcpu, 0, 0, 0); err = emulate_instruction(vcpu, 0);
if (err == EMULATE_DO_MMIO) { if (err == EMULATE_DO_MMIO) {
ret = 0; ret = 0;
......
...@@ -4363,10 +4363,9 @@ static bool reexecute_instruction(struct kvm_vcpu *vcpu, gva_t gva) ...@@ -4363,10 +4363,9 @@ static bool reexecute_instruction(struct kvm_vcpu *vcpu, gva_t gva)
return false; return false;
} }
int emulate_instruction(struct kvm_vcpu *vcpu, int x86_emulate_instruction(struct kvm_vcpu *vcpu,
unsigned long cr2, unsigned long cr2,
u16 error_code, int emulation_type)
int emulation_type)
{ {
int r; int r;
struct decode_cache *c = &vcpu->arch.emulate_ctxt.decode; struct decode_cache *c = &vcpu->arch.emulate_ctxt.decode;
...@@ -4474,7 +4473,7 @@ int emulate_instruction(struct kvm_vcpu *vcpu, ...@@ -4474,7 +4473,7 @@ int emulate_instruction(struct kvm_vcpu *vcpu,
return r; 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) 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) ...@@ -5398,7 +5397,7 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
vcpu->mmio_needed = 0; vcpu->mmio_needed = 0;
} }
vcpu->srcu_idx = srcu_read_lock(&vcpu->kvm->srcu); 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); srcu_read_unlock(&vcpu->kvm->srcu, vcpu->srcu_idx);
if (r != EMULATE_DONE) { if (r != EMULATE_DONE) {
r = 0; r = 0;
......
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