From patchwork Thu Sep 3 17:31:33 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dustin Kirkland X-Patchwork-Id: 45404 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n83HVh7w017383 for ; Thu, 3 Sep 2009 17:31:43 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754460AbZICRbi (ORCPT ); Thu, 3 Sep 2009 13:31:38 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1753086AbZICRbi (ORCPT ); Thu, 3 Sep 2009 13:31:38 -0400 Received: from mail-bw0-f219.google.com ([209.85.218.219]:63803 "EHLO mail-bw0-f219.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753291AbZICRbh (ORCPT ); Thu, 3 Sep 2009 13:31:37 -0400 Received: by bwz19 with SMTP id 19so109321bwz.37 for ; Thu, 03 Sep 2009 10:31:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:sender:received:date :x-google-sender-auth:message-id:subject:from:to:content-type; bh=g1zo6qJvWUoAYGGB60iDa8V8nGqQQIA67vJDQKHuC4E=; b=fQW/P9Rb0LNM1Wb8LXGOLArkk9RWzmzGTqLGGVAHQ0jigKrhmtiZgVO5PkrElsPhN1 vywMHvdCoRkY8h26ipjR+BiBsDO0PqpwWhQTN5wzUozKQhhSLKkLUDz8+PPpCzeEBMLO yGD3FavTAGX9Q8AYIpA/EheU9l0EfdLKDB0DU= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:sender:date:x-google-sender-auth:message-id:subject :from:to:content-type; b=prxCqsmmXriTcROxuXC430lGPXm1oroOzvHfqqQnx0YsQcoZ+p/FaP2RbD3zjhb9vY NxW/1DNkMcybRFFaZ8bH/v1ubsk9yZwvt1A/YSFvo5FmQFb/mOH/Job7Go41blBsRRkc jXI45KZz7sV425u3G4ecv568X/1qpAtb3wK0M= MIME-Version: 1.0 Received: by 10.223.76.79 with SMTP id b15mr4235165fak.66.1251999093170; Thu, 03 Sep 2009 10:31:33 -0700 (PDT) Date: Thu, 3 Sep 2009 12:31:33 -0500 X-Google-Sender-Auth: 7a57224f2ccdfc1a Message-ID: Subject: [PATCH] qemu-kvm: fix segfault when running kvm without /dev/kvm, falling back to non-accelerated mode From: Dustin Kirkland To: qemu-devel@nongnu.org, kvm@vger.kernel.org Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org qemu-kvm: fix segfault when running kvm without /dev/kvm, falling back to non-accelerated mode We're seeing segfaults on systems without access to /dev/kvm. It looks like the global kvm_allowed is being set just a little too late in vl.c. This patch moves the kvm initialization a bit higher in the vl.c main, just after options processing, and solves the segfaults. We're carrying this patch in Ubuntu 9.10 Alpha. Please apply upstream, or advise if and why this might not be the optimal solution. Signed-off-by: Dustin Kirkland Move the kvm_init() call a bit higher to fix a segfault when /dev/kvm is not available. The kvm_allowed global needs to be set correctly a little earlier. Signed-off-by: Dustin Kirkland --- qemu-kvm-0.11.0~rc1.orig/vl.c +++ qemu-kvm-0.11.0~rc1/vl.c @@ -5748,6 +5748,20 @@ } } + if (kvm_enabled()) { + int ret; + + ret = kvm_init(smp_cpus); + if (ret < 0) { +#if defined(KVM_UPSTREAM) || defined(NO_CPU_EMULATION) + fprintf(stderr, "failed to initialize KVM\n"); + exit(1); +#endif + fprintf(stderr, "Could not initialize KVM, will disable KVM support\n"); + kvm_allowed = 0; + } + } + /* If no data_dir is specified then try to find it relative to the executable path. */ if (!data_dir) { @@ -6008,20 +6022,6 @@ } } - if (kvm_enabled()) { - int ret; - - ret = kvm_init(smp_cpus); - if (ret < 0) { -#if defined(KVM_UPSTREAM) || defined(NO_CPU_EMULATION) - fprintf(stderr, "failed to initialize KVM\n"); - exit(1); -#endif - fprintf(stderr, "Could not initialize KVM, will disable KVM support\n"); - kvm_allowed = 0; - } - } - if (monitor_device) { monitor_hd = qemu_chr_open("monitor", monitor_device, NULL); if (!monitor_hd) {