Skip to content

Commit

Permalink
KVM: x86: leave vcpu->arch.pio.count alone in emulator_pio_in_out
Browse files Browse the repository at this point in the history
Currently emulator_pio_in clears vcpu->arch.pio.count twice if
emulator_pio_in_out performs kernel PIO.  Move the clear into
emulator_pio_out where it is actually necessary.

No functional change intended.

Cc: [email protected]
Fixes: 7ed9abf ("KVM: SVM: Support string IO operations for an SEV-ES guest")
Reviewed-by: Maxim Levitsky <[email protected]>
Signed-off-by: Paolo Bonzini <[email protected]>
  • Loading branch information
bonzini committed Oct 22, 2021
1 parent b599840 commit 0d33b1b
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions arch/x86/kvm/x86.c
Original file line number Diff line number Diff line change
Expand Up @@ -6914,10 +6914,8 @@ static int emulator_pio_in_out(struct kvm_vcpu *vcpu, int size,
vcpu->arch.pio.count = count;
vcpu->arch.pio.size = size;

if (!kernel_pio(vcpu, vcpu->arch.pio_data)) {
vcpu->arch.pio.count = 0;
if (!kernel_pio(vcpu, vcpu->arch.pio_data))
return 1;
}

vcpu->run->exit_reason = KVM_EXIT_IO;
vcpu->run->io.direction = in ? KVM_EXIT_IO_IN : KVM_EXIT_IO_OUT;
Expand Down Expand Up @@ -6963,9 +6961,16 @@ static int emulator_pio_out(struct kvm_vcpu *vcpu, int size,
unsigned short port, const void *val,
unsigned int count)
{
int ret;

memcpy(vcpu->arch.pio_data, val, size * count);
trace_kvm_pio(KVM_PIO_OUT, port, size, count, vcpu->arch.pio_data);
return emulator_pio_in_out(vcpu, size, port, (void *)val, count, false);
ret = emulator_pio_in_out(vcpu, size, port, (void *)val, count, false);
if (ret)
vcpu->arch.pio.count = 0;

return ret;

}

static int emulator_pio_out_emulated(struct x86_emulate_ctxt *ctxt,
Expand Down

0 comments on commit 0d33b1b

Please sign in to comment.