aboutsummaryrefslogtreecommitdiffstats
path: root/virt
diff options
context:
space:
mode:
authorJan Kiszka <jan.kiszka@siemens.com>2010-11-09 11:02:49 -0500
committerAvi Kivity <avi@redhat.com>2011-01-12 04:29:09 -0500
commitd89f5eff70a31237ffa1e21c51d23ca532110aea (patch)
tree13b47648a564d8382e08d7e5937ea30ff0fb838c /virt
parent9d893c6bc177b6ac5a1e937f4fdc359d272d68ff (diff)
KVM: Clean up vm creation and release
IA64 support forces us to abstract the allocation of the kvm structure. But instead of mixing this up with arch-specific initialization and doing the same on destruction, split both steps. This allows to move generic destruction calls into generic code. It also fixes error clean-up on failures of kvm_create_vm for IA64. Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com> Signed-off-by: Avi Kivity <avi@redhat.com>
Diffstat (limited to 'virt')
-rw-r--r--virt/kvm/kvm_main.c19
1 files changed, 13 insertions, 6 deletions
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index fce0578eab0e..4023264c4cd5 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -383,11 +383,15 @@ static int kvm_init_mmu_notifier(struct kvm *kvm)
383 383
384static struct kvm *kvm_create_vm(void) 384static struct kvm *kvm_create_vm(void)
385{ 385{
386 int r = 0, i; 386 int r, i;
387 struct kvm *kvm = kvm_arch_create_vm(); 387 struct kvm *kvm = kvm_arch_alloc_vm();
388 388
389 if (IS_ERR(kvm)) 389 if (!kvm)
390 goto out; 390 return ERR_PTR(-ENOMEM);
391
392 r = kvm_arch_init_vm(kvm);
393 if (r)
394 goto out_err_nodisable;
391 395
392 r = hardware_enable_all(); 396 r = hardware_enable_all();
393 if (r) 397 if (r)
@@ -427,7 +431,7 @@ static struct kvm *kvm_create_vm(void)
427 spin_lock(&kvm_lock); 431 spin_lock(&kvm_lock);
428 list_add(&kvm->vm_list, &vm_list); 432 list_add(&kvm->vm_list, &vm_list);
429 spin_unlock(&kvm_lock); 433 spin_unlock(&kvm_lock);
430out: 434
431 return kvm; 435 return kvm;
432 436
433out_err: 437out_err:
@@ -438,7 +442,7 @@ out_err_nodisable:
438 for (i = 0; i < KVM_NR_BUSES; i++) 442 for (i = 0; i < KVM_NR_BUSES; i++)
439 kfree(kvm->buses[i]); 443 kfree(kvm->buses[i]);
440 kfree(kvm->memslots); 444 kfree(kvm->memslots);
441 kfree(kvm); 445 kvm_arch_free_vm(kvm);
442 return ERR_PTR(r); 446 return ERR_PTR(r);
443} 447}
444 448
@@ -512,6 +516,9 @@ static void kvm_destroy_vm(struct kvm *kvm)
512 kvm_arch_flush_shadow(kvm); 516 kvm_arch_flush_shadow(kvm);
513#endif 517#endif
514 kvm_arch_destroy_vm(kvm); 518 kvm_arch_destroy_vm(kvm);
519 kvm_free_physmem(kvm);
520 cleanup_srcu_struct(&kvm->srcu);
521 kvm_arch_free_vm(kvm);
515 hardware_disable_all(); 522 hardware_disable_all();
516 mmdrop(mm); 523 mmdrop(mm);
517} 524}