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

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