[PATCH 3/6] qemu: Drop disabled CPU features unknown to QEMU

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

 



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@xxxxxxxxxx>
---
 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 ed8666e9d1..06c9eba16c 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -6068,6 +6068,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,
@@ -6133,6 +6153,18 @@ qemuProcessUpdateGuestCPU(virDomainDefPtr def,
                                 &def->os.arch) < 0)
         return -1;
 
+    if (ARCH_IS_X86(def->os.arch)) {
+        VIR_AUTOSTRINGLIST features = NULL;
+
+        if (virQEMUCapsGetCPUFeatures(qemuCaps, def->virtType, false, &features) < 0)
+            return -1;
+
+        if (features &&
+            virCPUDefFilterFeatures(def->cpu, qemuProcessDropUnknownCPUFeatures,
+                                    features) < 0)
+            return -1;
+    }
+
     return 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 d6f5a0ad98..88d05a482a 100644
--- a/tests/qemuxml2argvdata/cpu-Icelake-Server-pconfig.x86_64-latest.args
+++ b/tests/qemuxml2argvdata/cpu-Icelake-Server-pconfig.x86_64-latest.args
@@ -13,7 +13,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 \
 -overcommit mem-lock=off \
 -smp 1,sockets=1,cores=1,threads=1 \
-- 
2.24.0

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list





[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