Commit 0967b7bf authored by Avi Kivity's avatar Avi Kivity

KVM: Skip pio instruction when it is emulated, not executed

If we defer updating rip until pio instructions are executed, we have a
problem with reset:  a pio reset updates rip, and when the instruction
completes we skip the emulated instruction, pointing rip somewhere completely
unrelated.

Fix by updating rip when we see decode the instruction, not after emulation.
Signed-off-by: default avatarAvi Kivity <avi@qumranet.com>
parent 535eabcf
...@@ -1815,8 +1815,6 @@ static int complete_pio(struct kvm_vcpu *vcpu) ...@@ -1815,8 +1815,6 @@ static int complete_pio(struct kvm_vcpu *vcpu)
io->count -= io->cur_count; io->count -= io->cur_count;
io->cur_count = 0; io->cur_count = 0;
if (!io->count)
kvm_x86_ops->skip_emulated_instruction(vcpu);
return 0; return 0;
} }
...@@ -1876,6 +1874,8 @@ int kvm_emulate_pio (struct kvm_vcpu *vcpu, struct kvm_run *run, int in, ...@@ -1876,6 +1874,8 @@ int kvm_emulate_pio (struct kvm_vcpu *vcpu, struct kvm_run *run, int in,
memcpy(vcpu->pio_data, &vcpu->regs[VCPU_REGS_RAX], 4); memcpy(vcpu->pio_data, &vcpu->regs[VCPU_REGS_RAX], 4);
kvm_x86_ops->decache_regs(vcpu); kvm_x86_ops->decache_regs(vcpu);
kvm_x86_ops->skip_emulated_instruction(vcpu);
pio_dev = vcpu_find_pio_dev(vcpu, port); pio_dev = vcpu_find_pio_dev(vcpu, port);
if (pio_dev) { if (pio_dev) {
kernel_pio(pio_dev, vcpu, vcpu->pio_data); kernel_pio(pio_dev, vcpu, vcpu->pio_data);
...@@ -1938,6 +1938,9 @@ int kvm_emulate_pio_string(struct kvm_vcpu *vcpu, struct kvm_run *run, int in, ...@@ -1938,6 +1938,9 @@ int kvm_emulate_pio_string(struct kvm_vcpu *vcpu, struct kvm_run *run, int in,
vcpu->run->io.count = now; vcpu->run->io.count = now;
vcpu->pio.cur_count = now; vcpu->pio.cur_count = now;
if (vcpu->pio.cur_count == vcpu->pio.count)
kvm_x86_ops->skip_emulated_instruction(vcpu);
for (i = 0; i < nr_pages; ++i) { for (i = 0; i < nr_pages; ++i) {
mutex_lock(&vcpu->kvm->lock); mutex_lock(&vcpu->kvm->lock);
page = gva_to_page(vcpu, address + i * PAGE_SIZE); page = gva_to_page(vcpu, address + i * PAGE_SIZE);
......
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