render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
Pablo Greco 40546a
From c7a8133cbe9d0612db2889038079d260c3a8334f Mon Sep 17 00:00:00 2001
Pablo Greco 40546a
Message-Id: <c7a8133cbe9d0612db2889038079d260c3a8334f@dist-git>
Pablo Greco 40546a
From: Jiri Denemark <jdenemar@redhat.com>
Pablo Greco 40546a
Date: Fri, 21 Jun 2019 09:25:00 +0200
Pablo Greco 40546a
Subject: [PATCH] cpu_x86: Store CPU signature in an array
Pablo Greco 40546a
MIME-Version: 1.0
Pablo Greco 40546a
Content-Type: text/plain; charset=UTF-8
Pablo Greco 40546a
Content-Transfer-Encoding: 8bit
Pablo Greco 40546a
Pablo Greco 40546a
In preparation for storing several CPU signatures in a single CPU model,
Pablo Greco 40546a
we need to turn virCPUx86Model's signature into an array of signatures.
Pablo Greco 40546a
Pablo Greco 40546a
The parser still hardcodes the number of signatures to 1, but the
Pablo Greco 40546a
following patch will drop this limit.
Pablo Greco 40546a
Pablo Greco 40546a
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Pablo Greco 40546a
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Pablo Greco 40546a
(cherry picked from commit b07b8b7750c6a505d4b00bd272e79ea0305cb610)
Pablo Greco 40546a
Pablo Greco 40546a
https://bugzilla.redhat.com/show_bug.cgi?id=1686895
Pablo Greco 40546a
Pablo Greco 40546a
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Pablo Greco 40546a
Message-Id: <1d24aad1c6b9aa8142a2e882511f52a41fbaff67.1561068591.git.jdenemar@redhat.com>
Pablo Greco 40546a
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Pablo Greco 40546a
---
Pablo Greco 40546a
 src/cpu/cpu_x86.c | 50 ++++++++++++++++++++++++++++++++++++++---------
Pablo Greco 40546a
 1 file changed, 41 insertions(+), 9 deletions(-)
Pablo Greco 40546a
Pablo Greco 40546a
diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c
Pablo Greco 40546a
index e25bc691ae..f8b8d8a96b 100644
Pablo Greco 40546a
--- a/src/cpu/cpu_x86.c
Pablo Greco 40546a
+++ b/src/cpu/cpu_x86.c
Pablo Greco 40546a
@@ -145,7 +145,8 @@ typedef virCPUx86Model *virCPUx86ModelPtr;
Pablo Greco 40546a
 struct _virCPUx86Model {
Pablo Greco 40546a
     char *name;
Pablo Greco 40546a
     virCPUx86VendorPtr vendor;
Pablo Greco 40546a
-    uint32_t signature;
Pablo Greco 40546a
+    size_t nsignatures;
Pablo Greco 40546a
+    uint32_t *signatures;
Pablo Greco 40546a
     virCPUx86Data data;
Pablo Greco 40546a
 };
Pablo Greco 40546a
 
Pablo Greco 40546a
@@ -972,6 +973,7 @@ x86ModelFree(virCPUx86ModelPtr model)
Pablo Greco 40546a
         return;
Pablo Greco 40546a
 
Pablo Greco 40546a
     VIR_FREE(model->name);
Pablo Greco 40546a
+    VIR_FREE(model->signatures);
Pablo Greco 40546a
     virCPUx86DataClear(&model->data);
Pablo Greco 40546a
     VIR_FREE(model);
Pablo Greco 40546a
 }
Pablo Greco 40546a
@@ -981,7 +983,14 @@ static int
Pablo Greco 40546a
 x86ModelCopySignatures(virCPUx86ModelPtr dst,
Pablo Greco 40546a
                        virCPUx86ModelPtr src)
Pablo Greco 40546a
 {
Pablo Greco 40546a
-    dst->signature = src->signature;
Pablo Greco 40546a
+    size_t i;
Pablo Greco 40546a
+
Pablo Greco 40546a
+    if (VIR_ALLOC_N(dst->signatures, src->nsignatures) < 0)
Pablo Greco 40546a
+        return -1;
Pablo Greco 40546a
+
Pablo Greco 40546a
+    dst->nsignatures = src->nsignatures;
Pablo Greco 40546a
+    for (i = 0; i < src->nsignatures; i++)
Pablo Greco 40546a
+        dst->signatures[i] = src->signatures[i];
Pablo Greco 40546a
 
Pablo Greco 40546a
     return 0;
Pablo Greco 40546a
 }
Pablo Greco 40546a
@@ -1198,12 +1207,18 @@ static int
Pablo Greco 40546a
 x86ModelParseSignature(virCPUx86ModelPtr model,
Pablo Greco 40546a
                        xmlXPathContextPtr ctxt)
Pablo Greco 40546a
 {
Pablo Greco 40546a
+    /* Remove inherited signatures. */
Pablo Greco 40546a
+    VIR_FREE(model->signatures);
Pablo Greco 40546a
 
Pablo Greco 40546a
     if (virXPathBoolean("boolean(./signature)", ctxt)) {
Pablo Greco 40546a
         unsigned int sigFamily = 0;
Pablo Greco 40546a
         unsigned int sigModel = 0;
Pablo Greco 40546a
         int rc;
Pablo Greco 40546a
 
Pablo Greco 40546a
+        model->nsignatures = 1;
Pablo Greco 40546a
+        if (VIR_ALLOC_N(model->signatures, 1) < 0)
Pablo Greco 40546a
+            return -1;
Pablo Greco 40546a
+
Pablo Greco 40546a
         rc = virXPathUInt("string(./signature/@family)", ctxt, &sigFamily);
Pablo Greco 40546a
         if (rc < 0 || sigFamily == 0) {
Pablo Greco 40546a
             virReportError(VIR_ERR_INTERNAL_ERROR,
Pablo Greco 40546a
@@ -1220,7 +1235,7 @@ x86ModelParseSignature(virCPUx86ModelPtr model,
Pablo Greco 40546a
             return -1;
Pablo Greco 40546a
         }
Pablo Greco 40546a
 
Pablo Greco 40546a
-        model->signature = x86MakeSignature(sigFamily, sigModel, 0);
Pablo Greco 40546a
+        model->signatures[0] = x86MakeSignature(sigFamily, sigModel, 0);
Pablo Greco 40546a
     }
Pablo Greco 40546a
 
Pablo Greco 40546a
     return 0;
Pablo Greco 40546a
@@ -1621,7 +1636,8 @@ x86Compute(virCPUDefPtr host,
Pablo Greco 40546a
                                      &host_model->vendor->cpuid) < 0)
Pablo Greco 40546a
             goto error;
Pablo Greco 40546a
 
Pablo Greco 40546a
-        if (x86DataAddSignature(&guest_model->data, host_model->signature) < 0)
Pablo Greco 40546a
+        if (host_model->signatures &&
Pablo Greco 40546a
+            x86DataAddSignature(&guest_model->data, *host_model->signatures) < 0)
Pablo Greco 40546a
             goto error;
Pablo Greco 40546a
 
Pablo Greco 40546a
         if (cpu->type == VIR_CPU_TYPE_GUEST
Pablo Greco 40546a
@@ -1727,6 +1743,21 @@ virCPUx86Compare(virCPUDefPtr host,
Pablo Greco 40546a
 }
Pablo Greco 40546a
 
Pablo Greco 40546a
 
Pablo Greco 40546a
+static bool
Pablo Greco 40546a
+x86ModelHasSignature(virCPUx86ModelPtr model,
Pablo Greco 40546a
+                     uint32_t signature)
Pablo Greco 40546a
+{
Pablo Greco 40546a
+    size_t i;
Pablo Greco 40546a
+
Pablo Greco 40546a
+    for (i = 0; i < model->nsignatures; i++) {
Pablo Greco 40546a
+        if (model->signatures[i] == signature)
Pablo Greco 40546a
+            return true;
Pablo Greco 40546a
+    }
Pablo Greco 40546a
+
Pablo Greco 40546a
+    return false;
Pablo Greco 40546a
+}
Pablo Greco 40546a
+
Pablo Greco 40546a
+
Pablo Greco 40546a
 /*
Pablo Greco 40546a
  * Checks whether a candidate model is a better fit for the CPU data than the
Pablo Greco 40546a
  * current model.
Pablo Greco 40546a
@@ -1768,8 +1799,8 @@ x86DecodeUseCandidate(virCPUx86ModelPtr current,
Pablo Greco 40546a
      * consider candidates with matching family/model.
Pablo Greco 40546a
      */
Pablo Greco 40546a
     if (signature &&
Pablo Greco 40546a
-        current->signature == signature &&
Pablo Greco 40546a
-        candidate->signature != signature) {
Pablo Greco 40546a
+        x86ModelHasSignature(current, signature) &&
Pablo Greco 40546a
+        !x86ModelHasSignature(candidate, signature)) {
Pablo Greco 40546a
         VIR_DEBUG("%s differs in signature from matching %s",
Pablo Greco 40546a
                   cpuCandidate->model, cpuCurrent->model);
Pablo Greco 40546a
         return 0;
Pablo Greco 40546a
@@ -1785,8 +1816,8 @@ x86DecodeUseCandidate(virCPUx86ModelPtr current,
Pablo Greco 40546a
      * result in longer list of features.
Pablo Greco 40546a
      */
Pablo Greco 40546a
     if (signature &&
Pablo Greco 40546a
-        candidate->signature == signature &&
Pablo Greco 40546a
-        current->signature != signature) {
Pablo Greco 40546a
+        x86ModelHasSignature(candidate, signature) &&
Pablo Greco 40546a
+        !x86ModelHasSignature(current, signature)) {
Pablo Greco 40546a
         VIR_DEBUG("%s provides matching signature", cpuCandidate->model);
Pablo Greco 40546a
         return 1;
Pablo Greco 40546a
     }
Pablo Greco 40546a
@@ -2854,7 +2885,8 @@ virCPUx86Translate(virCPUDefPtr cpu,
Pablo Greco 40546a
         virCPUx86DataAddCPUIDInt(&model->data, &model->vendor->cpuid) < 0)
Pablo Greco 40546a
         goto cleanup;
Pablo Greco 40546a
 
Pablo Greco 40546a
-    if (x86DataAddSignature(&model->data, model->signature) < 0)
Pablo Greco 40546a
+    if (model->signatures &&
Pablo Greco 40546a
+        x86DataAddSignature(&model->data, model->signatures[0]) < 0)
Pablo Greco 40546a
         goto cleanup;
Pablo Greco 40546a
 
Pablo Greco 40546a
     if (!(translated = virCPUDefCopyWithoutModel(cpu)))
Pablo Greco 40546a
-- 
Pablo Greco 40546a
2.22.0
Pablo Greco 40546a