[PATCH 2/6] KVM: x86: WARN if emulated kernel port I/O fails after a successful iteration

From: Sean Christopherson
Date: Thu Oct 21 2021 - 18:40:36 EST


Signed-off-by: Sean Christopherson <seanjc@xxxxxxxxxx>
---
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


--kTbyx1pw6IySRUfp
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment;
filename="0003-KVM-x86-Use-an-unsigned-int-when-emulating-string-po.patch"