提交 277bc0dc 编写于 作者: J Jiri Denemark

cpu: Update guest CPU in host-* mode

VIR_DOMAIN_XML_UPDATE_CPU flag for virDomainGetXMLDesc may be used to
get updated custom mode guest CPU definition in case it depends on host
CPU. This patch implements the same behavior for host-model and
host-passthrough CPU modes.
上级 f7dd3a4e
master openEuler-20.03-LTS openEuler-20.09 v0.10.2-maint v0.9.11-maint v0.9.12-maint v1.0.0-maint v1.0.1-maint v1.0.2-maint v1.0.3-maint v1.0.4-maint v1.0.5-maint v1.0.6-maint v1.1.0-maint v1.1.1-maint v1.1.2-maint v1.1.3-maint v1.1.4-maint v1.2.0-maint v1.2.1-maint v1.2.10-maint v1.2.11-maint v1.2.12-maint v1.2.13-maint v1.2.14-maint v1.2.15-maint v1.2.16-maint v1.2.17-maint v1.2.18-maint v1.2.19-maint v1.2.2-maint v1.2.20-maint v1.2.21-maint v1.2.3-maint v1.2.4-maint v1.2.5-maint v1.2.6-maint v1.2.7-maint v1.2.8-maint v1.2.9-maint v1.3.0-maint v1.3.1-maint v1.3.2-maint v1.3.3-maint v1.3.4-maint v1.3.5-maint v2.0-maint v2.1-maint v2.2-maint v3.0-maint v3.2-maint v3.7-maint v4.1-maint v4.10-maint v4.2-maint v4.3-maint v4.4-maint v4.5-maint v4.6-maint v4.7-maint v4.8-maint v4.9-maint v5.0-maint v5.1-maint v5.1.0-maint v5.2-maint v5.3-maint v6.5.0-rc2 v6.5.0-rc1 v6.4.0 v6.4.0-rc1 v6.3.0 v6.3.0-rc1 v6.2.0 v6.2.0-rc1 v6.1.0 v6.1.0-rc2 v6.1.0-rc1 v6.0.0 v6.0.0-rc2 v6.0.0-rc1 v5.10.0 v5.10.0-rc2 v5.10.0-rc1 v5.9.0 v5.9.0-rc1 v5.8.0 v5.8.0-rc2 v5.8.0-rc1 v5.7.0 v5.7.0-rc2 v5.7.0-rc1 v5.6.0 v5.6.0-rc2 v5.6.0-rc1 v5.5.0 v5.5.0-rc2 v5.5.0-rc1 v5.4.0 v5.4.0-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v1.1.0-rc1 v1.0.6 v1.0.6-rc2 v1.0.6-rc1 v1.0.5.9 v1.0.5.8 v1.0.5.7 v1.0.5.6 v1.0.5.5 v1.0.5.4 v1.0.5.3 v1.0.5.2 v1.0.5.1 v1.0.5 v1.0.5-rc1 v1.0.4 v1.0.4-rc2 v1.0.4-rc1 v1.0.3 v1.0.3-rc2 v1.0.3-rc1 v1.0.2 v1.0.2-rc2 v1.0.2-rc1 v1.0.1 v1.0.1-rc2 v1.0.1-rc1 v1.0.0 v1.0.0-rc3 v1.0.0-rc2 v1.0.0-rc1 v0.10.2.8 v0.10.2.7 v0.10.2.6 v0.10.2.5 v0.10.2.4 v0.10.2.3 v0.10.2.2 v0.10.2.1 v0.10.2 v0.10.2-rc2 v0.10.2-rc1 v0.10.1 v0.10.0 v0.10.0-rc2 v0.10.0-rc1 v0.10.0-rc0 v0.9.13 v0.9.13-rc2 v0.9.13-rc1 v0.9.12.3 v0.9.12.2 v0.9.12.1 v0.9.12 v0.9.12-rc2 v0.9.12-rc1 v0.9.11.10 v0.9.11.9 v0.9.11.8 v0.9.11.7 v0.9.11.6 v0.9.11.5 v0.9.11.4 v0.9.11.3 v0.9.11.2 v0.9.11.1 v0.9.11 v0.9.11-rc2 v0.9.11-rc1 v0.9.10 v0.9.10-rc2 v0.9.10-rc1 CVE-2017-1000256 CVE-2017-2635 CVE-2016-5008 CVE-2015-5313 CVE-2015-5247-3 CVE-2015-5247-2 CVE-2015-5247-1 CVE-2015-0236-2 CVE-2015-0236-1 CVE-2014-8136 CVE-2014-8135 CVE-2014-8131-2 CVE-2014-8131-1 CVE-2014-7823 CVE-2014-3657 CVE-2014-3633 CVE-2014-1447-2 CVE-2014-1447-1 CVE-2014-0179 CVE-2014-0028 CVE-2013-7336 CVE-2013-6458-4 CVE-2013-6458-3 CVE-2013-6458-2 CVE-2013-6458-1 CVE-2013-6457 CVE-2013-6436 CVE-2013-5651 CVE-2013-4401 CVE-2013-4400-3 CVE-2013-4400-2 CVE-2013-4400-1 CVE-2013-4399 CVE-2013-4311 CVE-2013-4297 CVE-2013-4296 CVE-2013-4292 CVE-2013-4291 CVE-2013-4239 CVE-2013-4154 CVE-2013-4153 CVE-2013-2230 CVE-2013-2218 CVE-2013-1962 CVE-2013-0170 CVE-2012-4423 CVE-2012-3445 CVE-2012-3411
无相关合并请求
......@@ -61,6 +61,19 @@ VIR_ENUM_IMPL(virCPUFeaturePolicy, VIR_CPU_FEATURE_LAST,
"forbid")
void ATTRIBUTE_NONNULL(1)
virCPUDefFreeModel(virCPUDefPtr def)
{
unsigned int i;
VIR_FREE(def->model);
VIR_FREE(def->vendor);
for (i = 0; i < def->nfeatures; i++)
VIR_FREE(def->features[i].name);
VIR_FREE(def->features);
}
void
virCPUDefFree(virCPUDefPtr def)
{
......@@ -69,13 +82,8 @@ virCPUDefFree(virCPUDefPtr def)
if (!def)
return;
VIR_FREE(def->model);
VIR_FREE(def->arch);
VIR_FREE(def->vendor);
for (i = 0 ; i < def->nfeatures ; i++)
VIR_FREE(def->features[i].name);
VIR_FREE(def->features);
virCPUDefFreeModel(def);
for (i = 0 ; i < def->ncells ; i++) {
VIR_FREE(def->cells[i].cpumask);
......@@ -87,6 +95,42 @@ virCPUDefFree(virCPUDefPtr def)
}
int ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2)
virCPUDefCopyModel(virCPUDefPtr dst,
const virCPUDefPtr src,
bool resetPolicy)
{
unsigned int i;
if ((src->model && !(dst->model = strdup(src->model)))
|| (src->vendor && !(dst->vendor = strdup(src->vendor)))
|| VIR_ALLOC_N(dst->features, src->nfeatures) < 0)
goto no_memory;
dst->nfeatures_max = dst->nfeatures = src->nfeatures;
for (i = 0; i < dst->nfeatures; i++) {
if (dst->type != src->type && resetPolicy) {
if (dst->type == VIR_CPU_TYPE_HOST)
dst->features[i].policy = -1;
else if (src->features[i].policy == -1)
dst->features[i].policy = VIR_CPU_FEATURE_REQUIRE;
else
dst->features[i].policy = src->features[i].policy;
} else {
dst->features[i].policy = src->features[i].policy;
}
if (!(dst->features[i].name = strdup(src->features[i].name)))
goto no_memory;
}
return 0;
no_memory:
virReportOOMError();
return -1;
}
virCPUDefPtr
virCPUDefCopy(const virCPUDefPtr cpu)
{
......@@ -96,13 +140,8 @@ virCPUDefCopy(const virCPUDefPtr cpu)
if (!cpu)
return NULL;
if (VIR_ALLOC(copy) < 0
|| (cpu->arch && !(copy->arch = strdup(cpu->arch)))
|| (cpu->model && !(copy->model = strdup(cpu->model)))
|| (cpu->vendor && !(copy->vendor = strdup(cpu->vendor)))
|| VIR_ALLOC_N(copy->features, cpu->nfeatures) < 0)
if (VIR_ALLOC(copy) < 0)
goto no_memory;
copy->nfeatures_max = cpu->nfeatures;
copy->type = cpu->type;
copy->mode = cpu->mode;
......@@ -111,13 +150,12 @@ virCPUDefCopy(const virCPUDefPtr cpu)
copy->sockets = cpu->sockets;
copy->cores = cpu->cores;
copy->threads = cpu->threads;
copy->nfeatures = cpu->nfeatures;
for (i = 0; i < copy->nfeatures; i++) {
copy->features[i].policy = cpu->features[i].policy;
if (!(copy->features[i].name = strdup(cpu->features[i].name)))
goto no_memory;
}
if (cpu->arch && !(copy->arch = strdup(cpu->arch)))
goto no_memory;
if (virCPUDefCopyModel(copy, cpu, false) < 0)
goto error;
if (cpu->ncells) {
if (VIR_ALLOC_N(copy->cells, cpu->ncells) < 0)
......@@ -144,6 +182,7 @@ virCPUDefCopy(const virCPUDefPtr cpu)
no_memory:
virReportOOMError();
error:
virCPUDefFree(copy);
return NULL;
}
......
......@@ -118,9 +118,17 @@ struct _virCPUDef {
};
void ATTRIBUTE_NONNULL(1)
virCPUDefFreeModel(virCPUDefPtr def);
void
virCPUDefFree(virCPUDefPtr def);
int ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2)
virCPUDefCopyModel(virCPUDefPtr dst,
const virCPUDefPtr src,
bool resetPolicy);
virCPUDefPtr
virCPUDefCopy(const virCPUDefPtr cpu);
......
......@@ -1686,8 +1686,8 @@ error:
static int
x86Update(virCPUDefPtr guest,
const virCPUDefPtr host)
x86UpdateCustom(virCPUDefPtr guest,
const virCPUDefPtr host)
{
int ret = -1;
unsigned int i;
......@@ -1731,6 +1731,32 @@ cleanup:
return ret;
}
static int
x86Update(virCPUDefPtr guest,
const virCPUDefPtr host)
{
switch ((enum virCPUMode) guest->mode) {
case VIR_CPU_MODE_CUSTOM:
return x86UpdateCustom(guest, host);
case VIR_CPU_MODE_HOST_MODEL:
case VIR_CPU_MODE_HOST_PASSTHROUGH:
if (guest->mode == VIR_CPU_MODE_HOST_MODEL)
guest->match = VIR_CPU_MATCH_EXACT;
else
guest->match = VIR_CPU_MATCH_MINIMUM;
virCPUDefFreeModel(guest);
return virCPUDefCopyModel(guest, host, true);
case VIR_CPU_MODE_LAST:
break;
}
virCPUReportError(VIR_ERR_INTERNAL_ERROR,
_("Unexpected CPU mode: %d"), guest->mode);
return -1;
}
static int x86HasFeature(const union cpuData *data,
const char *name)
{
......
......@@ -181,9 +181,11 @@ cpuUpdate;
# cpu_conf.h
virCPUDefAddFeature;
virCPUDefCopy;
virCPUDefCopyModel;
virCPUDefFormat;
virCPUDefFormatBuf;
virCPUDefFree;
virCPUDefFreeModel;
virCPUDefParseXML;
......
......@@ -1050,20 +1050,20 @@ char *qemuDomainDefFormatXML(struct qemud_driver *driver,
{
char *ret = NULL;
virCPUDefPtr cpu = NULL;
virCPUDefPtr def_cpu;
def_cpu = def->cpu;
virCPUDefPtr def_cpu = def->cpu;
/* Update guest CPU requirements according to host CPU */
if ((flags & VIR_DOMAIN_XML_UPDATE_CPU) && def_cpu && def_cpu->model) {
if ((flags & VIR_DOMAIN_XML_UPDATE_CPU) &&
def_cpu &&
(def_cpu->mode != VIR_CPU_MODE_CUSTOM || def_cpu->model)) {
if (!driver->caps || !driver->caps->host.cpu) {
qemuReportError(VIR_ERR_OPERATION_FAILED,
"%s", _("cannot get host CPU capabilities"));
goto cleanup;
}
if (!(cpu = virCPUDefCopy(def_cpu))
|| cpuUpdate(cpu, driver->caps->host.cpu))
if (!(cpu = virCPUDefCopy(def_cpu)) ||
cpuUpdate(cpu, driver->caps->host.cpu) < 0)
goto cleanup;
def->cpu = cpu;
}
......
......@@ -162,7 +162,8 @@ error:
static int
cpuTestCompareXML(const char *arch,
const virCPUDefPtr cpu,
const char *name)
const char *name,
unsigned int flags)
{
char *xml = NULL;
char *expected = NULL;
......@@ -176,7 +177,7 @@ cpuTestCompareXML(const char *arch,
if (virtTestLoadFile(xml, &expected) < 0)
goto cleanup;
if (!(actual = virCPUDefFormat(cpu, 0)))
if (!(actual = virCPUDefFormat(cpu, flags)))
goto cleanup;
if (STRNEQ(expected, actual)) {
......@@ -310,7 +311,7 @@ cpuTestGuestData(const void *arg)
}
result = virBufferContentAndReset(&buf);
ret = cpuTestCompareXML(data->arch, guest, result);
ret = cpuTestCompareXML(data->arch, guest, result, 0);
cleanup:
VIR_FREE(result);
......@@ -354,7 +355,7 @@ cpuTestBaseline(const void *arg)
if (virAsprintf(&result, "%s-result", data->name) < 0)
goto cleanup;
if (cpuTestCompareXML(data->arch, baseline, result) < 0)
if (cpuTestCompareXML(data->arch, baseline, result, 0) < 0)
goto cleanup;
for (i = 0; i < ncpus; i++) {
......@@ -406,7 +407,8 @@ cpuTestUpdate(const void *arg)
if (virAsprintf(&result, "%s+%s", data->host, data->name) < 0)
goto cleanup;
ret = cpuTestCompareXML(data->arch, cpu, result);
ret = cpuTestCompareXML(data->arch, cpu, result,
VIR_DOMAIN_XML_UPDATE_CPU);
cleanup:
virCPUDefFree(host);
......@@ -592,6 +594,9 @@ mymain(void)
DO_TEST_UPDATE("x86", "host", "min", IDENTICAL);
DO_TEST_UPDATE("x86", "host", "pentium3", IDENTICAL);
DO_TEST_UPDATE("x86", "host", "guest", SUPERSET);
DO_TEST_UPDATE("x86", "host", "host-model", IDENTICAL);
DO_TEST_UPDATE("x86", "host", "host-model-nofallback", IDENTICAL);
DO_TEST_UPDATE("x86", "host", "host-passthrough", IDENTICAL);
/* computing baseline CPUs */
DO_TEST_BASELINE("x86", "incompatible-vendors", -1);
......@@ -622,6 +627,9 @@ mymain(void)
DO_TEST_GUESTDATA("x86", "host", "guest", models, "qemu64", 0);
DO_TEST_GUESTDATA("x86", "host", "guest", nomodel, NULL, -1);
DO_TEST_GUESTDATA("x86", "host", "guest-nofallback", models, "Penryn", -1);
DO_TEST_GUESTDATA("x86", "host", "host+host-model", models, "Penryn", 0);
DO_TEST_GUESTDATA("x86", "host", "host+host-model-nofallback",
models, "Penryn", -1);
free(map);
return (ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE);
......
<cpu mode='custom' match='exact'>
<arch>x86_64</arch>
<model fallback='allow'>core2duo</model>
<feature policy='require' name='lahf_lm'/>
<feature policy='require' name='sse4.1'/>
<feature policy='require' name='dca'/>
<feature policy='require' name='xtpr'/>
<feature policy='require' name='cx16'/>
<feature policy='require' name='tm2'/>
<feature policy='require' name='est'/>
<feature policy='require' name='vmx'/>
<feature policy='require' name='ds_cpl'/>
<feature policy='require' name='pbe'/>
<feature policy='require' name='tm'/>
<feature policy='require' name='ht'/>
<feature policy='require' name='ss'/>
<feature policy='require' name='acpi'/>
<feature policy='require' name='ds'/>
</cpu>
<cpu mode='host-model' match='exact'>
<model fallback='forbid'>Penryn</model>
<vendor>Intel</vendor>
<topology sockets='1' cores='2' threads='1'/>
<feature policy='require' name='dca'/>
<feature policy='require' name='xtpr'/>
<feature policy='require' name='tm2'/>
<feature policy='require' name='est'/>
<feature policy='require' name='vmx'/>
<feature policy='require' name='ds_cpl'/>
<feature policy='require' name='monitor'/>
<feature policy='require' name='pbe'/>
<feature policy='require' name='tm'/>
<feature policy='require' name='ht'/>
<feature policy='require' name='ss'/>
<feature policy='require' name='acpi'/>
<feature policy='require' name='ds'/>
<feature policy='require' name='vme'/>
</cpu>
<cpu mode='host-model' match='exact'>
<model fallback='allow'>Penryn</model>
<vendor>Intel</vendor>
<feature policy='require' name='dca'/>
<feature policy='require' name='xtpr'/>
<feature policy='require' name='tm2'/>
<feature policy='require' name='est'/>
<feature policy='require' name='vmx'/>
<feature policy='require' name='ds_cpl'/>
<feature policy='require' name='monitor'/>
<feature policy='require' name='pbe'/>
<feature policy='require' name='tm'/>
<feature policy='require' name='ht'/>
<feature policy='require' name='ss'/>
<feature policy='require' name='acpi'/>
<feature policy='require' name='ds'/>
<feature policy='require' name='vme'/>
</cpu>
<cpu mode='host-passthrough' match='minimum'>
<model>Penryn</model>
<vendor>Intel</vendor>
<feature policy='require' name='dca'/>
<feature policy='require' name='xtpr'/>
<feature policy='require' name='tm2'/>
<feature policy='require' name='est'/>
<feature policy='require' name='vmx'/>
<feature policy='require' name='ds_cpl'/>
<feature policy='require' name='monitor'/>
<feature policy='require' name='pbe'/>
<feature policy='require' name='tm'/>
<feature policy='require' name='ht'/>
<feature policy='require' name='ss'/>
<feature policy='require' name='acpi'/>
<feature policy='require' name='ds'/>
<feature policy='require' name='vme'/>
</cpu>
<cpu mode='host-model'>
<model fallback='forbid'/>
<topology sockets='1' cores='2' threads='1'/>
</cpu>
<cpu mode='host-model'/>
<cpu mode='host-passthrough'/>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册