mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Avi Kivity <avi@qumranet.com>
To: linux-kernel@vger.kernel.org, kvm-devel@lists.sourceforge.net
Cc: Zhang Xiantao <xiantao@vtsmp-build32.los-vmm.org>
Subject: [PATCH 03/52] KVM: Portability: Add two hooks to handle kvm_create and destroy vm
Date: Sun, 30 Dec 2007 09:09:49 +0200	[thread overview]
Message-ID: <1198998638-22713-4-git-send-email-avi@qumranet.com> (raw)
In-Reply-To: <1198998638-22713-1-git-send-email-avi@qumranet.com>

From: Zhang Xiantao <xiantao@vtsmp-build32.los-vmm.org>

Add two arch hooks to handle kvm_create_vm and kvm destroy_vm. Now, just
put io_bus init and destory in common.

Signed-off-by: Zhang Xiantao <xiantao.zhang@intel.com>
Signed-off-by: Avi Kivity <avi@qumranet.com>
---
 drivers/kvm/kvm.h      |    4 ++++
 drivers/kvm/kvm_main.c |   42 ++++++------------------------------------
 drivers/kvm/x86.c      |   47 +++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 57 insertions(+), 36 deletions(-)

diff --git a/drivers/kvm/kvm.h b/drivers/kvm/kvm.h
index c4ad66b..59e001c 100644
--- a/drivers/kvm/kvm.h
+++ b/drivers/kvm/kvm.h
@@ -674,6 +674,10 @@ int kvm_arch_hardware_setup(void);
 void kvm_arch_hardware_unsetup(void);
 void kvm_arch_check_processor_compat(void *rtn);
 
+void kvm_free_physmem(struct kvm *kvm);
+
+struct  kvm *kvm_arch_create_vm(void);
+void kvm_arch_destroy_vm(struct kvm *kvm);
 
 static inline void kvm_guest_enter(void)
 {
diff --git a/drivers/kvm/kvm_main.c b/drivers/kvm/kvm_main.c
index acd26cf..3aa34de 100644
--- a/drivers/kvm/kvm_main.c
+++ b/drivers/kvm/kvm_main.c
@@ -156,18 +156,18 @@ EXPORT_SYMBOL_GPL(kvm_vcpu_uninit);
 
 static struct kvm *kvm_create_vm(void)
 {
-	struct kvm *kvm = kzalloc(sizeof(struct kvm), GFP_KERNEL);
+	struct kvm *kvm = kvm_arch_create_vm();
 
-	if (!kvm)
-		return ERR_PTR(-ENOMEM);
+	if (IS_ERR(kvm))
+		goto out;
 
 	kvm_io_bus_init(&kvm->pio_bus);
 	mutex_init(&kvm->lock);
-	INIT_LIST_HEAD(&kvm->active_mmu_pages);
 	kvm_io_bus_init(&kvm->mmio_bus);
 	spin_lock(&kvm_lock);
 	list_add(&kvm->vm_list, &vm_list);
 	spin_unlock(&kvm_lock);
+out:
 	return kvm;
 }
 
@@ -188,7 +188,7 @@ static void kvm_free_physmem_slot(struct kvm_memory_slot *free,
 	free->rmap = NULL;
 }
 
-static void kvm_free_physmem(struct kvm *kvm)
+void kvm_free_physmem(struct kvm *kvm)
 {
 	int i;
 
@@ -196,32 +196,6 @@ static void kvm_free_physmem(struct kvm *kvm)
 		kvm_free_physmem_slot(&kvm->memslots[i], NULL);
 }
 
-static void kvm_unload_vcpu_mmu(struct kvm_vcpu *vcpu)
-{
-	vcpu_load(vcpu);
-	kvm_mmu_unload(vcpu);
-	vcpu_put(vcpu);
-}
-
-static void kvm_free_vcpus(struct kvm *kvm)
-{
-	unsigned int i;
-
-	/*
-	 * Unpin any mmu pages first.
-	 */
-	for (i = 0; i < KVM_MAX_VCPUS; ++i)
-		if (kvm->vcpus[i])
-			kvm_unload_vcpu_mmu(kvm->vcpus[i]);
-	for (i = 0; i < KVM_MAX_VCPUS; ++i) {
-		if (kvm->vcpus[i]) {
-			kvm_arch_vcpu_free(kvm->vcpus[i]);
-			kvm->vcpus[i] = NULL;
-		}
-	}
-
-}
-
 static void kvm_destroy_vm(struct kvm *kvm)
 {
 	spin_lock(&kvm_lock);
@@ -229,11 +203,7 @@ static void kvm_destroy_vm(struct kvm *kvm)
 	spin_unlock(&kvm_lock);
 	kvm_io_bus_destroy(&kvm->pio_bus);
 	kvm_io_bus_destroy(&kvm->mmio_bus);
-	kfree(kvm->vpic);
-	kfree(kvm->vioapic);
-	kvm_free_vcpus(kvm);
-	kvm_free_physmem(kvm);
-	kfree(kvm);
+	kvm_arch_destroy_vm(kvm);
 }
 
 static int kvm_vm_release(struct inode *inode, struct file *filp)
diff --git a/drivers/kvm/x86.c b/drivers/kvm/x86.c
index abb7bee..b7c72ac 100644
--- a/drivers/kvm/x86.c
+++ b/drivers/kvm/x86.c
@@ -2543,3 +2543,50 @@ void kvm_arch_vcpu_uninit(struct kvm_vcpu *vcpu)
 	kvm_mmu_destroy(vcpu);
 	free_page((unsigned long)vcpu->pio_data);
 }
+
+struct  kvm *kvm_arch_create_vm(void)
+{
+	struct kvm *kvm = kzalloc(sizeof(struct kvm), GFP_KERNEL);
+
+	if (!kvm)
+		return ERR_PTR(-ENOMEM);
+
+	INIT_LIST_HEAD(&kvm->active_mmu_pages);
+
+	return kvm;
+}
+
+static void kvm_unload_vcpu_mmu(struct kvm_vcpu *vcpu)
+{
+	vcpu_load(vcpu);
+	kvm_mmu_unload(vcpu);
+	vcpu_put(vcpu);
+}
+
+static void kvm_free_vcpus(struct kvm *kvm)
+{
+	unsigned int i;
+
+	/*
+	 * Unpin any mmu pages first.
+	 */
+	for (i = 0; i < KVM_MAX_VCPUS; ++i)
+		if (kvm->vcpus[i])
+			kvm_unload_vcpu_mmu(kvm->vcpus[i]);
+	for (i = 0; i < KVM_MAX_VCPUS; ++i) {
+		if (kvm->vcpus[i]) {
+			kvm_arch_vcpu_free(kvm->vcpus[i]);
+			kvm->vcpus[i] = NULL;
+		}
+	}
+
+}
+
+void kvm_arch_destroy_vm(struct kvm *kvm)
+{
+	kfree(kvm->vpic);
+	kfree(kvm->vioapic);
+	kvm_free_vcpus(kvm);
+	kvm_free_physmem(kvm);
+	kfree(kvm);
+}
-- 
1.5.3.7


  parent reply	other threads:[~2007-12-30  7:11 UTC|newest]

Thread overview: 55+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-12-30  7:09 [PATCH 00/52] KVM patch queue review for 2.6.25 merge window (part III) Avi Kivity
2007-12-30  7:09 ` [PATCH 01/52] KVM: Remove ptr comparisons to 0 Avi Kivity
2007-12-30  7:09 ` [PATCH 02/52] KVM: Remove __init attributes for kvm_init_debug and kvm_init_msr_list Avi Kivity
2007-12-30  7:09 ` Avi Kivity [this message]
2007-12-30  7:09 ` [PATCH 04/52] KVM: Replace 'light_exits' stat with 'host_state_reload' Avi Kivity
2007-12-30  7:09 ` [PATCH 05/52] KVM: Add fpu_reload counter Avi Kivity
2007-12-30  7:09 ` [PATCH 06/52] KVM: Add instruction emulation statistics Avi Kivity
2007-12-30  7:09 ` [PATCH 07/52] KVM: Extend stats support for VM stats Avi Kivity
2007-12-30  7:09 ` [PATCH 08/52] KVM: MMU: Add some mmu statistics Avi Kivity
2007-12-30  7:09 ` [PATCH 09/52] KVM: Make unloading of FPU state when putting vcpu arch-independent Avi Kivity
2007-12-30  7:09 ` [PATCH 10/52] KVM: Portability: Move kvm_vcpu_ioctl_get_dirty_log to arch-specific file Avi Kivity
2007-12-30  7:09 ` [PATCH 11/52] KVM: Portability: MMU initialization and teardown split Avi Kivity
2007-12-30  7:09 ` [PATCH 12/52] KVM: Portability: Move some macro definitions from kvm.h to x86.h Avi Kivity
2007-12-30  7:09 ` [PATCH 13/52] KVM: Portability: Move struct kvm_x86_ops definition " Avi Kivity
2007-12-30  7:10 ` [PATCH 14/52] KVM: Portability: Move vcpu regs enumeration " Avi Kivity
2007-12-30  7:10 ` [PATCH 15/52] KVM: Move some static inline functions out from kvm.h into x86.h Avi Kivity
2007-12-30  7:10 ` [PATCH 16/52] KVM: Portability: Move some function declarations to x86.h Avi Kivity
2007-12-30  7:10 ` [PATCH 17/52] KVM: VMX: Force seg.base == (seg.sel << 4) in real mode Avi Kivity
2007-12-30  7:10 ` [PATCH 18/52] KVM: MMU: Change guest pte access to kvm_{read,write}_guest() Avi Kivity
2007-12-30  7:10 ` [PATCH 19/52] KVM: Simplify kvm_clear_guest_page() Avi Kivity
2007-12-30  7:10 ` [PATCH 20/52] KVM: Add missing #include <asm/pgtable.h> Avi Kivity
2008-01-03 18:14   ` Adrian Bunk
2008-01-06  9:09     ` [kvm-devel] " Avi Kivity
2007-12-30  7:10 ` [PATCH 21/52] KVM: MMU: Remove unused variable Avi Kivity
2007-12-30  7:10 ` [PATCH 22/52] KVM: Remove unused "rmap_overflow" variable Avi Kivity
2007-12-30  7:10 ` [PATCH 23/52] KVM: Correct consistent typo: "destory" -> "destroy" Avi Kivity
2007-12-30  7:10 ` [PATCH 24/52] KVM: Move misplaced comment Avi Kivity
2007-12-30  7:10 ` [PATCH 25/52] KVM: Portability: Move kvm_memory_alias to asm/kvm.h Avi Kivity
2007-12-30  7:10 ` [PATCH 26/52] KVM: Portability: Move x86 pic strutctures Avi Kivity
2007-12-30  7:10 ` [PATCH 27/52] KVM: Portability: Move kvm_regs to <asm/kvm.h> Avi Kivity
2007-12-30  7:10 ` [PATCH 28/52] KVM: Portability: Move structure lapic_state " Avi Kivity
2007-12-30  7:10 ` [PATCH 29/52] KVM: Portability: Move kvm_segment & kvm_dtable structure " Avi Kivity
2007-12-30  7:10 ` [PATCH 30/52] KVM: Portability: Move kvm_sregs and msr structures " Avi Kivity
2007-12-30  7:10 ` [PATCH 31/52] KVM: Portability: Move cpuid " Avi Kivity
2007-12-30  7:10 ` [PATCH 32/52] KVM: Export include/asm-x86/kvm.h Avi Kivity
2007-12-30  7:10 ` [PATCH 33/52] KVM: MMU: Fix potential memory leak with smp real-mode Avi Kivity
2007-12-30  7:10 ` [PATCH 34/52] KVM: MMU: Selectively set PageDirty when releasing guest memory Avi Kivity
2007-12-30  7:10 ` [PATCH 35/52] KVM: x86 emulator: retire ->write_std() Avi Kivity
2007-12-30  7:10 ` [PATCH 36/52] KVM: x86 emulator: prefetch up to 15 bytes of the instruction executed Avi Kivity
2007-12-30  7:10 ` [PATCH 37/52] KVM: Recalculate mmu pages needed for every memory region change Avi Kivity
2007-12-30  7:10 ` [PATCH 38/52] KVM: Portability: Split kvm_set_memory_region() to have an arch callout Avi Kivity
2007-12-30  7:10 ` [PATCH 39/52] KVM: Split vcpu creation to avoid vcpu_load() before preemption setup Avi Kivity
2007-12-30  7:10 ` [PATCH 40/52] KVM: MMU: Implement guest page fault bypass for nonpae Avi Kivity
2007-12-30  7:10 ` [PATCH 41/52] KVM: Add statistic for remote tlb flushes Avi Kivity
2007-12-30  7:10 ` [PATCH 42/52] KVM: MMU: Avoid unnecessary remote tlb flushes when guest updates a pte Avi Kivity
2007-12-30  7:10 ` [PATCH 43/52] KVM: Don't bother the mmu if cr3 load doesn't change cr3 Avi Kivity
2007-12-30  7:10 ` [PATCH 44/52] KVM: MMU: Code cleanup Avi Kivity
2007-12-30  7:10 ` [PATCH 45/52] KVM: MMU: Introduce and use gpte_to_gfn() Avi Kivity
2007-12-30  7:10 ` [PATCH 46/52] KVM: MMU: Move pse36 handling to the guest walker Avi Kivity
2007-12-30  7:10 ` [PATCH 47/52] KVM: MMU: Remove extra gaddr parameter from set_pte_common() Avi Kivity
2007-12-30  7:10 ` [PATCH 48/52] KVM: MMU: Remove set_pde() Avi Kivity
2007-12-30  7:10 ` [PATCH 49/52] KVM: MMU: Merge set_pte() and set_pte_common() Avi Kivity
2007-12-30  7:10 ` [PATCH 50/52] KVM: MMU: Adjust page_header_update_slot() to accept a gfn instead of a gpa Avi Kivity
2007-12-30  7:10 ` [PATCH 51/52] KVM: MMU: Introduce gfn_to_gpa() Avi Kivity
2007-12-30  7:10 ` [PATCH 52/52] KVM: MMU: Simplify nonpaging_map() Avi Kivity

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=1198998638-22713-4-git-send-email-avi@qumranet.com \
    --to=avi@qumranet.com \
    --cc=kvm-devel@lists.sourceforge.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=xiantao@vtsmp-build32.los-vmm.org \
    /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

all inboxes | Powered by JetHome®