public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Peter Xu <peterx@redhat.com>
To: kvm@vger.kernel.org
Cc: "David Hildenbrand" <david@redhat.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	peterx@redhat.com, "Radim Krčmář" <rkrcmar@redhat.com>
Subject: [PATCH v2 1/3] KVM: x86: clear bus pointer when destroyed
Date: Wed, 15 Mar 2017 16:01:17 +0800	[thread overview]
Message-ID: <1489564879-6097-2-git-send-email-peterx@redhat.com> (raw)
In-Reply-To: <1489564879-6097-1-git-send-email-peterx@redhat.com>

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>
---
 virt/kvm/kvm_main.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index a17d787..7445566 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -727,8 +727,10 @@ static void kvm_destroy_vm(struct kvm *kvm)
 	list_del(&kvm->vm_list);
 	spin_unlock(&kvm_lock);
 	kvm_free_irq_routing(kvm);
-	for (i = 0; i < KVM_NR_BUSES; i++)
+	for (i = 0; i < KVM_NR_BUSES; i++) {
 		kvm_io_bus_destroy(kvm->buses[i]);
+		kvm->buses[i] = NULL;
+	}
 	kvm_coalesced_mmio_free(kvm);
 #if defined(CONFIG_MMU_NOTIFIER) && defined(KVM_ARCH_WANT_MMU_NOTIFIER)
 	mmu_notifier_unregister(&kvm->mmu_notifier, kvm->mm);
@@ -3579,6 +3581,14 @@ int kvm_io_bus_unregister_dev(struct kvm *kvm, enum kvm_bus bus_idx,
 	struct kvm_io_bus *new_bus, *bus;
 
 	bus = kvm->buses[bus_idx];
+
+	/*
+	 * It's possible the bus being released before hand. If so,
+	 * we're done here.
+	 */
+	if (!bus)
+		return 0;
+
 	r = -ENOENT;
 	for (i = 0; i < bus->dev_count; i++)
 		if (bus->range[i].dev == dev) {
-- 
2.7.4

  reply	other threads:[~2017-03-15  8:01 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-15  8:01 [PATCH v2 0/3] KVM: x86: use pic/ioapic destructor when proper Peter Xu
2017-03-15  8:01 ` Peter Xu [this message]
2017-03-21  9:24   ` [PATCH v2 1/3] KVM: x86: clear bus pointer when destroyed David Hildenbrand
2017-03-15  8:01 ` [PATCH v2 2/3] KVM: x86: check existance before destroy Peter Xu
2017-03-21  9:24   ` David Hildenbrand
2017-03-15  8:01 ` [PATCH v2 3/3] KVM: x86: use pic/ioapic destructor when destroy vm Peter Xu
2017-03-21  9:25   ` David Hildenbrand
2017-03-15  8:47 ` [PATCH v2 0/3] KVM: x86: use pic/ioapic destructor when proper David Hildenbrand
2017-03-15  8:59   ` Peter Xu
2017-03-15  9:04     ` David Hildenbrand
2017-03-15 11:15     ` David Hildenbrand
2017-03-16  6:04       ` Peter Xu
2017-03-16 19:32         ` Radim Krčmář
2017-03-17  6:05           ` Peter Xu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1489564879-6097-2-git-send-email-peterx@redhat.com \
    --to=peterx@redhat.com \
    --cc=david@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=rkrcmar@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox