diff options
author | Zhang Xiantao <xiantao@vtsmp-build32.los-vmm.org> | 2007-11-18 18:43:45 +0800 |
---|---|---|
committer | Avi Kivity <avi@qumranet.com> | 2008-01-30 17:53:04 +0200 |
commit | d19a9cd275b0fdc793d1bb8b644b7aad0517e4bc (patch) | |
tree | 5dba36f58295f165e4fd3380742875d1867266f5 /drivers/kvm/kvm_main.c | |
parent | a16b043cc96db4a01abb337bef4a51cebcfcbb1b (diff) | |
download | lwn-d19a9cd275b0fdc793d1bb8b644b7aad0517e4bc.tar.gz lwn-d19a9cd275b0fdc793d1bb8b644b7aad0517e4bc.zip |
KVM: Portability: Add two hooks to handle kvm_create and destroy vm
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>
Diffstat (limited to 'drivers/kvm/kvm_main.c')
-rw-r--r-- | drivers/kvm/kvm_main.c | 42 |
1 files changed, 6 insertions, 36 deletions
diff --git a/drivers/kvm/kvm_main.c b/drivers/kvm/kvm_main.c index e24489b409cf..bde3cf741892 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) |