Skip to content

Commit 2d710d4

Browse files
Zeng Chigregkh
authored andcommitted
LoongArch: KVM: Add missing slots_lock for device register/unregister
commit aeded60 upstream. kvm_io_bus_register_dev() and kvm_io_bus_unregister_dev() should be called under kvm->slots_lock. The unregister calls in ipi.c, eiointc.c and pch_pic.c were also missing this protection. Add it to match the register side. Cc: stable@vger.kernel.org Reviewed-by: Bibo Mao <maobibo@loongson.cn> Signed-off-by: Zeng Chi <zengchi@kylinos.cn> Signed-off-by: Huacai Chen <chenhuacai@loongson.cn> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 7c73a26 commit 2d710d4

3 files changed

Lines changed: 10 additions & 0 deletions

File tree

arch/loongarch/kvm/intc/eiointc.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -654,10 +654,14 @@ static int kvm_eiointc_create(struct kvm_device *dev, u32 type)
654654

655655
device = &s->device_vext;
656656
kvm_iodevice_init(device, &kvm_eiointc_virt_ops);
657+
mutex_lock(&kvm->slots_lock);
657658
ret = kvm_io_bus_register_dev(kvm, KVM_IOCSR_BUS,
658659
EIOINTC_VIRT_BASE, EIOINTC_VIRT_SIZE, device);
660+
mutex_unlock(&kvm->slots_lock);
659661
if (ret < 0) {
662+
mutex_lock(&kvm->slots_lock);
660663
kvm_io_bus_unregister_dev(kvm, KVM_IOCSR_BUS, &s->device);
664+
mutex_unlock(&kvm->slots_lock);
661665
kfree(s);
662666
return ret;
663667
}
@@ -676,8 +680,10 @@ static void kvm_eiointc_destroy(struct kvm_device *dev)
676680

677681
kvm = dev->kvm;
678682
eiointc = kvm->arch.eiointc;
683+
mutex_lock(&kvm->slots_lock);
679684
kvm_io_bus_unregister_dev(kvm, KVM_IOCSR_BUS, &eiointc->device);
680685
kvm_io_bus_unregister_dev(kvm, KVM_IOCSR_BUS, &eiointc->device_vext);
686+
mutex_unlock(&kvm->slots_lock);
681687
kfree(eiointc);
682688
kfree(dev);
683689
}

arch/loongarch/kvm/intc/ipi.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,9 @@ static void kvm_ipi_destroy(struct kvm_device *dev)
457457

458458
kvm = dev->kvm;
459459
ipi = kvm->arch.ipi;
460+
mutex_lock(&kvm->slots_lock);
460461
kvm_io_bus_unregister_dev(kvm, KVM_IOCSR_BUS, &ipi->device);
462+
mutex_unlock(&kvm->slots_lock);
461463
kfree(ipi);
462464
kfree(dev);
463465
}

arch/loongarch/kvm/intc/pch_pic.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,9 @@ static void kvm_pch_pic_destroy(struct kvm_device *dev)
473473
kvm = dev->kvm;
474474
s = kvm->arch.pch_pic;
475475
/* unregister pch pic device and free it's memory */
476+
mutex_lock(&kvm->slots_lock);
476477
kvm_io_bus_unregister_dev(kvm, KVM_MMIO_BUS, &s->device);
478+
mutex_unlock(&kvm->slots_lock);
477479
kfree(s);
478480
kfree(dev);
479481
}

0 commit comments

Comments
 (0)