render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
6d1f90
From 5e1f4ab125d37efb4c8224184f4cd7dd7a0cfdcd Mon Sep 17 00:00:00 2001
6d1f90
Message-Id: <5e1f4ab125d37efb4c8224184f4cd7dd7a0cfdcd@dist-git>
6d1f90
From: Jiri Denemark <jdenemar@redhat.com>
6d1f90
Date: Fri, 22 Nov 2019 11:19:22 +0100
6d1f90
Subject: [PATCH] qemu: Drop disabled CPU features unknown to QEMU
6d1f90
MIME-Version: 1.0
6d1f90
Content-Type: text/plain; charset=UTF-8
6d1f90
Content-Transfer-Encoding: 8bit
6d1f90
6d1f90
When a CPU definition wants to explicitly disable some features that are
6d1f90
unknown to QEMU, we can safely drop them from the definition before
6d1f90
starting QEMU. Naturally QEMU won't enable such features implicitly.
6d1f90
6d1f90
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
6d1f90
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
6d1f90
(cherry picked from commit ac34e141596fab70fbe91a396311f80db6cb57c5)
6d1f90
6d1f90
https://bugzilla.redhat.com/show_bug.cgi?id=1775133
6d1f90
https://bugzilla.redhat.com/show_bug.cgi?id=1775134
6d1f90
https://bugzilla.redhat.com/show_bug.cgi?id=1775137
6d1f90
6d1f90
Conflicts:
6d1f90
	src/qemu/qemu_process.c
6d1f90
            - downstream still uses cleanup label
6d1f90
6d1f90
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
6d1f90
Message-Id: <1c07cf7bb969d38770555e7369d4578ba57bd38c.1574417839.git.jdenemar@redhat.com>
6d1f90
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
6d1f90
---
6d1f90
 src/qemu/qemu_process.c                       | 32 +++++++++++++++++++
6d1f90
 ...-Icelake-Server-pconfig.x86_64-latest.args |  2 +-
6d1f90
 2 files changed, 33 insertions(+), 1 deletion(-)
6d1f90
6d1f90
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
6d1f90
index 0cd61f02bb..0700b054f3 100644
6d1f90
--- a/src/qemu/qemu_process.c
6d1f90
+++ b/src/qemu/qemu_process.c
6d1f90
@@ -5730,6 +5730,26 @@ qemuProcessSetupHotpluggableVcpus(virQEMUDriverPtr driver,
6d1f90
 }
6d1f90
 
6d1f90
 
6d1f90
+static bool
6d1f90
+qemuProcessDropUnknownCPUFeatures(const char *name,
6d1f90
+                                  virCPUFeaturePolicy policy,
6d1f90
+                                  void *opaque)
6d1f90
+{
6d1f90
+    const char **features = opaque;
6d1f90
+
6d1f90
+    if (policy != VIR_CPU_FEATURE_DISABLE &&
6d1f90
+        policy != VIR_CPU_FEATURE_FORBID)
6d1f90
+        return true;
6d1f90
+
6d1f90
+    if (virStringListHasString(features, name))
6d1f90
+        return true;
6d1f90
+
6d1f90
+    /* Features unknown to QEMU are implicitly disabled, we can just drop them
6d1f90
+     * from the definition. */
6d1f90
+    return false;
6d1f90
+}
6d1f90
+
6d1f90
+
6d1f90
 static int
6d1f90
 qemuProcessUpdateGuestCPU(virDomainDefPtr def,
6d1f90
                           virQEMUCapsPtr qemuCaps,
6d1f90
@@ -5792,6 +5812,18 @@ qemuProcessUpdateGuestCPU(virDomainDefPtr def,
6d1f90
                         virQEMUCapsGetCPUDefinitions(qemuCaps, def->virtType)) < 0)
6d1f90
         goto cleanup;
6d1f90
 
6d1f90
+    if (ARCH_IS_X86(def->os.arch)) {
6d1f90
+        VIR_AUTOSTRINGLIST features = NULL;
6d1f90
+
6d1f90
+        if (virQEMUCapsGetCPUFeatures(qemuCaps, def->virtType, false, &features) < 0)
6d1f90
+            goto cleanup;
6d1f90
+
6d1f90
+        if (features &&
6d1f90
+            virCPUDefFilterFeatures(def->cpu, qemuProcessDropUnknownCPUFeatures,
6d1f90
+                                    features) < 0)
6d1f90
+            goto cleanup;
6d1f90
+    }
6d1f90
+
6d1f90
     def->cpu->fallback = VIR_CPU_FALLBACK_FORBID;
6d1f90
     ret = 0;
6d1f90
 
6d1f90
diff --git a/tests/qemuxml2argvdata/cpu-Icelake-Server-pconfig.x86_64-latest.args b/tests/qemuxml2argvdata/cpu-Icelake-Server-pconfig.x86_64-latest.args
6d1f90
index 664db44e7b..de737bfed7 100644
6d1f90
--- a/tests/qemuxml2argvdata/cpu-Icelake-Server-pconfig.x86_64-latest.args
6d1f90
+++ b/tests/qemuxml2argvdata/cpu-Icelake-Server-pconfig.x86_64-latest.args
6d1f90
@@ -10,7 +10,7 @@ QEMU_AUDIO_DRV=none \
6d1f90
 -object secret,id=masterKey0,format=raw,\
6d1f90
 file=/tmp/lib/domain--1-test/master-key.aes \
6d1f90
 -machine pc,accel=kvm,usb=off,dump-guest-core=off \
6d1f90
--cpu Icelake-Server,pconfig=off \
6d1f90
+-cpu Icelake-Server \
6d1f90
 -m 214 \
6d1f90
 -realtime mlock=off \
6d1f90
 -smp 1,sockets=1,cores=1,threads=1 \
6d1f90
-- 
6d1f90
2.24.0
6d1f90