>From cdb6bceeceda3eb3bd3755b99f00d526e2b9045e Mon Sep 17 00:00:00 2001 From: Sean Christopherson Date: Thu, 21 Oct 2021 15:40:36 -0700 Subject: [PATCH 2/6] KVM: x86: WARN if emulated kernel port I/O fails after a successful iteration Signed-off-by: Sean Christopherson --- arch/x86/kvm/x86.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index c245edfd974c..13a21a05a75d 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -7046,7 +7046,7 @@ static int emulator_cmpxchg_emulated(struct x86_emulate_ctxt *ctxt, static int kernel_pio(struct kvm_vcpu *vcpu, void *pd) { - int r = 0, i; + int r, i; for (i = 0; i < vcpu->arch.pio.count; i++) { if (vcpu->arch.pio.in) @@ -7056,11 +7056,17 @@ static int kernel_pio(struct kvm_vcpu *vcpu, void *pd) r = kvm_io_bus_write(vcpu, KVM_PIO_BUS, vcpu->arch.pio.port, vcpu->arch.pio.size, pd); - if (r) - break; + if (r) { + /* + * The port doesn't change on subsequent iterations and + * the kernel I/O device should not disappear. + */ + WARN_ON_ONCE(i); + return r; + } pd += vcpu->arch.pio.size; } - return r; + return 0; } static int emulator_pio_in_out(struct kvm_vcpu *vcpu, int size, -- 2.33.0.1079.g6e70778dc9-goog