Skip to contentSkip to conversation

Bail out when VCPU_CREATE fails

PATCH Applied Alexander Graf 2 participants 3 messages Mar 22, 2010 – Mar 24, 2010 KVM

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Bail out when VCPU_CREATE fails

When we fail to create a VCPU we have no way to tell our callers that something failed. So the caller happily uses a completely broken state.

This code should become deprecated in the process of converting qemu-kvm to qemu anyways, so let's not care about remdeling it but just bailing out when something breaks. Also give the user a hint on why the VCPU_CREATE might have failed.

This fixes a segmentation fault with -smp > VCPU_MAX in the host kernel.

---

Please also commit this to the -stable branch.

---
 qemu-kvm.c |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)
qemu-kvm.c +5 -1
index 7772434..4d19c80 100644
@@ -448,7 +448,8 @@ static void kvm_create_vcpu(CPUState *env, int id)
     r = kvm_vm_ioctl(kvm_state, KVM_CREATE_VCPU, id);
     if (r < 0) {
         fprintf(stderr, "kvm_create_vcpu: %m\n");
-        return;
+        fprintf(stderr, "Failed to create vCPU. Check the -smp parameter.\n");
+        goto err;
     }
 
     env->kvm_fd = r;
@@ -476,6 +477,9 @@ static void kvm_create_vcpu(CPUState *env, int id)
     return;
   err_fd:
     close(env->kvm_fd);
+  err:
+    /* We're no good with semi-broken states. */
+    abort();
 }
 
 static int kvm_set_boot_vcpu_id(kvm_context_t kvm, uint32_t id)
Signature · 1 line
1.6.0.2
Applied
#1 lore raw
Quoted 11 lines · Alexander Graf

When we fail to create a VCPU we have no way to tell our callers that something failed. So the caller happily uses a completely broken state.

This code should become deprecated in the process of converting qemu-kvm to qemu anyways, so let's not care about remdeling it but just bailing out when something breaks. Also give the user a hint on why the VCPU_CREATE might have failed.

This fixes a segmentation fault with -smp> VCPU_MAX in the host kernel.

Applied, thanks. Note, kvm reports the number of supported vcpus using KVM_CAP_NR_VCPUS, so we can fail in vl.c.

Signature · 1 line
error compiling committee.c: too many arguments to function
#2 lore raw
Quoted 9 lines · Avi Kivity
Quoted 8 lines · Alexander Graf

When we fail to create a VCPU we have no way to tell our callers that something failed. So the caller happily uses a completely broken state.

This code should become deprecated in the process of converting qemu-kvm to qemu anyways, so let's not care about remdeling it but just bailing out when something breaks. Also give the user a hint on why the VCPU_CREATE might have failed.

Quoted 5 lines
Quoted 3 lines

This fixes a segmentation fault with -smp> VCPU_MAX in the host kernel.

Applied, thanks. Note, kvm reports the number of supported vcpus using KVM_CAP_NR_VCPUS, so we can fail in vl.c.

Sounds like the right fix to do for qemu.git. As soon as SMP support is in there.

Alex