All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] KVM: x86: use pic/ioapic destructor when proper
@ 2017-03-15  6:53 Peter Xu
  2017-03-15  6:53 ` [PATCH 1/2] KVM: x86: clear bus pointer when destroyed Peter Xu
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Peter Xu @ 2017-03-15  6:53 UTC (permalink / raw)
  To: kvm; +Cc: David Hildenbrand, Paolo Bonzini, peterx, Radim Krčmář

A tiny cleanup series for pic/ioapic destruction when vm destroys.
Please review, Thanks.

Peter Xu (2):
  KVM: x86: clear bus pointer when destroyed
  KVM: x86: use pic/ioapic destructor when destroy vm

 arch/x86/kvm/x86.c  |  4 ++--
 virt/kvm/kvm_main.c | 12 +++++++++++-
 2 files changed, 13 insertions(+), 3 deletions(-)

-- 
2.7.4

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/2] KVM: x86: clear bus pointer when destroyed
  2017-03-15  6:53 [PATCH 0/2] KVM: x86: use pic/ioapic destructor when proper Peter Xu
@ 2017-03-15  6:53 ` Peter Xu
  2017-03-15  6:53 ` [PATCH 2/2] KVM: x86: use pic/ioapic destructor when destroy vm Peter Xu
  2017-03-15  7:58 ` [PATCH 0/2] KVM: x86: use pic/ioapic destructor when proper Peter Xu
  2 siblings, 0 replies; 4+ messages in thread
From: Peter Xu @ 2017-03-15  6:53 UTC (permalink / raw)
  To: kvm; +Cc: David Hildenbrand, Paolo Bonzini, peterx, Radim Krčmář

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

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] KVM: x86: use pic/ioapic destructor when destroy vm
  2017-03-15  6:53 [PATCH 0/2] KVM: x86: use pic/ioapic destructor when proper Peter Xu
  2017-03-15  6:53 ` [PATCH 1/2] KVM: x86: clear bus pointer when destroyed Peter Xu
@ 2017-03-15  6:53 ` Peter Xu
  2017-03-15  7:58 ` [PATCH 0/2] KVM: x86: use pic/ioapic destructor when proper Peter Xu
  2 siblings, 0 replies; 4+ messages in thread
From: Peter Xu @ 2017-03-15  6:53 UTC (permalink / raw)
  To: kvm; +Cc: David Hildenbrand, Paolo Bonzini, peterx, Radim Krčmář

We have specific destructors for pic/ioapic, we'd better use them when
destroying the VM as well.

Signed-off-by: Peter Xu <peterx@redhat.com>
---
 arch/x86/kvm/x86.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 1faf620..d30ff49 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -8153,8 +8153,8 @@ void kvm_arch_destroy_vm(struct kvm *kvm)
 	if (kvm_x86_ops->vm_destroy)
 		kvm_x86_ops->vm_destroy(kvm);
 	kvm_iommu_unmap_guest(kvm);
-	kfree(kvm->arch.vpic);
-	kfree(kvm->arch.vioapic);
+	kvm_pic_destroy(kvm);
+	kvm_ioapic_destroy(kvm);
 	kvm_free_vcpus(kvm);
 	kvfree(rcu_dereference_check(kvm->arch.apic_map, 1));
 	kvm_mmu_uninit_vm(kvm);
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 0/2] KVM: x86: use pic/ioapic destructor when proper
  2017-03-15  6:53 [PATCH 0/2] KVM: x86: use pic/ioapic destructor when proper Peter Xu
  2017-03-15  6:53 ` [PATCH 1/2] KVM: x86: clear bus pointer when destroyed Peter Xu
  2017-03-15  6:53 ` [PATCH 2/2] KVM: x86: use pic/ioapic destructor when destroy vm Peter Xu
@ 2017-03-15  7:58 ` Peter Xu
  2 siblings, 0 replies; 4+ messages in thread
From: Peter Xu @ 2017-03-15  7:58 UTC (permalink / raw)
  To: kvm; +Cc: David Hildenbrand, Paolo Bonzini, Radim Krčmář

On Wed, Mar 15, 2017 at 02:53:29PM +0800, Peter Xu wrote:
> A tiny cleanup series for pic/ioapic destruction when vm destroys.
> Please review, Thanks.
> 
> Peter Xu (2):
>   KVM: x86: clear bus pointer when destroyed
>   KVM: x86: use pic/ioapic destructor when destroy vm

NACK. Patch 2 breaks split irqchip.

The old code can live with split irqchip since it's using kfree() and
kfree() allows null pointer. Will repost. Sorry for the noise...

-- peterx

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-03-15  7:58 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-15  6:53 [PATCH 0/2] KVM: x86: use pic/ioapic destructor when proper Peter Xu
2017-03-15  6:53 ` [PATCH 1/2] KVM: x86: clear bus pointer when destroyed Peter Xu
2017-03-15  6:53 ` [PATCH 2/2] KVM: x86: use pic/ioapic destructor when destroy vm Peter Xu
2017-03-15  7:58 ` [PATCH 0/2] KVM: x86: use pic/ioapic destructor when proper Peter Xu

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.