b971b8
From ba2f2a8c39f2e7fe5684d9b84a0a832be482a3ab Mon Sep 17 00:00:00 2001
b971b8
Message-Id: <ba2f2a8c39f2e7fe5684d9b84a0a832be482a3ab@dist-git>
b971b8
From: Jiri Denemark <jdenemar@redhat.com>
b971b8
Date: Tue, 26 May 2020 10:58:57 +0200
b971b8
Subject: [PATCH] cpu_x86: Honor CPU models' <decode> element
b971b8
MIME-Version: 1.0
b971b8
Content-Type: text/plain; charset=UTF-8
b971b8
Content-Transfer-Encoding: 8bit
b971b8
b971b8
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
b971b8
Reviewed-by: Christian Ehrhardt <christian.ehrhardt@canonical.com>
b971b8
Tested-by: Christian Ehrhardt <christian.ehrhardt@canonical.com>
b971b8
(cherry picked from commit 7cd896ef31d33f78d40df918a33fe3867e251509)
b971b8
b971b8
https://bugzilla.redhat.com/show_bug.cgi?id=1840008
b971b8
b971b8
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
b971b8
Message-Id: <15f1eedf2c0df29a3942b4b28bc4575fa51ca19a.1590483392.git.jdenemar@redhat.com>
b971b8
Reviewed-by: Ján Tomko <jtomko@redhat.com>
b971b8
---
b971b8
 src/cpu/cpu_x86.c | 22 +++++++++++++++++-----
b971b8
 1 file changed, 17 insertions(+), 5 deletions(-)
b971b8
b971b8
diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c
b971b8
index 7fbb4c9a6c..b4d5c795f7 100644
b971b8
--- a/src/cpu/cpu_x86.c
b971b8
+++ b/src/cpu/cpu_x86.c
b971b8
@@ -2044,10 +2044,23 @@ x86DecodeUseCandidate(virCPUx86ModelPtr current,
b971b8
                       virCPUx86ModelPtr candidate,
b971b8
                       virCPUDefPtr cpuCandidate,
b971b8
                       uint32_t signature,
b971b8
-                      const char *preferred,
b971b8
-                      bool checkPolicy)
b971b8
+                      const char *preferred)
b971b8
 {
b971b8
-    if (checkPolicy) {
b971b8
+    if (cpuCandidate->type == VIR_CPU_TYPE_HOST &&
b971b8
+        !candidate->decodeHost) {
b971b8
+        VIR_DEBUG("%s is not supposed to be used for host CPU definition",
b971b8
+                  cpuCandidate->model);
b971b8
+        return 0;
b971b8
+    }
b971b8
+
b971b8
+    if (cpuCandidate->type == VIR_CPU_TYPE_GUEST &&
b971b8
+        !candidate->decodeGuest) {
b971b8
+        VIR_DEBUG("%s is not supposed to be used for guest CPU definition",
b971b8
+                  cpuCandidate->model);
b971b8
+        return 0;
b971b8
+    }
b971b8
+
b971b8
+    if (cpuCandidate->type == VIR_CPU_TYPE_HOST) {
b971b8
         size_t i;
b971b8
         for (i = 0; i < cpuCandidate->nfeatures; i++) {
b971b8
             if (cpuCandidate->features[i].policy == VIR_CPU_FEATURE_DISABLE)
b971b8
@@ -2209,8 +2222,7 @@ x86Decode(virCPUDefPtr cpu,
b971b8
 
b971b8
         if ((rc = x86DecodeUseCandidate(model, cpuModel,
b971b8
                                         candidate, cpuCandidate,
b971b8
-                                        signature, preferred,
b971b8
-                                        cpu->type == VIR_CPU_TYPE_HOST))) {
b971b8
+                                        signature, preferred))) {
b971b8
             virCPUDefFree(cpuModel);
b971b8
             cpuModel = cpuCandidate;
b971b8
             model = candidate;
b971b8
-- 
b971b8
2.26.2
b971b8