Blob Blame History Raw
From e4f000025ac57ed4c731ffb0939f2e02bb84d856 Mon Sep 17 00:00:00 2001
Message-Id: <e4f000025ac57ed4c731ffb0939f2e02bb84d856@dist-git>
From: Jiri Denemark <jdenemar@redhat.com>
Date: Fri, 21 Jun 2019 09:26:11 +0200
Subject: [PATCH] qemu: Forbid MSR features with old QEMU
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Without "unavailable-features" CPU property we cannot properly detect
whether a specific MSR feature we asked for (either explicitly or
implicitly via a CPU model) was disabled by QEMU for some reason.
Because this could break migration, snapshots, and save/restore
operaions, it's better to just forbid any use of MSR features with QEMU
which lacks "unavailable-features" CPU property.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
(cherry picked from commit 8eb4a89f5f7973f50aa8b6fa0b1a45b825dda208)

https://bugzilla.redhat.com/show_bug.cgi?id=1697627

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Message-Id: <b077794613a01d8ebd69b27afef1ad2452a4810d.1561068591.git.jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
---
 src/qemu/qemu_process.c | 30 +++++++++++++++++++++++++++---
 1 file changed, 27 insertions(+), 3 deletions(-)

diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index d147e524ee..db14d322f5 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -53,6 +53,7 @@
 #include "qemu_extdevice.h"
 
 #include "cpu/cpu.h"
+#include "cpu/cpu_x86.h"
 #include "datatypes.h"
 #include "virlog.h"
 #include "virerror.h"
@@ -5226,9 +5227,32 @@ qemuProcessStartValidate(virQEMUDriverPtr driver,
     if (qemuProcessStartValidateShmem(vm) < 0)
         return -1;
 
-    if (vm->def->cpu &&
-        virCPUValidateFeatures(vm->def->os.arch, vm->def->cpu) < 0)
-        return -1;
+    if (vm->def->cpu) {
+        if (virCPUValidateFeatures(vm->def->os.arch, vm->def->cpu) < 0)
+            return -1;
+
+        if (ARCH_IS_X86(vm->def->os.arch) &&
+            !virQEMUCapsGet(qemuCaps, QEMU_CAPS_CPU_UNAVAILABLE_FEATURES)) {
+            VIR_AUTOSTRINGLIST features = NULL;
+            int n;
+
+            if ((n = virCPUDefCheckFeatures(vm->def->cpu,
+                                            virCPUx86FeatureFilterSelectMSR,
+                                            NULL,
+                                            &features)) < 0)
+                return -1;
+
+            if (n > 0) {
+                VIR_AUTOFREE(char *) str = NULL;
+
+                str = virStringListJoin((const char **)features, ", ");
+                virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                               _("Some features cannot be reliably used "
+                                 "with this QEMU: %s"), str);
+                return -1;
+            }
+        }
+    }
 
     if (qemuProcessStartValidateDisks(vm, qemuCaps) < 0)
         return -1;
-- 
2.22.0