ef961da
From 70415c7d31bf6420d1a2d685fe14661ce1cfd9cb Mon Sep 17 00:00:00 2001
6780ef8
From: Dustin Kirkland <kirkland@canonical.com>
6780ef8
Date: Fri, 4 Sep 2009 14:38:30 -0500
6780ef8
Subject: [PATCH] qemu-kvm: fix segfault when running kvm without /dev/kvm
9d0bd0d
6780ef8
qemu-kvm segfaults on systems without access to /dev/kvm.
6780ef8
The global kvm_allowed is being set too late in vl.c.
9d0bd0d
6780ef8
This patch moves the kvm initialization a bit higher in the
6780ef8
vl.c main, just after the daemonize fork.
9d0bd0d
6780ef8
This fix is intended to be a short term solution, solving the
6780ef8
segfaults.
b77f8ba
6780ef8
In the longer term, the suggested approach requires a bit more
6780ef8
development and testing:
6780ef8
 * If no arg given          => try kvm, try kqemu, try tcg
6780ef8
 * If --accelmode arg given => try $arg, and fail if unavailable
6780ef8
6780ef8
(cherry picked from commit c06b44bfc9814930b6a94db7bbeb3be1cd39c0d2)
6780ef8
6780ef8
Signed-off-by: Dustin Kirkland <kirkland@canonical.com>
6780ef8
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
6780ef8
Signed-off-by: Mark McLoughlin <markmc@redhat.com>
b77f8ba
Fedora-patch: qemu-fix-no-kvm-segfault.patch
9d0bd0d
---
6780ef8
 vl.c |   28 ++++++++++++++--------------
6780ef8
 1 files changed, 14 insertions(+), 14 deletions(-)
6780ef8
6780ef8
diff --git a/vl.c b/vl.c
6780ef8
index db75470..26bced8 100644
6780ef8
--- a/vl.c
6780ef8
+++ b/vl.c
6780ef8
@@ -5831,6 +5831,20 @@ int main(int argc, char **argv, char **envp)
6780ef8
     }
6780ef8
 #endif
9d0bd0d
 
6780ef8
+    if (kvm_enabled()) {
6780ef8
+        int ret;
6780ef8
+
6780ef8
+        ret = kvm_init(smp_cpus);
6780ef8
+        if (ret < 0) {
6780ef8
+#if defined(KVM_UPSTREAM) || defined(NO_CPU_EMULATION)
6780ef8
+            fprintf(stderr, "failed to initialize KVM\n");
6780ef8
+            exit(1);
6780ef8
+#endif
6780ef8
+            fprintf(stderr, "Could not initialize KVM, will disable KVM support\n");
6780ef8
+            kvm_allowed = 0;
6780ef8
+        }
6780ef8
+    }
6780ef8
+
6780ef8
 #ifdef CONFIG_KQEMU
6780ef8
     if (smp_cpus > 1)
6780ef8
         kqemu_allowed = 0;
6780ef8
@@ -6002,20 +6016,6 @@ int main(int argc, char **argv, char **envp)
6780ef8
         }
6780ef8
     }
6780ef8
 
6780ef8
-    if (kvm_enabled()) {
6780ef8
-        int ret;
6780ef8
-
6780ef8
-        ret = kvm_init(smp_cpus);
6780ef8
-        if (ret < 0) {
6780ef8
-#if defined(KVM_UPSTREAM) || defined(NO_CPU_EMULATION)
6780ef8
-            fprintf(stderr, "failed to initialize KVM\n");
6780ef8
-            exit(1);
6780ef8
-#endif
6780ef8
-            fprintf(stderr, "Could not initialize KVM, will disable KVM support\n");
6780ef8
-	     kvm_allowed = 0;
6780ef8
-        }
6780ef8
-    }
9d0bd0d
-
6780ef8
     if (monitor_device) {
6780ef8
         monitor_hd = qemu_chr_open("monitor", monitor_device, NULL);
6780ef8
         if (!monitor_hd) {
9d0bd0d
-- 
b77f8ba
1.6.2.5
9d0bd0d