Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 371453 - app-emulation/qemu-kvm - qemu-kvm crashes with SIGSEGV on i686 without -no-kvm
Summary: app-emulation/qemu-kvm - qemu-kvm crashes with SIGSEGV on i686 without -no-kvm
Status: RESOLVED NEEDINFO
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: x86 Linux
: Normal normal
Assignee: Gentoo QEMU Project
URL:
Whiteboard:
Keywords:
: 384435 (view as bug list)
Depends on:
Blocks:
 
Reported: 2011-06-13 18:44 UTC by Stejarel Veres
Modified: 2012-01-25 16:54 UTC (History)
1 user (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
emerge --info output (emerge-info.txt,4.28 KB, text/plain)
2011-06-13 18:45 UTC, Stejarel Veres
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Stejarel Veres 2011-06-13 18:44:06 UTC
Recent qemu-kvm versions, including the most recent one (0.14.1-r1) crashes with SIGSEGV when KVM is not explicitly disabled on the command line on an amd64 machine:

# /usr/bin/qemu-kvm 
Segmentation fault

vs.

# /usr/bin/qemu-kvm -no-kvm
VNC server running on `127.0.0.1:5900'


Reproducible: Always

Steps to Reproduce:
1. qemu-kvm
2. qemu-kvm -no-kvm
Actual Results:  
1. SIGSEGV
2. Runs normally

Expected Results:  
1. Should run normally, just like 2.

When compiling qemu from source (http://wiki.qemu.org/Download), it does not exhibit this behavior.
Comment 1 Stejarel Veres 2011-06-13 18:45:35 UTC
Created attachment 276939 [details]
emerge --info output
Comment 2 Stejarel Veres 2011-06-13 18:47:57 UTC
Correction: the machine in question is actually i686, not amd64.
Comment 3 Doug Goldstein (RETIRED) gentoo-dev 2011-06-14 05:14:25 UTC
$ qemu-kvm 
VNC server running on `127.0.0.1:5904'

Works just fine here. I even tried it on an x86_64 machine that had 32 bit Gentoo installed.

It's likely related to your USE flags or some other funky setup with your system. Please read the Gentoo Backtraces guide to get a useful backtrace that can be debugged and re-open the ticket.

http://www.gentoo.org/proj/en/qa/backtraces.xml
Comment 4 Stejarel Veres 2011-06-14 18:55:54 UTC
I think I got to the end of it.

I was going to re-compile qemu-kvm with -ggdb when I had the idea of trying to build it with i686-pc-linux-gnu-4.5.2-vanilla instead of i686-pc-linux-gnu-4.5.2. Sure enough, now it does not crash anymore.
Comment 5 Stejarel Veres 2011-06-14 19:41:11 UTC
As it turns out, it doesn't work that well. qemu-kvm doesn't crash anymore, but VMs freeze randomly. This does not happen if I compile qemu from source.

So I am back to investigating the crash... After having re-built qemu-kvm with -ggdb and splitdebug, I re-executed qemu-kvm and tried to debug the resulted core dump.

Here is what it produced:

Core was generated by `qemu-system-x86_64 -enable-kvm'.
Program terminated with signal 11, Segmentation fault.
#0  0xb75ef261 in ap_main_loop (_env=0xb7ea8018)
    at /var/tmp/portage/app-emulation/qemu-kvm-0.14.1-r1/work/qemu-kvm-0.14.1/qemu-kvm.c:1455
1455        current_env->created = 1;

Any ideas?
Comment 6 Stejarel Veres 2011-06-26 05:06:17 UTC
Since there was no reaction to my previous comment, I went ahead and tried to match CFLAGS, LDFLAGS and configuration options between the two instances of qemu I have on my machine (one from the qemu-kvm ebuild and the other compiled from the original source). The result is that the one compiled from source still works, while the other still crashes.

Here is a diff between the two configure outputs. I've removed non-relevant lines (install prefix...) and I've left only actual configuration differences, and the CFLAGS and LDFLAGS I'm using.

--- qemu-src.txt    2011-06-26 00:47:14.622109347 -0400
+++ qemu-kvm.txt        2011-06-26 00:52:06.002038406 -0400
@@ -1,12 +1,12 @@
 CFLAGS            -g -march=nocona -O2 -pipe -fforce-addr -ggdb
 LDFLAGS           -Wl,--warn-common -m32 -g -Wl,-z,execheap -Wl,-O1 -Wl,--as-needed

+CPU emulation     yes

-PIE user targets  no
+PIE user targets  yes

-IO thread         yes
+IO thread         no

+KVM PIT support   yes
+KVM device assig. yes

I couldn't find a way to enable IO threads from qemu-kvm's USE flags, but I doubt the issue is there. 

Now the next question would be: what exactly are the differences between the source used by the ebuild and the upstream (original) source? I see that the ebuild applies two patches, but are they applied to the upstream stable source or to a different revision from their git or...?

Operationally, one difference I noticed is that the qemu from qemu-kvm will start with kvm enabled by default, and it can be disabled from the command line with -no-kvm; the qemu from the upstream 0.14.1 stable starts with kvm disabled by default and is enabled with -enable-kvm; the -no-kvm option does not exist for this one.

Any ideas? I can go further and diff the two source trees, but that's as far as it goes, since I'm not familiar with the code and I couldn't possibly tell what exactly generates this problem.

Stejarel
Comment 7 Stejarel Veres 2011-06-26 05:54:03 UTC
As it turns out, it helps if you do your homework, and I hadn't. For a moment there, I though that original qemu and qemu-kvm were the same thing.

Having learned that they aren't, I tried to compile qemu-kvm from source. The first attempt was to compile it with exactly the same CFLAGS, LDFLAGS and configure options as the ebuild. The resulting binary crashes if I don't disable KVM, exactly as the one from the ebuild does.

Next, I tried to compile it with its default CFLAGS and LDFLAGS, i.e.:

-CFLAGS            -g -march=nocona -O2 -pipe -fforce-addr -ggdb
+CFLAGS            -g

-LDFLAGS           -Wl,--warn-common -m32 -g -Wl,-z,execheap -Wl,-O1 -Wl,--as-needed
+LDFLAGS           -Wl,--warn-common -m32 -g

The resulting binary does not crash anymore with KVM enabled, but VMs freeze randomly, so I'm back to the situation I was when I compiled it with i686-pc-linux-gnu-4.5.2-vanilla (see comment #5). Therefore, I'm all out of ideas, again.

Any help would be greatly appreciated.
Comment 8 Doug Goldstein (RETIRED) gentoo-dev 2012-01-25 04:47:12 UTC
Can you attach the exact command line of how qemu-kvm was executed where your VMs hang? What OS is the guest running? What is the guest doing when it hangs?
Comment 9 Doug Goldstein (RETIRED) gentoo-dev 2012-01-25 04:51:34 UTC
*** Bug 384435 has been marked as a duplicate of this bug. ***
Comment 10 Stejarel Veres 2012-01-25 05:14:15 UTC
I don't recall what the command line was exactly, but there was nothing fancy. The guest OS was FreeBSD and, as I mentioned, it would hang up randomly - sometimes during boot, some other times just sitting there idle and doing "nothing".
Comment 11 Sergei Trofimovich (RETIRED) gentoo-dev 2012-01-25 16:54:12 UTC
(In reply to comment #5)
> As it turns out, it doesn't work that well. qemu-kvm doesn't crash anymore, but
> VMs freeze randomly. This does not happen if I compile qemu from source.

If your kernel was still 2.6.38 it might well be the same issue i have seen at that time. I had to fix kernel to make freebsds not hang:

    http://www.mail-archive.com/kvm@vger.kernel.org/msg50789.html