Blame SOURCES/kvm-target-ppc-Update-setting-of-cpu-features-to-account.patch

4a2fec
From ba38a0071969c6a428cf165e31ec0e91b7167af8 Mon Sep 17 00:00:00 2001
4a2fec
From: Suraj Jitindar Singh <sursingh@redhat.com>
4a2fec
Date: Fri, 24 Nov 2017 00:58:17 +0100
4a2fec
Subject: [PATCH 12/15] target/ppc: Update setting of cpu features to account
4a2fec
 for compat modes
4a2fec
4a2fec
RH-Author: Suraj Jitindar Singh <sursingh@redhat.com>
4a2fec
Message-id: <1511485097-25676-3-git-send-email-sursingh@redhat.com>
4a2fec
Patchwork-id: 77847
4a2fec
O-Subject: [RHEL7.5 qemu-kvm-rhev PATCH 2/2] target/ppc: Update setting of cpu features to account for compat modes
4a2fec
Bugzilla: 1396120
4a2fec
RH-Acked-by: David Gibson <dgibson@redhat.com>
4a2fec
RH-Acked-by: Laurent Vivier <lvivier@redhat.com>
4a2fec
RH-Acked-by: Thomas Huth <thuth@redhat.com>
4a2fec
4a2fec
From: Suraj Jitindar Singh <sjitindarsingh@gmail.com>
4a2fec
4a2fec
The device tree nodes ibm,arch-vec-5-platform-support and ibm,pa-features
4a2fec
are used to communicate features of the cpu to the guest operating
4a2fec
system. The properties of each of these are determined based on the
4a2fec
selected cpu model and the availability of hypervisor features.
4a2fec
Currently the compatibility mode of the cpu is not taken into account.
4a2fec
4a2fec
The ibm,arch-vec-5-platform-support node is used to communicate the
4a2fec
level of support for various ISAv3 processor features to the guest
4a2fec
before CAS to inform the guests' request. The available mmu mode should
4a2fec
only be hash unless the cpu is a POWER9 which is not in a prePOWER9
4a2fec
compat mode, in which case the available modes depend on the
4a2fec
accelerator and the hypervisor capabilities.
4a2fec
4a2fec
The ibm,pa-featues node is used to communicate the level of cpu support
4a2fec
for various features to the guest os. This should only contain features
4a2fec
relevant to the operating mode of the processor, that is the selected
4a2fec
cpu model taking into account any compat mode. This means that the
4a2fec
compat mode should be taken into account when choosing the properties of
4a2fec
ibm,pa-features and they should match the compat mode selected, or the
4a2fec
cpu model selected if no compat mode.
4a2fec
4a2fec
Update the setting of these cpu features in the device tree as described
4a2fec
above to properly take into account any compat mode. We use the
4a2fec
ppc_check_compat function which takes into account the current processor
4a2fec
model and the cpu compat mode.
4a2fec
4a2fec
Signed-off-by: Suraj Jitindar Singh <sjitindarsingh@gmail.com>
4a2fec
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
4a2fec
(cherry picked from commit 7abd43baec0649002d32bbb1380e936bec6f5867)
4a2fec
4a2fec
Signed-off-by: Suraj Jitindar Singh <sursingh@redhat.com>
4a2fec
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
4a2fec
---
4a2fec
 hw/ppc/spapr.c | 43 +++++++++++++++++++++----------------------
4a2fec
 1 file changed, 21 insertions(+), 22 deletions(-)
4a2fec
4a2fec
diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
4a2fec
index 42028ef..96df3a7 100644
4a2fec
--- a/hw/ppc/spapr.c
4a2fec
+++ b/hw/ppc/spapr.c
4a2fec
@@ -44,6 +44,7 @@
4a2fec
 #include "migration/register.h"
4a2fec
 #include "mmu-hash64.h"
4a2fec
 #include "mmu-book3s-v3.h"
4a2fec
+#include "cpu-models.h"
4a2fec
 #include "qom/cpu.h"
4a2fec
 
4a2fec
 #include "hw/boards.h"
4a2fec
@@ -252,9 +253,10 @@ static int spapr_fixup_cpu_numa_dt(void *fdt, int offset, PowerPCCPU *cpu)
4a2fec
 }
4a2fec
 
4a2fec
 /* Populate the "ibm,pa-features" property */
4a2fec
-static void spapr_populate_pa_features(CPUPPCState *env, void *fdt, int offset,
4a2fec
-                                      bool legacy_guest)
4a2fec
+static void spapr_populate_pa_features(PowerPCCPU *cpu, void *fdt, int offset,
4a2fec
+                                       bool legacy_guest)
4a2fec
 {
4a2fec
+    CPUPPCState *env = &cpu->env;
4a2fec
     uint8_t pa_features_206[] = { 6, 0,
4a2fec
         0xf6, 0x1f, 0xc7, 0x00, 0x80, 0xc0 };
4a2fec
     uint8_t pa_features_207[] = { 24, 0,
4a2fec
@@ -287,23 +289,22 @@ static void spapr_populate_pa_features(CPUPPCState *env, void *fdt, int offset,
4a2fec
         /* 60: NM atomic, 62: RNG */
4a2fec
         0x80, 0x00, 0x80, 0x00, 0x00, 0x00, /* 60 - 65 */
4a2fec
     };
4a2fec
-    uint8_t *pa_features;
4a2fec
+    uint8_t *pa_features = NULL;
4a2fec
     size_t pa_size;
4a2fec
 
4a2fec
-    switch (POWERPC_MMU_VER(env->mmu_model)) {
4a2fec
-    case POWERPC_MMU_VER_2_06:
4a2fec
+    if (ppc_check_compat(cpu, CPU_POWERPC_LOGICAL_2_06, 0, cpu->compat_pvr)) {
4a2fec
         pa_features = pa_features_206;
4a2fec
         pa_size = sizeof(pa_features_206);
4a2fec
-        break;
4a2fec
-    case POWERPC_MMU_VER_2_07:
4a2fec
+    }
4a2fec
+    if (ppc_check_compat(cpu, CPU_POWERPC_LOGICAL_2_07, 0, cpu->compat_pvr)) {
4a2fec
         pa_features = pa_features_207;
4a2fec
         pa_size = sizeof(pa_features_207);
4a2fec
-        break;
4a2fec
-    case POWERPC_MMU_VER_3_00:
4a2fec
+    }
4a2fec
+    if (ppc_check_compat(cpu, CPU_POWERPC_LOGICAL_3_00, 0, cpu->compat_pvr)) {
4a2fec
         pa_features = pa_features_300;
4a2fec
         pa_size = sizeof(pa_features_300);
4a2fec
-        break;
4a2fec
-    default:
4a2fec
+    }
4a2fec
+    if (!pa_features) {
4a2fec
         return;
4a2fec
     }
4a2fec
 
4a2fec
@@ -340,7 +341,6 @@ static int spapr_fixup_cpu_dt(void *fdt, sPAPRMachineState *spapr)
4a2fec
 
4a2fec
     CPU_FOREACH(cs) {
4a2fec
         PowerPCCPU *cpu = POWERPC_CPU(cs);
4a2fec
-        CPUPPCState *env = &cpu->env;
4a2fec
         DeviceClass *dc = DEVICE_GET_CLASS(cs);
4a2fec
         int index = ppc_get_vcpu_dt_id(cpu);
4a2fec
         int compat_smt = MIN(smp_threads, ppc_compat_max_threads(cpu));
4a2fec
@@ -385,7 +385,7 @@ static int spapr_fixup_cpu_dt(void *fdt, sPAPRMachineState *spapr)
4a2fec
             return ret;
4a2fec
         }
4a2fec
 
4a2fec
-        spapr_populate_pa_features(env, fdt, offset,
4a2fec
+        spapr_populate_pa_features(cpu, fdt, offset,
4a2fec
                                          spapr->cas_legacy_guest_workaround);
4a2fec
     }
4a2fec
     return ret;
4a2fec
@@ -582,7 +582,7 @@ static void spapr_populate_cpu_dt(CPUState *cs, void *fdt, int offset,
4a2fec
                           page_sizes_prop, page_sizes_prop_size)));
4a2fec
     }
4a2fec
 
4a2fec
-    spapr_populate_pa_features(env, fdt, offset, false);
4a2fec
+    spapr_populate_pa_features(cpu, fdt, offset, false);
4a2fec
 
4a2fec
     _FDT((fdt_setprop_cell(fdt, offset, "ibm,chip-id",
4a2fec
                            cs->cpu_index / vcpus_per_socket)));
4a2fec
@@ -945,7 +945,11 @@ static void spapr_dt_ov5_platform_support(void *fdt, int chosen)
4a2fec
         26, 0x40, /* Radix options: GTSE == yes. */
4a2fec
     };
4a2fec
 
4a2fec
-    if (kvm_enabled()) {
4a2fec
+    if (!ppc_check_compat(first_ppc_cpu, CPU_POWERPC_LOGICAL_3_00, 0,
4a2fec
+                          first_ppc_cpu->compat_pvr)) {
4a2fec
+        /* If we're in a pre POWER9 compat mode then the guest should do hash */
4a2fec
+        val[3] = 0x00; /* Hash */
4a2fec
+    } else if (kvm_enabled()) {
4a2fec
         if (kvmppc_has_cap_mmu_radix() && kvmppc_has_cap_mmu_hash_v3()) {
4a2fec
             val[3] = 0x80; /* OV5_MMU_BOTH */
4a2fec
         } else if (kvmppc_has_cap_mmu_radix()) {
4a2fec
@@ -954,13 +958,8 @@ static void spapr_dt_ov5_platform_support(void *fdt, int chosen)
4a2fec
             val[3] = 0x00; /* Hash */
4a2fec
         }
4a2fec
     } else {
4a2fec
-        if (first_ppc_cpu->env.mmu_model & POWERPC_MMU_V3) {
4a2fec
-            /* V3 MMU supports both hash and radix (with dynamic switching) */
4a2fec
-            val[3] = 0xC0;
4a2fec
-        } else {
4a2fec
-            /* Otherwise we can only do hash */
4a2fec
-            val[3] = 0x00;
4a2fec
-        }
4a2fec
+        /* V3 MMU supports both hash and radix in tcg (with dynamic switching) */
4a2fec
+        val[3] = 0xC0;
4a2fec
     }
4a2fec
     _FDT(fdt_setprop(fdt, chosen, "ibm,arch-vec-5-platform-support",
4a2fec
                      val, sizeof(val)));
4a2fec
-- 
4a2fec
1.8.3.1
4a2fec