cpu: Add optional list of allowed features to virCPUBaseline

When computing a baseline CPU for a specific hypervisor we have to make
sure to include only CPU features supported by the hypervisor. Otherwise
the computed CPU could not be used for starting a new domain.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Collin Walling <walling@linux.ibm.com>
This commit is contained in:
Jiri Denemark 2018-05-15 11:57:35 +02:00
parent f277fb39b7
commit 7fb950958a
11 changed files with 33 additions and 9 deletions

View File

@ -1398,7 +1398,7 @@ bhyveConnectBaselineCPU(virConnectPtr conn,
if (!(cpus = virCPUDefListParse(xmlCPUs, ncpus, VIR_CPU_TYPE_HOST))) if (!(cpus = virCPUDefListParse(xmlCPUs, ncpus, VIR_CPU_TYPE_HOST)))
goto cleanup; goto cleanup;
if (!(cpu = virCPUBaseline(VIR_ARCH_NONE, cpus, ncpus, NULL, if (!(cpu = virCPUBaseline(VIR_ARCH_NONE, cpus, ncpus, NULL, NULL,
!!(flags & VIR_CONNECT_BASELINE_CPU_MIGRATABLE)))) !!(flags & VIR_CONNECT_BASELINE_CPU_MIGRATABLE))))
goto cleanup; goto cleanup;

View File

@ -485,6 +485,7 @@ virCPUProbeHost(virArch arch)
* @cpus: list of host CPU definitions * @cpus: list of host CPU definitions
* @ncpus: number of CPUs in @cpus * @ncpus: number of CPUs in @cpus
* @models: list of CPU models that can be considered for the baseline CPU * @models: list of CPU models that can be considered for the baseline CPU
* @features: optional NULL terminated list of allowed features
* @migratable: requests non-migratable features to be removed from the result * @migratable: requests non-migratable features to be removed from the result
* *
* Computes the most feature-rich CPU which is compatible with all given * Computes the most feature-rich CPU which is compatible with all given
@ -499,13 +500,14 @@ virCPUBaseline(virArch arch,
virCPUDefPtr *cpus, virCPUDefPtr *cpus,
unsigned int ncpus, unsigned int ncpus,
virDomainCapsCPUModelsPtr models, virDomainCapsCPUModelsPtr models,
const char **features,
bool migratable) bool migratable)
{ {
struct cpuArchDriver *driver; struct cpuArchDriver *driver;
size_t i; size_t i;
VIR_DEBUG("arch=%s, ncpus=%u, models=%p, migratable=%d", VIR_DEBUG("arch=%s, ncpus=%u, models=%p, features=%p, migratable=%d",
virArchToString(arch), ncpus, models, migratable); virArchToString(arch), ncpus, models, features, migratable);
if (cpus) { if (cpus) {
for (i = 0; i < ncpus; i++) for (i = 0; i < ncpus; i++)
VIR_DEBUG("cpus[%zu]=%p", i, cpus[i]); VIR_DEBUG("cpus[%zu]=%p", i, cpus[i]);
@ -552,7 +554,7 @@ virCPUBaseline(virArch arch,
return NULL; return NULL;
} }
return driver->baseline(cpus, ncpus, models, migratable); return driver->baseline(cpus, ncpus, models, features, migratable);
} }

View File

@ -76,6 +76,7 @@ typedef virCPUDefPtr
(*virCPUArchBaseline)(virCPUDefPtr *cpus, (*virCPUArchBaseline)(virCPUDefPtr *cpus,
unsigned int ncpus, unsigned int ncpus,
virDomainCapsCPUModelsPtr models, virDomainCapsCPUModelsPtr models,
const char **features,
bool migratable); bool migratable);
typedef int typedef int
@ -198,6 +199,7 @@ virCPUBaseline(virArch arch,
virCPUDefPtr *cpus, virCPUDefPtr *cpus,
unsigned int ncpus, unsigned int ncpus,
virDomainCapsCPUModelsPtr models, virDomainCapsCPUModelsPtr models,
const char **features,
bool migratable); bool migratable);
int int

View File

@ -76,6 +76,7 @@ static virCPUDefPtr
virCPUarmBaseline(virCPUDefPtr *cpus, virCPUarmBaseline(virCPUDefPtr *cpus,
unsigned int ncpus ATTRIBUTE_UNUSED, unsigned int ncpus ATTRIBUTE_UNUSED,
virDomainCapsCPUModelsPtr models ATTRIBUTE_UNUSED, virDomainCapsCPUModelsPtr models ATTRIBUTE_UNUSED,
const char **features ATTRIBUTE_UNUSED,
bool migratable ATTRIBUTE_UNUSED) bool migratable ATTRIBUTE_UNUSED)
{ {
virCPUDefPtr cpu = NULL; virCPUDefPtr cpu = NULL;

View File

@ -770,6 +770,7 @@ static virCPUDefPtr
virCPUppc64Baseline(virCPUDefPtr *cpus, virCPUppc64Baseline(virCPUDefPtr *cpus,
unsigned int ncpus, unsigned int ncpus,
virDomainCapsCPUModelsPtr models ATTRIBUTE_UNUSED, virDomainCapsCPUModelsPtr models ATTRIBUTE_UNUSED,
const char **features ATTRIBUTE_UNUSED,
bool migratable ATTRIBUTE_UNUSED) bool migratable ATTRIBUTE_UNUSED)
{ {
struct ppc64_map *map; struct ppc64_map *map;

View File

@ -2467,6 +2467,7 @@ static virCPUDefPtr
virCPUx86Baseline(virCPUDefPtr *cpus, virCPUx86Baseline(virCPUDefPtr *cpus,
unsigned int ncpus, unsigned int ncpus,
virDomainCapsCPUModelsPtr models, virDomainCapsCPUModelsPtr models,
const char **features,
bool migratable) bool migratable)
{ {
virCPUx86MapPtr map = NULL; virCPUx86MapPtr map = NULL;
@ -2478,6 +2479,7 @@ virCPUx86Baseline(virCPUDefPtr *cpus,
bool outputVendor = true; bool outputVendor = true;
const char *modelName; const char *modelName;
bool matchingNames = true; bool matchingNames = true;
virCPUDataPtr featData = NULL;
if (!(map = virCPUx86GetMap())) if (!(map = virCPUx86GetMap()))
goto error; goto error;
@ -2550,6 +2552,21 @@ virCPUx86Baseline(virCPUDefPtr *cpus,
model = NULL; model = NULL;
} }
if (features) {
virCPUx86FeaturePtr feat;
if (!(featData = virCPUDataNew(archs[0])))
goto cleanup;
for (i = 0; features[i]; i++) {
if ((feat = x86FeatureFind(map, features[i])) &&
x86DataAdd(&featData->data.x86, &feat->data) < 0)
goto cleanup;
}
x86DataIntersect(&base_model->data, &featData->data.x86);
}
if (x86DataIsEmpty(&base_model->data)) { if (x86DataIsEmpty(&base_model->data)) {
virReportError(VIR_ERR_OPERATION_FAILED, virReportError(VIR_ERR_OPERATION_FAILED,
"%s", _("CPUs are incompatible")); "%s", _("CPUs are incompatible"));
@ -2571,6 +2588,7 @@ virCPUx86Baseline(virCPUDefPtr *cpus,
cleanup: cleanup:
x86ModelFree(base_model); x86ModelFree(base_model);
virCPUx86DataFree(featData);
return cpu; return cpu;

View File

@ -6349,7 +6349,7 @@ libxlConnectBaselineCPU(virConnectPtr conn,
if (!(cpus = virCPUDefListParse(xmlCPUs, ncpus, VIR_CPU_TYPE_HOST))) if (!(cpus = virCPUDefListParse(xmlCPUs, ncpus, VIR_CPU_TYPE_HOST)))
goto cleanup; goto cleanup;
if (!(cpu = virCPUBaseline(VIR_ARCH_NONE, cpus, ncpus, NULL, if (!(cpu = virCPUBaseline(VIR_ARCH_NONE, cpus, ncpus, NULL, NULL,
!!(flags & VIR_CONNECT_BASELINE_CPU_MIGRATABLE)))) !!(flags & VIR_CONNECT_BASELINE_CPU_MIGRATABLE))))
goto cleanup; goto cleanup;

View File

@ -13315,7 +13315,7 @@ qemuConnectBaselineCPU(virConnectPtr conn ATTRIBUTE_UNUSED,
if (!(cpus = virCPUDefListParse(xmlCPUs, ncpus, VIR_CPU_TYPE_HOST))) if (!(cpus = virCPUDefListParse(xmlCPUs, ncpus, VIR_CPU_TYPE_HOST)))
goto cleanup; goto cleanup;
if (!(baseline = virCPUBaseline(VIR_ARCH_NONE, cpus, ncpus, NULL, if (!(baseline = virCPUBaseline(VIR_ARCH_NONE, cpus, ncpus, NULL, NULL,
!!(flags & VIR_CONNECT_BASELINE_CPU_MIGRATABLE)))) !!(flags & VIR_CONNECT_BASELINE_CPU_MIGRATABLE))))
goto cleanup; goto cleanup;

View File

@ -1541,7 +1541,7 @@ testConnectBaselineCPU(virConnectPtr conn ATTRIBUTE_UNUSED,
if (!(cpus = virCPUDefListParse(xmlCPUs, ncpus, VIR_CPU_TYPE_HOST))) if (!(cpus = virCPUDefListParse(xmlCPUs, ncpus, VIR_CPU_TYPE_HOST)))
goto cleanup; goto cleanup;
if (!(cpu = virCPUBaseline(VIR_ARCH_NONE, cpus, ncpus, NULL, false))) if (!(cpu = virCPUBaseline(VIR_ARCH_NONE, cpus, ncpus, NULL, NULL, false)))
goto cleanup; goto cleanup;
if ((flags & VIR_CONNECT_BASELINE_CPU_EXPAND_FEATURES) && if ((flags & VIR_CONNECT_BASELINE_CPU_EXPAND_FEATURES) &&

View File

@ -934,7 +934,7 @@ vzConnectBaselineCPU(virConnectPtr conn,
if (!(cpus = virCPUDefListParse(xmlCPUs, ncpus, VIR_CPU_TYPE_HOST))) if (!(cpus = virCPUDefListParse(xmlCPUs, ncpus, VIR_CPU_TYPE_HOST)))
goto cleanup; goto cleanup;
if (!(cpu = virCPUBaseline(VIR_ARCH_NONE, cpus, ncpus, NULL, false))) if (!(cpu = virCPUBaseline(VIR_ARCH_NONE, cpus, ncpus, NULL, NULL, false)))
goto cleanup; goto cleanup;
if ((flags & VIR_CONNECT_BASELINE_CPU_EXPAND_FEATURES) && if ((flags & VIR_CONNECT_BASELINE_CPU_EXPAND_FEATURES) &&

View File

@ -321,7 +321,7 @@ cpuTestBaseline(const void *arg)
if (!(cpus = cpuTestLoadMultiXML(data->arch, data->name, &ncpus))) if (!(cpus = cpuTestLoadMultiXML(data->arch, data->name, &ncpus)))
goto cleanup; goto cleanup;
baseline = virCPUBaseline(data->arch, cpus, ncpus, NULL, baseline = virCPUBaseline(data->arch, cpus, ncpus, NULL, NULL,
!!(data->flags & VIR_CONNECT_BASELINE_CPU_MIGRATABLE)); !!(data->flags & VIR_CONNECT_BASELINE_CPU_MIGRATABLE));
if (baseline && if (baseline &&