aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndre Przywara <andre.przywara@amd.com>2010-12-21 05:12:02 -0500
committerAvi Kivity <avi@redhat.com>2011-01-12 04:31:00 -0500
commit51d8b66199e94284e7725a79eae4a38de4b80d54 (patch)
tree904e8c206d9d1d52eb673c235c08b7a612cce9b0
parentdb8fcefaa704ccb40b6dcd24e3b75bad3ce7dde3 (diff)
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: Andre Przywara <andre.przywara@amd.com> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
-rw-r--r--arch/x86/include/asm/kvm_host.h11
-rw-r--r--arch/x86/kvm/mmu.c2
-rw-r--r--arch/x86/kvm/svm.c14
-rw-r--r--arch/x86/kvm/vmx.c12
-rw-r--r--arch/x86/kvm/x86.c11
5 files changed, 28 insertions, 22 deletions
diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index cd4a990e8a12..de00b6026b76 100644
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -634,8 +634,15 @@ enum emulation_result {
634#define EMULTYPE_NO_DECODE (1 << 0) 634#define EMULTYPE_NO_DECODE (1 << 0)
635#define EMULTYPE_TRAP_UD (1 << 1) 635#define EMULTYPE_TRAP_UD (1 << 1)
636#define EMULTYPE_SKIP (1 << 2) 636#define EMULTYPE_SKIP (1 << 2)
637int emulate_instruction(struct kvm_vcpu *vcpu, 637int x86_emulate_instruction(struct kvm_vcpu *vcpu,
638 unsigned long cr2, u16 error_code, int emulation_type); 638 unsigned long cr2, int emulation_type);
639
640static inline int emulate_instruction(struct kvm_vcpu *vcpu,
641 int emulation_type)
642{
643 return x86_emulate_instruction(vcpu, 0, emulation_type);
644}
645
639void realmode_lgdt(struct kvm_vcpu *vcpu, u16 size, unsigned long address); 646void realmode_lgdt(struct kvm_vcpu *vcpu, u16 size, unsigned long address);
640void realmode_lidt(struct kvm_vcpu *vcpu, u16 size, unsigned long address); 647void realmode_lidt(struct kvm_vcpu *vcpu, u16 size, unsigned long address);
641 648
diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c
index 475a1225f6ec..01c5a104031f 100644
--- a/arch/x86/kvm/mmu.c
+++ b/arch/x86/kvm/mmu.c
@@ -3348,7 +3348,7 @@ int kvm_mmu_page_fault(struct kvm_vcpu *vcpu, gva_t cr2, u32 error_code)
3348 if (r) 3348 if (r)
3349 goto out; 3349 goto out;
3350 3350
3351 er = emulate_instruction(vcpu, cr2, error_code, 0); 3351 er = x86_emulate_instruction(vcpu, cr2, 0);
3352 3352
3353 switch (er) { 3353 switch (er) {
3354 case EMULATE_DONE: 3354 case EMULATE_DONE:
diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
index 3d4b88af50f9..90d06582aac0 100644
--- a/arch/x86/kvm/svm.c
+++ b/arch/x86/kvm/svm.c
@@ -475,7 +475,7 @@ static void skip_emulated_instruction(struct kvm_vcpu *vcpu)
475 svm->next_rip = svm->vmcb->control.next_rip; 475 svm->next_rip = svm->vmcb->control.next_rip;
476 476
477 if (!svm->next_rip) { 477 if (!svm->next_rip) {
478 if (emulate_instruction(vcpu, 0, 0, EMULTYPE_SKIP) != 478 if (emulate_instruction(vcpu, EMULTYPE_SKIP) !=
479 EMULATE_DONE) 479 EMULATE_DONE)
480 printk(KERN_DEBUG "%s: NOP\n", __func__); 480 printk(KERN_DEBUG "%s: NOP\n", __func__);
481 return; 481 return;
@@ -1586,7 +1586,7 @@ static int ud_interception(struct vcpu_svm *svm)
1586{ 1586{
1587 int er; 1587 int er;
1588 1588
1589 er = emulate_instruction(&svm->vcpu, 0, 0, EMULTYPE_TRAP_UD); 1589 er = emulate_instruction(&svm->vcpu, EMULTYPE_TRAP_UD);
1590 if (er != EMULATE_DONE) 1590 if (er != EMULATE_DONE)
1591 kvm_queue_exception(&svm->vcpu, UD_VECTOR); 1591 kvm_queue_exception(&svm->vcpu, UD_VECTOR);
1592 return 1; 1592 return 1;
@@ -1703,7 +1703,7 @@ static int io_interception(struct vcpu_svm *svm)
1703 string = (io_info & SVM_IOIO_STR_MASK) != 0; 1703 string = (io_info & SVM_IOIO_STR_MASK) != 0;
1704 in = (io_info & SVM_IOIO_TYPE_MASK) != 0; 1704 in = (io_info & SVM_IOIO_TYPE_MASK) != 0;
1705 if (string || in) 1705 if (string || in)
1706 return emulate_instruction(vcpu, 0, 0, 0) == EMULATE_DONE; 1706 return emulate_instruction(vcpu, 0) == EMULATE_DONE;
1707 1707
1708 port = io_info >> 16; 1708 port = io_info >> 16;
1709 size = (io_info & SVM_IOIO_SIZE_MASK) >> SVM_IOIO_SIZE_SHIFT; 1709 size = (io_info & SVM_IOIO_SIZE_MASK) >> SVM_IOIO_SIZE_SHIFT;
@@ -2648,12 +2648,12 @@ static int iret_interception(struct vcpu_svm *svm)
2648 2648
2649static int invlpg_interception(struct vcpu_svm *svm) 2649static int invlpg_interception(struct vcpu_svm *svm)
2650{ 2650{
2651 return emulate_instruction(&svm->vcpu, 0, 0, 0) == EMULATE_DONE; 2651 return emulate_instruction(&svm->vcpu, 0) == EMULATE_DONE;
2652} 2652}
2653 2653
2654static int emulate_on_interception(struct vcpu_svm *svm) 2654static int emulate_on_interception(struct vcpu_svm *svm)
2655{ 2655{
2656 return emulate_instruction(&svm->vcpu, 0, 0, 0) == EMULATE_DONE; 2656 return emulate_instruction(&svm->vcpu, 0) == EMULATE_DONE;
2657} 2657}
2658 2658
2659static int cr0_write_interception(struct vcpu_svm *svm) 2659static int cr0_write_interception(struct vcpu_svm *svm)
@@ -2661,7 +2661,7 @@ static int cr0_write_interception(struct vcpu_svm *svm)
2661 struct kvm_vcpu *vcpu = &svm->vcpu; 2661 struct kvm_vcpu *vcpu = &svm->vcpu;
2662 int r; 2662 int r;
2663 2663
2664 r = emulate_instruction(&svm->vcpu, 0, 0, 0); 2664 r = emulate_instruction(&svm->vcpu, 0);
2665 2665
2666 if (svm->nested.vmexit_rip) { 2666 if (svm->nested.vmexit_rip) {
2667 kvm_register_write(vcpu, VCPU_REGS_RIP, svm->nested.vmexit_rip); 2667 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 2680
2681 u8 cr8_prev = kvm_get_cr8(&svm->vcpu); 2681 u8 cr8_prev = kvm_get_cr8(&svm->vcpu);
2682 /* instruction emulation calls kvm_set_cr8() */ 2682 /* instruction emulation calls kvm_set_cr8() */
2683 r = emulate_instruction(&svm->vcpu, 0, 0, 0); 2683 r = emulate_instruction(&svm->vcpu, 0);
2684 if (irqchip_in_kernel(svm->vcpu.kvm)) { 2684 if (irqchip_in_kernel(svm->vcpu.kvm)) {
2685 clr_cr_intercept(svm, INTERCEPT_CR8_WRITE); 2685 clr_cr_intercept(svm, INTERCEPT_CR8_WRITE);
2686 return r == EMULATE_DONE; 2686 return r == EMULATE_DONE;
diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index fd8ffde73755..f3c60fb8d95e 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -2939,7 +2939,7 @@ static int handle_rmode_exception(struct kvm_vcpu *vcpu,
2939 * Cause the #SS fault with 0 error code in VM86 mode. 2939 * Cause the #SS fault with 0 error code in VM86 mode.
2940 */ 2940 */
2941 if (((vec == GP_VECTOR) || (vec == SS_VECTOR)) && err_code == 0) 2941 if (((vec == GP_VECTOR) || (vec == SS_VECTOR)) && err_code == 0)
2942 if (emulate_instruction(vcpu, 0, 0, 0) == EMULATE_DONE) 2942 if (emulate_instruction(vcpu, 0) == EMULATE_DONE)
2943 return 1; 2943 return 1;
2944 /* 2944 /*
2945 * Forward all other exceptions that are valid in real mode. 2945 * Forward all other exceptions that are valid in real mode.
@@ -3036,7 +3036,7 @@ static int handle_exception(struct kvm_vcpu *vcpu)
3036 } 3036 }
3037 3037
3038 if (is_invalid_opcode(intr_info)) { 3038 if (is_invalid_opcode(intr_info)) {
3039 er = emulate_instruction(vcpu, 0, 0, EMULTYPE_TRAP_UD); 3039 er = emulate_instruction(vcpu, EMULTYPE_TRAP_UD);
3040 if (er != EMULATE_DONE) 3040 if (er != EMULATE_DONE)
3041 kvm_queue_exception(vcpu, UD_VECTOR); 3041 kvm_queue_exception(vcpu, UD_VECTOR);
3042 return 1; 3042 return 1;
@@ -3127,7 +3127,7 @@ static int handle_io(struct kvm_vcpu *vcpu)
3127 ++vcpu->stat.io_exits; 3127 ++vcpu->stat.io_exits;
3128 3128
3129 if (string || in) 3129 if (string || in)
3130 return emulate_instruction(vcpu, 0, 0, 0) == EMULATE_DONE; 3130 return emulate_instruction(vcpu, 0) == EMULATE_DONE;
3131 3131
3132 port = exit_qualification >> 16; 3132 port = exit_qualification >> 16;
3133 size = (exit_qualification & 7) + 1; 3133 size = (exit_qualification & 7) + 1;
@@ -3372,7 +3372,7 @@ static int handle_vmx_insn(struct kvm_vcpu *vcpu)
3372 3372
3373static int handle_invd(struct kvm_vcpu *vcpu) 3373static int handle_invd(struct kvm_vcpu *vcpu)
3374{ 3374{
3375 return emulate_instruction(vcpu, 0, 0, 0) == EMULATE_DONE; 3375 return emulate_instruction(vcpu, 0) == EMULATE_DONE;
3376} 3376}
3377 3377
3378static int handle_invlpg(struct kvm_vcpu *vcpu) 3378static int handle_invlpg(struct kvm_vcpu *vcpu)
@@ -3403,7 +3403,7 @@ static int handle_xsetbv(struct kvm_vcpu *vcpu)
3403 3403
3404static int handle_apic_access(struct kvm_vcpu *vcpu) 3404static int handle_apic_access(struct kvm_vcpu *vcpu)
3405{ 3405{
3406 return emulate_instruction(vcpu, 0, 0, 0) == EMULATE_DONE; 3406 return emulate_instruction(vcpu, 0) == EMULATE_DONE;
3407} 3407}
3408 3408
3409static int handle_task_switch(struct kvm_vcpu *vcpu) 3409static int handle_task_switch(struct kvm_vcpu *vcpu)
@@ -3618,7 +3618,7 @@ static int handle_invalid_guest_state(struct kvm_vcpu *vcpu)
3618 && (kvm_get_rflags(&vmx->vcpu) & X86_EFLAGS_IF)) 3618 && (kvm_get_rflags(&vmx->vcpu) & X86_EFLAGS_IF))
3619 return handle_interrupt_window(&vmx->vcpu); 3619 return handle_interrupt_window(&vmx->vcpu);
3620 3620
3621 err = emulate_instruction(vcpu, 0, 0, 0); 3621 err = emulate_instruction(vcpu, 0);
3622 3622
3623 if (err == EMULATE_DO_MMIO) { 3623 if (err == EMULATE_DO_MMIO) {
3624 ret = 0; 3624 ret = 0;
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 1d54cb7f3358..a6fcb76196b7 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -4363,10 +4363,9 @@ static bool reexecute_instruction(struct kvm_vcpu *vcpu, gva_t gva)
4363 return false; 4363 return false;
4364} 4364}
4365 4365
4366int emulate_instruction(struct kvm_vcpu *vcpu, 4366int x86_emulate_instruction(struct kvm_vcpu *vcpu,
4367 unsigned long cr2, 4367 unsigned long cr2,
4368 u16 error_code, 4368 int emulation_type)
4369 int emulation_type)
4370{ 4369{
4371 int r; 4370 int r;
4372 struct decode_cache *c = &vcpu->arch.emulate_ctxt.decode; 4371 struct decode_cache *c = &vcpu->arch.emulate_ctxt.decode;
@@ -4474,7 +4473,7 @@ done:
4474 4473
4475 return r; 4474 return r;
4476} 4475}
4477EXPORT_SYMBOL_GPL(emulate_instruction); 4476EXPORT_SYMBOL_GPL(x86_emulate_instruction);
4478 4477
4479int kvm_fast_pio_out(struct kvm_vcpu *vcpu, int size, unsigned short port) 4478int kvm_fast_pio_out(struct kvm_vcpu *vcpu, int size, unsigned short port)
4480{ 4479{
@@ -5398,7 +5397,7 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
5398 vcpu->mmio_needed = 0; 5397 vcpu->mmio_needed = 0;
5399 } 5398 }
5400 vcpu->srcu_idx = srcu_read_lock(&vcpu->kvm->srcu); 5399 vcpu->srcu_idx = srcu_read_lock(&vcpu->kvm->srcu);
5401 r = emulate_instruction(vcpu, 0, 0, EMULTYPE_NO_DECODE); 5400 r = emulate_instruction(vcpu, EMULTYPE_NO_DECODE);
5402 srcu_read_unlock(&vcpu->kvm->srcu, vcpu->srcu_idx); 5401 srcu_read_unlock(&vcpu->kvm->srcu, vcpu->srcu_idx);
5403 if (r != EMULATE_DONE) { 5402 if (r != EMULATE_DONE) {
5404 r = 0; 5403 r = 0;