[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH 3/3] qemu: caps: Advertise arm 32-on-64 KVM option



We need to use qemu-system-aarch64 to run armv7l KVM VMs on an aarch64
host.
---
 src/qemu/qemu_capabilities.c | 42 ++++++++++++++++++++++--------------------
 1 file changed, 22 insertions(+), 20 deletions(-)

diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index 1e7bddb..7181865 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -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,30 @@ 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,
+        };
+
+        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)
-- 
2.4.1


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]