If QEMU is started with KVM enabled and -cpu specified, and the CPU is not from the family which the host is running on, an error should be displayed so this the patch does.
Cc: Andreas Färber <afaer...@suse.de> Signed-off-by: Alexey Kardashevskiy <a...@ozlabs.ru> --- Is that correct to assume that the closest abstract class is a CPU family? It is most likely true but I want to double check :) Is there any nicer way of doing what the patch does? Thanks. --- target-ppc/translate_init.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/target-ppc/translate_init.c b/target-ppc/translate_init.c index 3d3952c..6888214 100644 --- a/target-ppc/translate_init.c +++ b/target-ppc/translate_init.c @@ -8314,6 +8314,14 @@ static ObjectClass *ppc_cpu_class_by_name(const char *name) return ret; } +ObjectClass *object_class_get_abstract_parent(ObjectClass *class) +{ + while (class && !object_class_is_abstract(class)) { + class = object_class_get_parent(class); + } + return class; +} + PowerPCCPU *cpu_ppc_init(const char *cpu_model) { PowerPCCPU *cpu; @@ -8325,6 +8333,26 @@ PowerPCCPU *cpu_ppc_init(const char *cpu_model) return NULL; } + /* + * Make sure that if we run with a specific CPU in the command line when + * KVM is enabled, it still from the same CPU family as the host CPU + * because if they are not, the compatibility mode should be used. + */ + if (strcmp(object_class_get_name(oc), TYPE_HOST_POWERPC_CPU)) { + ObjectClass *oc_host = object_class_by_name(TYPE_HOST_POWERPC_CPU); + ObjectClass *ocp = object_class_get_abstract_parent(oc); + + if (oc_host) { + ObjectClass *ocp_host = object_class_get_abstract_parent(oc_host); + if (ocp != ocp_host) { + error_report("The chosen CPU \"%s\" is incompatible with the host CPU \"%s\"", + object_class_get_name(oc), + object_class_get_name(ocp_host)); + return NULL; + } + } + } + cpu = POWERPC_CPU(object_new(object_class_get_name(oc))); object_property_set_bool(OBJECT(cpu), true, "realized", &err); -- 1.8.4.rc4