render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
Blob Blame History Raw
From 5196a4b5fad475a8489faa9b5542536a941bd9da Mon Sep 17 00:00:00 2001
Message-Id: <5196a4b5fad475a8489faa9b5542536a941bd9da@dist-git>
From: Jiri Denemark <jdenemar@redhat.com>
Date: Fri, 21 Jun 2019 09:25:01 +0200
Subject: [PATCH] cpu_x86: Allow multiple signatures for a CPU model
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

CPU signatures in the cpu_map serve as a hint for CPUID to CPU model
matching algorithm. If the CPU signatures matches any CPU model in the
cpu_map, this model will be the preferred one.

This works out well and solved several mismatches, but in real world
CPUs which should match a single CPU model may be produced with several
different signatures. For example, low voltage Broadwell CPUs for
laptops and Broadwell CPUs for servers differ in CPU model numbers while
we should detect them all as Broadwell CPU model.

This patch adds support for storing several signatures for a single CPU
model to make this hint useful for more CPUs. Later commits will provide
additional signatures for existing CPU models, which will correct some
results in our CPU test suite.

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

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

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Message-Id: <393649e6301769c297f2d09bcb88d6200882eb9d.1561068591.git.jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
---
 src/cpu/cpu_x86.c | 31 +++++++++++++++++++++----------
 1 file changed, 21 insertions(+), 10 deletions(-)

diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c
index f8b8d8a96b..7bd8119c23 100644
--- a/src/cpu/cpu_x86.c
+++ b/src/cpu/cpu_x86.c
@@ -1204,22 +1204,32 @@ x86ModelParseAncestor(virCPUx86ModelPtr model,
 
 
 static int
-x86ModelParseSignature(virCPUx86ModelPtr model,
-                       xmlXPathContextPtr ctxt)
+x86ModelParseSignatures(virCPUx86ModelPtr model,
+                        xmlXPathContextPtr ctxt)
 {
+    VIR_AUTOFREE(xmlNodePtr *) nodes = NULL;
+    xmlNodePtr root = ctxt->node;
+    size_t i;
+    int n;
+
+    if ((n = virXPathNodeSet("./signature", ctxt, &nodes)) <= 0)
+        return n;
+
     /* Remove inherited signatures. */
     VIR_FREE(model->signatures);
 
-    if (virXPathBoolean("boolean(./signature)", ctxt)) {
+    model->nsignatures = n;
+    if (VIR_ALLOC_N(model->signatures, n) < 0)
+       return -1;
+
+    for (i = 0; i < n; i++) {
         unsigned int sigFamily = 0;
         unsigned int sigModel = 0;
         int rc;
 
-        model->nsignatures = 1;
-        if (VIR_ALLOC_N(model->signatures, 1) < 0)
-            return -1;
+        ctxt->node = nodes[i];
 
-        rc = virXPathUInt("string(./signature/@family)", ctxt, &sigFamily);
+        rc = virXPathUInt("string(@family)", ctxt, &sigFamily);
         if (rc < 0 || sigFamily == 0) {
             virReportError(VIR_ERR_INTERNAL_ERROR,
                            _("Invalid CPU signature family in model %s"),
@@ -1227,7 +1237,7 @@ x86ModelParseSignature(virCPUx86ModelPtr model,
             return -1;
         }
 
-        rc = virXPathUInt("string(./signature/@model)", ctxt, &sigModel);
+        rc = virXPathUInt("string(@model)", ctxt, &sigModel);
         if (rc < 0 || sigModel == 0) {
             virReportError(VIR_ERR_INTERNAL_ERROR,
                            _("Invalid CPU signature model in model %s"),
@@ -1235,9 +1245,10 @@ x86ModelParseSignature(virCPUx86ModelPtr model,
             return -1;
         }
 
-        model->signatures[0] = x86MakeSignature(sigFamily, sigModel, 0);
+        model->signatures[i] = x86MakeSignature(sigFamily, sigModel, 0);
     }
 
+    ctxt->node = root;
     return 0;
 }
 
@@ -1334,7 +1345,7 @@ x86ModelParse(xmlXPathContextPtr ctxt,
     if (x86ModelParseAncestor(model, ctxt, map) < 0)
         goto cleanup;
 
-    if (x86ModelParseSignature(model, ctxt) < 0)
+    if (x86ModelParseSignatures(model, ctxt) < 0)
         goto cleanup;
 
     if (x86ModelParseVendor(model, ctxt, map) < 0)
-- 
2.22.0