From 768ecdcd4b189cfe1d86a50bc1730f3948379f6f Mon Sep 17 00:00:00 2001 From: Jiri Denemark Date: Tue, 25 Feb 2020 16:05:06 +0100 Subject: [PATCH] qemu: Do not set default CPU for archs without CPU driver MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Whenever there is a guest CPU configured in domain XML, we will call some CPU driver APIs to validate the CPU definition and check its compatibility with the hypervisor. Thus domains with guest CPU specification can only be started if the guest architecture is supported by the CPU driver. But we would add a default CPU to any domain as long as QEMU reports it causing failures to start any domain on affected architectures. https://bugzilla.redhat.com/show_bug.cgi?id=1805755 Signed-off-by: Jiri Denemark Reviewed-by: Daniel P. Berrangé --- src/cpu/cpu.c | 24 ++++++++++++++++++++++++ src/cpu/cpu.h | 3 +++ src/libvirt_private.syms | 1 + src/qemu/qemu_domain.c | 3 +++ 4 files changed, 31 insertions(+) diff --git a/src/cpu/cpu.c b/src/cpu/cpu.c index ae3a0acc10..6d6191fe4e 100644 --- a/src/cpu/cpu.c +++ b/src/cpu/cpu.c @@ -1096,3 +1096,27 @@ virCPUDataAddFeature(virCPUDataPtr cpuData, return driver->dataAddFeature(cpuData, name); } + + +/** + * virCPUArchIsSupported: + * + * @arch: CPU architecture + * + * Returns true if the architecture is supported by any CPU driver. + */ +bool +virCPUArchIsSupported(virArch arch) +{ + size_t i; + size_t j; + + for (i = 0; i < G_N_ELEMENTS(drivers); i++) { + for (j = 0; j < drivers[i]->narch; j++) { + if (arch == drivers[i]->arch[j]) + return true; + } + } + + return false; +} diff --git a/src/cpu/cpu.h b/src/cpu/cpu.h index 2e8b8923ae..f779d2be17 100644 --- a/src/cpu/cpu.h +++ b/src/cpu/cpu.h @@ -265,6 +265,9 @@ int virCPUDataAddFeature(virCPUDataPtr cpuData, const char *name); +bool +virCPUArchIsSupported(virArch arch); + /* virCPUDataFormat and virCPUDataParse are implemented for unit tests only and * have no real-life usage */ diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 3fc8d7de3f..de0c7a3133 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1310,6 +1310,7 @@ virStoragePoolObjVolumeListExport; # cpu/cpu.h cpuDecode; cpuEncode; +virCPUArchIsSupported; virCPUBaseline; virCPUCheckFeature; virCPUCompare; diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index a28b51c10e..3dfa71650d 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -4576,6 +4576,9 @@ qemuDomainDefSetDefaultCPU(virDomainDefPtr def, def->cpu->model)) return 0; + if (!virCPUArchIsSupported(def->os.arch)) + return 0; + /* Default CPU model info from QEMU is usable for TCG only except for * x86, s390, and ppc64. */ if (!ARCH_IS_X86(def->os.arch) &&