render / rpms / libvirt

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