]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
LoongArch: KVM: Add missing slots_lock for device register/unregister
authorZeng Chi <zengchi@kylinos.cn>
Thu, 11 Jun 2026 12:46:44 +0000 (20:46 +0800)
committerHuacai Chen <chenhuacai@loongson.cn>
Thu, 11 Jun 2026 12:46:44 +0000 (20:46 +0800)
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>
arch/loongarch/kvm/intc/eiointc.c
arch/loongarch/kvm/intc/ipi.c
arch/loongarch/kvm/intc/pch_pic.c

index 2ab7fafa86d59453e1f2299a12ac5d9b69b492d5..2b14485d14a708dc38235b48cdf363b9d663fdc4 100644 (file)
@@ -645,10 +645,14 @@ static int kvm_eiointc_create(struct kvm_device *dev, u32 type)
 
        device = &s->device_vext;
        kvm_iodevice_init(device, &kvm_eiointc_virt_ops);
+       mutex_lock(&kvm->slots_lock);
        ret = kvm_io_bus_register_dev(kvm, KVM_IOCSR_BUS,
                        EIOINTC_VIRT_BASE, EIOINTC_VIRT_SIZE, device);
+       mutex_unlock(&kvm->slots_lock);
        if (ret < 0) {
+               mutex_lock(&kvm->slots_lock);
                kvm_io_bus_unregister_dev(kvm, KVM_IOCSR_BUS, &s->device);
+               mutex_unlock(&kvm->slots_lock);
                kfree(s);
                return ret;
        }
@@ -667,8 +671,10 @@ static void kvm_eiointc_destroy(struct kvm_device *dev)
 
        kvm = dev->kvm;
        eiointc = kvm->arch.eiointc;
+       mutex_lock(&kvm->slots_lock);
        kvm_io_bus_unregister_dev(kvm, KVM_IOCSR_BUS, &eiointc->device);
        kvm_io_bus_unregister_dev(kvm, KVM_IOCSR_BUS, &eiointc->device_vext);
+       mutex_unlock(&kvm->slots_lock);
        kfree(eiointc);
        kfree(dev);
 }
index 1f6ebbd0af5c8c92eac5e9ff8baca2edbfcdd484..4fa0897d7bdb0011d5a292b22854d04200bcff95 100644 (file)
@@ -447,7 +447,9 @@ static void kvm_ipi_destroy(struct kvm_device *dev)
 
        kvm = dev->kvm;
        ipi = kvm->arch.ipi;
+       mutex_lock(&kvm->slots_lock);
        kvm_io_bus_unregister_dev(kvm, KVM_IOCSR_BUS, &ipi->device);
+       mutex_unlock(&kvm->slots_lock);
        kfree(ipi);
        kfree(dev);
 }
index aa0ed59ae8cf9c2d6441fd8df0aad6f857179668..175a630aceb416d0898b6f4ede6853549412bce2 100644 (file)
@@ -481,7 +481,9 @@ static void kvm_pch_pic_destroy(struct kvm_device *dev)
        kvm = dev->kvm;
        s = kvm->arch.pch_pic;
        /* unregister pch pic device and free it's memory */
+       mutex_lock(&kvm->slots_lock);
        kvm_io_bus_unregister_dev(kvm, KVM_MMIO_BUS, &s->device);
+       mutex_unlock(&kvm->slots_lock);
        kfree(s);
        kfree(dev);
 }