[libvirt PATCH 03/17] qemu: Query hvf capability on macOS

Andrea Bolognani posted 17 patches 4 years, 1 month ago
There is a newer version of this series
[libvirt PATCH 03/17] qemu: Query hvf capability on macOS
Posted by Andrea Bolognani 4 years, 1 month ago
From: Roman Bolshakov <r.bolshakov@yadro.com>

There's no QMP command for querying if hvf is supported, therefore we
use sysctl interface that tells if Hypervisor.framework works/available
on the host.

Signed-off-by: Roman Bolshakov <r.bolshakov@yadro.com>
Signed-off-by: Andrea Bolognani <abologna@redhat.com>
---
 src/qemu/qemu_capabilities.c | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index 7823cb3d48..9b4f695770 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -56,6 +56,10 @@
 #include <unistd.h>
 #include <stdarg.h>
 #include <sys/utsname.h>
+#ifdef __APPLE__
+# include <sys/types.h>
+# include <sys/sysctl.h>
+#endif
 
 #define VIR_FROM_THIS VIR_FROM_QEMU
 
@@ -3191,6 +3195,32 @@ virQEMUCapsProbeQMPKVMState(virQEMUCaps *qemuCaps,
     return 0;
 }
 
+#ifdef __APPLE__
+static int
+virQEMUCapsProbeHVF(virQEMUCaps *qemuCaps)
+{
+    int hv_support;
+    size_t len = sizeof(hv_support);
+
+    if (sysctlbyname("kern.hv_support", &hv_support, &len, NULL, 0) < 0)
+        hv_support = 0;
+
+    if (qemuCaps->version >= 2012000 &&
+        ARCH_IS_X86(qemuCaps->arch) &&
+        hv_support) {
+        virQEMUCapsSet(qemuCaps, QEMU_CAPS_HVF);
+    }
+
+    return 0;
+}
+#else
+static int
+virQEMUCapsProbeHVF(virQEMUCaps *qemuCaps G_GNUC_UNUSED)
+{
+  return 0;
+}
+#endif
+
 struct virQEMUCapsCommandLineProps {
     const char *option;
     const char *param;
@@ -5335,6 +5365,9 @@ virQEMUCapsInitQMPMonitor(virQEMUCaps *qemuCaps,
     if (virQEMUCapsProbeQMPKVMState(qemuCaps, mon) < 0)
         return -1;
 
+    if (virQEMUCapsProbeHVF(qemuCaps) < 0)
+        return -1;
+
     type = virQEMUCapsGetVirtType(qemuCaps);
     accel = virQEMUCapsGetAccel(qemuCaps, type);
 
-- 
2.31.1

Re: [libvirt PATCH 03/17] qemu: Query hvf capability on macOS
Posted by Daniel P. Berrangé 4 years, 1 month ago
On Tue, Jan 04, 2022 at 07:52:42PM +0100, Andrea Bolognani wrote:
> From: Roman Bolshakov <r.bolshakov@yadro.com>
> 
> There's no QMP command for querying if hvf is supported, therefore we
> use sysctl interface that tells if Hypervisor.framework works/available
> on the host.
> 
> Signed-off-by: Roman Bolshakov <r.bolshakov@yadro.com>
> Signed-off-by: Andrea Bolognani <abologna@redhat.com>
> ---
>  src/qemu/qemu_capabilities.c | 33 +++++++++++++++++++++++++++++++++
>  1 file changed, 33 insertions(+)

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>


Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|