Pablo Greco 40546a
From e4f000025ac57ed4c731ffb0939f2e02bb84d856 Mon Sep 17 00:00:00 2001
Pablo Greco 40546a
Message-Id: <e4f000025ac57ed4c731ffb0939f2e02bb84d856@dist-git>
Pablo Greco 40546a
From: Jiri Denemark <jdenemar@redhat.com>
Pablo Greco 40546a
Date: Fri, 21 Jun 2019 09:26:11 +0200
Pablo Greco 40546a
Subject: [PATCH] qemu: Forbid MSR features with old QEMU
Pablo Greco 40546a
MIME-Version: 1.0
Pablo Greco 40546a
Content-Type: text/plain; charset=UTF-8
Pablo Greco 40546a
Content-Transfer-Encoding: 8bit
Pablo Greco 40546a
Pablo Greco 40546a
Without "unavailable-features" CPU property we cannot properly detect
Pablo Greco 40546a
whether a specific MSR feature we asked for (either explicitly or
Pablo Greco 40546a
implicitly via a CPU model) was disabled by QEMU for some reason.
Pablo Greco 40546a
Because this could break migration, snapshots, and save/restore
Pablo Greco 40546a
operaions, it's better to just forbid any use of MSR features with QEMU
Pablo Greco 40546a
which lacks "unavailable-features" CPU property.
Pablo Greco 40546a
Pablo Greco 40546a
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Pablo Greco 40546a
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Pablo Greco 40546a
(cherry picked from commit 8eb4a89f5f7973f50aa8b6fa0b1a45b825dda208)
Pablo Greco 40546a
Pablo Greco 40546a
https://bugzilla.redhat.com/show_bug.cgi?id=1697627
Pablo Greco 40546a
Pablo Greco 40546a
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Pablo Greco 40546a
Message-Id: <b077794613a01d8ebd69b27afef1ad2452a4810d.1561068591.git.jdenemar@redhat.com>
Pablo Greco 40546a
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Pablo Greco 40546a
---
Pablo Greco 40546a
 src/qemu/qemu_process.c | 30 +++++++++++++++++++++++++++---
Pablo Greco 40546a
 1 file changed, 27 insertions(+), 3 deletions(-)
Pablo Greco 40546a
Pablo Greco 40546a
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
Pablo Greco 40546a
index d147e524ee..db14d322f5 100644
Pablo Greco 40546a
--- a/src/qemu/qemu_process.c
Pablo Greco 40546a
+++ b/src/qemu/qemu_process.c
Pablo Greco 40546a
@@ -53,6 +53,7 @@
Pablo Greco 40546a
 #include "qemu_extdevice.h"
Pablo Greco 40546a
 
Pablo Greco 40546a
 #include "cpu/cpu.h"
Pablo Greco 40546a
+#include "cpu/cpu_x86.h"
Pablo Greco 40546a
 #include "datatypes.h"
Pablo Greco 40546a
 #include "virlog.h"
Pablo Greco 40546a
 #include "virerror.h"
Pablo Greco 40546a
@@ -5226,9 +5227,32 @@ qemuProcessStartValidate(virQEMUDriverPtr driver,
Pablo Greco 40546a
     if (qemuProcessStartValidateShmem(vm) < 0)
Pablo Greco 40546a
         return -1;
Pablo Greco 40546a
 
Pablo Greco 40546a
-    if (vm->def->cpu &&
Pablo Greco 40546a
-        virCPUValidateFeatures(vm->def->os.arch, vm->def->cpu) < 0)
Pablo Greco 40546a
-        return -1;
Pablo Greco 40546a
+    if (vm->def->cpu) {
Pablo Greco 40546a
+        if (virCPUValidateFeatures(vm->def->os.arch, vm->def->cpu) < 0)
Pablo Greco 40546a
+            return -1;
Pablo Greco 40546a
+
Pablo Greco 40546a
+        if (ARCH_IS_X86(vm->def->os.arch) &&
Pablo Greco 40546a
+            !virQEMUCapsGet(qemuCaps, QEMU_CAPS_CPU_UNAVAILABLE_FEATURES)) {
Pablo Greco 40546a
+            VIR_AUTOSTRINGLIST features = NULL;
Pablo Greco 40546a
+            int n;
Pablo Greco 40546a
+
Pablo Greco 40546a
+            if ((n = virCPUDefCheckFeatures(vm->def->cpu,
Pablo Greco 40546a
+                                            virCPUx86FeatureFilterSelectMSR,
Pablo Greco 40546a
+                                            NULL,
Pablo Greco 40546a
+                                            &features)) < 0)
Pablo Greco 40546a
+                return -1;
Pablo Greco 40546a
+
Pablo Greco 40546a
+            if (n > 0) {
Pablo Greco 40546a
+                VIR_AUTOFREE(char *) str = NULL;
Pablo Greco 40546a
+
Pablo Greco 40546a
+                str = virStringListJoin((const char **)features, ", ");
Pablo Greco 40546a
+                virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
Pablo Greco 40546a
+                               _("Some features cannot be reliably used "
Pablo Greco 40546a
+                                 "with this QEMU: %s"), str);
Pablo Greco 40546a
+                return -1;
Pablo Greco 40546a
+            }
Pablo Greco 40546a
+        }
Pablo Greco 40546a
+    }
Pablo Greco 40546a
 
Pablo Greco 40546a
     if (qemuProcessStartValidateDisks(vm, qemuCaps) < 0)
Pablo Greco 40546a
         return -1;
Pablo Greco 40546a
-- 
Pablo Greco 40546a
2.22.0
Pablo Greco 40546a