]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
qemu: caps: Advertise arm 32-on-64 KVM option
authorCole Robinson <crobinso@redhat.com>
Thu, 21 May 2015 22:18:30 +0000 (18:18 -0400)
committerCole Robinson <crobinso@redhat.com>
Mon, 8 Jun 2015 21:56:31 +0000 (17:56 -0400)
We need to use qemu-system-aarch64 to run armv7l KVM VMs on an aarch64
host.

src/qemu/qemu_capabilities.c

index d42494d3b4f2421e55ae8601f264e24a300c3b3c..ca7a7c21ea39349582de158af377c58bd809d75e 100644 (file)
@@ -723,19 +723,6 @@ virQEMUCapsFindBinaryForArch(virArch hostarch,
     return ret;
 }
 
-
-static bool
-virQEMUCapsIsValidForKVM(virArch hostarch,
-                         virArch guestarch)
-{
-    if (hostarch == guestarch)
-        return true;
-    if (hostarch == VIR_ARCH_X86_64 &&
-        guestarch == VIR_ARCH_I686)
-        return true;
-    return false;
-}
-
 static int
 virQEMUCapsInitGuest(virCapsPtr caps,
                      virQEMUCapsCachePtr cache,
@@ -747,6 +734,7 @@ virQEMUCapsInitGuest(virCapsPtr caps,
     char *binary = NULL;
     virQEMUCapsPtr qemubinCaps = NULL;
     virQEMUCapsPtr kvmbinCaps = NULL;
+    bool native_kvm, x86_32on64_kvm, arm_32on64_kvm;
     int ret = -1;
 
     /* Check for existence of base emulator, or alternate base
@@ -764,16 +752,38 @@ virQEMUCapsInitGuest(virCapsPtr caps,
 
     /* qemu-kvm/kvm binaries can only be used if
      *  - host & guest arches match
-     * Or
-     *  - hostarch is x86_64 and guest arch is i686
-     * The latter simply needs "-cpu qemu32"
+     *  - hostarch is x86_64 and guest arch is i686 (needs -cpu qemu32)
+     *  - hostarch is aarch64 and guest arch is armv7l (needs -cpu aarch64=off)
      */
-    if (virQEMUCapsIsValidForKVM(hostarch, guestarch)) {
-        const char *const kvmbins[] = { "/usr/libexec/qemu-kvm", /* RHEL */
-                                        "qemu-kvm", /* Fedora */
-                                        "kvm" }; /* Upstream .spec */
+    native_kvm = (hostarch == guestarch);
+    x86_32on64_kvm = (hostarch == VIR_ARCH_X86_64 &&
+        guestarch == VIR_ARCH_I686);
+    arm_32on64_kvm = (hostarch == VIR_ARCH_AARCH64 &&
+        guestarch == VIR_ARCH_ARMV7L);
+
+    if (native_kvm || x86_32on64_kvm || arm_32on64_kvm) {
+        const char *kvmbins[] = {
+            "/usr/libexec/qemu-kvm", /* RHEL */
+            "qemu-kvm", /* Fedora */
+            "kvm", /* Debian/Ubuntu */
+            NULL,
+        };
+
+        /* x86 32-on-64 can be used with qemu-system-i386 and
+         * qemu-system-x86_64, so if we don't find a specific kvm binary,
+         * we can just fall back to the host arch native binary and
+         * everything works fine.
+         *
+         * arm is different in that 32-on-64 _only_ works with
+         * qemu-system-aarch64. So we have to add it to the kvmbins list
+         */
+        if (arm_32on64_kvm)
+            kvmbins[3] = "qemu-system-aarch64";
 
         for (i = 0; i < ARRAY_CARDINALITY(kvmbins); ++i) {
+            if (!kvmbins[i])
+                continue;
+
             kvmbin = virFindFileInPath(kvmbins[i]);
 
             if (!kvmbin)