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

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