Skip to content

Commit 0967b7b

Browse files
committed
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: Avi Kivity <avi@qumranet.com>
1 parent 535eabc commit 0967b7b

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

drivers/kvm/kvm_main.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1815,8 +1815,6 @@ static int complete_pio(struct kvm_vcpu *vcpu)
18151815
io->count -= io->cur_count;
18161816
io->cur_count = 0;
18171817

1818-
if (!io->count)
1819-
kvm_x86_ops->skip_emulated_instruction(vcpu);
18201818
return 0;
18211819
}
18221820

@@ -1876,6 +1874,8 @@ int kvm_emulate_pio (struct kvm_vcpu *vcpu, struct kvm_run *run, int in,
18761874
memcpy(vcpu->pio_data, &vcpu->regs[VCPU_REGS_RAX], 4);
18771875
kvm_x86_ops->decache_regs(vcpu);
18781876

1877+
kvm_x86_ops->skip_emulated_instruction(vcpu);
1878+
18791879
pio_dev = vcpu_find_pio_dev(vcpu, port);
18801880
if (pio_dev) {
18811881
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,
19381938
vcpu->run->io.count = now;
19391939
vcpu->pio.cur_count = now;
19401940

1941+
if (vcpu->pio.cur_count == vcpu->pio.count)
1942+
kvm_x86_ops->skip_emulated_instruction(vcpu);
1943+
19411944
for (i = 0; i < nr_pages; ++i) {
19421945
mutex_lock(&vcpu->kvm->lock);
19431946
page = gva_to_page(vcpu, address + i * PAGE_SIZE);

0 commit comments

Comments
 (0)