Blob Blame History Raw
From 6227a5d2d70dd396c428af4864ab38b1a32ef0f5 Mon Sep 17 00:00:00 2001
Message-Id: <6227a5d2d70dd396c428af4864ab38b1a32ef0f5@dist-git>
From: Jiri Denemark <jdenemar@redhat.com>
Date: Fri, 15 Nov 2019 17:52:34 +0100
Subject: [PATCH] qemu: Drop disabled CPU features unknown to QEMU
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

When a CPU definition wants to explicitly disable some features that are
unknown to QEMU, we can safely drop them from the definition before
starting QEMU. Naturally QEMU won't enable such features implicitly.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
(cherry picked from commit ac34e141596fab70fbe91a396311f80db6cb57c5)

https://bugzilla.redhat.com/show_bug.cgi?id=1749672
https://bugzilla.redhat.com/show_bug.cgi?id=1756156
https://bugzilla.redhat.com/show_bug.cgi?id=1721608

Conflicts:
	src/qemu/qemu_process.c
            - downstream still uses cleanup label

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Message-Id: <92f146f8754300266d688dd92dfe95e737dda7da.1573836581.git.jdenemar@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
---
 src/qemu/qemu_process.c                       | 32 +++++++++++++++++++
 ...-Icelake-Server-pconfig.x86_64-latest.args |  2 +-
 2 files changed, 33 insertions(+), 1 deletion(-)

diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 0cd61f02bb..0700b054f3 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -5730,6 +5730,26 @@ qemuProcessSetupHotpluggableVcpus(virQEMUDriverPtr driver,
 }
 
 
+static bool
+qemuProcessDropUnknownCPUFeatures(const char *name,
+                                  virCPUFeaturePolicy policy,
+                                  void *opaque)
+{
+    const char **features = opaque;
+
+    if (policy != VIR_CPU_FEATURE_DISABLE &&
+        policy != VIR_CPU_FEATURE_FORBID)
+        return true;
+
+    if (virStringListHasString(features, name))
+        return true;
+
+    /* Features unknown to QEMU are implicitly disabled, we can just drop them
+     * from the definition. */
+    return false;
+}
+
+
 static int
 qemuProcessUpdateGuestCPU(virDomainDefPtr def,
                           virQEMUCapsPtr qemuCaps,
@@ -5792,6 +5812,18 @@ qemuProcessUpdateGuestCPU(virDomainDefPtr def,
                         virQEMUCapsGetCPUDefinitions(qemuCaps, def->virtType)) < 0)
         goto cleanup;
 
+    if (ARCH_IS_X86(def->os.arch)) {
+        VIR_AUTOSTRINGLIST features = NULL;
+
+        if (virQEMUCapsGetCPUFeatures(qemuCaps, def->virtType, false, &features) < 0)
+            goto cleanup;
+
+        if (features &&
+            virCPUDefFilterFeatures(def->cpu, qemuProcessDropUnknownCPUFeatures,
+                                    features) < 0)
+            goto cleanup;
+    }
+
     def->cpu->fallback = VIR_CPU_FALLBACK_FORBID;
     ret = 0;
 
diff --git a/tests/qemuxml2argvdata/cpu-Icelake-Server-pconfig.x86_64-latest.args b/tests/qemuxml2argvdata/cpu-Icelake-Server-pconfig.x86_64-latest.args
index 664db44e7b..de737bfed7 100644
--- a/tests/qemuxml2argvdata/cpu-Icelake-Server-pconfig.x86_64-latest.args
+++ b/tests/qemuxml2argvdata/cpu-Icelake-Server-pconfig.x86_64-latest.args
@@ -10,7 +10,7 @@ QEMU_AUDIO_DRV=none \
 -object secret,id=masterKey0,format=raw,\
 file=/tmp/lib/domain--1-test/master-key.aes \
 -machine pc,accel=kvm,usb=off,dump-guest-core=off \
--cpu Icelake-Server,pconfig=off \
+-cpu Icelake-Server \
 -m 214 \
 -realtime mlock=off \
 -smp 1,sockets=1,cores=1,threads=1 \
-- 
2.24.0