qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Alexey Kardashevskiy <aik@ozlabs.ru>
To: qemu-devel@nongnu.org
Cc: "Alexey Kardashevskiy" <aik@ozlabs.ru>,
	qemu-ppc@nongnu.org, "Alexander Graf" <agraf@suse.de>,
	"Anthony Liguori" <anthony@codemonkey.ws>,
	"Andreas Färber" <afaerber@suse.de>
Subject: [Qemu-devel] [PATCH] RFC: powerpc: add PVR compatibility check
Date: Mon,  4 Nov 2013 14:36:06 +1100	[thread overview]
Message-ID: <1383536166-8673-1-git-send-email-aik@ozlabs.ru> (raw)

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 <afaerber@suse.de>
Signed-off-by: Alexey Kardashevskiy <aik@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

             reply	other threads:[~2013-11-04  3:36 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-11-04  3:36 Alexey Kardashevskiy [this message]
2013-11-04  7:47 ` [Qemu-devel] [PATCH] RFC: powerpc: add PVR compatibility check Alexander Graf
2013-11-04  8:58   ` Alexey Kardashevskiy
2013-11-04  9:05     ` Alexander Graf
2013-11-04  9:24       ` Alexey Kardashevskiy
2013-11-04  9:29         ` Alexander Graf
2013-11-05  4:00       ` Paul Mackerras
2013-11-05  6:05         ` Alexander Graf
2013-11-05 16:16           ` Andreas Färber
2013-11-05 16:18             ` Alexander Graf
2013-11-06  3:02             ` Paul Mackerras
2013-11-06 12:19               ` Alexander Graf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1383536166-8673-1-git-send-email-aik@ozlabs.ru \
    --to=aik@ozlabs.ru \
    --cc=afaerber@suse.de \
    --cc=agraf@suse.de \
    --cc=anthony@codemonkey.ws \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-ppc@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).