4372d3
From 99a298a4a0575bf0072f504c4b8e4551400c44c0 Mon Sep 17 00:00:00 2001
4372d3
Message-Id: <99a298a4a0575bf0072f504c4b8e4551400c44c0@dist-git>
abb18f
From: Jiri Denemark <jdenemar@redhat.com>
abb18f
Date: Tue, 26 Apr 2022 11:58:07 +0200
abb18f
Subject: [PATCH] cpu_x86: Consolidate signature match in x86DecodeUseCandidate
abb18f
abb18f
Checking the signature in two different places makes no sense since the
abb18f
code in between can only mark the candidate as the best option so far,
abb18f
which is what the second signature match does as well.
abb18f
abb18f
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
abb18f
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
abb18f
(cherry picked from commit 35ce086667e68e8f546cf36473591dd7c19c72eb)
abb18f
4372d3
https://bugzilla.redhat.com/show_bug.cgi?id=1851227
abb18f
abb18f
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
abb18f
---
abb18f
 src/cpu/cpu_x86.c | 31 ++++++++++++++-----------------
abb18f
 1 file changed, 14 insertions(+), 17 deletions(-)
abb18f
abb18f
diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c
abb18f
index 5cb9caef8a..f007487824 100644
abb18f
--- a/src/cpu/cpu_x86.c
abb18f
+++ b/src/cpu/cpu_x86.c
abb18f
@@ -2020,15 +2020,22 @@ x86DecodeUseCandidate(virCPUx86Model *current,
abb18f
     }
abb18f
 
abb18f
     /* Ideally we want to select a model with family/model equal to
abb18f
-     * family/model of the real CPU. Once we found such model, we only
abb18f
+     * family/model of the real CPU and once we found such model, we only
abb18f
      * consider candidates with matching family/model.
abb18f
      */
abb18f
-    if (signature &&
abb18f
-        virCPUx86SignaturesMatch(current->signatures, signature) &&
abb18f
-        !virCPUx86SignaturesMatch(candidate->signatures, signature)) {
abb18f
-        VIR_DEBUG("%s differs in signature from matching %s",
abb18f
-                  cpuCandidate->model, cpuCurrent->model);
abb18f
-        return 0;
abb18f
+    if (signature) {
abb18f
+        if (virCPUx86SignaturesMatch(current->signatures, signature) &&
abb18f
+            !virCPUx86SignaturesMatch(candidate->signatures, signature)) {
abb18f
+            VIR_DEBUG("%s differs in signature from matching %s",
abb18f
+                      cpuCandidate->model, cpuCurrent->model);
abb18f
+            return 0;
abb18f
+        }
abb18f
+
abb18f
+        if (!virCPUx86SignaturesMatch(current->signatures, signature) &&
abb18f
+            virCPUx86SignaturesMatch(candidate->signatures, signature)) {
abb18f
+            VIR_DEBUG("%s provides matching signature", cpuCandidate->model);
abb18f
+            return 1;
abb18f
+        }
abb18f
     }
abb18f
 
abb18f
     if (cpuCurrent->nfeatures > cpuCandidate->nfeatures) {
abb18f
@@ -2037,16 +2044,6 @@ x86DecodeUseCandidate(virCPUx86Model *current,
abb18f
         return 1;
abb18f
     }
abb18f
 
abb18f
-    /* Prefer a candidate with matching signature even though it would
abb18f
-     * result in longer list of features.
abb18f
-     */
abb18f
-    if (signature &&
abb18f
-        virCPUx86SignaturesMatch(candidate->signatures, signature) &&
abb18f
-        !virCPUx86SignaturesMatch(current->signatures, signature)) {
abb18f
-        VIR_DEBUG("%s provides matching signature", cpuCandidate->model);
abb18f
-        return 1;
abb18f
-    }
abb18f
-
abb18f
     VIR_DEBUG("%s does not result in shorter feature list than %s",
abb18f
               cpuCandidate->model, cpuCurrent->model);
abb18f
     return 0;
abb18f
-- 
abb18f
2.35.1
abb18f