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: 32904 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by bilbo.ozlabs.org (Postfix) with ESMTPS id DB906B70BA for ; Fri, 4 Sep 2009 03:32:16 +1000 (EST) Received: from localhost ([127.0.0.1]:37404 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MjGAO-0003dv-Pq for incoming@patchwork.ozlabs.org; Thu, 03 Sep 2009 13:32:12 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MjG9u-0003dq-9o for qemu-devel@nongnu.org; Thu, 03 Sep 2009 13:31:42 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MjG9o-0003dS-QV for qemu-devel@nongnu.org; Thu, 03 Sep 2009 13:31:41 -0400 Received: from [199.232.76.173] (port=37680 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MjG9o-0003dP-Kq for qemu-devel@nongnu.org; Thu, 03 Sep 2009 13:31:36 -0400 Received: from mail-bw0-f227.google.com ([209.85.218.227]:43052) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MjG9n-0000XP-LW for qemu-devel@nongnu.org; Thu, 03 Sep 2009 13:31:36 -0400 Received: by bwz27 with SMTP id 27so107685bwz.34 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: From: Dustin Kirkland To: qemu-devel@nongnu.org, kvm@vger.kernel.org X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 2) Cc: Subject: [Qemu-devel] [PATCH] qemu-kvm: fix segfault when running kvm without /dev/kvm, falling back to non-accelerated mode X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.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) {