]> asedeno.scripts.mit.edu Git - linux.git/blobdiff - arch/powerpc/kvm/powerpc.c
KVM: Introduce kvm_vcpu_destroy()
[linux.git] / arch / powerpc / kvm / powerpc.c
index 416fb3d2a1d0b6ec6fe1356820a5b743caf76a1f..e3e2b88d3d8bc408e2c045752adf4449a338bcb8 100644 (file)
@@ -475,7 +475,7 @@ void kvm_arch_destroy_vm(struct kvm *kvm)
 #endif
 
        kvm_for_each_vcpu(i, vcpu, kvm)
-               kvm_arch_vcpu_free(vcpu);
+               kvm_vcpu_destroy(vcpu);
 
        mutex_lock(&kvm->lock);
        for (i = 0; i < atomic_read(&kvm->online_vcpus); i++)
@@ -720,22 +720,44 @@ void kvm_arch_flush_shadow_memslot(struct kvm *kvm,
        kvmppc_core_flush_memslot(kvm, slot);
 }
 
+int kvm_arch_vcpu_precreate(struct kvm *kvm, unsigned int id)
+{
+       return 0;
+}
+
 struct kvm_vcpu *kvm_arch_vcpu_create(struct kvm *kvm, unsigned int id)
 {
        struct kvm_vcpu *vcpu;
-       vcpu = kvmppc_core_vcpu_create(kvm, id);
-       if (!IS_ERR(vcpu)) {
-               vcpu->arch.wqp = &vcpu->wq;
-               kvmppc_create_vcpu_debugfs(vcpu, id);
-       }
+       int err;
+
+       vcpu = kmem_cache_zalloc(kvm_vcpu_cache, GFP_KERNEL);
+       if (!vcpu)
+               return ERR_PTR(-ENOMEM);
+
+       err = kvm_vcpu_init(vcpu, kvm, id);
+       if (err)
+               goto free_vcpu;
+
+       err = kvmppc_core_vcpu_create(vcpu);
+       if (err)
+               goto uninit_vcpu;
+
+       vcpu->arch.wqp = &vcpu->wq;
+       kvmppc_create_vcpu_debugfs(vcpu, id);
        return vcpu;
+
+uninit_vcpu:
+       kvm_vcpu_uninit(vcpu);
+free_vcpu:
+       kmem_cache_free(kvm_vcpu_cache, vcpu);
+       return ERR_PTR(err);
 }
 
 void kvm_arch_vcpu_postcreate(struct kvm_vcpu *vcpu)
 {
 }
 
-void kvm_arch_vcpu_free(struct kvm_vcpu *vcpu)
+void kvm_arch_vcpu_destroy(struct kvm_vcpu *vcpu)
 {
        /* Make sure we're not using the vcpu anymore */
        hrtimer_cancel(&vcpu->arch.dec_timer);
@@ -758,11 +780,10 @@ void kvm_arch_vcpu_free(struct kvm_vcpu *vcpu)
        }
 
        kvmppc_core_vcpu_free(vcpu);
-}
 
-void kvm_arch_vcpu_destroy(struct kvm_vcpu *vcpu)
-{
-       kvm_arch_vcpu_free(vcpu);
+       kvm_vcpu_uninit(vcpu);
+
+       kmem_cache_free(kvm_vcpu_cache, vcpu);
 }
 
 int kvm_cpu_has_pending_timer(struct kvm_vcpu *vcpu)