render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
99cbc7
From b4bc2a799e6e305dc0595a29aae68a39a5983dee Mon Sep 17 00:00:00 2001
99cbc7
Message-Id: <b4bc2a799e6e305dc0595a29aae68a39a5983dee@dist-git>
99cbc7
From: Jiri Denemark <jdenemar@redhat.com>
99cbc7
Date: Mon, 4 Mar 2019 16:36:33 +0100
99cbc7
Subject: [PATCH] cpu_x86: Store CPU signature in an array
99cbc7
MIME-Version: 1.0
99cbc7
Content-Type: text/plain; charset=UTF-8
99cbc7
Content-Transfer-Encoding: 8bit
99cbc7
99cbc7
In preparation for storing several CPU signatures in a single CPU model,
99cbc7
we need to turn virCPUx86Model's signature into an array of signatures.
99cbc7
99cbc7
The parser still hardcodes the number of signatures to 1, but the
99cbc7
following patch will drop this limit.
99cbc7
99cbc7
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
99cbc7
Reviewed-by: Ján Tomko <jtomko@redhat.com>
99cbc7
(cherry picked from commit b07b8b7750c6a505d4b00bd272e79ea0305cb610)
99cbc7
99cbc7
https://bugzilla.redhat.com/show_bug.cgi?id=1558558
99cbc7
https://bugzilla.redhat.com/show_bug.cgi?id=1687515
99cbc7
99cbc7
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
99cbc7
Reviewed-by: Ján Tomko <jtomko@redhat.com>
99cbc7
---
99cbc7
 src/cpu/cpu_x86.c | 50 ++++++++++++++++++++++++++++++++++++++---------
99cbc7
 1 file changed, 41 insertions(+), 9 deletions(-)
99cbc7
99cbc7
diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c
99cbc7
index e54a3986a1..543533148f 100644
99cbc7
--- a/src/cpu/cpu_x86.c
99cbc7
+++ b/src/cpu/cpu_x86.c
99cbc7
@@ -136,7 +136,8 @@ typedef virCPUx86Model *virCPUx86ModelPtr;
99cbc7
 struct _virCPUx86Model {
99cbc7
     char *name;
99cbc7
     virCPUx86VendorPtr vendor;
99cbc7
-    uint32_t signature;
99cbc7
+    size_t nsignatures;
99cbc7
+    uint32_t *signatures;
99cbc7
     virCPUx86Data data;
99cbc7
 };
99cbc7
 
99cbc7
@@ -1008,6 +1009,7 @@ x86ModelFree(virCPUx86ModelPtr model)
99cbc7
         return;
99cbc7
 
99cbc7
     VIR_FREE(model->name);
99cbc7
+    VIR_FREE(model->signatures);
99cbc7
     virCPUx86DataClear(&model->data);
99cbc7
     VIR_FREE(model);
99cbc7
 }
99cbc7
@@ -1017,7 +1019,14 @@ static int
99cbc7
 x86ModelCopySignatures(virCPUx86ModelPtr dst,
99cbc7
                        virCPUx86ModelPtr src)
99cbc7
 {
99cbc7
-    dst->signature = src->signature;
99cbc7
+    size_t i;
99cbc7
+
99cbc7
+    if (VIR_ALLOC_N(dst->signatures, src->nsignatures) < 0)
99cbc7
+        return -1;
99cbc7
+
99cbc7
+    dst->nsignatures = src->nsignatures;
99cbc7
+    for (i = 0; i < src->nsignatures; i++)
99cbc7
+        dst->signatures[i] = src->signatures[i];
99cbc7
 
99cbc7
     return 0;
99cbc7
 }
99cbc7
@@ -1198,12 +1207,18 @@ static int
99cbc7
 x86ModelParseSignature(virCPUx86ModelPtr model,
99cbc7
                        xmlXPathContextPtr ctxt)
99cbc7
 {
99cbc7
+    /* Remove inherited signatures. */
99cbc7
+    VIR_FREE(model->signatures);
99cbc7
 
99cbc7
     if (virXPathBoolean("boolean(./signature)", ctxt)) {
99cbc7
         unsigned int sigFamily = 0;
99cbc7
         unsigned int sigModel = 0;
99cbc7
         int rc;
99cbc7
 
99cbc7
+        model->nsignatures = 1;
99cbc7
+        if (VIR_ALLOC_N(model->signatures, 1) < 0)
99cbc7
+            return -1;
99cbc7
+
99cbc7
         rc = virXPathUInt("string(./signature/@family)", ctxt, &sigFamily);
99cbc7
         if (rc < 0 || sigFamily == 0) {
99cbc7
             virReportError(VIR_ERR_INTERNAL_ERROR,
99cbc7
@@ -1220,7 +1235,7 @@ x86ModelParseSignature(virCPUx86ModelPtr model,
99cbc7
             return -1;
99cbc7
         }
99cbc7
 
99cbc7
-        model->signature = x86MakeSignature(sigFamily, sigModel, 0);
99cbc7
+        model->signatures[0] = x86MakeSignature(sigFamily, sigModel, 0);
99cbc7
     }
99cbc7
 
99cbc7
     return 0;
99cbc7
@@ -1665,7 +1680,8 @@ x86Compute(virCPUDefPtr host,
99cbc7
                                      &host_model->vendor->cpuid) < 0)
99cbc7
             goto error;
99cbc7
 
99cbc7
-        if (x86DataAddSignature(&guest_model->data, host_model->signature) < 0)
99cbc7
+        if (host_model->signatures &&
99cbc7
+            x86DataAddSignature(&guest_model->data, *host_model->signatures) < 0)
99cbc7
             goto error;
99cbc7
 
99cbc7
         if (cpu->type == VIR_CPU_TYPE_GUEST
99cbc7
@@ -1771,6 +1787,21 @@ virCPUx86Compare(virCPUDefPtr host,
99cbc7
 }
99cbc7
 
99cbc7
 
99cbc7
+static bool
99cbc7
+x86ModelHasSignature(virCPUx86ModelPtr model,
99cbc7
+                     uint32_t signature)
99cbc7
+{
99cbc7
+    size_t i;
99cbc7
+
99cbc7
+    for (i = 0; i < model->nsignatures; i++) {
99cbc7
+        if (model->signatures[i] == signature)
99cbc7
+            return true;
99cbc7
+    }
99cbc7
+
99cbc7
+    return false;
99cbc7
+}
99cbc7
+
99cbc7
+
99cbc7
 /*
99cbc7
  * Checks whether a candidate model is a better fit for the CPU data than the
99cbc7
  * current model.
99cbc7
@@ -1812,8 +1843,8 @@ x86DecodeUseCandidate(virCPUx86ModelPtr current,
99cbc7
      * consider candidates with matching family/model.
99cbc7
      */
99cbc7
     if (signature &&
99cbc7
-        current->signature == signature &&
99cbc7
-        candidate->signature != signature) {
99cbc7
+        x86ModelHasSignature(current, signature) &&
99cbc7
+        !x86ModelHasSignature(candidate, signature)) {
99cbc7
         VIR_DEBUG("%s differs in signature from matching %s",
99cbc7
                   cpuCandidate->model, cpuCurrent->model);
99cbc7
         return 0;
99cbc7
@@ -1829,8 +1860,8 @@ x86DecodeUseCandidate(virCPUx86ModelPtr current,
99cbc7
      * result in longer list of features.
99cbc7
      */
99cbc7
     if (signature &&
99cbc7
-        candidate->signature == signature &&
99cbc7
-        current->signature != signature) {
99cbc7
+        x86ModelHasSignature(candidate, signature) &&
99cbc7
+        !x86ModelHasSignature(current, signature)) {
99cbc7
         VIR_DEBUG("%s provides matching signature", cpuCandidate->model);
99cbc7
         return 1;
99cbc7
     }
99cbc7
@@ -2898,7 +2929,8 @@ virCPUx86Translate(virCPUDefPtr cpu,
99cbc7
         virCPUx86DataAddCPUIDInt(&model->data, &model->vendor->cpuid) < 0)
99cbc7
         goto cleanup;
99cbc7
 
99cbc7
-    if (x86DataAddSignature(&model->data, model->signature) < 0)
99cbc7
+    if (model->signatures &&
99cbc7
+        x86DataAddSignature(&model->data, model->signatures[0]) < 0)
99cbc7
         goto cleanup;
99cbc7
 
99cbc7
     if (!(translated = virCPUDefCopyWithoutModel(cpu)))
99cbc7
-- 
99cbc7
2.21.0
99cbc7