Blame SOURCES/0010-launch-direct-Don-t-use-cpu-host-on-TCG.patch

022f11
From 75ea7130586243c500d6e27d26942facf516226f Mon Sep 17 00:00:00 2001
022f11
From: "Richard W.M. Jones" <rjones@redhat.com>
022f11
Date: Wed, 14 Aug 2013 15:08:04 +0100
022f11
Subject: [PATCH] launch: direct: Don't use -cpu host on TCG.
022f11
022f11
qemu -cpu \? documents this as:
022f11
022f11
host  KVM processor with all supported host features (only available in KVM mode)
022f11
022f11
And indeed if you try it with TCG you'll get this error:
022f11
022f11
Unable to find CPU definition: host
022f11
022f11
This fixes commit 038ed0a08eaed33e62a27c9f91780a25de0bc08c.
022f11
022f11
(cherry picked from commit c53b459fdd7fc340f48a76496b7e7e18256a2d64)
022f11
---
022f11
 src/launch-direct.c | 39 ++++++++++++++++++++++++++-------------
022f11
 1 file changed, 26 insertions(+), 13 deletions(-)
022f11
022f11
diff --git a/src/launch-direct.c b/src/launch-direct.c
022f11
index 90d0df9..299a3d9 100644
022f11
--- a/src/launch-direct.c
022f11
+++ b/src/launch-direct.c
022f11
@@ -20,6 +20,7 @@
022f11
 
022f11
 #include <stdio.h>
022f11
 #include <stdlib.h>
022f11
+#include <stdbool.h>
022f11
 #include <stdint.h>
022f11
 #include <inttypes.h>
022f11
 #include <unistd.h>
022f11
@@ -258,6 +259,7 @@ launch_direct (guestfs_h *g, const char *arg)
022f11
     char buf[256];
022f11
     int virtio_scsi = qemu_supports_virtio_scsi (g);
022f11
     struct qemu_param *qp;
022f11
+    bool has_kvm;
022f11
 
022f11
     /* Set up the full command line.  Do this in the subprocess so we
022f11
      * don't need to worry about cleaning up.
022f11
@@ -290,6 +292,14 @@ launch_direct (guestfs_h *g, const char *arg)
022f11
 
022f11
     add_cmdline (g, "-nographic");
022f11
 
022f11
+    /* Try to guess if KVM is available.  We are just checking that
022f11
+     * /dev/kvm is openable.  That's not reliable, since /dev/kvm
022f11
+     * might be openable by qemu but not by us (think: SELinux) in
022f11
+     * which case the user would not get hardware virtualization,
022f11
+     * although at least shouldn't fail.
022f11
+     */
022f11
+    has_kvm = is_openable (g, "/dev/kvm", O_RDWR|O_CLOEXEC);
022f11
+
022f11
     /* The qemu -machine option (added 2010-12) is a bit more sane
022f11
      * since it falls back through various different acceleration
022f11
      * modes, so try that first (thanks Markus Armbruster).
022f11
@@ -301,23 +311,26 @@ launch_direct (guestfs_h *g, const char *arg)
022f11
       /* qemu sometimes needs this option to enable hardware
022f11
        * virtualization, but some versions of 'qemu-kvm' will use KVM
022f11
        * regardless (even where this option appears in the help text).
022f11
-       * It is rumoured that there are versions of qemu where supplying
022f11
-       * this option when hardware virtualization is not available will
022f11
-       * cause qemu to fail, so we we have to check at least that
022f11
-       * /dev/kvm is openable.  That's not reliable, since /dev/kvm
022f11
-       * might be openable by qemu but not by us (think: SELinux) in
022f11
-       * which case the user would not get hardware virtualization,
022f11
-       * although at least shouldn't fail.  A giant clusterfuck with the
022f11
-       * qemu command line, again.
022f11
+       * It is rumoured that there are versions of qemu where
022f11
+       * supplying this option when hardware virtualization is not
022f11
+       * available will cause qemu to fail.  A giant clusterfuck with
022f11
+       * the qemu command line, again.
022f11
        */
022f11
-      if (qemu_supports (g, "-enable-kvm") &&
022f11
-          is_openable (g, "/dev/kvm", O_RDWR|O_CLOEXEC))
022f11
+      if (qemu_supports (g, "-enable-kvm") && has_kvm)
022f11
         add_cmdline (g, "-enable-kvm");
022f11
     }
022f11
 
022f11
-    /* Specify the host CPU for speed, and kvmclock for stability. */
022f11
-    add_cmdline (g, "-cpu");
022f11
-    add_cmdline (g, "host,+kvmclock");
022f11
+    /* -cpu host only works if KVM is available. */
022f11
+    if (has_kvm) {
022f11
+      /* Specify the host CPU for speed, and kvmclock for stability. */
022f11
+      add_cmdline (g, "-cpu");
022f11
+      add_cmdline (g, "host,+kvmclock");
022f11
+    } else {
022f11
+      /* Specify default CPU for speed, and kvmclock for stability. */
022f11
+      snprintf (buf, sizeof buf, "qemu%d,+kvmclock", SIZEOF_LONG*8);
022f11
+      add_cmdline (g, "-cpu");
022f11
+      add_cmdline (g, buf);
022f11
+    }
022f11
 
022f11
     if (g->smp > 1) {
022f11
       snprintf (buf, sizeof buf, "%d", g->smp);
022f11
-- 
022f11
1.8.3.1
022f11