|
|
fbe740 |
From 22fecd96659495908f37e1c33c1ed52be5fb2d44 Mon Sep 17 00:00:00 2001
|
|
|
fbe740 |
Message-Id: <22fecd96659495908f37e1c33c1ed52be5fb2d44@dist-git>
|
|
|
fbe740 |
From: Jiri Denemark <jdenemar@redhat.com>
|
|
|
fbe740 |
Date: Tue, 26 May 2020 10:59:32 +0200
|
|
|
fbe740 |
Subject: [PATCH] cpu_x86: Replace 32b signatures in virCPUx86Model with a
|
|
|
fbe740 |
struct
|
|
|
fbe740 |
MIME-Version: 1.0
|
|
|
fbe740 |
Content-Type: text/plain; charset=UTF-8
|
|
|
fbe740 |
Content-Transfer-Encoding: 8bit
|
|
|
fbe740 |
|
|
|
fbe740 |
The CPU models in our cpu_map define their signatures using separate
|
|
|
fbe740 |
family and model numbers. Let's store the signatures in the same way in
|
|
|
fbe740 |
our runtime representation of the cpu_map.
|
|
|
fbe740 |
|
|
|
fbe740 |
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
|
|
|
fbe740 |
Reviewed-by: Ján Tomko <jtomko@redhat.com>
|
|
|
fbe740 |
(cherry picked from commit 22bded201ffc91661e44065203dcb987e51084ca)
|
|
|
fbe740 |
|
|
|
fbe740 |
https://bugzilla.redhat.com/show_bug.cgi?id=1840010
|
|
|
fbe740 |
|
|
|
fbe740 |
Conflicts:
|
|
|
fbe740 |
src/cpu/cpu_x86.c
|
|
|
fbe740 |
- v6.0.0-264-g0a125c7144 which removes the third argument
|
|
|
fbe740 |
from virBufferTrim was not backported
|
|
|
fbe740 |
|
|
|
fbe740 |
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
|
|
|
fbe740 |
Message-Id: <21c1eee9c7bb3811f43aa044bb97fa373a159e26.1590483392.git.jdenemar@redhat.com>
|
|
|
fbe740 |
Reviewed-by: Ján Tomko <jtomko@redhat.com>
|
|
|
fbe740 |
---
|
|
|
fbe740 |
src/cpu/cpu_x86.c | 149 +++++++++++++++++++++++++++++-----------------
|
|
|
fbe740 |
1 file changed, 95 insertions(+), 54 deletions(-)
|
|
|
fbe740 |
|
|
|
fbe740 |
diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c
|
|
|
fbe740 |
index dad3bceff0..b87e3753da 100644
|
|
|
fbe740 |
--- a/src/cpu/cpu_x86.c
|
|
|
fbe740 |
+++ b/src/cpu/cpu_x86.c
|
|
|
fbe740 |
@@ -121,6 +121,19 @@ static virCPUx86Feature x86_kvm_features[] =
|
|
|
fbe740 |
KVM_FEATURE(VIR_CPU_x86_HV_STIMER_DIRECT),
|
|
|
fbe740 |
};
|
|
|
fbe740 |
|
|
|
fbe740 |
+typedef struct _virCPUx86Signature virCPUx86Signature;
|
|
|
fbe740 |
+struct _virCPUx86Signature {
|
|
|
fbe740 |
+ unsigned int family;
|
|
|
fbe740 |
+ unsigned int model;
|
|
|
fbe740 |
+};
|
|
|
fbe740 |
+
|
|
|
fbe740 |
+typedef struct _virCPUx86Signatures virCPUx86Signatures;
|
|
|
fbe740 |
+typedef virCPUx86Signatures *virCPUx86SignaturesPtr;
|
|
|
fbe740 |
+struct _virCPUx86Signatures {
|
|
|
fbe740 |
+ size_t count;
|
|
|
fbe740 |
+ virCPUx86Signature *items;
|
|
|
fbe740 |
+};
|
|
|
fbe740 |
+
|
|
|
fbe740 |
typedef struct _virCPUx86Model virCPUx86Model;
|
|
|
fbe740 |
typedef virCPUx86Model *virCPUx86ModelPtr;
|
|
|
fbe740 |
struct _virCPUx86Model {
|
|
|
fbe740 |
@@ -128,8 +141,7 @@ struct _virCPUx86Model {
|
|
|
fbe740 |
bool decodeHost;
|
|
|
fbe740 |
bool decodeGuest;
|
|
|
fbe740 |
virCPUx86VendorPtr vendor;
|
|
|
fbe740 |
- size_t nsignatures;
|
|
|
fbe740 |
- uint32_t *signatures;
|
|
|
fbe740 |
+ virCPUx86SignaturesPtr signatures;
|
|
|
fbe740 |
virCPUx86Data data;
|
|
|
fbe740 |
};
|
|
|
fbe740 |
|
|
|
fbe740 |
@@ -717,6 +729,13 @@ x86MakeSignature(unsigned int family,
|
|
|
fbe740 |
}
|
|
|
fbe740 |
|
|
|
fbe740 |
|
|
|
fbe740 |
+static uint32_t
|
|
|
fbe740 |
+virCPUx86SignatureToCPUID(virCPUx86Signature *sig)
|
|
|
fbe740 |
+{
|
|
|
fbe740 |
+ return x86MakeSignature(sig->family, sig->model, 0);
|
|
|
fbe740 |
+}
|
|
|
fbe740 |
+
|
|
|
fbe740 |
+
|
|
|
fbe740 |
static void
|
|
|
fbe740 |
virCPUx86SignatureFromCPUID(uint32_t sig,
|
|
|
fbe740 |
unsigned int *family,
|
|
|
fbe740 |
@@ -1099,41 +1118,65 @@ x86FeatureParse(xmlXPathContextPtr ctxt,
|
|
|
fbe740 |
}
|
|
|
fbe740 |
|
|
|
fbe740 |
|
|
|
fbe740 |
+static virCPUx86SignaturesPtr
|
|
|
fbe740 |
+virCPUx86SignaturesNew(size_t count)
|
|
|
fbe740 |
+{
|
|
|
fbe740 |
+ virCPUx86SignaturesPtr sigs;
|
|
|
fbe740 |
+
|
|
|
fbe740 |
+ sigs = g_new0(virCPUx86Signatures, 1);
|
|
|
fbe740 |
+ sigs->items = g_new0(virCPUx86Signature, count);
|
|
|
fbe740 |
+ sigs->count = count;
|
|
|
fbe740 |
+
|
|
|
fbe740 |
+ return sigs;
|
|
|
fbe740 |
+}
|
|
|
fbe740 |
+
|
|
|
fbe740 |
+
|
|
|
fbe740 |
static void
|
|
|
fbe740 |
-virCPUx86SignaturesFree(uint32_t *signatures)
|
|
|
fbe740 |
+virCPUx86SignaturesFree(virCPUx86SignaturesPtr sigs)
|
|
|
fbe740 |
{
|
|
|
fbe740 |
- g_free(signatures);
|
|
|
fbe740 |
+ if (!sigs)
|
|
|
fbe740 |
+ return;
|
|
|
fbe740 |
+
|
|
|
fbe740 |
+ g_free(sigs->items);
|
|
|
fbe740 |
+ g_free(sigs);
|
|
|
fbe740 |
}
|
|
|
fbe740 |
|
|
|
fbe740 |
|
|
|
fbe740 |
-static int
|
|
|
fbe740 |
-virCPUx86SignaturesCopy(virCPUx86ModelPtr dst,
|
|
|
fbe740 |
- virCPUx86ModelPtr src)
|
|
|
fbe740 |
+static virCPUx86SignaturesPtr
|
|
|
fbe740 |
+virCPUx86SignaturesCopy(virCPUx86SignaturesPtr src)
|
|
|
fbe740 |
{
|
|
|
fbe740 |
+ virCPUx86SignaturesPtr dst;
|
|
|
fbe740 |
size_t i;
|
|
|
fbe740 |
|
|
|
fbe740 |
- if (src->nsignatures == 0)
|
|
|
fbe740 |
- return 0;
|
|
|
fbe740 |
+ if (!src || src->count == 0)
|
|
|
fbe740 |
+ return NULL;
|
|
|
fbe740 |
|
|
|
fbe740 |
- if (VIR_ALLOC_N(dst->signatures, src->nsignatures) < 0)
|
|
|
fbe740 |
- return -1;
|
|
|
fbe740 |
+ dst = virCPUx86SignaturesNew(src->count);
|
|
|
fbe740 |
|
|
|
fbe740 |
- dst->nsignatures = src->nsignatures;
|
|
|
fbe740 |
- for (i = 0; i < src->nsignatures; i++)
|
|
|
fbe740 |
- dst->signatures[i] = src->signatures[i];
|
|
|
fbe740 |
+ for (i = 0; i < src->count; i++)
|
|
|
fbe740 |
+ dst->items[i] = src->items[i];
|
|
|
fbe740 |
|
|
|
fbe740 |
- return 0;
|
|
|
fbe740 |
+ return dst;
|
|
|
fbe740 |
}
|
|
|
fbe740 |
|
|
|
fbe740 |
|
|
|
fbe740 |
static bool
|
|
|
fbe740 |
-virCPUx86SignaturesMatch(virCPUx86ModelPtr model,
|
|
|
fbe740 |
+virCPUx86SignaturesMatch(virCPUx86SignaturesPtr sigs,
|
|
|
fbe740 |
uint32_t signature)
|
|
|
fbe740 |
{
|
|
|
fbe740 |
size_t i;
|
|
|
fbe740 |
+ unsigned int family;
|
|
|
fbe740 |
+ unsigned int model;
|
|
|
fbe740 |
+ unsigned int stepping;
|
|
|
fbe740 |
|
|
|
fbe740 |
- for (i = 0; i < model->nsignatures; i++) {
|
|
|
fbe740 |
- if (model->signatures[i] == signature)
|
|
|
fbe740 |
+ if (!sigs)
|
|
|
fbe740 |
+ return false;
|
|
|
fbe740 |
+
|
|
|
fbe740 |
+ virCPUx86SignatureFromCPUID(signature, &family, &model, &stepping);
|
|
|
fbe740 |
+
|
|
|
fbe740 |
+ for (i = 0; i < sigs->count; i++) {
|
|
|
fbe740 |
+ if (sigs->items[i].family == family &&
|
|
|
fbe740 |
+ sigs->items[i].model == model)
|
|
|
fbe740 |
return true;
|
|
|
fbe740 |
}
|
|
|
fbe740 |
|
|
|
fbe740 |
@@ -1142,17 +1185,21 @@ virCPUx86SignaturesMatch(virCPUx86ModelPtr model,
|
|
|
fbe740 |
|
|
|
fbe740 |
|
|
|
fbe740 |
static char *
|
|
|
fbe740 |
-virCPUx86SignaturesFormat(virCPUx86ModelPtr model)
|
|
|
fbe740 |
+virCPUx86SignaturesFormat(virCPUx86SignaturesPtr sigs)
|
|
|
fbe740 |
{
|
|
|
fbe740 |
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
|
|
fbe740 |
size_t i;
|
|
|
fbe740 |
|
|
|
fbe740 |
- for (i = 0; i < model->nsignatures; i++) {
|
|
|
fbe740 |
- virBufferAsprintf(&buf, "%06lx,",
|
|
|
fbe740 |
- (unsigned long)model->signatures[i]);
|
|
|
fbe740 |
+ if (!sigs)
|
|
|
fbe740 |
+ return virBufferContentAndReset(&buf;;
|
|
|
fbe740 |
+
|
|
|
fbe740 |
+ for (i = 0; i < sigs->count; i++) {
|
|
|
fbe740 |
+ virBufferAsprintf(&buf, "(%u,%u,0), ",
|
|
|
fbe740 |
+ sigs->items[i].family,
|
|
|
fbe740 |
+ sigs->items[i].model);
|
|
|
fbe740 |
}
|
|
|
fbe740 |
|
|
|
fbe740 |
- virBufferTrim(&buf, ",", -1);
|
|
|
fbe740 |
+ virBufferTrim(&buf, ", ", -1);
|
|
|
fbe740 |
|
|
|
fbe740 |
return virBufferContentAndReset(&buf;;
|
|
|
fbe740 |
}
|
|
|
fbe740 |
@@ -1179,16 +1226,11 @@ x86ModelCopy(virCPUx86ModelPtr model)
|
|
|
fbe740 |
|
|
|
fbe740 |
copy = g_new0(virCPUx86Model, 1);
|
|
|
fbe740 |
copy->name = g_strdup(model->name);
|
|
|
fbe740 |
-
|
|
|
fbe740 |
- if (virCPUx86SignaturesCopy(copy, model) < 0) {
|
|
|
fbe740 |
- x86ModelFree(copy);
|
|
|
fbe740 |
- return NULL;
|
|
|
fbe740 |
- }
|
|
|
fbe740 |
+ copy->signatures = virCPUx86SignaturesCopy(model->signatures);
|
|
|
fbe740 |
x86DataCopy(©->data, &model->data);
|
|
|
fbe740 |
-
|
|
|
fbe740 |
copy->vendor = model->vendor;
|
|
|
fbe740 |
|
|
|
fbe740 |
- return copy;
|
|
|
fbe740 |
+ return g_steal_pointer(©);
|
|
|
fbe740 |
}
|
|
|
fbe740 |
|
|
|
fbe740 |
|
|
|
fbe740 |
@@ -1408,9 +1450,7 @@ x86ModelParseAncestor(virCPUx86ModelPtr model,
|
|
|
fbe740 |
}
|
|
|
fbe740 |
|
|
|
fbe740 |
model->vendor = ancestor->vendor;
|
|
|
fbe740 |
- if (virCPUx86SignaturesCopy(model, ancestor) < 0)
|
|
|
fbe740 |
- return -1;
|
|
|
fbe740 |
-
|
|
|
fbe740 |
+ model->signatures = virCPUx86SignaturesCopy(ancestor->signatures);
|
|
|
fbe740 |
x86DataCopy(&model->data, &ancestor->data);
|
|
|
fbe740 |
|
|
|
fbe740 |
return 0;
|
|
|
fbe740 |
@@ -1432,34 +1472,29 @@ x86ModelParseSignatures(virCPUx86ModelPtr model,
|
|
|
fbe740 |
/* Remove inherited signatures. */
|
|
|
fbe740 |
virCPUx86SignaturesFree(model->signatures);
|
|
|
fbe740 |
|
|
|
fbe740 |
- model->nsignatures = n;
|
|
|
fbe740 |
- if (VIR_ALLOC_N(model->signatures, n) < 0)
|
|
|
fbe740 |
- return -1;
|
|
|
fbe740 |
+ model->signatures = virCPUx86SignaturesNew(n);
|
|
|
fbe740 |
|
|
|
fbe740 |
for (i = 0; i < n; i++) {
|
|
|
fbe740 |
- unsigned int sigFamily = 0;
|
|
|
fbe740 |
- unsigned int sigModel = 0;
|
|
|
fbe740 |
+ virCPUx86Signature *sig = &model->signatures->items[i];
|
|
|
fbe740 |
int rc;
|
|
|
fbe740 |
|
|
|
fbe740 |
ctxt->node = nodes[i];
|
|
|
fbe740 |
|
|
|
fbe740 |
- rc = virXPathUInt("string(@family)", ctxt, &sigFamily);
|
|
|
fbe740 |
- if (rc < 0 || sigFamily == 0) {
|
|
|
fbe740 |
+ rc = virXPathUInt("string(@family)", ctxt, &sig->family);
|
|
|
fbe740 |
+ if (rc < 0 || sig->family == 0) {
|
|
|
fbe740 |
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
fbe740 |
_("Invalid CPU signature family in model %s"),
|
|
|
fbe740 |
model->name);
|
|
|
fbe740 |
return -1;
|
|
|
fbe740 |
}
|
|
|
fbe740 |
|
|
|
fbe740 |
- rc = virXPathUInt("string(@model)", ctxt, &sigModel);
|
|
|
fbe740 |
+ rc = virXPathUInt("string(@model)", ctxt, &sig->model);
|
|
|
fbe740 |
if (rc < 0) {
|
|
|
fbe740 |
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
fbe740 |
_("Invalid CPU signature model in model %s"),
|
|
|
fbe740 |
model->name);
|
|
|
fbe740 |
return -1;
|
|
|
fbe740 |
}
|
|
|
fbe740 |
-
|
|
|
fbe740 |
- model->signatures[i] = x86MakeSignature(sigFamily, sigModel, 0);
|
|
|
fbe740 |
}
|
|
|
fbe740 |
|
|
|
fbe740 |
ctxt->node = root;
|
|
|
fbe740 |
@@ -1865,9 +1900,12 @@ x86Compute(virCPUDefPtr host,
|
|
|
fbe740 |
&host_model->vendor->data) < 0)
|
|
|
fbe740 |
return VIR_CPU_COMPARE_ERROR;
|
|
|
fbe740 |
|
|
|
fbe740 |
- if (host_model->signatures &&
|
|
|
fbe740 |
- x86DataAddSignature(&guest_model->data, *host_model->signatures) < 0)
|
|
|
fbe740 |
- return VIR_CPU_COMPARE_ERROR;
|
|
|
fbe740 |
+ if (host_model->signatures && host_model->signatures->count > 0) {
|
|
|
fbe740 |
+ virCPUx86Signature *sig = &host_model->signatures->items[0];
|
|
|
fbe740 |
+ if (x86DataAddSignature(&guest_model->data,
|
|
|
fbe740 |
+ virCPUx86SignatureToCPUID(sig)) < 0)
|
|
|
fbe740 |
+ return VIR_CPU_COMPARE_ERROR;
|
|
|
fbe740 |
+ }
|
|
|
fbe740 |
|
|
|
fbe740 |
if (cpu->type == VIR_CPU_TYPE_GUEST
|
|
|
fbe740 |
&& cpu->match == VIR_CPU_MATCH_EXACT)
|
|
|
fbe740 |
@@ -1977,8 +2015,8 @@ x86DecodeUseCandidate(virCPUx86ModelPtr current,
|
|
|
fbe740 |
* consider candidates with matching family/model.
|
|
|
fbe740 |
*/
|
|
|
fbe740 |
if (signature &&
|
|
|
fbe740 |
- virCPUx86SignaturesMatch(current, signature) &&
|
|
|
fbe740 |
- !virCPUx86SignaturesMatch(candidate, signature)) {
|
|
|
fbe740 |
+ virCPUx86SignaturesMatch(current->signatures, signature) &&
|
|
|
fbe740 |
+ !virCPUx86SignaturesMatch(candidate->signatures, signature)) {
|
|
|
fbe740 |
VIR_DEBUG("%s differs in signature from matching %s",
|
|
|
fbe740 |
cpuCandidate->model, cpuCurrent->model);
|
|
|
fbe740 |
return 0;
|
|
|
fbe740 |
@@ -1994,8 +2032,8 @@ x86DecodeUseCandidate(virCPUx86ModelPtr current,
|
|
|
fbe740 |
* result in longer list of features.
|
|
|
fbe740 |
*/
|
|
|
fbe740 |
if (signature &&
|
|
|
fbe740 |
- virCPUx86SignaturesMatch(candidate, signature) &&
|
|
|
fbe740 |
- !virCPUx86SignaturesMatch(current, signature)) {
|
|
|
fbe740 |
+ virCPUx86SignaturesMatch(candidate->signatures, signature) &&
|
|
|
fbe740 |
+ !virCPUx86SignaturesMatch(current->signatures, signature)) {
|
|
|
fbe740 |
VIR_DEBUG("%s provides matching signature", cpuCandidate->model);
|
|
|
fbe740 |
return 1;
|
|
|
fbe740 |
}
|
|
|
fbe740 |
@@ -2150,7 +2188,7 @@ x86Decode(virCPUDefPtr cpu,
|
|
|
fbe740 |
if (vendor)
|
|
|
fbe740 |
cpu->vendor = g_strdup(vendor->name);
|
|
|
fbe740 |
|
|
|
fbe740 |
- sigs = virCPUx86SignaturesFormat(model);
|
|
|
fbe740 |
+ sigs = virCPUx86SignaturesFormat(model->signatures);
|
|
|
fbe740 |
|
|
|
fbe740 |
VIR_DEBUG("Using CPU model %s (signatures %s) for CPU with signature %06lx",
|
|
|
fbe740 |
model->name, NULLSTR(sigs), (unsigned long)signature);
|
|
|
fbe740 |
@@ -3046,9 +3084,12 @@ virCPUx86Translate(virCPUDefPtr cpu,
|
|
|
fbe740 |
virCPUx86DataAddItem(&model->data, &model->vendor->data) < 0)
|
|
|
fbe740 |
return -1;
|
|
|
fbe740 |
|
|
|
fbe740 |
- if (model->signatures &&
|
|
|
fbe740 |
- x86DataAddSignature(&model->data, model->signatures[0]) < 0)
|
|
|
fbe740 |
- return -1;
|
|
|
fbe740 |
+ if (model->signatures && model->signatures->count > 0) {
|
|
|
fbe740 |
+ virCPUx86Signature *sig = &model->signatures->items[0];
|
|
|
fbe740 |
+ if (x86DataAddSignature(&model->data,
|
|
|
fbe740 |
+ virCPUx86SignatureToCPUID(sig)) < 0)
|
|
|
fbe740 |
+ return -1;
|
|
|
fbe740 |
+ }
|
|
|
fbe740 |
|
|
|
fbe740 |
if (!(translated = virCPUDefCopyWithoutModel(cpu)))
|
|
|
fbe740 |
return -1;
|
|
|
fbe740 |
--
|
|
|
fbe740 |
2.26.2
|
|
|
fbe740 |
|