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