Commit 3090dd73 authored by Laurent Vivier's avatar Laurent Vivier Committed by Avi Kivity

KVM: Clean up kvm_setup_pio()

Split kvm_setup_pio() into two functions, one to setup in/out pio
(kvm_emulate_pio()) and one to setup ins/outs pio (kvm_emulate_pio_string()).
Signed-off-by: default avatarLaurent Vivier <Laurent.Vivier@bull.net>
Signed-off-by: default avatarAvi Kivity <avi@qumranet.com>
parent e70669ab
...@@ -539,9 +539,11 @@ int kvm_set_msr(struct kvm_vcpu *vcpu, u32 msr_index, u64 data); ...@@ -539,9 +539,11 @@ int kvm_set_msr(struct kvm_vcpu *vcpu, u32 msr_index, u64 data);
struct x86_emulate_ctxt; struct x86_emulate_ctxt;
int kvm_setup_pio(struct kvm_vcpu *vcpu, struct kvm_run *run, int in, int kvm_emulate_pio (struct kvm_vcpu *vcpu, struct kvm_run *run, int in,
int size, unsigned long count, int string, int down, int size, unsigned port);
gva_t address, int rep, unsigned port); int kvm_emulate_pio_string(struct kvm_vcpu *vcpu, struct kvm_run *run, int in,
int size, unsigned long count, int down,
gva_t address, int rep, unsigned port);
void kvm_emulate_cpuid(struct kvm_vcpu *vcpu); void kvm_emulate_cpuid(struct kvm_vcpu *vcpu);
int kvm_emulate_halt(struct kvm_vcpu *vcpu); int kvm_emulate_halt(struct kvm_vcpu *vcpu);
int emulate_invlpg(struct kvm_vcpu *vcpu, gva_t address); int emulate_invlpg(struct kvm_vcpu *vcpu, gva_t address);
......
...@@ -1735,8 +1735,39 @@ static void pio_string_write(struct kvm_io_device *pio_dev, ...@@ -1735,8 +1735,39 @@ static void pio_string_write(struct kvm_io_device *pio_dev,
} }
} }
int kvm_setup_pio(struct kvm_vcpu *vcpu, struct kvm_run *run, int in, int kvm_emulate_pio (struct kvm_vcpu *vcpu, struct kvm_run *run, int in,
int size, unsigned long count, int string, int down, int size, unsigned port)
{
struct kvm_io_device *pio_dev;
vcpu->run->exit_reason = KVM_EXIT_IO;
vcpu->run->io.direction = in ? KVM_EXIT_IO_IN : KVM_EXIT_IO_OUT;
vcpu->run->io.size = vcpu->pio.size = size;
vcpu->run->io.data_offset = KVM_PIO_PAGE_OFFSET * PAGE_SIZE;
vcpu->run->io.count = vcpu->pio.count = vcpu->pio.cur_count = 1;
vcpu->run->io.port = vcpu->pio.port = port;
vcpu->pio.in = in;
vcpu->pio.string = 0;
vcpu->pio.down = 0;
vcpu->pio.guest_page_offset = 0;
vcpu->pio.rep = 0;
kvm_arch_ops->cache_regs(vcpu);
memcpy(vcpu->pio_data, &vcpu->regs[VCPU_REGS_RAX], 4);
kvm_arch_ops->decache_regs(vcpu);
pio_dev = vcpu_find_pio_dev(vcpu, port);
if (pio_dev) {
kernel_pio(pio_dev, vcpu, vcpu->pio_data);
complete_pio(vcpu);
return 1;
}
return 0;
}
EXPORT_SYMBOL_GPL(kvm_emulate_pio);
int kvm_emulate_pio_string(struct kvm_vcpu *vcpu, struct kvm_run *run, int in,
int size, unsigned long count, int down,
gva_t address, int rep, unsigned port) gva_t address, int rep, unsigned port)
{ {
unsigned now, in_page; unsigned now, in_page;
...@@ -1747,33 +1778,16 @@ int kvm_setup_pio(struct kvm_vcpu *vcpu, struct kvm_run *run, int in, ...@@ -1747,33 +1778,16 @@ int kvm_setup_pio(struct kvm_vcpu *vcpu, struct kvm_run *run, int in,
vcpu->run->exit_reason = KVM_EXIT_IO; vcpu->run->exit_reason = KVM_EXIT_IO;
vcpu->run->io.direction = in ? KVM_EXIT_IO_IN : KVM_EXIT_IO_OUT; vcpu->run->io.direction = in ? KVM_EXIT_IO_IN : KVM_EXIT_IO_OUT;
vcpu->run->io.size = size; vcpu->run->io.size = vcpu->pio.size = size;
vcpu->run->io.data_offset = KVM_PIO_PAGE_OFFSET * PAGE_SIZE; vcpu->run->io.data_offset = KVM_PIO_PAGE_OFFSET * PAGE_SIZE;
vcpu->run->io.count = count; vcpu->run->io.count = vcpu->pio.count = vcpu->pio.cur_count = count;
vcpu->run->io.port = port; vcpu->run->io.port = vcpu->pio.port = port;
vcpu->pio.count = count;
vcpu->pio.cur_count = count;
vcpu->pio.size = size;
vcpu->pio.in = in; vcpu->pio.in = in;
vcpu->pio.port = port; vcpu->pio.string = 1;
vcpu->pio.string = string;
vcpu->pio.down = down; vcpu->pio.down = down;
vcpu->pio.guest_page_offset = offset_in_page(address); vcpu->pio.guest_page_offset = offset_in_page(address);
vcpu->pio.rep = rep; vcpu->pio.rep = rep;
pio_dev = vcpu_find_pio_dev(vcpu, port);
if (!string) {
kvm_arch_ops->cache_regs(vcpu);
memcpy(vcpu->pio_data, &vcpu->regs[VCPU_REGS_RAX], 4);
kvm_arch_ops->decache_regs(vcpu);
if (pio_dev) {
kernel_pio(pio_dev, vcpu, vcpu->pio_data);
complete_pio(vcpu);
return 1;
}
return 0;
}
if (!count) { if (!count) {
kvm_arch_ops->skip_emulated_instruction(vcpu); kvm_arch_ops->skip_emulated_instruction(vcpu);
return 1; return 1;
...@@ -1818,6 +1832,7 @@ int kvm_setup_pio(struct kvm_vcpu *vcpu, struct kvm_run *run, int in, ...@@ -1818,6 +1832,7 @@ int kvm_setup_pio(struct kvm_vcpu *vcpu, struct kvm_run *run, int in,
} }
} }
pio_dev = vcpu_find_pio_dev(vcpu, port);
if (!vcpu->pio.in) { if (!vcpu->pio.in) {
/* string PIO write */ /* string PIO write */
ret = pio_copy_data(vcpu); ret = pio_copy_data(vcpu);
...@@ -1834,7 +1849,7 @@ int kvm_setup_pio(struct kvm_vcpu *vcpu, struct kvm_run *run, int in, ...@@ -1834,7 +1849,7 @@ int kvm_setup_pio(struct kvm_vcpu *vcpu, struct kvm_run *run, int in,
return ret; return ret;
} }
EXPORT_SYMBOL_GPL(kvm_setup_pio); EXPORT_SYMBOL_GPL(kvm_emulate_pio_string);
static int kvm_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run) static int kvm_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
{ {
......
...@@ -1005,8 +1005,7 @@ static int io_interception(struct vcpu_svm *svm, struct kvm_run *kvm_run) ...@@ -1005,8 +1005,7 @@ static int io_interception(struct vcpu_svm *svm, struct kvm_run *kvm_run)
rep = (io_info & SVM_IOIO_REP_MASK) != 0; rep = (io_info & SVM_IOIO_REP_MASK) != 0;
down = (svm->vmcb->save.rflags & X86_EFLAGS_DF) != 0; down = (svm->vmcb->save.rflags & X86_EFLAGS_DF) != 0;
return kvm_setup_pio(&svm->vcpu, kvm_run, in, size, 1, 0, return kvm_emulate_pio(&svm->vcpu, kvm_run, in, size, port);
down, 0, rep, port);
} }
static int nop_on_interception(struct vcpu_svm *svm, struct kvm_run *kvm_run) static int nop_on_interception(struct vcpu_svm *svm, struct kvm_run *kvm_run)
......
...@@ -1785,8 +1785,7 @@ static int handle_io(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run) ...@@ -1785,8 +1785,7 @@ static int handle_io(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
rep = (exit_qualification & 32) != 0; rep = (exit_qualification & 32) != 0;
port = exit_qualification >> 16; port = exit_qualification >> 16;
return kvm_setup_pio(vcpu, kvm_run, in, size, 1, 0, down, return kvm_emulate_pio(vcpu, kvm_run, in, size, port);
0, rep, port);
} }
static void static void
......
...@@ -1123,12 +1123,11 @@ x86_emulate_memop(struct x86_emulate_ctxt *ctxt, struct x86_emulate_ops *ops) ...@@ -1123,12 +1123,11 @@ x86_emulate_memop(struct x86_emulate_ctxt *ctxt, struct x86_emulate_ops *ops)
switch(b) { switch(b) {
case 0x6c: /* insb */ case 0x6c: /* insb */
case 0x6d: /* insw/insd */ case 0x6d: /* insw/insd */
if (kvm_setup_pio(ctxt->vcpu, NULL, if (kvm_emulate_pio_string(ctxt->vcpu, NULL,
1, /* in */ 1, /* in */
(d & ByteOp) ? 1 : op_bytes, /* size */ (d & ByteOp) ? 1 : op_bytes, /* size */
rep_prefix ? rep_prefix ?
address_mask(_regs[VCPU_REGS_RCX]) : 1, /* count */ address_mask(_regs[VCPU_REGS_RCX]) : 1, /* count */
1, /* strings */
(_eflags & EFLG_DF), /* down */ (_eflags & EFLG_DF), /* down */
register_address(ctxt->es_base, register_address(ctxt->es_base,
_regs[VCPU_REGS_RDI]), /* address */ _regs[VCPU_REGS_RDI]), /* address */
...@@ -1139,12 +1138,11 @@ x86_emulate_memop(struct x86_emulate_ctxt *ctxt, struct x86_emulate_ops *ops) ...@@ -1139,12 +1138,11 @@ x86_emulate_memop(struct x86_emulate_ctxt *ctxt, struct x86_emulate_ops *ops)
return 0; return 0;
case 0x6e: /* outsb */ case 0x6e: /* outsb */
case 0x6f: /* outsw/outsd */ case 0x6f: /* outsw/outsd */
if (kvm_setup_pio(ctxt->vcpu, NULL, if (kvm_emulate_pio_string(ctxt->vcpu, NULL,
0, /* in */ 0, /* in */
(d & ByteOp) ? 1 : op_bytes, /* size */ (d & ByteOp) ? 1 : op_bytes, /* size */
rep_prefix ? rep_prefix ?
address_mask(_regs[VCPU_REGS_RCX]) : 1, /* count */ address_mask(_regs[VCPU_REGS_RCX]) : 1, /* count */
1, /* strings */
(_eflags & EFLG_DF), /* down */ (_eflags & EFLG_DF), /* down */
register_address(override_base ? register_address(override_base ?
*override_base : ctxt->ds_base, *override_base : ctxt->ds_base,
......
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