KVM: Hoist kvm_create_lapic() into kvm_vcpu_init()
authorRusty Russell <rusty@rustcorp.com.au>
Mon, 8 Oct 2007 00:50:48 +0000 (10:50 +1000)
committerAvi Kivity <avi@qumranet.com>
Wed, 30 Jan 2008 15:52:50 +0000 (17:52 +0200)
Move kvm_create_lapic() into kvm_vcpu_init(), rather than having svm
and vmx do it.  And make it return the error rather than a fairly
random -ENOMEM.

This also solves the problem that neither svm.c nor vmx.c actually
handles the error path properly.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Signed-off-by: Avi Kivity <avi@qumranet.com>
drivers/kvm/kvm_main.c
drivers/kvm/svm.c
drivers/kvm/vmx.c

index b19734606cd9d6f6e1dac3bd97181fdf873d4ef1..9ea9277014aa00bab47b125ff8857595bb0cbd1c 100644 (file)
@@ -255,14 +255,22 @@ int kvm_vcpu_init(struct kvm_vcpu *vcpu, struct kvm *kvm, unsigned id)
        if (r < 0)
                goto fail_free_pio_data;
 
+       if (irqchip_in_kernel(kvm)) {
+               r = kvm_create_lapic(vcpu);
+               if (r < 0)
+                       goto fail_mmu_destroy;
+       }
+
        return 0;
 
+fail_mmu_destroy:
+       kvm_mmu_destroy(vcpu);
 fail_free_pio_data:
        free_page((unsigned long)vcpu->pio_data);
 fail_free_run:
        free_page((unsigned long)vcpu->run);
 fail:
-       return -ENOMEM;
+       return r;
 }
 EXPORT_SYMBOL_GPL(kvm_vcpu_init);
 
index f268bd51f337f40c9fbc346f9892da1388bc28fc..fb2e591d5397f341f35c7924f65bcc86f3d2a463 100644 (file)
@@ -588,12 +588,6 @@ static struct kvm_vcpu *svm_create_vcpu(struct kvm *kvm, unsigned int id)
        if (err)
                goto free_svm;
 
-       if (irqchip_in_kernel(kvm)) {
-               err = kvm_create_lapic(&svm->vcpu);
-               if (err < 0)
-                       goto free_svm;
-       }
-
        page = alloc_page(GFP_KERNEL);
        if (!page) {
                err = -ENOMEM;
index 894fd45ecc985cfb8bfe14eadbbd49726eaf83ef..7b742901e783ae3deb836486ed09a8900f1d79ce 100644 (file)
@@ -2431,12 +2431,6 @@ static struct kvm_vcpu *vmx_create_vcpu(struct kvm *kvm, unsigned int id)
        if (err)
                goto free_vcpu;
 
-       if (irqchip_in_kernel(kvm)) {
-               err = kvm_create_lapic(&vmx->vcpu);
-               if (err < 0)
-                       goto free_vcpu;
-       }
-
        vmx->guest_msrs = kmalloc(PAGE_SIZE, GFP_KERNEL);
        if (!vmx->guest_msrs) {
                err = -ENOMEM;