Blame SOURCES/kvm-spapr-Handle-VMX-VSX-presence-as-an-spapr-capability.patch

9bac43
From 268880a2fee41c5c1929aac996a3292db41233cb Mon Sep 17 00:00:00 2001
9bac43
From: David Gibson <dgibson@redhat.com>
9bac43
Date: Fri, 19 Jan 2018 02:34:39 +0100
9bac43
Subject: [PATCH 11/21] spapr: Handle VMX/VSX presence as an spapr capability
9bac43
 flag
9bac43
9bac43
RH-Author: David Gibson <dgibson@redhat.com>
9bac43
Message-id: <20180119023442.28577-5-dgibson@redhat.com>
9bac43
Patchwork-id: 78671
9bac43
O-Subject: [RHEL-7.5 qemu-kvm-rhev PATCH 4/7] spapr: Handle VMX/VSX presence as an spapr capability flag
9bac43
Bugzilla: 1523414
9bac43
RH-Acked-by: Laurent Vivier <lvivier@redhat.com>
9bac43
RH-Acked-by: Thomas Huth <thuth@redhat.com>
9bac43
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
9bac43
9bac43
From: David Gibson <david@gibson.dropbear.id.au>
9bac43
9bac43
We currently have some conditionals in the spapr device tree code to decide
9bac43
whether or not to advertise the availability of the VMX (aka Altivec) and
9bac43
VSX vector extensions to the guest, based on whether the guest cpu has
9bac43
those features.
9bac43
9bac43
This can lead to confusion and subtle failures on migration, since it makes
9bac43
a guest visible change based only on host capabilities.  We now have a
9bac43
better mechanism for this, in spapr capabilities flags, which explicitly
9bac43
depend on user options rather than host capabilities.
9bac43
9bac43
Rework the advertisement of VSX and VMX based on a new VSX capability.  We
9bac43
no longer bother with a conditional for VMX support, because every CPU
9bac43
that's ever been supported by the pseries machine type supports VMX.
9bac43
9bac43
NOTE: Some userspace distributions (e.g. RHEL7.4) already rely on
9bac43
availability of VSX in libc, so using cap-vsx=off may lead to a fatal
9bac43
SIGILL in init.
9bac43
9bac43
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
9bac43
Reviewed-by: Greg Kurz <groug@kaod.org>
9bac43
(cherry picked from commit 2938664286499c0c30d6e455a7e2e5d3e6c3f63d)
9bac43
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
9bac43
9bac43
Conflicts:
9bac43
	hw/ppc/spapr.c
9bac43
9bac43
Because of the difference between upstream and downstream machine type
9bac43
versions.  Adjusted the logic to enable CAP_VSX on all downstream
9bac43
machine types, as it is for all upstream types.
9bac43
9bac43
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1523414
9bac43
9bac43
Signed-off-by: David Gibson <dgibson@redhat.com>
9bac43
---
9bac43
 hw/ppc/spapr.c         | 20 +++++++++++---------
9bac43
 hw/ppc/spapr_caps.c    | 25 +++++++++++++++++++++++++
9bac43
 include/hw/ppc/spapr.h |  3 +++
9bac43
 3 files changed, 39 insertions(+), 9 deletions(-)
9bac43
9bac43
diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
9bac43
index 846b906..0ef2af9 100644
9bac43
--- a/hw/ppc/spapr.c
9bac43
+++ b/hw/ppc/spapr.c
9bac43
@@ -560,14 +560,16 @@ static void spapr_populate_cpu_dt(CPUState *cs, void *fdt, int offset,
9bac43
                           segs, sizeof(segs))));
9bac43
     }
9bac43
 
9bac43
-    /* Advertise VMX/VSX (vector extensions) if available
9bac43
-     *   0 / no property == no vector extensions
9bac43
+    /* Advertise VSX (vector extensions) if available
9bac43
      *   1               == VMX / Altivec available
9bac43
-     *   2               == VSX available */
9bac43
-    if (env->insns_flags & PPC_ALTIVEC) {
9bac43
-        uint32_t vmx = (env->insns_flags2 & PPC2_VSX) ? 2 : 1;
9bac43
-
9bac43
-        _FDT((fdt_setprop_cell(fdt, offset, "ibm,vmx", vmx)));
9bac43
+     *   2               == VSX available
9bac43
+     *
9bac43
+     * Only CPUs for which we create core types in spapr_cpu_core.c
9bac43
+     * are possible, and all of those have VMX */
9bac43
+    if (spapr_has_cap(spapr, SPAPR_CAP_VSX)) {
9bac43
+        _FDT((fdt_setprop_cell(fdt, offset, "ibm,vmx", 2)));
9bac43
+    } else {
9bac43
+        _FDT((fdt_setprop_cell(fdt, offset, "ibm,vmx", 1)));
9bac43
     }
9bac43
 
9bac43
     /* Advertise DFP (Decimal Floating Point) if available
9bac43
@@ -3648,7 +3650,7 @@ static void spapr_machine_class_init(ObjectClass *oc, void *data)
9bac43
     mc->numa_mem_align_shift = 28;
9bac43
     smc->has_power9_support = true;
9bac43
 
9bac43
-    smc->default_caps = spapr_caps(0);
9bac43
+    smc->default_caps = spapr_caps(SPAPR_CAP_VSX);
9bac43
     spapr_caps_add_properties(smc, &error_abort);
9bac43
 }
9bac43
 
9bac43
@@ -4054,7 +4056,7 @@ static void spapr_machine_rhel740_class_options(MachineClass *mc)
9bac43
     smc->has_power9_support = false;
9bac43
     smc->pre_2_10_has_unused_icps = true;
9bac43
     smc->resize_hpt_default = SPAPR_RESIZE_HPT_DISABLED;
9bac43
-    smc->default_caps = spapr_caps(SPAPR_CAP_HTM);
9bac43
+    smc->default_caps = spapr_caps(SPAPR_CAP_HTM | SPAPR_CAP_VSX);
9bac43
 }
9bac43
 
9bac43
 DEFINE_SPAPR_MACHINE(rhel740, "rhel7.4.0", false);
9bac43
diff --git a/hw/ppc/spapr_caps.c b/hw/ppc/spapr_caps.c
9bac43
index 2bdc202..9f901fb 100644
9bac43
--- a/hw/ppc/spapr_caps.c
9bac43
+++ b/hw/ppc/spapr_caps.c
9bac43
@@ -57,6 +57,19 @@ static void cap_htm_allow(sPAPRMachineState *spapr, Error **errp)
9bac43
     }
9bac43
 }
9bac43
 
9bac43
+static void cap_vsx_allow(sPAPRMachineState *spapr, Error **errp)
9bac43
+{
9bac43
+    PowerPCCPU *cpu = POWERPC_CPU(first_cpu);
9bac43
+    CPUPPCState *env = &cpu->env;
9bac43
+
9bac43
+    /* Allowable CPUs in spapr_cpu_core.c should already have gotten
9bac43
+     * rid of anything that doesn't do VMX */
9bac43
+    g_assert(env->insns_flags & PPC_ALTIVEC);
9bac43
+    if (!(env->insns_flags2 & PPC2_VSX)) {
9bac43
+        error_setg(errp, "VSX support not available, try cap-vsx=off");
9bac43
+    }
9bac43
+}
9bac43
+
9bac43
 static sPAPRCapabilityInfo capability_table[] = {
9bac43
     {
9bac43
         .name = "htm",
9bac43
@@ -65,6 +78,13 @@ static sPAPRCapabilityInfo capability_table[] = {
9bac43
         .allow = cap_htm_allow,
9bac43
         /* TODO: add cap_htm_disallow */
9bac43
     },
9bac43
+    {
9bac43
+        .name = "vsx",
9bac43
+        .description = "Allow Vector Scalar Extensions (VSX)",
9bac43
+        .flag = SPAPR_CAP_VSX,
9bac43
+        .allow = cap_vsx_allow,
9bac43
+        /* TODO: add cap_vsx_disallow */
9bac43
+    },
9bac43
 };
9bac43
 
9bac43
 static sPAPRCapabilities default_caps_with_cpu(sPAPRMachineState *spapr,
9bac43
@@ -81,6 +101,11 @@ static sPAPRCapabilities default_caps_with_cpu(sPAPRMachineState *spapr,
9bac43
         caps.mask &= ~SPAPR_CAP_HTM;
9bac43
     }
9bac43
 
9bac43
+    if (!ppc_check_compat(cpu, CPU_POWERPC_LOGICAL_2_06,
9bac43
+                          0, spapr->max_compat_pvr)) {
9bac43
+        caps.mask &= ~SPAPR_CAP_VSX;
9bac43
+    }
9bac43
+
9bac43
     return caps;
9bac43
 }
9bac43
 
9bac43
diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h
9bac43
index f32967a..36f6816 100644
9bac43
--- a/include/hw/ppc/spapr.h
9bac43
+++ b/include/hw/ppc/spapr.h
9bac43
@@ -59,6 +59,9 @@ typedef enum {
9bac43
 /* Hardware Transactional Memory */
9bac43
 #define SPAPR_CAP_HTM               0x0000000000000001ULL
9bac43
 
9bac43
+/* Vector Scalar Extensions */
9bac43
+#define SPAPR_CAP_VSX               0x0000000000000002ULL
9bac43
+
9bac43
 typedef struct sPAPRCapabilities sPAPRCapabilities;
9bac43
 struct sPAPRCapabilities {
9bac43
     uint64_t mask;
9bac43
-- 
9bac43
1.8.3.1
9bac43