[libvirt PATCH 06/20] fixup! qemu: Fix / improve virQEMUCapsProbeHVF()

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

 



Fix the architecture check so that hardware acceleration is only
ever advertised when the guest and host architecture match; exit
early if possible instead of calling sysctl every single time;
add some comments.

Signed-off-by: Andrea Bolognani <abologna@xxxxxxxxxx>
Tested-by: Brad Laue <brad@xxxxxxxxxx>
---
 src/qemu/qemu_capabilities.c | 22 ++++++++++++++++------
 1 file changed, 16 insertions(+), 6 deletions(-)

diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index 146bbb97f8..f1f1b37678 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -3204,17 +3204,27 @@ virQEMUCapsProbeQMPKVMState(virQEMUCaps *qemuCaps,
 static int
 virQEMUCapsProbeHVF(virQEMUCaps *qemuCaps)
 {
-    int hv_support;
+    int hv_support = 0;
     size_t len = sizeof(hv_support);
+    virArch hostArch = virArchFromHost();
 
+    /* Guest and host arch need to match for hardware acceleration
+     * to be usable */
+    if (qemuCaps->arch != hostArch)
+        return 0;
+
+    /* We don't have a nice way to probe whether the QEMU binary
+     * contains HVF support, but we know that versions older than
+     * QEMU 2.12 didn't have the feature at all */
+    if (qemuCaps->version < 2012000)
+        return 0;
+
+    /* We need the OS to report Hypervisor.framework availability */
     if (sysctlbyname("kern.hv_support", &hv_support, &len, NULL, 0) < 0)
-        hv_support = 0;
+        return 0;
 
-    if (qemuCaps->version >= 2012000 &&
-        ARCH_IS_X86(qemuCaps->arch) &&
-        hv_support) {
+    if (hv_support)
         virQEMUCapsSet(qemuCaps, QEMU_CAPS_HVF);
-    }
 
     return 0;
 }
-- 
2.34.1




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux