From patchwork Fri Sep 4 19:38:30 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Dustin Kirkland X-Patchwork-Id: 33015 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 48178B7B66 for ; Sat, 5 Sep 2009 05:39:12 +1000 (EST) Received: from localhost ([127.0.0.1]:43692 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Mjecm-0002VZ-Oi for incoming@patchwork.ozlabs.org; Fri, 04 Sep 2009 15:39:08 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MjecJ-0002Un-EF for qemu-devel@nongnu.org; Fri, 04 Sep 2009 15:38:39 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MjecE-0002Rk-5n for qemu-devel@nongnu.org; Fri, 04 Sep 2009 15:38:38 -0400 Received: from [199.232.76.173] (port=43398 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MjecD-0002Rf-RR for qemu-devel@nongnu.org; Fri, 04 Sep 2009 15:38:33 -0400 Received: from mail-fx0-f211.google.com ([209.85.220.211]:58662) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MjecC-0000QL-Qh for qemu-devel@nongnu.org; Fri, 04 Sep 2009 15:38:33 -0400 Received: by fxm7 with SMTP id 7so857223fxm.34 for ; Fri, 04 Sep 2009 12:38:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:sender:received:in-reply-to :references:date:x-google-sender-auth:message-id:subject:from:to:cc :content-type; bh=ioW3bcNeg2ik8T1NC4rEAGDK+4cwNC9orcive1srGBg=; b=bEfB9yJwh3c4WXUyqJu4PRsMD50oNmnKh1Ppl30CEbhdVSkShqUM/Asfdhx9pZUN88 HLeVhOdbAPBK0iJGTOIr+40pRncbp0MzTcdO6ZyrMAxZEpmAVDVJIweczRx+wo2+DRYJ qwsraZ6M65gez9BbFrv9uJxUQ9lTwHOgS7FF8= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type; b=G/4gpiVE7kqpWROP4EmxR66O3tnNcgAcZTkPTsYOEWE1URRvDQCQAMeJ1JHlz0/v4Y 6SYBZaFmktYLsUnxVPuW/DrO1/VvMgVQtBPuK8ULeyoVaS11xZu4uPlMThM6DgC45pia QylasiEmwcGaVz7LqcE4AhM5URuBXSmMAtaeM= MIME-Version: 1.0 Received: by 10.223.6.9 with SMTP id 9mr4706195fax.84.1252093110786; Fri, 04 Sep 2009 12:38:30 -0700 (PDT) In-Reply-To: <20090904163611.GC5132@amt.cnet> References: <1252008114.3084.136.camel@blaa> <5d6222a80909031518h2bf804fbk1f7a52424d3e8649@mail.gmail.com> <1252048961.3144.8.camel@blaa> <1252080398.4625.47.camel@x200> <20090904163611.GC5132@amt.cnet> Date: Fri, 4 Sep 2009 14:38:30 -0500 X-Google-Sender-Auth: 2368685e5bcce8d7 Message-ID: From: Dustin Kirkland To: Marcelo Tosatti X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 2) Cc: Mark McLoughlin , qemu-devel@nongnu.org, kvm@vger.kernel.org, Glauber Costa Subject: [Qemu-devel] Re: [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 On Fri, Sep 4, 2009 at 11:36 AM, Marcelo Tosatti wrote: > On Fri, Sep 04, 2009 at 11:06:38AM -0500, Dustin Kirkland wrote: >> On Fri, 2009-09-04 at 08:22 +0100, Mark McLoughlin wrote: >> > On Thu, 2009-09-03 at 19:18 -0300, Glauber Costa wrote: >> > > On Thu, Sep 3, 2009 at 6:48 PM, Dustin Kirkland wrote: >> > > > On Thu, Sep 3, 2009 at 3:01 PM, Mark McLoughlin wrote: >> > > >> On Thu, 2009-09-03 at 12:31 -0500, Dustin Kirkland wrote: >> > > >>> 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. >> > > >> >> > > >> Ah discussion about an alternative fix for this fizzled out recently: >> > > >> >> > > >>  http://www.mail-archive.com/kvm@vger.kernel.org/msg19890.html >> > > > >> > > > Ah, thanks Mark.  In that thread, I found Daniel's suggestion the most >> > > > reasonable, and user-friendly: >> > > > >> > > > On Mon, Jul 27, 2009 at 1:44 PM, Daniel P. Berrange wrote: >> > > >> Well, we could go for logic like: >> > > >> >> > > >>  * No arg given          => try kvm, try kqemu, try tcg >> > > >>  * --accelmode arg given => try $arg, and fail if unavailable >> > > >> >> > > >> then libvirt would simply always supply --accelmode for all VMs, >> > > >> while people running qemu manually would get best available >> > > I sent some patches to do that, but they were incomplete, and I was >> > > preempted by something else. >> > > If you want, you can wait for my cycles to come back, or pick from where I left >> >> Thanks for the pointer, Glauber.  My cycles a bit constrained too, but >> I'll have a look when I get a chance. >> >> > In the meantime, can we commit to stable-0.11 either Dustin's fix or >> > this: >> > >> >   http://git.et.redhat.com/?p=qemu-fedora.git;a=commitdiff;h=aa1620047b >> >> +1.  We're looking for something agreeable in stable-0.11, that solves >> the segfault and proceeds without VT acceleration. > > Dustin, > > Can you please resend the patch with the suggestion i made earlier, for > stable-0.11? Sure, Marcelo. It's attached. I tested it, and it still does avoid the segfault. Luiz, could you re-test this patch on your side too? :-Dustin qemu-kvm: fix segfault when running kvm without /dev/kvm qemu-kvm segfaults on systems without access to /dev/kvm. The global kvm_allowed is being set too late in vl.c. This patch moves the kvm initialization a bit higher in the vl.c main, just after the daemonize fork. This fix is intended to be a short term solution, solving the segfaults. In the longer term, the suggested approach requires a bit more development and testing: * If no arg given => try kvm, try kqemu, try tcg * If --accelmode arg given => try $arg, and fail if unavailable Signed-off-by: Dustin Kirkland diff --git a/vl.c b/vl.c index db75470..26bced8 100644 --- a/vl.c +++ b/vl.c @@ -5831,6 +5831,20 @@ int main(int argc, char **argv, char **envp) } #endif + 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; + } + } + #ifdef CONFIG_KQEMU if (smp_cpus > 1) kqemu_allowed = 0; @@ -6002,20 +6016,6 @@ int main(int argc, char **argv, char **envp) } } - 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) {