1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-03-07 17:28:15 +00:00

qemu: Fix segfault when host CPU is empty

In case libvirtd cannot detect host CPU model (which may happen if it
runs inside a virtual machine), the daemon is likely to segfault when
starting a new qemu domain. It segfaults when domain XML asks for host
(either model or passthrough) CPU or does not ask for any specific CPU
model at all.
This commit is contained in:
Jiri Denemark 2012-02-15 12:18:25 +01:00
parent 286088567d
commit 2ccc4a607f

View File

@ -3509,22 +3509,13 @@ qemuBuildCpuArgStr(const struct qemud_driver *driver,
*hasHwVirt = false; *hasHwVirt = false;
if (def->cpu &&
(def->cpu->mode != VIR_CPU_MODE_CUSTOM || def->cpu->model)) {
if (!(cpu = virCPUDefCopy(def->cpu)))
goto cleanup;
if (cpu->mode != VIR_CPU_MODE_CUSTOM &&
!migrating &&
cpuUpdate(cpu, host) < 0)
goto cleanup;
}
if (STREQ(def->os.arch, "i686")) if (STREQ(def->os.arch, "i686"))
default_model = "qemu32"; default_model = "qemu32";
else else
default_model = "qemu64"; default_model = "qemu64";
if (cpu) { if (def->cpu &&
(def->cpu->mode != VIR_CPU_MODE_CUSTOM || def->cpu->model)) {
virCPUCompareResult cmp; virCPUCompareResult cmp;
const char *preferred; const char *preferred;
int hasSVM; int hasSVM;
@ -3540,6 +3531,14 @@ qemuBuildCpuArgStr(const struct qemud_driver *driver,
goto cleanup; goto cleanup;
} }
if (!(cpu = virCPUDefCopy(def->cpu)))
goto cleanup;
if (cpu->mode != VIR_CPU_MODE_CUSTOM &&
!migrating &&
cpuUpdate(cpu, host) < 0)
goto cleanup;
cmp = cpuGuestData(host, cpu, &data); cmp = cpuGuestData(host, cpu, &data);
switch (cmp) { switch (cmp) {
case VIR_CPU_COMPARE_INCOMPATIBLE: case VIR_CPU_COMPARE_INCOMPATIBLE:
@ -3648,6 +3647,7 @@ qemuBuildCpuArgStr(const struct qemud_driver *driver,
ret = 0; ret = 0;
cleanup: cleanup:
if (host)
cpuDataFree(host->arch, data); cpuDataFree(host->arch, data);
virCPUDefFree(guest); virCPUDefFree(guest);
virCPUDefFree(cpu); virCPUDefFree(cpu);