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: 45730 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 n84JccTQ026795 for ; Fri, 4 Sep 2009 19:38:38 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757260AbZIDTia (ORCPT ); Fri, 4 Sep 2009 15:38:30 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1757248AbZIDTia (ORCPT ); Fri, 4 Sep 2009 15:38:30 -0400 Received: from mail-bw0-f219.google.com ([209.85.218.219]:57564 "EHLO mail-bw0-f219.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757247AbZIDTi3 (ORCPT ); Fri, 4 Sep 2009 15:38:29 -0400 Received: by bwz19 with SMTP id 19so484767bwz.37 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: Subject: Re: [PATCH] qemu-kvm: fix segfault when running kvm without /dev/kvm, falling back to non-accelerated mode From: Dustin Kirkland To: Marcelo Tosatti Cc: Mark McLoughlin , Glauber Costa , 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 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) {