Skip to content

Commit 3eb3920

Browse files
xzpetergregkh
authored andcommitted
KVM: x86: clear bus pointer when destroyed
commit df630b8c1e851b5e265dc2ca9c87222e342c093b upstream. When releasing the bus, let's clear the bus pointers to mark it out. If any further device unregister happens on this bus, we know that we're done if we found the bus being released already. Signed-off-by: Peter Xu <peterx@redhat.com> Signed-off-by: Radim Krčmář <rkrcmar@redhat.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent eac3ab3 commit 3eb3920

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

virt/kvm/kvm_main.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -654,8 +654,10 @@ static void kvm_destroy_vm(struct kvm *kvm)
654654
list_del(&kvm->vm_list);
655655
spin_unlock(&kvm_lock);
656656
kvm_free_irq_routing(kvm);
657-
for (i = 0; i < KVM_NR_BUSES; i++)
657+
for (i = 0; i < KVM_NR_BUSES; i++) {
658658
kvm_io_bus_destroy(kvm->buses[i]);
659+
kvm->buses[i] = NULL;
660+
}
659661
kvm_coalesced_mmio_free(kvm);
660662
#if defined(CONFIG_MMU_NOTIFIER) && defined(KVM_ARCH_WANT_MMU_NOTIFIER)
661663
mmu_notifier_unregister(&kvm->mmu_notifier, kvm->mm);
@@ -3376,6 +3378,14 @@ int kvm_io_bus_unregister_dev(struct kvm *kvm, enum kvm_bus bus_idx,
33763378
struct kvm_io_bus *new_bus, *bus;
33773379

33783380
bus = kvm->buses[bus_idx];
3381+
3382+
/*
3383+
* It's possible the bus being released before hand. If so,
3384+
* we're done here.
3385+
*/
3386+
if (!bus)
3387+
return 0;
3388+
33793389
r = -ENOENT;
33803390
for (i = 0; i < bus->dev_count; i++)
33813391
if (bus->range[i].dev == dev) {

0 commit comments

Comments
 (0)