render / rpms / libvirt

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