diff options
author | Marc Zyngier <maz@kernel.org> | 2021-12-16 10:45:26 +0000 |
---|---|---|
committer | Marc Zyngier <maz@kernel.org> | 2021-12-16 10:47:24 +0000 |
commit | c95b1d7ca794ac3ea49a8f85c729f9841444d5e5 (patch) | |
tree | 070cf237a7e24a5ee703011bf34d69baf5dc52d9 /arch/arm64/kvm/vgic | |
parent | d58071a8a76d779eedab38033ae4c821c30295a5 (diff) | |
download | linux-stable-c95b1d7ca794ac3ea49a8f85c729f9841444d5e5.tar.gz linux-stable-c95b1d7ca794ac3ea49a8f85c729f9841444d5e5.tar.bz2 linux-stable-c95b1d7ca794ac3ea49a8f85c729f9841444d5e5.zip |
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 <maz@kernel.org>
Link: https://lore.kernel.org/r/20211216104526.1482124-1-maz@kernel.org
Diffstat (limited to 'arch/arm64/kvm/vgic')
-rw-r--r-- | arch/arm64/kvm/vgic/vgic-mmio-v3.c | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/arch/arm64/kvm/vgic/vgic-mmio-v3.c b/arch/arm64/kvm/vgic/vgic-mmio-v3.c index bf7ec4a78497..9943a3fe1b0a 100644 --- a/arch/arm64/kvm/vgic/vgic-mmio-v3.c +++ b/arch/arm64/kvm/vgic/vgic-mmio-v3.c @@ -763,10 +763,12 @@ static int vgic_register_all_redist_iodevs(struct kvm *kvm) } if (ret) { - /* The current c failed, so we start with the previous one. */ + /* The current c failed, so iterate over the previous ones. */ + int i; + mutex_lock(&kvm->slots_lock); - for (c--; c >= 0; c--) { - vcpu = kvm_get_vcpu(kvm, c); + for (i = 0; i < c; i++) { + vcpu = kvm_get_vcpu(kvm, i); vgic_unregister_redist_iodev(vcpu); } mutex_unlock(&kvm->slots_lock); |