From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49297) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VdAxu-0005DT-GF for qemu-devel@nongnu.org; Sun, 03 Nov 2013 22:36:41 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VdAxl-0000XF-Kt for qemu-devel@nongnu.org; Sun, 03 Nov 2013 22:36:34 -0500 Received: from e23smtp06.au.ibm.com ([202.81.31.148]:39902) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VdAxl-0000St-08 for qemu-devel@nongnu.org; Sun, 03 Nov 2013 22:36:25 -0500 Received: from /spool/local by e23smtp06.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 4 Nov 2013 13:36:16 +1000 From: Alexey Kardashevskiy Date: Mon, 4 Nov 2013 14:36:06 +1100 Message-Id: <1383536166-8673-1-git-send-email-aik@ozlabs.ru> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Subject: [Qemu-devel] [PATCH] RFC: powerpc: add PVR compatibility check List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Alexey Kardashevskiy , qemu-ppc@nongnu.org, Alexander Graf , Anthony Liguori , =?UTF-8?q?Andreas=20F=C3=A4rber?= 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 Signed-off-by: Alexey Kardashevskiy --- 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