2009-12-18 13:44:55 +00:00
|
|
|
/*
|
2013-07-15 09:12:18 +00:00
|
|
|
* cpu_conf.c: CPU XML handling
|
2009-12-18 13:44:55 +00:00
|
|
|
*
|
2015-01-05 16:03:58 +00:00
|
|
|
* Copyright (C) 2009-2015 Red Hat, Inc.
|
2009-12-18 13:44:55 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2012-09-20 22:30:55 +00:00
|
|
|
* License along with this library. If not, see
|
2012-07-21 10:06:23 +00:00
|
|
|
* <http://www.gnu.org/licenses/>.
|
2009-12-18 13:44:55 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2020-10-07 08:54:55 +00:00
|
|
|
#include "configmake.h"
|
2012-12-13 18:21:53 +00:00
|
|
|
#include "virerror.h"
|
2012-12-12 18:06:53 +00:00
|
|
|
#include "viralloc.h"
|
2012-12-04 12:04:07 +00:00
|
|
|
#include "virbuffer.h"
|
2020-10-07 08:54:55 +00:00
|
|
|
#include "virfile.h"
|
2009-12-18 13:44:55 +00:00
|
|
|
#include "cpu_conf.h"
|
2017-09-13 13:23:43 +00:00
|
|
|
#include "virlog.h"
|
2009-12-18 13:44:55 +00:00
|
|
|
|
|
|
|
#define VIR_FROM_THIS VIR_FROM_CPU
|
|
|
|
|
2017-09-13 13:23:43 +00:00
|
|
|
VIR_LOG_INIT("conf.cpu_conf");
|
|
|
|
|
2019-03-16 18:20:32 +00:00
|
|
|
VIR_ENUM_IMPL(virCPU,
|
|
|
|
VIR_CPU_TYPE_LAST,
|
2019-01-20 16:30:15 +00:00
|
|
|
"host", "guest", "auto",
|
|
|
|
);
|
2011-05-27 09:47:30 +00:00
|
|
|
|
2019-03-16 18:20:32 +00:00
|
|
|
VIR_ENUM_IMPL(virCPUMode,
|
|
|
|
VIR_CPU_MODE_LAST,
|
2011-08-18 10:14:36 +00:00
|
|
|
"custom",
|
|
|
|
"host-model",
|
2019-01-20 16:30:15 +00:00
|
|
|
"host-passthrough",
|
2021-02-05 15:51:09 +00:00
|
|
|
"maximum",
|
2019-01-20 16:30:15 +00:00
|
|
|
);
|
2011-08-18 10:14:36 +00:00
|
|
|
|
2019-03-16 18:20:32 +00:00
|
|
|
VIR_ENUM_IMPL(virCPUMatch,
|
|
|
|
VIR_CPU_MATCH_LAST,
|
2009-12-18 13:44:55 +00:00
|
|
|
"exact",
|
2019-11-12 14:26:23 +00:00
|
|
|
"minimum",
|
2019-01-20 16:30:15 +00:00
|
|
|
"strict",
|
|
|
|
);
|
2009-12-18 13:44:55 +00:00
|
|
|
|
2019-03-16 18:20:32 +00:00
|
|
|
VIR_ENUM_IMPL(virCPUCheck,
|
|
|
|
VIR_CPU_CHECK_LAST,
|
2017-03-01 14:18:22 +00:00
|
|
|
"default",
|
|
|
|
"none",
|
|
|
|
"partial",
|
2019-01-20 16:30:15 +00:00
|
|
|
"full",
|
|
|
|
);
|
2017-03-01 14:18:22 +00:00
|
|
|
|
2019-03-16 18:20:32 +00:00
|
|
|
VIR_ENUM_IMPL(virCPUFallback,
|
|
|
|
VIR_CPU_FALLBACK_LAST,
|
2011-12-21 13:27:16 +00:00
|
|
|
"allow",
|
2019-01-20 16:30:15 +00:00
|
|
|
"forbid",
|
|
|
|
);
|
2011-12-21 13:27:16 +00:00
|
|
|
|
2019-03-16 18:20:32 +00:00
|
|
|
VIR_ENUM_IMPL(virCPUFeaturePolicy,
|
|
|
|
VIR_CPU_FEATURE_LAST,
|
2009-12-18 13:44:55 +00:00
|
|
|
"force",
|
|
|
|
"require",
|
|
|
|
"optional",
|
|
|
|
"disable",
|
2019-01-20 16:30:15 +00:00
|
|
|
"forbid",
|
|
|
|
);
|
2009-12-18 13:44:55 +00:00
|
|
|
|
2019-03-16 18:20:32 +00:00
|
|
|
VIR_ENUM_IMPL(virCPUCacheMode,
|
|
|
|
VIR_CPU_CACHE_MODE_LAST,
|
2017-04-24 13:40:07 +00:00
|
|
|
"emulate",
|
|
|
|
"passthrough",
|
2019-01-20 16:30:15 +00:00
|
|
|
"disable",
|
|
|
|
);
|
2017-04-24 13:40:07 +00:00
|
|
|
|
2022-07-29 19:34:33 +00:00
|
|
|
VIR_ENUM_IMPL(virCPUMaxPhysAddrMode,
|
|
|
|
VIR_CPU_MAX_PHYS_ADDR_MODE_LAST,
|
|
|
|
"emulate",
|
|
|
|
"passthrough",
|
|
|
|
);
|
|
|
|
|
2017-04-24 13:40:07 +00:00
|
|
|
|
2021-03-11 07:16:13 +00:00
|
|
|
virCPUDef *virCPUDefNew(void)
|
2019-11-29 11:00:26 +00:00
|
|
|
{
|
2021-03-11 07:16:13 +00:00
|
|
|
virCPUDef *cpu = g_new0(virCPUDef, 1);
|
2019-11-29 11:00:26 +00:00
|
|
|
cpu->refs = 1;
|
|
|
|
return cpu;
|
|
|
|
}
|
|
|
|
|
2017-03-16 11:21:58 +00:00
|
|
|
void
|
2021-03-11 07:16:13 +00:00
|
|
|
virCPUDefFreeFeatures(virCPUDef *def)
|
2017-03-16 11:21:58 +00:00
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
for (i = 0; i < def->nfeatures; i++)
|
|
|
|
VIR_FREE(def->features[i].name);
|
|
|
|
VIR_FREE(def->features);
|
|
|
|
|
|
|
|
def->nfeatures = def->nfeatures_max = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-12-19 14:41:16 +00:00
|
|
|
void ATTRIBUTE_NONNULL(1)
|
2021-03-11 07:16:13 +00:00
|
|
|
virCPUDefFreeModel(virCPUDef *def)
|
2011-12-19 14:41:16 +00:00
|
|
|
{
|
|
|
|
VIR_FREE(def->model);
|
|
|
|
VIR_FREE(def->vendor);
|
2012-06-28 10:21:17 +00:00
|
|
|
VIR_FREE(def->vendor_id);
|
2017-03-16 11:21:58 +00:00
|
|
|
virCPUDefFreeFeatures(def);
|
2011-12-19 14:41:16 +00:00
|
|
|
}
|
|
|
|
|
2019-11-29 11:00:26 +00:00
|
|
|
void
|
2021-03-11 07:16:13 +00:00
|
|
|
virCPUDefRef(virCPUDef *def)
|
2019-11-29 11:00:26 +00:00
|
|
|
{
|
|
|
|
g_atomic_int_inc(&def->refs);
|
|
|
|
}
|
|
|
|
|
2009-12-18 13:44:55 +00:00
|
|
|
void
|
2021-03-11 07:16:13 +00:00
|
|
|
virCPUDefFree(virCPUDef *def)
|
2009-12-18 13:44:55 +00:00
|
|
|
{
|
|
|
|
if (!def)
|
|
|
|
return;
|
|
|
|
|
2019-11-29 11:00:26 +00:00
|
|
|
if (g_atomic_int_dec_and_test(&def->refs)) {
|
|
|
|
virCPUDefFreeModel(def);
|
2021-01-30 19:05:50 +00:00
|
|
|
g_free(def->cache);
|
2022-07-29 19:34:33 +00:00
|
|
|
g_free(def->addr);
|
2021-01-30 19:05:50 +00:00
|
|
|
g_free(def->tsc);
|
|
|
|
g_free(def);
|
2019-11-29 11:00:26 +00:00
|
|
|
}
|
2009-12-18 13:44:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-03-03 09:04:47 +00:00
|
|
|
void ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2)
|
2021-03-11 07:16:13 +00:00
|
|
|
virCPUDefCopyModel(virCPUDef *dst,
|
maint: avoid 'const fooPtr' in cpu files
'const fooPtr' is the same as 'foo * const' (the pointer won't
change, but it's contents can). But in general, if an interface
is trying to be const-correct, it should be using 'const foo *'
(the pointer is to data that can't be changed).
Fix up offenders in src/cpu.
* src/cpu/cpu.h (cpuArchDecode, cpuArchEncode, cpuArchUpdate)
(cpuArchHasFeature, cpuDecode, cpuEncode, cpuUpdate)
(cpuHasFeature): Use intended type.
* src/conf/cpu_conf.h (virCPUDefCopyModel, virCPUDefCopy):
Likewise.
(virCPUDefParseXML): Drop const.
* src/cpu/cpu.c (cpuDecode, cpuEncode, cpuUpdate, cpuHasFeature):
Fix fallout.
* src/cpu/cpu_x86.c (x86ModelFromCPU, x86ModelSubtractCPU)
(x86DecodeCPUData, x86EncodePolicy, x86Encode, x86UpdateCustom)
(x86UpdateHostModel, x86Update, x86HasFeature): Likewise.
* src/cpu/cpu_s390.c (s390Decode): Likewise.
* src/cpu/cpu_arm.c (ArmDecode): Likewise.
* src/cpu/cpu_powerpc.c (ppcModelFromCPU, ppcCompute, ppcDecode)
(ppcUpdate): Likewise.
* src/conf/cpu_conf.c (virCPUDefCopyModel, virCPUDefCopy)
(virCPUDefParseXML): Likewise.
Signed-off-by: Eric Blake <eblake@redhat.com>
2013-10-05 20:01:02 +00:00
|
|
|
const virCPUDef *src,
|
2011-12-19 14:41:16 +00:00
|
|
|
bool resetPolicy)
|
2016-06-28 08:44:20 +00:00
|
|
|
{
|
2023-03-03 09:04:47 +00:00
|
|
|
virCPUDefCopyModelFilter(dst, src, resetPolicy, NULL, NULL);
|
2016-06-28 08:44:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-03-03 09:04:47 +00:00
|
|
|
void
|
2021-03-11 07:16:13 +00:00
|
|
|
virCPUDefCopyModelFilter(virCPUDef *dst,
|
2016-06-28 08:44:20 +00:00
|
|
|
const virCPUDef *src,
|
|
|
|
bool resetPolicy,
|
|
|
|
virCPUDefFeatureFilter filter,
|
|
|
|
void *opaque)
|
2011-12-19 14:41:16 +00:00
|
|
|
{
|
Convert 'int i' to 'size_t i' in src/conf/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
size_t i;
|
2016-06-28 08:44:20 +00:00
|
|
|
size_t n;
|
2011-12-19 14:41:16 +00:00
|
|
|
|
2020-10-07 19:15:39 +00:00
|
|
|
dst->features = g_new0(virCPUFeatureDef, src->nfeatures);
|
2019-10-20 11:49:46 +00:00
|
|
|
dst->model = g_strdup(src->model);
|
|
|
|
dst->vendor = g_strdup(src->vendor);
|
|
|
|
dst->vendor_id = g_strdup(src->vendor_id);
|
2017-12-12 15:23:40 +00:00
|
|
|
dst->microcodeVersion = src->microcodeVersion;
|
2016-06-28 08:44:20 +00:00
|
|
|
dst->nfeatures_max = src->nfeatures;
|
|
|
|
dst->nfeatures = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < src->nfeatures; i++) {
|
2019-11-07 15:25:47 +00:00
|
|
|
if (filter && !filter(src->features[i].name, src->features[i].policy, opaque))
|
2016-06-28 08:44:20 +00:00
|
|
|
continue;
|
2011-12-19 14:41:16 +00:00
|
|
|
|
2016-06-28 08:44:20 +00:00
|
|
|
n = dst->nfeatures++;
|
2011-12-19 14:41:16 +00:00
|
|
|
if (dst->type != src->type && resetPolicy) {
|
|
|
|
if (dst->type == VIR_CPU_TYPE_HOST)
|
2016-06-28 08:44:20 +00:00
|
|
|
dst->features[n].policy = -1;
|
2011-12-19 14:41:16 +00:00
|
|
|
else if (src->features[i].policy == -1)
|
2016-06-28 08:44:20 +00:00
|
|
|
dst->features[n].policy = VIR_CPU_FEATURE_REQUIRE;
|
2011-12-19 14:41:16 +00:00
|
|
|
else
|
2016-06-28 08:44:20 +00:00
|
|
|
dst->features[n].policy = src->features[i].policy;
|
2011-12-19 14:41:16 +00:00
|
|
|
} else {
|
2016-06-28 08:44:20 +00:00
|
|
|
dst->features[n].policy = src->features[i].policy;
|
2011-12-19 14:41:16 +00:00
|
|
|
}
|
|
|
|
|
2019-10-20 11:49:46 +00:00
|
|
|
dst->features[n].name = g_strdup(src->features[i].name);
|
2011-12-19 14:41:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-17 07:44:43 +00:00
|
|
|
|
2016-11-10 09:26:03 +00:00
|
|
|
/**
|
|
|
|
* virCPUDefStealModel:
|
|
|
|
*
|
|
|
|
* Move CPU model related parts virCPUDef from @src to @dst. If @keepVendor
|
|
|
|
* is true, the function keeps the original vendor/vendor_id in @dst rather
|
|
|
|
* than overwriting it with the values from @src.
|
|
|
|
*/
|
2016-06-23 10:54:19 +00:00
|
|
|
void
|
2021-03-11 07:16:13 +00:00
|
|
|
virCPUDefStealModel(virCPUDef *dst,
|
|
|
|
virCPUDef *src,
|
2016-11-10 09:26:03 +00:00
|
|
|
bool keepVendor)
|
2016-06-23 10:54:19 +00:00
|
|
|
{
|
2016-11-16 07:55:30 +00:00
|
|
|
char *vendor = NULL;
|
|
|
|
char *vendor_id = NULL;
|
2016-11-10 09:26:03 +00:00
|
|
|
|
|
|
|
if (keepVendor) {
|
2019-10-16 11:43:01 +00:00
|
|
|
vendor = g_steal_pointer(&dst->vendor);
|
|
|
|
vendor_id = g_steal_pointer(&dst->vendor_id);
|
2016-11-10 09:26:03 +00:00
|
|
|
}
|
|
|
|
|
2016-06-23 10:54:19 +00:00
|
|
|
virCPUDefFreeModel(dst);
|
|
|
|
|
2019-10-16 11:43:01 +00:00
|
|
|
dst->model = g_steal_pointer(&src->model);
|
|
|
|
dst->features = g_steal_pointer(&src->features);
|
2017-12-12 15:23:40 +00:00
|
|
|
dst->microcodeVersion = src->microcodeVersion;
|
2016-06-23 10:54:19 +00:00
|
|
|
dst->nfeatures_max = src->nfeatures_max;
|
|
|
|
src->nfeatures_max = 0;
|
|
|
|
dst->nfeatures = src->nfeatures;
|
|
|
|
src->nfeatures = 0;
|
2016-11-10 09:26:03 +00:00
|
|
|
|
|
|
|
if (keepVendor) {
|
|
|
|
dst->vendor = vendor;
|
|
|
|
dst->vendor_id = vendor_id;
|
|
|
|
} else {
|
2019-10-16 11:43:01 +00:00
|
|
|
dst->vendor = g_steal_pointer(&src->vendor);
|
|
|
|
dst->vendor_id = g_steal_pointer(&src->vendor_id);
|
2016-11-10 09:26:03 +00:00
|
|
|
}
|
2016-06-23 10:54:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-11 07:16:13 +00:00
|
|
|
virCPUDef *
|
2016-06-17 07:44:43 +00:00
|
|
|
virCPUDefCopyWithoutModel(const virCPUDef *cpu)
|
2010-03-23 08:34:04 +00:00
|
|
|
{
|
2020-05-22 19:56:16 +00:00
|
|
|
g_autoptr(virCPUDef) copy = NULL;
|
2010-03-23 08:34:04 +00:00
|
|
|
|
2019-11-29 11:00:26 +00:00
|
|
|
if (!cpu)
|
2010-03-23 08:34:04 +00:00
|
|
|
return NULL;
|
|
|
|
|
2019-11-29 11:00:26 +00:00
|
|
|
copy = virCPUDefNew();
|
2010-03-23 08:34:04 +00:00
|
|
|
copy->type = cpu->type;
|
2011-08-18 10:14:36 +00:00
|
|
|
copy->mode = cpu->mode;
|
2010-03-23 08:34:04 +00:00
|
|
|
copy->match = cpu->match;
|
2017-03-01 14:18:22 +00:00
|
|
|
copy->check = cpu->check;
|
2011-12-21 13:27:16 +00:00
|
|
|
copy->fallback = cpu->fallback;
|
2010-03-23 08:34:04 +00:00
|
|
|
copy->sockets = cpu->sockets;
|
2019-12-16 11:16:51 +00:00
|
|
|
copy->dies = cpu->dies;
|
2010-03-23 08:34:04 +00:00
|
|
|
copy->cores = cpu->cores;
|
|
|
|
copy->threads = cpu->threads;
|
2012-12-11 12:58:54 +00:00
|
|
|
copy->arch = cpu->arch;
|
2020-06-02 10:29:57 +00:00
|
|
|
copy->migratable = cpu->migratable;
|
2022-06-11 16:24:37 +00:00
|
|
|
copy->sigFamily = cpu->sigFamily;
|
|
|
|
copy->sigModel = cpu->sigModel;
|
|
|
|
copy->sigStepping = cpu->sigStepping;
|
2011-12-19 14:41:16 +00:00
|
|
|
|
2017-04-24 13:40:07 +00:00
|
|
|
if (cpu->cache) {
|
2020-10-07 19:15:39 +00:00
|
|
|
copy->cache = g_new0(virCPUCacheDef, 1);
|
2017-04-24 13:40:07 +00:00
|
|
|
*copy->cache = *cpu->cache;
|
|
|
|
}
|
|
|
|
|
2022-07-29 19:34:33 +00:00
|
|
|
if (cpu->addr) {
|
|
|
|
copy->addr = g_new0(virCPUMaxPhysAddrDef, 1);
|
|
|
|
*copy->addr = *cpu->addr;
|
|
|
|
}
|
|
|
|
|
2019-05-30 19:47:49 +00:00
|
|
|
if (cpu->tsc) {
|
2020-10-07 19:15:39 +00:00
|
|
|
copy->tsc = g_new0(virHostCPUTscInfo, 1);
|
2019-05-30 19:47:49 +00:00
|
|
|
*copy->tsc = *cpu->tsc;
|
|
|
|
}
|
|
|
|
|
2020-05-22 19:56:16 +00:00
|
|
|
return g_steal_pointer(©);
|
2016-06-17 07:44:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-11 07:16:13 +00:00
|
|
|
virCPUDef *
|
2016-06-17 07:44:43 +00:00
|
|
|
virCPUDefCopy(const virCPUDef *cpu)
|
|
|
|
{
|
2020-05-22 19:56:16 +00:00
|
|
|
g_autoptr(virCPUDef) copy = NULL;
|
2016-06-17 07:44:43 +00:00
|
|
|
|
|
|
|
if (!(copy = virCPUDefCopyWithoutModel(cpu)))
|
|
|
|
return NULL;
|
|
|
|
|
2023-03-03 09:04:47 +00:00
|
|
|
virCPUDefCopyModel(copy, cpu, false);
|
2010-03-23 08:34:04 +00:00
|
|
|
|
2020-05-22 19:56:16 +00:00
|
|
|
return g_steal_pointer(©);
|
2010-03-23 08:34:04 +00:00
|
|
|
}
|
|
|
|
|
2016-06-17 07:44:43 +00:00
|
|
|
|
2019-09-19 20:25:04 +00:00
|
|
|
int
|
|
|
|
virCPUDefParseXMLString(const char *xml,
|
|
|
|
virCPUType type,
|
2021-03-11 07:16:13 +00:00
|
|
|
virCPUDef **cpu,
|
2020-10-07 08:54:55 +00:00
|
|
|
bool validateXML)
|
2019-09-19 20:25:04 +00:00
|
|
|
{
|
2021-08-11 11:57:18 +00:00
|
|
|
g_autoptr(xmlDoc) doc = NULL;
|
2021-08-11 11:30:26 +00:00
|
|
|
g_autoptr(xmlXPathContext) ctxt = NULL;
|
2019-09-19 20:25:04 +00:00
|
|
|
|
|
|
|
if (!xml) {
|
|
|
|
virReportError(VIR_ERR_INVALID_ARG, "%s", _("missing CPU definition"));
|
2021-08-17 10:17:31 +00:00
|
|
|
return -1;
|
2019-09-19 20:25:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!(doc = virXMLParseStringCtxt(xml, _("(CPU_definition)"), &ctxt)))
|
2021-08-17 10:17:31 +00:00
|
|
|
return -1;
|
2019-09-19 20:25:04 +00:00
|
|
|
|
2020-10-07 08:54:55 +00:00
|
|
|
if (virCPUDefParseXML(ctxt, NULL, type, cpu, validateXML) < 0)
|
2021-08-17 10:17:31 +00:00
|
|
|
return -1;
|
2019-09-19 20:25:04 +00:00
|
|
|
|
2021-08-17 10:17:31 +00:00
|
|
|
return 0;
|
2019-09-19 20:25:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-10-05 10:58:30 +00:00
|
|
|
static int
|
|
|
|
virCPUDefParseXMLCache(virCPUDef *def,
|
|
|
|
xmlNodePtr node)
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
def->cache = g_new0(virCPUCacheDef, 1);
|
|
|
|
|
|
|
|
if ((rc = virXMLPropInt(node, "level", 10, VIR_XML_PROP_NONNEGATIVE,
|
|
|
|
&def->cache->level, -1)) < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (rc == 1) {
|
|
|
|
if (def->cache->level < 1 || def->cache->level > 3) {
|
|
|
|
virReportError(VIR_ERR_XML_ERROR, "%s",
|
|
|
|
_("invalid CPU cache level, must be in range [1,3]"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (virXMLPropEnum(node, "mode", virCPUCacheModeTypeFromString,
|
|
|
|
VIR_XML_PROP_REQUIRED, &def->cache->mode) < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-05-23 07:29:36 +00:00
|
|
|
/*
|
|
|
|
* Parses CPU definition XML from a node pointed to by @xpath. If @xpath is
|
|
|
|
* NULL, the current node of @ctxt is used (i.e., it is a shortcut to ".").
|
|
|
|
*
|
|
|
|
* Missing <cpu> element in the XML document is not considered an error unless
|
|
|
|
* @xpath is NULL in which case the function expects it was provided with a
|
|
|
|
* valid <cpu> element already. In other words, the function returns success
|
|
|
|
* and sets @cpu to NULL if @xpath is not NULL and the node pointed to by
|
|
|
|
* @xpath is not found.
|
|
|
|
*
|
|
|
|
* Returns 0 on success, -1 on error.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
virCPUDefParseXML(xmlXPathContextPtr ctxt,
|
|
|
|
const char *xpath,
|
|
|
|
virCPUType type,
|
2021-03-11 07:16:13 +00:00
|
|
|
virCPUDef **cpu,
|
2020-10-07 08:54:55 +00:00
|
|
|
bool validateXML)
|
2009-12-18 13:44:55 +00:00
|
|
|
{
|
2020-05-29 12:41:26 +00:00
|
|
|
g_autoptr(virCPUDef) def = NULL;
|
|
|
|
g_autofree xmlNodePtr *nodes = NULL;
|
2021-09-21 14:26:48 +00:00
|
|
|
xmlNodePtr topology = NULL;
|
2022-07-29 19:34:33 +00:00
|
|
|
xmlNodePtr maxphysaddrNode = NULL;
|
2022-10-05 10:58:30 +00:00
|
|
|
g_autofree xmlNodePtr *cacheNodes = NULL;
|
|
|
|
ssize_t ncacheNodes = 0;
|
2020-07-28 19:47:48 +00:00
|
|
|
VIR_XPATH_NODE_AUTORESTORE(ctxt)
|
2009-12-18 13:44:55 +00:00
|
|
|
int n;
|
2022-01-20 10:24:55 +00:00
|
|
|
int rv;
|
Convert 'int i' to 'size_t i' in src/conf/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
size_t i;
|
2020-05-29 12:41:26 +00:00
|
|
|
g_autofree char *cpuMode = NULL;
|
|
|
|
g_autofree char *fallback = NULL;
|
|
|
|
g_autofree char *vendor_id = NULL;
|
2021-03-11 07:16:13 +00:00
|
|
|
g_autofree virHostCPUTscInfo *tsc = NULL;
|
2009-12-18 13:44:55 +00:00
|
|
|
|
2017-05-23 07:29:36 +00:00
|
|
|
*cpu = NULL;
|
|
|
|
|
2020-05-29 12:41:26 +00:00
|
|
|
if (xpath && !(ctxt->node = virXPathNode(xpath, ctxt)))
|
|
|
|
return 0;
|
2017-05-23 07:29:36 +00:00
|
|
|
|
2017-08-14 12:31:52 +00:00
|
|
|
if (!virXMLNodeNameEqual(ctxt->node, "cpu")) {
|
2013-07-15 09:12:18 +00:00
|
|
|
virReportError(VIR_ERR_XML_ERROR, "%s",
|
2012-07-18 10:50:44 +00:00
|
|
|
_("XML does not contain expected 'cpu' element"));
|
2020-05-29 12:41:26 +00:00
|
|
|
return -1;
|
2010-03-31 23:02:57 +00:00
|
|
|
}
|
|
|
|
|
2020-10-07 08:54:55 +00:00
|
|
|
if (validateXML) {
|
|
|
|
g_autofree char *schemafile = NULL;
|
|
|
|
|
|
|
|
if (!(schemafile = virFileFindResource("cpu.rng",
|
2022-03-22 08:18:57 +00:00
|
|
|
abs_top_srcdir "/src/conf/schemas",
|
2020-10-07 08:54:55 +00:00
|
|
|
PKGDATADIR "/schemas")))
|
|
|
|
return -1;
|
|
|
|
|
2021-04-20 11:27:49 +00:00
|
|
|
if (virXMLValidateNodeAgainstSchema(schemafile, ctxt->node) < 0)
|
2020-10-07 08:54:55 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2019-11-29 11:00:26 +00:00
|
|
|
def = virCPUDefNew();
|
2009-12-18 13:44:55 +00:00
|
|
|
|
2017-04-24 13:38:41 +00:00
|
|
|
if (type == VIR_CPU_TYPE_AUTO) {
|
2010-07-12 14:08:00 +00:00
|
|
|
if (virXPathBoolean("boolean(./arch)", ctxt)) {
|
|
|
|
if (virXPathBoolean("boolean(./@match)", ctxt)) {
|
2012-07-18 10:50:44 +00:00
|
|
|
virReportError(VIR_ERR_XML_ERROR, "%s",
|
2014-09-22 15:41:42 +00:00
|
|
|
_("'arch' element cannot be used inside 'cpu'"
|
2012-07-18 10:50:44 +00:00
|
|
|
" element with 'match' attribute'"));
|
2020-05-29 12:41:26 +00:00
|
|
|
return -1;
|
2010-07-12 14:08:00 +00:00
|
|
|
}
|
2010-01-12 14:25:36 +00:00
|
|
|
def->type = VIR_CPU_TYPE_HOST;
|
2011-08-18 10:14:36 +00:00
|
|
|
} else {
|
2010-01-12 14:25:36 +00:00
|
|
|
def->type = VIR_CPU_TYPE_GUEST;
|
2011-08-18 10:14:36 +00:00
|
|
|
}
|
|
|
|
} else {
|
2017-04-24 13:38:41 +00:00
|
|
|
def->type = type;
|
2011-08-18 10:14:36 +00:00
|
|
|
}
|
|
|
|
|
2017-05-23 07:29:36 +00:00
|
|
|
if ((cpuMode = virXMLPropString(ctxt->node, "mode"))) {
|
2011-08-18 10:14:36 +00:00
|
|
|
if (def->type == VIR_CPU_TYPE_HOST) {
|
2012-07-18 10:50:44 +00:00
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
|
|
|
_("Attribute mode is only allowed for guest CPU"));
|
2020-05-29 12:41:26 +00:00
|
|
|
return -1;
|
2011-08-18 10:14:36 +00:00
|
|
|
} else {
|
|
|
|
def->mode = virCPUModeTypeFromString(cpuMode);
|
|
|
|
|
|
|
|
if (def->mode < 0) {
|
2014-01-10 16:41:33 +00:00
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
2012-07-18 10:50:44 +00:00
|
|
|
_("Invalid mode attribute '%s'"),
|
|
|
|
cpuMode);
|
2020-05-29 12:41:26 +00:00
|
|
|
return -1;
|
2011-08-18 10:14:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (def->type == VIR_CPU_TYPE_HOST)
|
|
|
|
def->mode = -1;
|
|
|
|
else
|
|
|
|
def->mode = VIR_CPU_MODE_CUSTOM;
|
|
|
|
}
|
2009-12-18 13:44:55 +00:00
|
|
|
|
2022-01-20 10:24:55 +00:00
|
|
|
if ((rv = virXMLPropTristateSwitch(ctxt->node, "migratable",
|
|
|
|
VIR_XML_PROP_NONE,
|
|
|
|
&def->migratable)) < 0) {
|
|
|
|
return -1;
|
|
|
|
} else if (rv > 0 &&
|
|
|
|
def->mode != VIR_CPU_MODE_HOST_PASSTHROUGH &&
|
|
|
|
def->mode != VIR_CPU_MODE_MAXIMUM) {
|
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
|
|
|
_("Attribute migratable is only allowed for "
|
|
|
|
"'host-passthrough' / 'maximum' CPU mode"));
|
|
|
|
return -1;
|
2020-06-02 10:29:57 +00:00
|
|
|
}
|
|
|
|
|
2009-12-18 13:44:55 +00:00
|
|
|
if (def->type == VIR_CPU_TYPE_GUEST) {
|
2022-01-20 20:57:35 +00:00
|
|
|
if (virXMLPropEnum(ctxt->node, "match",
|
|
|
|
virCPUMatchTypeFromString,
|
|
|
|
VIR_XML_PROP_NONE,
|
|
|
|
&def->match) < 0)
|
|
|
|
return -1;
|
2017-03-01 14:18:22 +00:00
|
|
|
|
2021-04-16 09:41:52 +00:00
|
|
|
if (virXMLPropEnum(ctxt->node, "check", virCPUCheckTypeFromString,
|
2021-04-21 06:49:51 +00:00
|
|
|
VIR_XML_PROP_NONE, &def->check) < 0)
|
2021-04-16 09:41:52 +00:00
|
|
|
return -1;
|
2009-12-18 13:44:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (def->type == VIR_CPU_TYPE_HOST) {
|
2020-05-29 12:41:26 +00:00
|
|
|
g_autofree char *arch = virXPathString("string(./arch[1])", ctxt);
|
2022-01-20 12:58:49 +00:00
|
|
|
xmlNodePtr counter_node = NULL;
|
2022-06-11 16:24:37 +00:00
|
|
|
xmlNodePtr signature_node = NULL;
|
2022-01-20 12:58:49 +00:00
|
|
|
|
2012-12-11 12:58:54 +00:00
|
|
|
if (!arch) {
|
2013-07-15 09:12:18 +00:00
|
|
|
virReportError(VIR_ERR_XML_ERROR, "%s",
|
|
|
|
_("Missing CPU architecture"));
|
2020-05-29 12:41:26 +00:00
|
|
|
return -1;
|
2009-12-18 13:44:55 +00:00
|
|
|
}
|
2012-12-11 12:58:54 +00:00
|
|
|
if ((def->arch = virArchFromString(arch)) == VIR_ARCH_NONE) {
|
2014-01-10 16:41:33 +00:00
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
2012-12-11 12:58:54 +00:00
|
|
|
_("Unknown architecture %s"), arch);
|
2020-05-29 12:41:26 +00:00
|
|
|
return -1;
|
2012-12-11 12:58:54 +00:00
|
|
|
}
|
2017-12-12 15:23:40 +00:00
|
|
|
|
|
|
|
if (virXPathBoolean("boolean(./microcode[1]/@version)", ctxt) > 0 &&
|
|
|
|
virXPathUInt("string(./microcode[1]/@version)", ctxt,
|
|
|
|
&def->microcodeVersion) < 0) {
|
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
|
|
|
_("invalid microcode version"));
|
2020-05-29 12:41:26 +00:00
|
|
|
return -1;
|
2017-12-12 15:23:40 +00:00
|
|
|
}
|
2019-05-30 19:47:49 +00:00
|
|
|
|
2022-06-11 16:24:37 +00:00
|
|
|
if ((signature_node = virXPathNode("./signature[1]", ctxt))) {
|
|
|
|
if (virXMLPropUInt(signature_node, "family", 10,
|
|
|
|
VIR_XML_PROP_REQUIRED | VIR_XML_PROP_NONZERO,
|
|
|
|
&def->sigFamily) < 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (virXMLPropUInt(signature_node, "model", 10,
|
|
|
|
VIR_XML_PROP_REQUIRED,
|
|
|
|
&def->sigModel) < 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (virXMLPropUInt(signature_node, "stepping", 10,
|
|
|
|
VIR_XML_PROP_REQUIRED,
|
|
|
|
&def->sigStepping) < 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-08 11:11:26 +00:00
|
|
|
if ((counter_node = virXPathNode("./counter[@name='tsc']", ctxt))) {
|
2020-05-29 12:41:26 +00:00
|
|
|
tsc = g_new0(virHostCPUTscInfo, 1);
|
2019-05-30 19:47:49 +00:00
|
|
|
|
2022-01-20 20:57:35 +00:00
|
|
|
if (virXMLPropULongLong(counter_node, "frequency", 10,
|
|
|
|
VIR_XML_PROP_REQUIRED,
|
|
|
|
&tsc->frequency) < 0)
|
2020-05-29 12:41:26 +00:00
|
|
|
return -1;
|
2019-05-30 19:47:49 +00:00
|
|
|
|
2022-01-20 12:58:49 +00:00
|
|
|
if (virXMLPropTristateBool(counter_node, "scaling",
|
|
|
|
VIR_XML_PROP_NONE,
|
|
|
|
&tsc->scaling) < 0)
|
|
|
|
return -1;
|
2019-05-30 19:47:49 +00:00
|
|
|
|
2019-10-16 11:43:01 +00:00
|
|
|
def->tsc = g_steal_pointer(&tsc);
|
2019-05-30 19:47:49 +00:00
|
|
|
}
|
2009-12-18 13:44:55 +00:00
|
|
|
}
|
|
|
|
|
2010-02-04 21:52:34 +00:00
|
|
|
if (!(def->model = virXPathString("string(./model[1])", ctxt)) &&
|
2010-01-12 14:25:36 +00:00
|
|
|
def->type == VIR_CPU_TYPE_HOST) {
|
2013-07-15 09:12:18 +00:00
|
|
|
virReportError(VIR_ERR_XML_ERROR, "%s",
|
|
|
|
_("Missing CPU model name"));
|
2020-05-29 12:41:26 +00:00
|
|
|
return -1;
|
2009-12-18 13:44:55 +00:00
|
|
|
}
|
|
|
|
|
2011-08-18 10:14:36 +00:00
|
|
|
if (def->type == VIR_CPU_TYPE_GUEST &&
|
2021-02-05 15:51:09 +00:00
|
|
|
def->mode != VIR_CPU_MODE_HOST_PASSTHROUGH &&
|
|
|
|
def->mode != VIR_CPU_MODE_MAXIMUM) {
|
2012-06-28 10:21:17 +00:00
|
|
|
|
2012-12-17 10:49:33 +00:00
|
|
|
if ((fallback = virXPathString("string(./model[1]/@fallback)", ctxt))) {
|
|
|
|
if ((def->fallback = virCPUFallbackTypeFromString(fallback)) < 0) {
|
2014-01-10 16:41:33 +00:00
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
2012-12-17 10:49:33 +00:00
|
|
|
_("Invalid fallback attribute"));
|
2020-05-29 12:41:26 +00:00
|
|
|
return -1;
|
2012-06-28 10:21:17 +00:00
|
|
|
}
|
2012-12-17 08:05:59 +00:00
|
|
|
}
|
2012-06-28 10:21:17 +00:00
|
|
|
|
2012-12-17 10:49:33 +00:00
|
|
|
if ((vendor_id = virXPathString("string(./model[1]/@vendor_id)",
|
|
|
|
ctxt))) {
|
|
|
|
if (strlen(vendor_id) != VIR_CPU_VENDOR_ID_LENGTH) {
|
2012-12-17 08:05:59 +00:00
|
|
|
virReportError(VIR_ERR_XML_ERROR,
|
2012-12-17 10:49:33 +00:00
|
|
|
_("vendor_id must be exactly %d characters long"),
|
2012-12-17 08:05:59 +00:00
|
|
|
VIR_CPU_VENDOR_ID_LENGTH);
|
2020-05-29 12:41:26 +00:00
|
|
|
return -1;
|
2012-12-17 08:05:59 +00:00
|
|
|
}
|
2012-12-17 10:49:33 +00:00
|
|
|
|
2020-01-24 20:30:04 +00:00
|
|
|
/* ensure that the string can be passed to qemu */
|
2012-12-17 10:49:33 +00:00
|
|
|
if (strchr(vendor_id, ',')) {
|
2012-12-17 08:05:59 +00:00
|
|
|
virReportError(VIR_ERR_XML_ERROR, "%s",
|
|
|
|
_("vendor id is invalid"));
|
2020-05-29 12:41:26 +00:00
|
|
|
return -1;
|
2011-12-21 13:27:16 +00:00
|
|
|
}
|
2012-12-17 10:49:33 +00:00
|
|
|
|
2020-05-29 12:41:26 +00:00
|
|
|
def->vendor_id = g_steal_pointer(&vendor_id);
|
2011-12-21 13:27:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-02 15:51:59 +00:00
|
|
|
def->vendor = virXPathString("string(./vendor[1])", ctxt);
|
|
|
|
if (def->vendor && !def->model) {
|
2013-07-15 09:12:18 +00:00
|
|
|
virReportError(VIR_ERR_XML_ERROR, "%s",
|
|
|
|
_("CPU vendor specified without CPU model"));
|
2020-05-29 12:41:26 +00:00
|
|
|
return -1;
|
2010-07-02 15:51:59 +00:00
|
|
|
}
|
|
|
|
|
2021-09-21 14:26:48 +00:00
|
|
|
if ((topology = virXPathNode("./topology[1]", ctxt))) {
|
|
|
|
int rc;
|
2009-12-18 13:44:55 +00:00
|
|
|
|
2021-09-21 14:26:48 +00:00
|
|
|
if (virXMLPropUInt(topology, "sockets", 10,
|
|
|
|
VIR_XML_PROP_REQUIRED | VIR_XML_PROP_NONZERO,
|
|
|
|
&def->sockets) < 0) {
|
|
|
|
return -1;
|
2019-12-16 11:16:51 +00:00
|
|
|
}
|
|
|
|
|
2021-09-21 14:26:48 +00:00
|
|
|
if ((rc = virXMLPropUInt(topology, "dies", 10,
|
|
|
|
VIR_XML_PROP_NONZERO,
|
|
|
|
&def->dies)) < 0) {
|
2020-05-29 12:41:26 +00:00
|
|
|
return -1;
|
2021-09-21 14:26:48 +00:00
|
|
|
} else if (rc == 0) {
|
|
|
|
def->dies = 1;
|
2009-12-18 13:44:55 +00:00
|
|
|
}
|
|
|
|
|
2021-09-21 14:26:48 +00:00
|
|
|
if (virXMLPropUInt(topology, "cores", 10,
|
|
|
|
VIR_XML_PROP_REQUIRED | VIR_XML_PROP_NONZERO,
|
|
|
|
&def->cores) < 0) {
|
2020-05-29 12:41:26 +00:00
|
|
|
return -1;
|
2009-12-18 13:44:55 +00:00
|
|
|
}
|
|
|
|
|
2021-09-21 14:26:48 +00:00
|
|
|
if (virXMLPropUInt(topology, "threads", 10,
|
|
|
|
VIR_XML_PROP_REQUIRED | VIR_XML_PROP_NONZERO,
|
|
|
|
&def->threads) < 0) {
|
2020-05-29 12:41:26 +00:00
|
|
|
return -1;
|
2009-12-18 13:44:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-15 13:40:40 +00:00
|
|
|
if ((n = virXPathNodeSet("./feature", ctxt, &nodes)) < 0)
|
2020-05-29 12:41:26 +00:00
|
|
|
return -1;
|
2009-12-18 13:44:55 +00:00
|
|
|
|
|
|
|
if (n > 0) {
|
2015-06-22 08:27:05 +00:00
|
|
|
if (!def->model && def->mode == VIR_CPU_MODE_CUSTOM) {
|
2013-07-15 09:12:18 +00:00
|
|
|
virReportError(VIR_ERR_XML_ERROR, "%s",
|
2012-12-17 11:04:14 +00:00
|
|
|
_("Non-empty feature list specified without "
|
|
|
|
"CPU model"));
|
2020-05-29 12:41:26 +00:00
|
|
|
return -1;
|
2010-01-12 14:25:36 +00:00
|
|
|
}
|
|
|
|
|
2021-03-19 23:37:01 +00:00
|
|
|
VIR_RESIZE_N(def->features, def->nfeatures_max, def->nfeatures, n);
|
2009-12-18 13:44:55 +00:00
|
|
|
def->nfeatures = n;
|
|
|
|
}
|
|
|
|
|
2013-05-21 07:21:17 +00:00
|
|
|
for (i = 0; i < n; i++) {
|
2020-05-29 12:41:26 +00:00
|
|
|
g_autofree char *name = NULL;
|
2009-12-18 13:44:55 +00:00
|
|
|
int policy; /* enum virDomainCPUFeaturePolicy */
|
Convert 'int i' to 'size_t i' in src/conf/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
size_t j;
|
2009-12-18 13:44:55 +00:00
|
|
|
|
|
|
|
if (def->type == VIR_CPU_TYPE_GUEST) {
|
2020-05-29 12:41:26 +00:00
|
|
|
g_autofree char *strpolicy = NULL;
|
2009-12-18 13:44:55 +00:00
|
|
|
|
|
|
|
strpolicy = virXMLPropString(nodes[i], "policy");
|
2010-09-22 11:47:48 +00:00
|
|
|
if (strpolicy == NULL)
|
|
|
|
policy = VIR_CPU_FEATURE_REQUIRE;
|
|
|
|
else
|
|
|
|
policy = virCPUFeaturePolicyTypeFromString(strpolicy);
|
2009-12-18 13:44:55 +00:00
|
|
|
|
|
|
|
if (policy < 0) {
|
2014-01-10 16:41:33 +00:00
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
2013-07-15 09:12:18 +00:00
|
|
|
_("Invalid CPU feature policy"));
|
2020-05-29 12:41:26 +00:00
|
|
|
return -1;
|
2009-12-18 13:44:55 +00:00
|
|
|
}
|
2011-08-18 10:14:36 +00:00
|
|
|
} else {
|
2009-12-18 13:44:55 +00:00
|
|
|
policy = -1;
|
2011-08-18 10:14:36 +00:00
|
|
|
}
|
2009-12-18 13:44:55 +00:00
|
|
|
|
|
|
|
if (!(name = virXMLPropString(nodes[i], "name")) || *name == 0) {
|
2013-07-15 09:12:18 +00:00
|
|
|
virReportError(VIR_ERR_XML_ERROR, "%s",
|
|
|
|
_("Invalid CPU feature name"));
|
2020-05-29 12:41:26 +00:00
|
|
|
return -1;
|
2009-12-18 13:44:55 +00:00
|
|
|
}
|
|
|
|
|
2013-05-21 07:21:17 +00:00
|
|
|
for (j = 0; j < i; j++) {
|
2009-12-18 13:44:55 +00:00
|
|
|
if (STREQ(name, def->features[j].name)) {
|
2013-07-15 09:12:18 +00:00
|
|
|
virReportError(VIR_ERR_XML_ERROR,
|
2014-09-23 01:45:21 +00:00
|
|
|
_("CPU feature '%s' specified more than once"),
|
2012-07-18 10:50:44 +00:00
|
|
|
name);
|
2020-05-29 12:41:26 +00:00
|
|
|
return -1;
|
2009-12-18 13:44:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-29 12:41:26 +00:00
|
|
|
def->features[i].name = g_steal_pointer(&name);
|
2009-12-18 13:44:55 +00:00
|
|
|
def->features[i].policy = policy;
|
|
|
|
}
|
|
|
|
|
2022-10-05 10:58:30 +00:00
|
|
|
if ((ncacheNodes = virXPathNodeSet("./cache", ctxt, &cacheNodes)) > 0) {
|
|
|
|
if (ncacheNodes > 1) {
|
2017-04-24 13:40:07 +00:00
|
|
|
virReportError(VIR_ERR_XML_ERROR, "%s",
|
2022-10-05 10:58:30 +00:00
|
|
|
_("at most one CPU cache element may be specified"));
|
2020-05-29 12:41:26 +00:00
|
|
|
return -1;
|
2017-04-24 13:40:07 +00:00
|
|
|
}
|
|
|
|
|
2022-10-05 10:58:30 +00:00
|
|
|
if (virCPUDefParseXMLCache(def, cacheNodes[0]) < 0)
|
2020-05-29 12:41:26 +00:00
|
|
|
return -1;
|
2017-04-24 13:40:07 +00:00
|
|
|
}
|
|
|
|
|
2022-07-29 19:34:33 +00:00
|
|
|
if ((maxphysaddrNode = virXPathNode("./maxphysaddr[1]", ctxt))) {
|
|
|
|
def->addr = g_new0(virCPUMaxPhysAddrDef, 1);
|
|
|
|
|
|
|
|
if (virXMLPropEnum(maxphysaddrNode, "mode",
|
|
|
|
virCPUMaxPhysAddrModeTypeFromString,
|
|
|
|
VIR_XML_PROP_REQUIRED,
|
|
|
|
&def->addr->mode) < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (virXMLPropInt(maxphysaddrNode, "bits", 10,
|
|
|
|
VIR_XML_PROP_NONNEGATIVE,
|
|
|
|
&def->addr->bits, -1) < 0)
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2019-10-16 11:43:01 +00:00
|
|
|
*cpu = g_steal_pointer(&def);
|
2020-05-29 12:41:26 +00:00
|
|
|
return 0;
|
2009-12-18 13:44:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
char *
|
2021-03-11 07:16:13 +00:00
|
|
|
virCPUDefFormat(virCPUDef *def,
|
|
|
|
virDomainNuma *numa)
|
2009-12-18 13:44:55 +00:00
|
|
|
{
|
2020-07-03 02:19:01 +00:00
|
|
|
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
|
2009-12-18 13:44:55 +00:00
|
|
|
|
2017-06-30 13:47:23 +00:00
|
|
|
if (virCPUDefFormatBufFull(&buf, def, numa) < 0)
|
2020-07-03 03:19:26 +00:00
|
|
|
return NULL;
|
2009-12-18 13:44:55 +00:00
|
|
|
|
|
|
|
return virBufferContentAndReset(&buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-21 23:42:07 +00:00
|
|
|
int
|
2021-03-11 07:16:13 +00:00
|
|
|
virCPUDefFormatBufFull(virBuffer *buf,
|
|
|
|
virCPUDef *def,
|
|
|
|
virDomainNuma *numa)
|
2011-09-21 23:42:07 +00:00
|
|
|
{
|
2020-07-03 02:19:01 +00:00
|
|
|
g_auto(virBuffer) attributeBuf = VIR_BUFFER_INITIALIZER;
|
|
|
|
g_auto(virBuffer) childrenBuf = VIR_BUFFER_INIT_CHILD(buf);
|
2015-02-18 17:06:44 +00:00
|
|
|
|
2011-09-21 23:42:07 +00:00
|
|
|
if (!def)
|
|
|
|
return 0;
|
|
|
|
|
2017-06-30 14:05:28 +00:00
|
|
|
/* Format attributes for guest CPUs unless they only specify
|
|
|
|
* topology or cache. */
|
|
|
|
if (def->type == VIR_CPU_TYPE_GUEST &&
|
|
|
|
(def->mode != VIR_CPU_MODE_CUSTOM || def->model)) {
|
2011-08-18 10:14:36 +00:00
|
|
|
const char *tmp;
|
|
|
|
|
2017-06-30 14:05:28 +00:00
|
|
|
if (!(tmp = virCPUModeTypeToString(def->mode))) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Unexpected CPU mode %d"), def->mode);
|
2020-07-03 03:19:26 +00:00
|
|
|
return -1;
|
2011-09-21 23:42:07 +00:00
|
|
|
}
|
2017-06-30 14:05:28 +00:00
|
|
|
virBufferAsprintf(&attributeBuf, " mode='%s'", tmp);
|
2011-09-21 23:42:07 +00:00
|
|
|
|
2017-06-30 14:05:28 +00:00
|
|
|
if (def->mode == VIR_CPU_MODE_CUSTOM) {
|
2011-08-18 10:14:36 +00:00
|
|
|
if (!(tmp = virCPUMatchTypeToString(def->match))) {
|
2012-07-18 10:50:44 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Unexpected CPU match policy %d"),
|
|
|
|
def->match);
|
2020-07-03 03:19:26 +00:00
|
|
|
return -1;
|
2011-08-18 10:14:36 +00:00
|
|
|
}
|
2015-04-10 13:09:59 +00:00
|
|
|
virBufferAsprintf(&attributeBuf, " match='%s'", tmp);
|
2011-08-18 10:14:36 +00:00
|
|
|
}
|
2017-03-01 14:18:22 +00:00
|
|
|
|
|
|
|
if (def->check) {
|
|
|
|
virBufferAsprintf(&attributeBuf, " check='%s'",
|
|
|
|
virCPUCheckTypeToString(def->check));
|
|
|
|
}
|
2020-06-02 10:29:57 +00:00
|
|
|
|
2021-02-05 15:51:09 +00:00
|
|
|
if ((def->mode == VIR_CPU_MODE_HOST_PASSTHROUGH ||
|
|
|
|
def->mode == VIR_CPU_MODE_MAXIMUM) &&
|
|
|
|
def->migratable) {
|
2020-06-02 10:29:57 +00:00
|
|
|
virBufferAsprintf(&attributeBuf, " migratable='%s'",
|
|
|
|
virTristateSwitchTypeToString(def->migratable));
|
|
|
|
}
|
2011-09-21 23:42:07 +00:00
|
|
|
}
|
|
|
|
|
2015-04-10 13:09:59 +00:00
|
|
|
/* Format children */
|
2013-07-24 08:15:38 +00:00
|
|
|
if (def->type == VIR_CPU_TYPE_HOST && def->arch)
|
2015-02-18 17:04:16 +00:00
|
|
|
virBufferAsprintf(&childrenBuf, "<arch>%s</arch>\n",
|
2012-12-11 12:58:54 +00:00
|
|
|
virArchToString(def->arch));
|
2017-06-30 13:47:23 +00:00
|
|
|
if (virCPUDefFormatBuf(&childrenBuf, def) < 0)
|
2020-07-03 03:19:26 +00:00
|
|
|
return -1;
|
2011-09-21 23:42:07 +00:00
|
|
|
|
2020-05-28 14:52:22 +00:00
|
|
|
if (virDomainNumaDefFormatXML(&childrenBuf, numa) < 0)
|
2020-07-03 03:19:26 +00:00
|
|
|
return -1;
|
2015-02-11 13:26:19 +00:00
|
|
|
|
2020-10-30 16:45:07 +00:00
|
|
|
virXMLFormatElement(buf, "cpu", &attributeBuf, &childrenBuf);
|
2011-09-21 23:42:07 +00:00
|
|
|
|
2020-07-03 03:19:26 +00:00
|
|
|
return 0;
|
2011-09-21 23:42:07 +00:00
|
|
|
}
|
|
|
|
|
2009-12-18 13:44:55 +00:00
|
|
|
int
|
2021-03-11 07:16:13 +00:00
|
|
|
virCPUDefFormatBuf(virBuffer *buf,
|
|
|
|
virCPUDef *def)
|
2009-12-18 13:44:55 +00:00
|
|
|
{
|
Convert 'int i' to 'size_t i' in src/conf/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
size_t i;
|
2011-08-18 10:14:36 +00:00
|
|
|
bool formatModel;
|
2009-12-18 13:44:55 +00:00
|
|
|
|
|
|
|
if (!def)
|
|
|
|
return 0;
|
|
|
|
|
2011-08-18 10:14:36 +00:00
|
|
|
formatModel = (def->mode == VIR_CPU_MODE_CUSTOM ||
|
2017-06-30 13:47:23 +00:00
|
|
|
def->mode == VIR_CPU_MODE_HOST_MODEL);
|
2011-08-18 10:14:36 +00:00
|
|
|
|
2015-06-22 08:27:05 +00:00
|
|
|
if (!def->model && def->mode == VIR_CPU_MODE_CUSTOM && def->nfeatures) {
|
2013-07-15 09:12:18 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Non-empty feature list specified without CPU model"));
|
2009-12-18 13:44:55 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2020-02-19 12:48:39 +00:00
|
|
|
if (formatModel && (def->model || def->vendor_id)) {
|
2011-12-21 13:27:16 +00:00
|
|
|
virBufferAddLit(buf, "<model");
|
2019-11-12 14:54:12 +00:00
|
|
|
|
2020-02-19 12:48:39 +00:00
|
|
|
if (def->type == VIR_CPU_TYPE_GUEST && def->model) {
|
2011-12-21 13:27:16 +00:00
|
|
|
const char *fallback;
|
|
|
|
|
|
|
|
fallback = virCPUFallbackTypeToString(def->fallback);
|
|
|
|
if (!fallback) {
|
2012-07-18 10:50:44 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Unexpected CPU fallback value: %d"),
|
|
|
|
def->fallback);
|
2011-12-21 13:27:16 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
virBufferAsprintf(buf, " fallback='%s'", fallback);
|
|
|
|
}
|
2019-11-12 14:54:12 +00:00
|
|
|
|
2020-02-19 12:48:39 +00:00
|
|
|
if (def->type == VIR_CPU_TYPE_GUEST)
|
|
|
|
virBufferEscapeString(buf, " vendor_id='%s'", def->vendor_id);
|
|
|
|
|
|
|
|
if (def->model)
|
|
|
|
virBufferEscapeString(buf, ">%s</model>\n", def->model);
|
|
|
|
else
|
|
|
|
virBufferAddLit(buf, "/>\n");
|
2011-12-21 13:27:16 +00:00
|
|
|
}
|
2009-12-18 13:44:55 +00:00
|
|
|
|
2011-08-18 10:14:36 +00:00
|
|
|
if (formatModel && def->vendor)
|
2015-05-05 14:52:46 +00:00
|
|
|
virBufferEscapeString(buf, "<vendor>%s</vendor>\n", def->vendor);
|
2010-07-02 15:51:59 +00:00
|
|
|
|
2017-12-12 15:23:40 +00:00
|
|
|
if (def->type == VIR_CPU_TYPE_HOST && def->microcodeVersion)
|
|
|
|
virBufferAsprintf(buf, "<microcode version='%u'/>\n",
|
|
|
|
def->microcodeVersion);
|
|
|
|
|
2022-06-11 16:24:37 +00:00
|
|
|
if (def->type == VIR_CPU_TYPE_HOST && def->sigFamily) {
|
|
|
|
virBufferAddLit(buf, "<signature");
|
|
|
|
virBufferAsprintf(buf, " family='%u'", def->sigFamily);
|
|
|
|
virBufferAsprintf(buf, " model='%u'", def->sigModel);
|
|
|
|
virBufferAsprintf(buf, " stepping='%u'", def->sigStepping);
|
|
|
|
virBufferAddLit(buf, "/>\n");
|
|
|
|
}
|
|
|
|
|
2019-05-30 19:47:49 +00:00
|
|
|
if (def->type == VIR_CPU_TYPE_HOST && def->tsc) {
|
|
|
|
virBufferAddLit(buf, "<counter name='tsc'");
|
|
|
|
virBufferAsprintf(buf, " frequency='%llu'", def->tsc->frequency);
|
|
|
|
if (def->tsc->scaling) {
|
|
|
|
virBufferAsprintf(buf, " scaling='%s'",
|
|
|
|
virTristateBoolTypeToString(def->tsc->scaling));
|
|
|
|
}
|
|
|
|
virBufferAddLit(buf, "/>\n");
|
|
|
|
}
|
|
|
|
|
2019-12-16 11:16:51 +00:00
|
|
|
if (def->sockets && def->dies && def->cores && def->threads) {
|
2011-09-21 23:42:07 +00:00
|
|
|
virBufferAddLit(buf, "<topology");
|
2011-04-30 16:34:49 +00:00
|
|
|
virBufferAsprintf(buf, " sockets='%u'", def->sockets);
|
2019-12-16 11:16:51 +00:00
|
|
|
virBufferAsprintf(buf, " dies='%u'", def->dies);
|
2011-04-30 16:34:49 +00:00
|
|
|
virBufferAsprintf(buf, " cores='%u'", def->cores);
|
|
|
|
virBufferAsprintf(buf, " threads='%u'", def->threads);
|
2009-12-18 13:44:55 +00:00
|
|
|
virBufferAddLit(buf, "/>\n");
|
|
|
|
}
|
|
|
|
|
2017-04-24 13:40:07 +00:00
|
|
|
if (def->cache) {
|
|
|
|
virBufferAddLit(buf, "<cache ");
|
|
|
|
if (def->cache->level != -1)
|
|
|
|
virBufferAsprintf(buf, "level='%d' ", def->cache->level);
|
|
|
|
virBufferAsprintf(buf, "mode='%s'",
|
|
|
|
virCPUCacheModeTypeToString(def->cache->mode));
|
|
|
|
virBufferAddLit(buf, "/>\n");
|
|
|
|
}
|
|
|
|
|
2022-07-29 19:34:33 +00:00
|
|
|
if (def->addr) {
|
|
|
|
virBufferAddLit(buf, "<maxphysaddr ");
|
|
|
|
virBufferAsprintf(buf, "mode='%s'",
|
|
|
|
virCPUMaxPhysAddrModeTypeToString(def->addr->mode));
|
|
|
|
if (def->addr->bits != -1)
|
|
|
|
virBufferAsprintf(buf, " bits='%d'", def->addr->bits);
|
|
|
|
virBufferAddLit(buf, "/>\n");
|
|
|
|
}
|
|
|
|
|
2015-01-15 11:49:13 +00:00
|
|
|
for (i = 0; i < def->nfeatures; i++) {
|
2021-03-11 07:16:13 +00:00
|
|
|
virCPUFeatureDef *feature = def->features + i;
|
2009-12-18 13:44:55 +00:00
|
|
|
|
2015-01-15 11:49:13 +00:00
|
|
|
if (!feature->name) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Missing CPU feature name"));
|
|
|
|
return -1;
|
|
|
|
}
|
2011-08-18 10:14:36 +00:00
|
|
|
|
2015-01-15 11:49:13 +00:00
|
|
|
if (def->type == VIR_CPU_TYPE_GUEST) {
|
|
|
|
const char *policy;
|
2013-07-15 15:38:55 +00:00
|
|
|
|
2015-01-15 11:49:13 +00:00
|
|
|
policy = virCPUFeaturePolicyTypeToString(feature->policy);
|
|
|
|
if (!policy) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Unexpected CPU feature policy %d"),
|
|
|
|
feature->policy);
|
|
|
|
return -1;
|
2011-08-18 10:14:36 +00:00
|
|
|
}
|
2015-01-15 11:49:13 +00:00
|
|
|
virBufferAsprintf(buf, "<feature policy='%s' name='%s'/>\n",
|
|
|
|
policy, feature->name);
|
|
|
|
} else {
|
|
|
|
virBufferAsprintf(buf, "<feature name='%s'/>\n",
|
|
|
|
feature->name);
|
2009-12-18 13:44:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-11-19 17:34:02 +00:00
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
VIR_CPU_ADD_FEATURE_MODE_EXCLUSIVE, /* Fail if feature exists */
|
|
|
|
VIR_CPU_ADD_FEATURE_MODE_UPDATE, /* Add feature or update policy */
|
2020-11-19 17:44:48 +00:00
|
|
|
VIR_CPU_ADD_FEATURE_MODE_NEW, /* Add feature if it does not exist */
|
2020-11-19 17:34:02 +00:00
|
|
|
} virCPUDefAddFeatureMode;
|
|
|
|
|
2013-07-15 12:36:09 +00:00
|
|
|
static int
|
2021-03-11 07:16:13 +00:00
|
|
|
virCPUDefAddFeatureInternal(virCPUDef *def,
|
2020-11-19 17:24:01 +00:00
|
|
|
const char *name,
|
|
|
|
int policy,
|
2020-11-19 17:34:02 +00:00
|
|
|
virCPUDefAddFeatureMode mode)
|
2009-12-18 13:44:55 +00:00
|
|
|
{
|
2021-03-11 07:16:13 +00:00
|
|
|
virCPUFeatureDef *feat;
|
2009-12-18 13:44:55 +00:00
|
|
|
|
2013-07-15 12:36:09 +00:00
|
|
|
if (def->type == VIR_CPU_TYPE_HOST)
|
|
|
|
policy = -1;
|
|
|
|
|
2017-10-09 14:20:43 +00:00
|
|
|
if ((feat = virCPUDefFindFeature(def, name))) {
|
2020-11-19 17:34:02 +00:00
|
|
|
switch (mode) {
|
2020-11-19 17:44:48 +00:00
|
|
|
case VIR_CPU_ADD_FEATURE_MODE_NEW:
|
|
|
|
return 0;
|
|
|
|
|
2020-11-19 17:34:02 +00:00
|
|
|
case VIR_CPU_ADD_FEATURE_MODE_UPDATE:
|
2017-10-09 14:20:43 +00:00
|
|
|
feat->policy = policy;
|
|
|
|
return 0;
|
2013-07-15 12:36:09 +00:00
|
|
|
|
2020-11-19 17:34:02 +00:00
|
|
|
case VIR_CPU_ADD_FEATURE_MODE_EXCLUSIVE:
|
|
|
|
default:
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("CPU feature '%s' specified more than once"),
|
|
|
|
name);
|
|
|
|
return -1;
|
|
|
|
}
|
2009-12-18 13:44:55 +00:00
|
|
|
}
|
|
|
|
|
2021-03-19 23:37:01 +00:00
|
|
|
VIR_RESIZE_N(def->features, def->nfeatures_max, def->nfeatures, 1);
|
2019-10-20 11:49:46 +00:00
|
|
|
def->features[def->nfeatures].name = g_strdup(name);
|
2009-12-18 13:44:55 +00:00
|
|
|
def->features[def->nfeatures].policy = policy;
|
|
|
|
def->nfeatures++;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2011-05-27 09:47:30 +00:00
|
|
|
|
2013-07-15 12:36:09 +00:00
|
|
|
int
|
2021-03-11 07:16:13 +00:00
|
|
|
virCPUDefUpdateFeature(virCPUDef *def,
|
2013-07-15 12:36:09 +00:00
|
|
|
const char *name,
|
|
|
|
int policy)
|
|
|
|
{
|
2020-11-19 17:34:02 +00:00
|
|
|
return virCPUDefAddFeatureInternal(def, name, policy,
|
|
|
|
VIR_CPU_ADD_FEATURE_MODE_UPDATE);
|
2013-07-15 12:36:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2021-03-11 07:16:13 +00:00
|
|
|
virCPUDefAddFeature(virCPUDef *def,
|
2013-07-15 12:36:09 +00:00
|
|
|
const char *name,
|
|
|
|
int policy)
|
|
|
|
{
|
2020-11-19 17:34:02 +00:00
|
|
|
return virCPUDefAddFeatureInternal(def, name, policy,
|
|
|
|
VIR_CPU_ADD_FEATURE_MODE_EXCLUSIVE);
|
2013-07-15 12:36:09 +00:00
|
|
|
}
|
|
|
|
|
2017-10-09 14:20:43 +00:00
|
|
|
|
2020-11-19 17:44:48 +00:00
|
|
|
int
|
2021-03-11 07:16:13 +00:00
|
|
|
virCPUDefAddFeatureIfMissing(virCPUDef *def,
|
2020-11-19 17:44:48 +00:00
|
|
|
const char *name,
|
|
|
|
int policy)
|
|
|
|
{
|
|
|
|
return virCPUDefAddFeatureInternal(def, name, policy,
|
|
|
|
VIR_CPU_ADD_FEATURE_MODE_NEW);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-11 07:16:13 +00:00
|
|
|
virCPUFeatureDef *
|
2021-03-23 10:01:53 +00:00
|
|
|
virCPUDefFindFeature(const virCPUDef *def,
|
2017-10-09 14:20:43 +00:00
|
|
|
const char *name)
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
for (i = 0; i < def->nfeatures; i++) {
|
|
|
|
if (STREQ(name, def->features[i].name))
|
|
|
|
return def->features + i;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-06-07 12:07:10 +00:00
|
|
|
int
|
2021-03-11 07:16:13 +00:00
|
|
|
virCPUDefFilterFeatures(virCPUDef *cpu,
|
2019-06-07 12:07:10 +00:00
|
|
|
virCPUDefFeatureFilter filter,
|
|
|
|
void *opaque)
|
|
|
|
{
|
|
|
|
size_t i = 0;
|
|
|
|
|
|
|
|
while (i < cpu->nfeatures) {
|
2019-11-07 15:25:47 +00:00
|
|
|
if (filter(cpu->features[i].name, cpu->features[i].policy, opaque)) {
|
2019-06-07 12:07:10 +00:00
|
|
|
i++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
VIR_FREE(cpu->features[i].name);
|
|
|
|
if (VIR_DELETE_ELEMENT_INPLACE(cpu->features, i, cpu->nfeatures) < 0)
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-06-19 17:01:30 +00:00
|
|
|
/**
|
|
|
|
* virCPUDefCheckFeatures:
|
|
|
|
*
|
|
|
|
* Check CPU features for which @filter reports true and store them in a NULL
|
|
|
|
* terminated list returned via @features.
|
|
|
|
*
|
|
|
|
* Returns the number of features matching @filter or -1 on error.
|
|
|
|
*/
|
|
|
|
int
|
2021-03-11 07:16:13 +00:00
|
|
|
virCPUDefCheckFeatures(virCPUDef *cpu,
|
2019-06-19 17:01:30 +00:00
|
|
|
virCPUDefFeatureFilter filter,
|
|
|
|
void *opaque,
|
|
|
|
char ***features)
|
|
|
|
{
|
|
|
|
size_t n = 0;
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
*features = NULL;
|
|
|
|
|
2021-02-05 14:13:28 +00:00
|
|
|
if (cpu->nfeatures == 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
*features = g_new0(char *, cpu->nfeatures + 1);
|
|
|
|
|
2019-06-19 17:01:30 +00:00
|
|
|
for (i = 0; i < cpu->nfeatures; i++) {
|
2021-02-05 14:13:28 +00:00
|
|
|
if (filter(cpu->features[i].name, cpu->features[i].policy, opaque))
|
|
|
|
(*features)[n++] = g_strdup(cpu->features[i].name);
|
2019-06-19 17:01:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-27 09:47:30 +00:00
|
|
|
bool
|
2021-03-11 07:16:13 +00:00
|
|
|
virCPUDefIsEqual(virCPUDef *src,
|
|
|
|
virCPUDef *dst,
|
2017-05-31 14:42:42 +00:00
|
|
|
bool reportError)
|
2011-05-27 09:47:30 +00:00
|
|
|
{
|
Convert 'int i' to 'size_t i' in src/conf/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
size_t i;
|
2011-05-27 09:47:30 +00:00
|
|
|
|
|
|
|
if (!src && !dst)
|
|
|
|
return true;
|
|
|
|
|
2017-11-03 12:09:47 +00:00
|
|
|
#define MISMATCH(fmt, ...) \
|
|
|
|
if (reportError) \
|
2017-05-31 14:42:42 +00:00
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, fmt, __VA_ARGS__)
|
|
|
|
|
2011-05-27 09:47:30 +00:00
|
|
|
if ((src && !dst) || (!src && dst)) {
|
2017-05-31 14:42:42 +00:00
|
|
|
MISMATCH("%s", _("Target CPU does not match source"));
|
2020-01-06 21:57:26 +00:00
|
|
|
return false;
|
2011-05-27 09:47:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (src->type != dst->type) {
|
2017-05-31 14:42:42 +00:00
|
|
|
MISMATCH(_("Target CPU type %s does not match source %s"),
|
|
|
|
virCPUTypeToString(dst->type),
|
|
|
|
virCPUTypeToString(src->type));
|
2020-01-06 21:57:26 +00:00
|
|
|
return false;
|
2011-05-27 09:47:30 +00:00
|
|
|
}
|
|
|
|
|
2011-08-18 10:14:36 +00:00
|
|
|
if (src->mode != dst->mode) {
|
2017-05-31 14:42:42 +00:00
|
|
|
MISMATCH(_("Target CPU mode %s does not match source %s"),
|
|
|
|
virCPUModeTypeToString(dst->mode),
|
|
|
|
virCPUModeTypeToString(src->mode));
|
2020-01-06 21:57:26 +00:00
|
|
|
return false;
|
2011-08-18 10:14:36 +00:00
|
|
|
}
|
|
|
|
|
2019-04-24 09:51:18 +00:00
|
|
|
if (src->check != dst->check) {
|
|
|
|
MISMATCH(_("Target CPU check %s does not match source %s"),
|
|
|
|
virCPUCheckTypeToString(dst->check),
|
|
|
|
virCPUCheckTypeToString(src->check));
|
2020-01-06 21:57:26 +00:00
|
|
|
return false;
|
2019-04-24 09:51:18 +00:00
|
|
|
}
|
|
|
|
|
2012-12-11 12:58:54 +00:00
|
|
|
if (src->arch != dst->arch) {
|
2017-05-31 14:42:42 +00:00
|
|
|
MISMATCH(_("Target CPU arch %s does not match source %s"),
|
|
|
|
virArchToString(dst->arch),
|
|
|
|
virArchToString(src->arch));
|
2020-01-06 21:57:26 +00:00
|
|
|
return false;
|
2011-05-27 09:47:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (STRNEQ_NULLABLE(src->model, dst->model)) {
|
2017-05-31 14:42:42 +00:00
|
|
|
MISMATCH(_("Target CPU model %s does not match source %s"),
|
|
|
|
NULLSTR(dst->model), NULLSTR(src->model));
|
2020-01-06 21:57:26 +00:00
|
|
|
return false;
|
2011-05-27 09:47:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (STRNEQ_NULLABLE(src->vendor, dst->vendor)) {
|
2017-05-31 14:42:42 +00:00
|
|
|
MISMATCH(_("Target CPU vendor %s does not match source %s"),
|
|
|
|
NULLSTR(dst->vendor), NULLSTR(src->vendor));
|
2020-01-06 21:57:26 +00:00
|
|
|
return false;
|
2011-05-27 09:47:30 +00:00
|
|
|
}
|
|
|
|
|
2012-06-28 10:21:17 +00:00
|
|
|
if (STRNEQ_NULLABLE(src->vendor_id, dst->vendor_id)) {
|
2017-05-31 14:42:42 +00:00
|
|
|
MISMATCH(_("Target CPU vendor id %s does not match source %s"),
|
|
|
|
NULLSTR(dst->vendor_id), NULLSTR(src->vendor_id));
|
2020-01-06 21:57:26 +00:00
|
|
|
return false;
|
2012-06-28 10:21:17 +00:00
|
|
|
}
|
|
|
|
|
2011-05-27 09:47:30 +00:00
|
|
|
if (src->sockets != dst->sockets) {
|
2017-05-31 14:42:42 +00:00
|
|
|
MISMATCH(_("Target CPU sockets %d does not match source %d"),
|
|
|
|
dst->sockets, src->sockets);
|
2020-01-06 21:57:26 +00:00
|
|
|
return false;
|
2011-05-27 09:47:30 +00:00
|
|
|
}
|
|
|
|
|
2019-12-16 11:16:51 +00:00
|
|
|
if (src->dies != dst->dies) {
|
|
|
|
MISMATCH(_("Target CPU dies %d does not match source %d"),
|
|
|
|
dst->dies, src->dies);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-05-27 09:47:30 +00:00
|
|
|
if (src->cores != dst->cores) {
|
2017-05-31 14:42:42 +00:00
|
|
|
MISMATCH(_("Target CPU cores %d does not match source %d"),
|
|
|
|
dst->cores, src->cores);
|
2020-01-06 21:57:26 +00:00
|
|
|
return false;
|
2011-05-27 09:47:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (src->threads != dst->threads) {
|
2017-05-31 14:42:42 +00:00
|
|
|
MISMATCH(_("Target CPU threads %d does not match source %d"),
|
|
|
|
dst->threads, src->threads);
|
2020-01-06 21:57:26 +00:00
|
|
|
return false;
|
2011-05-27 09:47:30 +00:00
|
|
|
}
|
|
|
|
|
2022-07-29 19:34:33 +00:00
|
|
|
if ((src->addr && !dst->addr) ||
|
|
|
|
(!src->addr && dst->addr) ||
|
|
|
|
(src->addr && dst->addr &&
|
|
|
|
(src->addr->mode != dst->addr->mode ||
|
|
|
|
src->addr->bits != dst->addr->bits))) {
|
|
|
|
MISMATCH("%s", _("Target CPU maxphysaddr does not match source"));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-05-27 09:47:30 +00:00
|
|
|
if (src->nfeatures != dst->nfeatures) {
|
2017-05-31 14:42:42 +00:00
|
|
|
MISMATCH(_("Target CPU feature count %zu does not match source %zu"),
|
|
|
|
dst->nfeatures, src->nfeatures);
|
2020-01-06 21:57:26 +00:00
|
|
|
return false;
|
2011-05-27 09:47:30 +00:00
|
|
|
}
|
|
|
|
|
2013-05-21 07:21:17 +00:00
|
|
|
for (i = 0; i < src->nfeatures; i++) {
|
2011-05-27 09:47:30 +00:00
|
|
|
if (STRNEQ(src->features[i].name, dst->features[i].name)) {
|
2017-05-31 14:42:42 +00:00
|
|
|
MISMATCH(_("Target CPU feature %s does not match source %s"),
|
|
|
|
dst->features[i].name, src->features[i].name);
|
2020-01-06 21:57:26 +00:00
|
|
|
return false;
|
2011-05-27 09:47:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (src->features[i].policy != dst->features[i].policy) {
|
2017-05-31 14:42:42 +00:00
|
|
|
MISMATCH(_("Target CPU feature policy %s does not match source %s"),
|
|
|
|
virCPUFeaturePolicyTypeToString(dst->features[i].policy),
|
|
|
|
virCPUFeaturePolicyTypeToString(src->features[i].policy));
|
2020-01-06 21:57:26 +00:00
|
|
|
return false;
|
2011-05-27 09:47:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-09 14:03:19 +00:00
|
|
|
if ((src->cache && !dst->cache) ||
|
|
|
|
(!src->cache && dst->cache) ||
|
|
|
|
(src->cache && dst->cache &&
|
|
|
|
(src->cache->level != dst->cache->level ||
|
|
|
|
src->cache->mode != dst->cache->mode))) {
|
2017-05-31 14:42:42 +00:00
|
|
|
MISMATCH("%s", _("Target CPU cache does not match source"));
|
2020-01-06 21:57:26 +00:00
|
|
|
return false;
|
2017-05-09 14:03:19 +00:00
|
|
|
}
|
|
|
|
|
2017-05-31 14:42:42 +00:00
|
|
|
#undef MISMATCH
|
|
|
|
|
2020-01-06 21:57:26 +00:00
|
|
|
return true;
|
2011-05-27 09:47:30 +00:00
|
|
|
}
|
2017-09-13 13:23:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Parses a list of CPU XMLs into a NULL-terminated list of CPU defs.
|
|
|
|
*/
|
2021-03-11 07:16:13 +00:00
|
|
|
virCPUDef **
|
2017-09-13 13:23:43 +00:00
|
|
|
virCPUDefListParse(const char **xmlCPUs,
|
|
|
|
unsigned int ncpus,
|
|
|
|
virCPUType cpuType)
|
|
|
|
{
|
2021-03-11 07:16:13 +00:00
|
|
|
virCPUDef **cpus = NULL;
|
2017-09-13 13:23:43 +00:00
|
|
|
size_t i;
|
|
|
|
|
|
|
|
VIR_DEBUG("xmlCPUs=%p, ncpus=%u", xmlCPUs, ncpus);
|
|
|
|
|
|
|
|
if (xmlCPUs) {
|
|
|
|
for (i = 0; i < ncpus; i++)
|
|
|
|
VIR_DEBUG("xmlCPUs[%zu]=%s", i, NULLSTR(xmlCPUs[i]));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!xmlCPUs && ncpus != 0) {
|
|
|
|
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("nonzero ncpus doesn't match with NULL xmlCPUs"));
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ncpus == 0) {
|
|
|
|
virReportError(VIR_ERR_INVALID_ARG, "%s", _("no CPUs given"));
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2021-03-11 07:16:13 +00:00
|
|
|
cpus = g_new0(virCPUDef *, ncpus + 1);
|
2017-09-13 13:23:43 +00:00
|
|
|
|
|
|
|
for (i = 0; i < ncpus; i++) {
|
2021-08-11 11:31:32 +00:00
|
|
|
g_autoptr(xmlDoc) doc = NULL;
|
|
|
|
g_autoptr(xmlXPathContext) ctxt = NULL;
|
|
|
|
|
2017-09-13 13:23:43 +00:00
|
|
|
if (!(doc = virXMLParseStringCtxt(xmlCPUs[i], _("(CPU_definition)"), &ctxt)))
|
|
|
|
goto error;
|
|
|
|
|
2020-10-07 08:54:55 +00:00
|
|
|
if (virCPUDefParseXML(ctxt, NULL, cpuType, &cpus[i], false) < 0)
|
2017-09-13 13:23:43 +00:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
return cpus;
|
|
|
|
|
|
|
|
error:
|
|
|
|
virCPUDefListFree(cpus);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Frees NULL-terminated list of CPUs created by virCPUDefListParse.
|
|
|
|
*/
|
|
|
|
void
|
2021-03-11 07:16:13 +00:00
|
|
|
virCPUDefListFree(virCPUDef **cpus)
|
2017-09-13 13:23:43 +00:00
|
|
|
{
|
2021-03-11 07:16:13 +00:00
|
|
|
virCPUDef **cpu;
|
2017-09-13 13:23:43 +00:00
|
|
|
|
|
|
|
if (!cpus)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (cpu = cpus; *cpu != NULL; cpu++)
|
|
|
|
virCPUDefFree(*cpu);
|
|
|
|
|
2021-01-30 19:05:50 +00:00
|
|
|
g_free(cpus);
|
2017-09-13 13:23:43 +00:00
|
|
|
}
|