From: Nikolay Shirokovskiy Date: Wed, 11 Apr 2018 08:57:32 +0000 (+0300) Subject: qemu: cpu: fix "full" CPU to include all "reported" CPU features X-Git-Tag: v4.3.0-rc1~176 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=49fb4769e12256c44996be68e279a096332bcd1f;p=thirdparty%2Flibvirt.git qemu: cpu: fix "full" CPU to include all "reported" CPU features On Core i5 650 x86_64 kvm guest fail to start with error [1] for next cpu config: The problem is in full CPU calculation in virQEMUCapsInitHostCPUModel. It is supposed to include features emulated by qemu and missed on host. Some of such features may be not included however. For Core i5 650 host CPU is detected as Westmere and reported CPU as SandyBridge. x2apic is missed on host and provided by installed qemu. The feature is not mentioned in reported CPU features explicitly because SandyBridge model include it. As a result full CPU does not include x2apic too. Solution is to expand guest cpu features before updating fullCPU features. [1] error: the CPU is incompatible with host CPU: \ Host CPU does not provide required features: x2apic Signed-off-by: Nikolay Shirokovskiy Reviewed-by: Jiri Denemark --- diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index 5e78336baa..42248dd19a 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -2702,6 +2702,7 @@ virQEMUCapsInitHostCPUModel(virQEMUCapsPtr qemuCaps, virDomainVirtType type) { virCPUDefPtr cpu = NULL; + virCPUDefPtr cpuExpanded = NULL; virCPUDefPtr migCPU = NULL; virCPUDefPtr hostCPU = NULL; virCPUDefPtr fullCPU = NULL; @@ -2736,9 +2737,13 @@ virQEMUCapsInitHostCPUModel(virQEMUCapsPtr qemuCaps, NULL, NULL))) goto error; - for (i = 0; i < cpu->nfeatures; i++) { - if (cpu->features[i].policy == VIR_CPU_FEATURE_REQUIRE && - virCPUDefUpdateFeature(fullCPU, cpu->features[i].name, + if (!(cpuExpanded = virCPUDefCopy(cpu)) || + virCPUExpandFeatures(qemuCaps->arch, cpuExpanded) < 0) + goto error; + + for (i = 0; i < cpuExpanded->nfeatures; i++) { + if (cpuExpanded->features[i].policy == VIR_CPU_FEATURE_REQUIRE && + virCPUDefUpdateFeature(fullCPU, cpuExpanded->features[i].name, VIR_CPU_FEATURE_REQUIRE) < 0) goto error; } @@ -2760,6 +2765,7 @@ virQEMUCapsInitHostCPUModel(virQEMUCapsPtr qemuCaps, virQEMUCapsSetHostModel(qemuCaps, type, cpu, migCPU, fullCPU); cleanup: + virCPUDefFree(cpuExpanded); virCPUDefFree(hostCPU); return;