aboutsummaryrefslogtreecommitdiffstats
path: root/virt
diff options
context:
space:
mode:
authorGlauber Costa <glommer@redhat.com>2008-09-17 22:16:59 -0400
committerAvi Kivity <avi@redhat.com>2008-10-15 08:25:10 -0400
commit7d8fece678c1abc2ca3e1ceda2277c3538a9161c (patch)
tree4a41eaf5fd8f8d04fcc483197c67a448981fc0c8 /virt
parentaf2152f5457448bd90cb019c108e0a85e716fdbe (diff)
KVM: Don't destroy vcpu in case vcpu_setup fails
One of vcpu_setup responsibilities is to do mmu initialization. However, in case we fail in kvm_arch_vcpu_reset, before we get the chance to init mmu. OTOH, vcpu_destroy will attempt to destroy mmu, triggering a bug. Keeping track of whether or not mmu is initialized would unnecessarily complicate things. Rather, we just make return, making sure any needed uninitialization is done before we return, in case we fail. Signed-off-by: Glauber Costa <glommer@redhat.com> Signed-off-by: Avi Kivity <avi@redhat.com>
Diffstat (limited to 'virt')
-rw-r--r--virt/kvm/kvm_main.c5
1 files changed, 2 insertions, 3 deletions
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index cd34f73513d3..ef9a121bbd13 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -1089,12 +1089,11 @@ static int kvm_vm_ioctl_create_vcpu(struct kvm *kvm, int n)
1089 1089
1090 r = kvm_arch_vcpu_setup(vcpu); 1090 r = kvm_arch_vcpu_setup(vcpu);
1091 if (r) 1091 if (r)
1092 goto vcpu_destroy; 1092 return r;
1093 1093
1094 mutex_lock(&kvm->lock); 1094 mutex_lock(&kvm->lock);
1095 if (kvm->vcpus[n]) { 1095 if (kvm->vcpus[n]) {
1096 r = -EEXIST; 1096 r = -EEXIST;
1097 mutex_unlock(&kvm->lock);
1098 goto vcpu_destroy; 1097 goto vcpu_destroy;
1099 } 1098 }
1100 kvm->vcpus[n] = vcpu; 1099 kvm->vcpus[n] = vcpu;
@@ -1110,8 +1109,8 @@ static int kvm_vm_ioctl_create_vcpu(struct kvm *kvm, int n)
1110unlink: 1109unlink:
1111 mutex_lock(&kvm->lock); 1110 mutex_lock(&kvm->lock);
1112 kvm->vcpus[n] = NULL; 1111 kvm->vcpus[n] = NULL;
1113 mutex_unlock(&kvm->lock);
1114vcpu_destroy: 1112vcpu_destroy:
1113 mutex_unlock(&kvm->lock);
1115 kvm_arch_vcpu_destroy(vcpu); 1114 kvm_arch_vcpu_destroy(vcpu);
1116 return r; 1115 return r;
1117} 1116}