From: Alexander Graf Subject: [PATCH] Bail out when VCPU_CREATE fails Date: Mon, 22 Mar 2010 11:49:13 +0100 Message-ID: <1269254953-20323-1-git-send-email-agraf@suse.de> To: KVM list Return-path: Received: from cantor.suse.de ([195.135.220.2]:47382 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754118Ab0CVKtO (ORCPT ); Mon, 22 Mar 2010 06:49:14 -0400 Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.221.2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.suse.de (Postfix) with ESMTP id DE4366CB00 for ; Mon, 22 Mar 2010 11:49:13 +0100 (CET) Sender: kvm-owner@vger.kernel.org List-ID: 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. Signed-off-by: Alexander Graf Reported-by: Michael Tokarev --- Please also commit this to the -stable branch. --- qemu-kvm.c | 6 +++++- 1 files changed, 5 insertions(+), 1 deletions(-) diff --git a/qemu-kvm.c b/qemu-kvm.c index 7772434..4d19c80 100644 --- a/qemu-kvm.c +++ b/qemu-kvm.c @@ -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) -- 1.6.0.2