Skip to contentSkip to conversation

target-ppc: Relax use of generic CPU name for KVM

PATCH New Alexey Kardashevskiy 1 participant 4 messages Apr 11, 2014

lore
Share & tools
lore
#0 lore raw

v2 cover target-ppc: Relax use of generic CPU name for KVM

This enables generic CPU family name use with "-cpu" for all CPUs across the family and not for the ones already defined in QEMU.

Changes:
v2:
* split one patch into 3
* added assert into ppc_cpu_get_family_class()

Alexey Kardashevskiy (3):
target-ppc: Create versionless CPU class per family if KVM
target-ppc: Move alias lookup after class lookup
target-ppc: Remove redundant POWER7 declarations

 target-ppc/cpu-models.c     |  4 ----
 target-ppc/cpu-models.h     |  2 --
 target-ppc/kvm.c            | 21 +++++++++++++++++++++
 target-ppc/translate_init.c | 18 +++++++++++-------
 4 files changed, 32 insertions(+), 13 deletions(-)
Signature · 1 line
1.8.4.rc4
#1 lore raw

PATCH v2 1/3 target-ppc: Create versionless CPU class per family if KVM

At the moment generic version-less CPUs are supported via hardcoded aliases. For example, POWER7 is an alias for POWER7_v2.1. So when QEMU is started with -cpu POWER7, the POWER7_v2.1 class instance is created.

This approach works for TCG and KVMs other than HV KVM. HV KVM cannot emulate PVR value so the guest always sees the real PVR. HV KVM will not allow setting PVR other that the host PVR because of that (the kernel patch for it is on its way). So in most cases it is impossible to run QEMU with -cpu POWER7 unless the host PVR is exactly the same as the one from the alias (which is now POWER7_v2.3). It was decided that under HV KVM QEMU should use -cpu host.

Using "host" CPU type creates a problem for management tools such as libvirt because they want to know in advance if the destination guest can possibly run on the destination. Since the "host" type is really not a type and will always work with any KVM, there is no way for libvirt to know if the migration will success.

This registers additional CPU class derived from the host CPU family. The name for it is taken from @desc field of the CPU family class.

---
 target-ppc/kvm.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
target-ppc/kvm.c +21 -0
index 8083ba9..cc4b26c 100644
@@ -1778,6 +1778,18 @@ bool kvmppc_has_cap_htab_fd(void)
     return cap_htab_fd;
 }
 
+static PowerPCCPUClass *ppc_cpu_get_family_class(PowerPCCPUClass *pcc)
+{
+    ObjectClass *oc = OBJECT_CLASS(pcc);
+
+    while (oc && !object_class_is_abstract(oc)) {
+        oc = object_class_get_parent(oc);
+    }
+    assert(oc);
+
+    return POWERPC_CPU_CLASS(oc);
+}
+
 static int kvm_ppc_register_host_cpu_type(void)
 {
     TypeInfo type_info = {
@@ -1787,6 +1799,7 @@ static int kvm_ppc_register_host_cpu_type(void)
     };
     uint32_t host_pvr = mfpvr();
     PowerPCCPUClass *pvr_pcc;
+    DeviceClass *dc;
 
     pvr_pcc = ppc_cpu_class_by_pvr(host_pvr);
     if (pvr_pcc == NULL) {
@@ -1797,6 +1810,14 @@ static int kvm_ppc_register_host_cpu_type(void)
     }
     type_info.parent = object_class_get_name(OBJECT_CLASS(pvr_pcc));
     type_register(&type_info);
+
+    /* Register generic family CPU class for a family */
+    pvr_pcc = ppc_cpu_get_family_class(pvr_pcc);
+    dc = DEVICE_CLASS(pvr_pcc);
+    type_info.parent = object_class_get_name(OBJECT_CLASS(pvr_pcc));
+    type_info.name = g_strdup_printf("%s-"TYPE_POWERPC_CPU, dc->desc);
+    type_register(&type_info);
+
     return 0;
 }
 
Signature · 1 line
1.8.4.rc4
#2 lore raw

PATCH v2 2/3 target-ppc: Move alias lookup after class lookup

In reply to Alexey Kardashevskiy

This moves aliases lookup after CPU class lookup. This is to let new generic CPU to be found first if it is present and only if it is not (TCG case), use aliases.

---
 target-ppc/translate_init.c | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)
target-ppc/translate_init.c +11 -7
index c7afa62..709094c 100644
@@ -8228,12 +8228,6 @@ static ObjectClass *ppc_cpu_class_by_name(const char *name)
         }
     }
 
-    for (i = 0; ppc_cpu_aliases[i].alias != NULL; i++) {
-        if (strcmp(ppc_cpu_aliases[i].alias, name) == 0) {
-            return ppc_cpu_class_by_alias(&ppc_cpu_aliases[i]);
-        }
-    }
-
     list = object_class_get_list(TYPE_POWERPC_CPU, false);
     item = g_slist_find_custom(list, name, ppc_cpu_compare_class_name);
     if (item != NULL) {
@@ -8241,7 +8235,17 @@ static ObjectClass *ppc_cpu_class_by_name(const char *name)
     }
     g_slist_free(list);
 
-    return ret;
+    if (ret) {
+        return ret;
+    }
+
+    for (i = 0; ppc_cpu_aliases[i].alias != NULL; i++) {
+        if (strcmp(ppc_cpu_aliases[i].alias, name) == 0) {
+            return ppc_cpu_class_by_alias(&ppc_cpu_aliases[i]);
+        }
+    }
+
+    return NULL;
 }
 
 PowerPCCPU *cpu_ppc_init(const char *cpu_model)
Signature · 1 line
1.8.4.rc4
#3 lore raw

PATCH v2 3/3 target-ppc: Remove redundant POWER7 declarations

In reply to Alexey Kardashevskiy

At the moment there are 3 versions of POWER7 CPUs defined. However we do not emulate these CPUs diffent and it does not make much sense to keep them all.

This removes POWER7_v2.0 and POWER7_v2.1 and leaves just one versioned CPU per family which is POWER7_v2.3 with POWER7 alias.

---
 target-ppc/cpu-models.c | 4 ----
 target-ppc/cpu-models.h | 2 --
 2 files changed, 6 deletions(-)
target-ppc/cpu-models.c +0 -4
index f6c9b3a..57cb4e4 100644
@@ -1134,10 +1134,6 @@
     POWERPC_DEF("POWER6A",       CPU_POWERPC_POWER6A,                POWER6,
                 "POWER6A")
 #endif
-    POWERPC_DEF("POWER7_v2.0",   CPU_POWERPC_POWER7_v20,             POWER7,
-                "POWER7 v2.0")
-    POWERPC_DEF("POWER7_v2.1",   CPU_POWERPC_POWER7_v21,             POWER7,
-                "POWER7 v2.1")
     POWERPC_DEF("POWER7_v2.3",   CPU_POWERPC_POWER7_v23,             POWER7,
                 "POWER7 v2.3")
     POWERPC_DEF("POWER7+_v2.1",  CPU_POWERPC_POWER7P_v21,            POWER7P,
target-ppc/cpu-models.h +0 -2
index 644a126..9a003b4 100644
@@ -555,8 +555,6 @@ enum {
     CPU_POWERPC_POWER6A            = 0x0F000002,
     CPU_POWERPC_POWER7_BASE        = 0x003F0000,
     CPU_POWERPC_POWER7_MASK        = 0xFFFF0000,
-    CPU_POWERPC_POWER7_v20         = 0x003F0200,
-    CPU_POWERPC_POWER7_v21         = 0x003F0201,
     CPU_POWERPC_POWER7_v23         = 0x003F0203,
     CPU_POWERPC_POWER7P_BASE       = 0x004A0000,
     CPU_POWERPC_POWER7P_MASK       = 0xFFFF0000,
Signature · 1 line
1.8.4.rc4