From a339c27b1598af3f0b76116760190dd71217a706 Mon Sep 17 00:00:00 2001 From: Roman Bolshakov Date: Fri, 19 Oct 2018 15:07:53 +0300 Subject: [PATCH] qemu: Query hvf capability on macOS MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 Signed-off-by: Andrea Bolognani Tested-by: Brad Laue Tested-by: Christophe Fergeau Reviewed-by: Daniel P. Berrangé --- src/qemu/qemu_capabilities.c | 43 ++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index 994dc3dad2..d01be3e892 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -56,6 +56,10 @@ #include #include #include +#ifdef __APPLE__ +# include +# include +#endif #define VIR_FROM_THIS VIR_FROM_QEMU @@ -3192,6 +3196,42 @@ virQEMUCapsProbeQMPKVMState(virQEMUCaps *qemuCaps, return 0; } +#ifdef __APPLE__ +static int +virQEMUCapsProbeHVF(virQEMUCaps *qemuCaps) +{ + 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) + return 0; + + if (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; @@ -5333,6 +5373,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.39.5