Skip to content

Commit c95b1d7

Browse files
author
Marc Zyngier
committed
KVM: arm64: vgic-v3: Fix vcpu index comparison
When handling an error at the point where we try and register all the redistributors, we unregister all the previously registered frames by counting down from the failing index. However, the way the code is written relies on that index being a signed value. Which won't be true once we switch to an xarray-based vcpu set. Since this code is pretty awkward the first place, and that the failure mode is hard to spot, rewrite this loop to iterate over the vcpus upwards rather than downwards. Signed-off-by: Marc Zyngier <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent d58071a commit c95b1d7

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

arch/arm64/kvm/vgic/vgic-mmio-v3.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -763,10 +763,12 @@ static int vgic_register_all_redist_iodevs(struct kvm *kvm)
763763
}
764764

765765
if (ret) {
766-
/* The current c failed, so we start with the previous one. */
766+
/* The current c failed, so iterate over the previous ones. */
767+
int i;
768+
767769
mutex_lock(&kvm->slots_lock);
768-
for (c--; c >= 0; c--) {
769-
vcpu = kvm_get_vcpu(kvm, c);
770+
for (i = 0; i < c; i++) {
771+
vcpu = kvm_get_vcpu(kvm, i);
770772
vgic_unregister_redist_iodev(vcpu);
771773
}
772774
mutex_unlock(&kvm->slots_lock);

0 commit comments

Comments
 (0)