ff9ada
From 3c65320ce5b8ad3bb8c0d8fd13a88c464d5c5845 Mon Sep 17 00:00:00 2001
ddf19c
From: Miroslav Rezanina <mrezanin@redhat.com>
ddf19c
Date: Fri, 19 Oct 2018 13:27:13 +0200
ddf19c
Subject: Add ppc64 machine types
ddf19c
ddf19c
Adding changes to add RHEL machine types for ppc64 architecture.
ddf19c
ddf19c
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
ddf19c
ddf19c
Rebase changes (4.0.0):
ddf19c
- remove instance options and use upstream solution
ddf19c
- Use upstream compat handling
ddf19c
- Replace SPAPR_PCI_2_7_MMIO_WIN_SIZE with value (changed upstream)
ddf19c
- re-add handling of instance_options (removed upstream)
ddf19c
- Use p8 as default for rhel machine types (p9 default upstream)
ddf19c
- sPAPRMachineClass renamed to SpaprMachineClass (upstream)
ddf19c
ddf19c
Rebase changes (4.1.0):
ddf19c
- Update format for compat structures
ddf19c
ff9ada
Rebase notes (weekly-210303):
ff9ada
- Use rhel-8.4.0 hw compat
ff9ada
ddf19c
Merged patches (4.0.0):
ddf19c
- 467d59a redhat: define pseries-rhel8.0.0 machine type
ddf19c
ddf19c
Merged patches (4.1.0):
ddf19c
- f21757edc target/ppc/spapr: Enable mitigations by default for pseries-4.0 machine type
ddf19c
- 2511c63 redhat: sync pseries-rhel7.6.0 with rhel-av-8.0.1
ddf19c
- 89f01da redhat: define pseries-rhel8.1.0 machine type
ddf19c
ddf19c
Merged patches (4.2.0):
ddf19c
- bcba728 redhat: update pseries-rhel8.1.0 machine type
ddf19c
- redhat: update pseries-rhel-7.6.0 machine type (patch 93039)
ddf19c
- redhat: define pseries-rhel8.2.0 machine type (patch 93041)
ddf19c
ff9ada
Merged patches (5.1.0):
ff9ada
- eb121ff spapr: Enable DD2.3 accelerated count cache flush in pseries-5.0 machine (partial)
ff9ada
ff9ada
Merged patches (5.2.0 rc0):
ff9ada
- 311a20f redhat: define pseries-rhel8.3.0 machine type
ff9ada
- 1284167 ppc: Set correct max_cpus value on spapr-rhel* machine types
ff9ada
- 1ab8783 redhat: update pseries-rhel8.2.0 machine type
ff9ada
- b162af531a target/ppc: Add experimental option for enabling secure guests
ff9ada
ff9ada
Merged patches (weekly-201216):
ff9ada
- 943c936df3 redhat: Add spapr_machine_rhel_default_class_options()
ff9ada
- 030b5e6fba redhat: Define pseries-rhel8.4.0 machine type
ff9ada
ff9ada
Merged patches (weekly-210602):
ff9ada
- b7128d8ef7 redhat: Define pseries-rhel8.5.0 machine type
ff9ada
ff9ada
Merged patches (weekly-211006):
ff9ada
- c8f68b47e9 redhat: Update pseries-rhel8.5.0
ddf19c
---
ff9ada
 hw/ppc/spapr.c          | 382 ++++++++++++++++++++++++++++++++++++++++
ddf19c
 hw/ppc/spapr_cpu_core.c |  13 ++
ff9ada
 include/hw/ppc/spapr.h  |   4 +
ddf19c
 target/ppc/compat.c     |  13 +-
ddf19c
 target/ppc/cpu.h        |   1 +
ff9ada
 target/ppc/kvm.c        |  27 +++
ff9ada
 target/ppc/kvm_ppc.h    |  13 ++
ff9ada
 7 files changed, 452 insertions(+), 1 deletion(-)
ddf19c
ddf19c
diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
ff9ada
index 3b5fd749be..cace86028d 100644
ddf19c
--- a/hw/ppc/spapr.c
ddf19c
+++ b/hw/ppc/spapr.c
ff9ada
@@ -1593,6 +1593,9 @@ static void spapr_machine_reset(MachineState *machine)
ff9ada
 
ff9ada
     pef_kvm_reset(machine->cgs, &error_fatal);
ff9ada
     spapr_caps_apply(spapr);
ff9ada
+    if (spapr->svm_allowed) {
ff9ada
+        kvmppc_svm_allow(&error_fatal);
ff9ada
+    }
ff9ada
 
ff9ada
     first_ppc_cpu = POWERPC_CPU(first_cpu);
ff9ada
     if (kvm_enabled() && kvmppc_has_cap_mmu_radix() &&
ff9ada
@@ -3288,6 +3291,20 @@ static void spapr_set_host_serial(Object *obj, const char *value, Error **errp)
ff9ada
     spapr->host_serial = g_strdup(value);
ff9ada
 }
ff9ada
 
ff9ada
+static bool spapr_get_svm_allowed(Object *obj, Error **errp)
ff9ada
+{
ff9ada
+    SpaprMachineState *spapr = SPAPR_MACHINE(obj);
ff9ada
+
ff9ada
+    return spapr->svm_allowed;
ff9ada
+}
ff9ada
+
ff9ada
+static void spapr_set_svm_allowed(Object *obj, bool value, Error **errp)
ff9ada
+{
ff9ada
+    SpaprMachineState *spapr = SPAPR_MACHINE(obj);
ff9ada
+
ff9ada
+    spapr->svm_allowed = value;
ff9ada
+}
ff9ada
+
ff9ada
 static void spapr_instance_init(Object *obj)
ff9ada
 {
ff9ada
     SpaprMachineState *spapr = SPAPR_MACHINE(obj);
ff9ada
@@ -3366,6 +3383,12 @@ static void spapr_instance_init(Object *obj)
ff9ada
         spapr_get_host_serial, spapr_set_host_serial);
ff9ada
     object_property_set_description(obj, "host-serial",
ff9ada
         "Host serial number to advertise in guest device tree");
ff9ada
+    object_property_add_bool(obj, "x-svm-allowed",
ff9ada
+                            spapr_get_svm_allowed,
ff9ada
+                            spapr_set_svm_allowed);
ff9ada
+    object_property_set_description(obj, "x-svm-allowed",
ff9ada
+                                    "Allow the guest to become a Secure Guest"
ff9ada
+                                    " (experimental only)");
ff9ada
 }
ff9ada
 
ff9ada
 static void spapr_machine_finalizefn(Object *obj)
ff9ada
@@ -4614,6 +4637,7 @@ static void spapr_machine_class_init(ObjectClass *oc, void *data)
ff9ada
     vmc->client_architecture_support = spapr_vof_client_architecture_support;
ff9ada
     vmc->quiesce = spapr_vof_quiesce;
ff9ada
     vmc->setprop = spapr_vof_setprop;
ddf19c
+    smc->has_power9_support = true;
ddf19c
 }
ddf19c
 
ddf19c
 static const TypeInfo spapr_machine_info = {
ff9ada
@@ -4665,6 +4689,7 @@ static void spapr_machine_latest_class_options(MachineClass *mc)
ddf19c
     }                                                                \
ddf19c
     type_init(spapr_machine_register_##suffix)
ddf19c
 
ddf19c
+#if 0 /* Disabled for Red Hat Enterprise Linux */
ddf19c
 /*
ff9ada
  * pseries-6.2
ddf19c
  */
ff9ada
@@ -4781,6 +4806,7 @@ static void spapr_machine_4_1_class_options(MachineClass *mc)
ddf19c
 }
ddf19c
 
ddf19c
 DEFINE_SPAPR_MACHINE(4_1, "4.1", false);
ddf19c
+#endif
ddf19c
 
ddf19c
 /*
ddf19c
  * pseries-4.0
ff9ada
@@ -4800,6 +4826,8 @@ static bool phb_placement_4_0(SpaprMachineState *spapr, uint32_t index,
ddf19c
     *nv2atsd = 0;
ff9ada
     return true;
ddf19c
 }
ff9ada
+
ddf19c
+#if 0 /* Disabled for Red Hat Enterprise Linux */
ddf19c
 static void spapr_machine_4_0_class_options(MachineClass *mc)
ddf19c
 {
ddf19c
     SpaprMachineClass *smc = SPAPR_MACHINE_CLASS(mc);
ff9ada
@@ -4958,6 +4986,7 @@ DEFINE_SPAPR_MACHINE(2_8, "2.8", false);
ddf19c
 /*
ddf19c
  * pseries-2.7
ddf19c
  */
ddf19c
+#endif
ddf19c
 
ff9ada
 static bool phb_placement_2_7(SpaprMachineState *spapr, uint32_t index,
ddf19c
                               uint64_t *buid, hwaddr *pio,
ff9ada
@@ -5013,6 +5042,7 @@ static bool phb_placement_2_7(SpaprMachineState *spapr, uint32_t index,
ff9ada
     return true;
ddf19c
 }
ddf19c
 
ddf19c
+#if 0 /* Disabled for Red Hat Enterprise Linux */
ddf19c
 static void spapr_machine_2_7_class_options(MachineClass *mc)
ddf19c
 {
ddf19c
     SpaprMachineClass *smc = SPAPR_MACHINE_CLASS(mc);
ff9ada
@@ -5127,6 +5157,358 @@ static void spapr_machine_2_1_class_options(MachineClass *mc)
ddf19c
     compat_props_add(mc->compat_props, hw_compat_2_1, hw_compat_2_1_len);
ddf19c
 }
ddf19c
 DEFINE_SPAPR_MACHINE(2_1, "2.1", false);
ddf19c
+#endif
ddf19c
+
ff9ada
+static void spapr_machine_rhel_default_class_options(MachineClass *mc)
ff9ada
+{
ff9ada
+    /*
ff9ada
+     * Defaults for the latest behaviour inherited from the base class
ff9ada
+     * can be overriden here for all pseries-rhel* machines.
ff9ada
+     */
ff9ada
+
ff9ada
+    /* Maximum supported VCPU count */
ff9ada
+    mc->max_cpus = 384;
ff9ada
+}
ff9ada
+
ff9ada
+/*
ff9ada
+ * pseries-rhel8.5.0
ff9ada
+ * like pseries-6.0
ff9ada
+ */
ff9ada
+
ff9ada
+static void spapr_machine_rhel850_class_options(MachineClass *mc)
ff9ada
+{
ff9ada
+    /* The default machine type must apply the RHEL specific defaults */
ff9ada
+    spapr_machine_rhel_default_class_options(mc);
ff9ada
+    compat_props_add(mc->compat_props, hw_compat_rhel_8_5,
ff9ada
+                     hw_compat_rhel_8_5_len);
ff9ada
+}
ff9ada
+
ff9ada
+DEFINE_SPAPR_MACHINE(rhel850, "rhel8.5.0", true);
ff9ada
+
ff9ada
+/*
ff9ada
+ * pseries-rhel8.4.0
ff9ada
+ * like pseries-5.2
ff9ada
+ */
ff9ada
+
ff9ada
+static void spapr_machine_rhel840_class_options(MachineClass *mc)
ff9ada
+{
ff9ada
+    spapr_machine_rhel850_class_options(mc);
ff9ada
+    compat_props_add(mc->compat_props, hw_compat_rhel_8_4,
ff9ada
+                     hw_compat_rhel_8_4_len);
ff9ada
+}
ff9ada
+
ff9ada
+DEFINE_SPAPR_MACHINE(rhel840, "rhel8.4.0", false);
ff9ada
+
ff9ada
+/*
ff9ada
+ * pseries-rhel8.3.0
ff9ada
+ * like pseries-5.1
ff9ada
+ */
ff9ada
+
ff9ada
+static void spapr_machine_rhel830_class_options(MachineClass *mc)
ff9ada
+{
ff9ada
+    SpaprMachineClass *smc = SPAPR_MACHINE_CLASS(mc);
ff9ada
+
ff9ada
+    spapr_machine_rhel840_class_options(mc);
ff9ada
+    compat_props_add(mc->compat_props, hw_compat_rhel_8_3,
ff9ada
+                     hw_compat_rhel_8_3_len);
ff9ada
+
ff9ada
+    /* from pseries-5.1 */
ff9ada
+    smc->pre_5_2_numa_associativity = true;
ff9ada
+}
ff9ada
+
ff9ada
+DEFINE_SPAPR_MACHINE(rhel830, "rhel8.3.0", false);
ff9ada
+
ddf19c
+/*
ddf19c
+ * pseries-rhel8.2.0
ff9ada
+ * like pseries-4.2 + pseries-5.0
ff9ada
+ * except SPAPR_CAP_CCF_ASSIST that has been backported to pseries-rhel8.1.0
ddf19c
+ */
ddf19c
+
ddf19c
+static void spapr_machine_rhel820_class_options(MachineClass *mc)
ddf19c
+{
ff9ada
+    SpaprMachineClass *smc = SPAPR_MACHINE_CLASS(mc);
ff9ada
+    /* from pseries-5.0 */
ff9ada
+    static GlobalProperty compat[] = {
ff9ada
+        { TYPE_SPAPR_PCI_HOST_BRIDGE, "pre-5.1-associativity", "on" },
ff9ada
+    };
ff9ada
+
ff9ada
+    spapr_machine_rhel830_class_options(mc);
ff9ada
+    compat_props_add(mc->compat_props, hw_compat_rhel_8_2,
ff9ada
+                     hw_compat_rhel_8_2_len);
ff9ada
+    compat_props_add(mc->compat_props, compat, G_N_ELEMENTS(compat));
ff9ada
+
ff9ada
+    /* from pseries-4.2 */
ff9ada
+    smc->default_caps.caps[SPAPR_CAP_FWNMI] = SPAPR_CAP_OFF;
ff9ada
+    smc->rma_limit = 16 * GiB;
ff9ada
+    mc->nvdimm_supported = false;
ff9ada
+
ff9ada
+    /* from pseries-5.0 */
ff9ada
+    mc->numa_mem_supported = true;
ff9ada
+    smc->pre_5_1_assoc_refpoints = true;
ddf19c
+}
ddf19c
+
ff9ada
+DEFINE_SPAPR_MACHINE(rhel820, "rhel8.2.0", false);
ddf19c
+
ddf19c
+/*
ddf19c
+ * pseries-rhel8.1.0
ddf19c
+ * like pseries-4.1
ddf19c
+ */
ddf19c
+
ddf19c
+static void spapr_machine_rhel810_class_options(MachineClass *mc)
ddf19c
+{
ddf19c
+    SpaprMachineClass *smc = SPAPR_MACHINE_CLASS(mc);
ddf19c
+    static GlobalProperty compat[] = {
ddf19c
+        /* Only allow 4kiB and 64kiB IOMMU pagesizes */
ddf19c
+        { TYPE_SPAPR_PCI_HOST_BRIDGE, "pgsz", "0x11000" },
ddf19c
+    };
ddf19c
+
ddf19c
+    spapr_machine_rhel820_class_options(mc);
ddf19c
+
ddf19c
+    /* from pseries-4.1 */
ddf19c
+    smc->linux_pci_probe = false;
ddf19c
+    smc->smp_threads_vsmt = false;
ddf19c
+    compat_props_add(mc->compat_props, hw_compat_rhel_8_1,
ddf19c
+                     hw_compat_rhel_8_1_len);
ddf19c
+    compat_props_add(mc->compat_props, compat, G_N_ELEMENTS(compat));
ddf19c
+
ff9ada
+    /* from pseries-4.2 */
ff9ada
+    smc->default_caps.caps[SPAPR_CAP_CCF_ASSIST] = SPAPR_CAP_OFF;
ddf19c
+}
ddf19c
+
ddf19c
+DEFINE_SPAPR_MACHINE(rhel810, "rhel8.1.0", false);
ddf19c
+
ddf19c
+/*
ddf19c
+ * pseries-rhel8.0.0
ddf19c
+ * like pseries-3.1 and pseries-4.0
ddf19c
+ * except SPAPR_CAP_CFPC, SPAPR_CAP_SBBC and SPAPR_CAP_IBS
ddf19c
+ * that have been backported to pseries-rhel8.0.0
ddf19c
+ */
ddf19c
+
ddf19c
+static void spapr_machine_rhel800_class_options(MachineClass *mc)
ddf19c
+{
ddf19c
+    SpaprMachineClass *smc = SPAPR_MACHINE_CLASS(mc);
ddf19c
+
ddf19c
+    spapr_machine_rhel810_class_options(mc);
ddf19c
+    compat_props_add(mc->compat_props, hw_compat_rhel_8_0,
ddf19c
+                     hw_compat_rhel_8_0_len);
ddf19c
+
ddf19c
+    /* pseries-4.0 */
ddf19c
+    smc->phb_placement = phb_placement_4_0;
ddf19c
+    smc->irq = &spapr_irq_xics;
ddf19c
+    smc->pre_4_1_migration = true;
ddf19c
+
ddf19c
+    /* pseries-3.1 */
ddf19c
+    mc->default_cpu_type = POWERPC_CPU_TYPE_NAME("power8_v2.0");
ddf19c
+    smc->update_dt_enabled = false;
ddf19c
+    smc->dr_phb_enabled = false;
ddf19c
+    smc->broken_host_serial_model = true;
ddf19c
+    smc->default_caps.caps[SPAPR_CAP_LARGE_DECREMENTER] = SPAPR_CAP_OFF;
ddf19c
+}
ddf19c
+
ddf19c
+DEFINE_SPAPR_MACHINE(rhel800, "rhel8.0.0", false);
ddf19c
+
ddf19c
+/*
ddf19c
+ * pseries-rhel7.6.0
ddf19c
+ * like spapr_compat_2_12 and spapr_compat_3_0
ddf19c
+ * spapr_compat_0 is empty
ddf19c
+ */
ddf19c
+GlobalProperty spapr_compat_rhel7_6[] = {
ddf19c
+    { TYPE_POWERPC_CPU, "pre-3.0-migration", "on" },
ddf19c
+    { TYPE_SPAPR_CPU_CORE, "pre-3.0-migration", "on" },
ddf19c
+};
ddf19c
+const size_t spapr_compat_rhel7_6_len = G_N_ELEMENTS(spapr_compat_rhel7_6);
ddf19c
+
ddf19c
+
ddf19c
+static void spapr_machine_rhel760_class_options(MachineClass *mc)
ddf19c
+{
ddf19c
+    SpaprMachineClass *smc = SPAPR_MACHINE_CLASS(mc);
ddf19c
+
ddf19c
+    spapr_machine_rhel800_class_options(mc);
ddf19c
+    compat_props_add(mc->compat_props, hw_compat_rhel_7_6, hw_compat_rhel_7_6_len);
ddf19c
+    compat_props_add(mc->compat_props, spapr_compat_rhel7_6, spapr_compat_rhel7_6_len);
ddf19c
+
ddf19c
+    /* from spapr_machine_3_0_class_options() */
ddf19c
+    smc->legacy_irq_allocation = true;
ddf19c
+    smc->nr_xirqs = 0x400;
ddf19c
+    smc->irq = &spapr_irq_xics_legacy;
ddf19c
+
ddf19c
+    /* from spapr_machine_2_12_class_options() */
ddf19c
+    /* We depend on kvm_enabled() to choose a default value for the
ddf19c
+     * hpt-max-page-size capability. Of course we can't do it here
ddf19c
+     * because this is too early and the HW accelerator isn't initialzed
ddf19c
+     * yet. Postpone this to machine init (see default_caps_with_cpu()).
ddf19c
+     */
ddf19c
+    smc->default_caps.caps[SPAPR_CAP_HPT_MAXPAGESIZE] = 0;
ddf19c
+
ddf19c
+    /* SPAPR_CAP_WORKAROUND enabled in pseries-rhel800 by
ddf19c
+     * f21757edc554
ddf19c
+     * "Enable mitigations by default for pseries-4.0 machine type")
ddf19c
+     */
ddf19c
+    smc->default_caps.caps[SPAPR_CAP_CFPC] = SPAPR_CAP_BROKEN;
ddf19c
+    smc->default_caps.caps[SPAPR_CAP_SBBC] = SPAPR_CAP_BROKEN;
ddf19c
+    smc->default_caps.caps[SPAPR_CAP_IBS] = SPAPR_CAP_BROKEN;
ddf19c
+}
ddf19c
+
ddf19c
+DEFINE_SPAPR_MACHINE(rhel760, "rhel7.6.0", false);
ddf19c
+
ddf19c
+/*
ddf19c
+ * pseries-rhel7.6.0-sxxm
ddf19c
+ *
ddf19c
+ * pseries-rhel7.6.0 with speculative execution exploit mitigations enabled by default
ddf19c
+ */
ddf19c
+
ddf19c
+static void spapr_machine_rhel760sxxm_class_options(MachineClass *mc)
ddf19c
+{
ddf19c
+    SpaprMachineClass *smc = SPAPR_MACHINE_CLASS(mc);
ddf19c
+
ddf19c
+    spapr_machine_rhel760_class_options(mc);
ddf19c
+    smc->default_caps.caps[SPAPR_CAP_CFPC] = SPAPR_CAP_WORKAROUND;
ddf19c
+    smc->default_caps.caps[SPAPR_CAP_SBBC] = SPAPR_CAP_WORKAROUND;
ddf19c
+    smc->default_caps.caps[SPAPR_CAP_IBS] = SPAPR_CAP_FIXED_CCD;
ddf19c
+}
ddf19c
+
ddf19c
+DEFINE_SPAPR_MACHINE(rhel760sxxm, "rhel7.6.0-sxxm", false);
ddf19c
+
ddf19c
+static void spapr_machine_rhel750_class_options(MachineClass *mc)
ddf19c
+{
ddf19c
+    spapr_machine_rhel760_class_options(mc);
ddf19c
+    compat_props_add(mc->compat_props, hw_compat_rhel_7_5, hw_compat_rhel_7_5_len);
ddf19c
+
ddf19c
+}
ddf19c
+
ddf19c
+DEFINE_SPAPR_MACHINE(rhel750, "rhel7.5.0", false);
ddf19c
+
ddf19c
+/*
ddf19c
+ * pseries-rhel7.5.0-sxxm
ddf19c
+ *
ddf19c
+ * pseries-rhel7.5.0 with speculative execution exploit mitigations enabled by default
ddf19c
+ */
ddf19c
+
ddf19c
+static void spapr_machine_rhel750sxxm_class_options(MachineClass *mc)
ddf19c
+{
ddf19c
+    SpaprMachineClass *smc = SPAPR_MACHINE_CLASS(mc);
ddf19c
+
ddf19c
+    spapr_machine_rhel750_class_options(mc);
ddf19c
+    smc->default_caps.caps[SPAPR_CAP_CFPC] = SPAPR_CAP_WORKAROUND;
ddf19c
+    smc->default_caps.caps[SPAPR_CAP_SBBC] = SPAPR_CAP_WORKAROUND;
ddf19c
+    smc->default_caps.caps[SPAPR_CAP_IBS] = SPAPR_CAP_FIXED_CCD;
ddf19c
+}
ddf19c
+
ddf19c
+DEFINE_SPAPR_MACHINE(rhel750sxxm, "rhel7.5.0-sxxm", false);
ddf19c
+
ddf19c
+/*
ddf19c
+ * pseries-rhel7.4.0
ddf19c
+ * like spapr_compat_2_9
ddf19c
+ */
ddf19c
+GlobalProperty spapr_compat_rhel7_4[] = {
ddf19c
+    { TYPE_POWERPC_CPU, "pre-2.10-migration", "on" },
ddf19c
+};
ddf19c
+const size_t spapr_compat_rhel7_4_len = G_N_ELEMENTS(spapr_compat_rhel7_4);
ddf19c
+
ddf19c
+static void spapr_machine_rhel740_class_options(MachineClass *mc)
ddf19c
+{
ddf19c
+    SpaprMachineClass *smc = SPAPR_MACHINE_CLASS(mc);
ddf19c
+
ddf19c
+    spapr_machine_rhel750_class_options(mc);
ddf19c
+    compat_props_add(mc->compat_props, hw_compat_rhel_7_4, hw_compat_rhel_7_4_len);
ddf19c
+    compat_props_add(mc->compat_props, spapr_compat_rhel7_4, spapr_compat_rhel7_4_len);
ddf19c
+    smc->has_power9_support = false;
ddf19c
+    smc->pre_2_10_has_unused_icps = true;
ddf19c
+    smc->resize_hpt_default = SPAPR_RESIZE_HPT_DISABLED;
ddf19c
+    smc->default_caps.caps[SPAPR_CAP_HTM] = SPAPR_CAP_ON;
ddf19c
+}
ddf19c
+
ddf19c
+DEFINE_SPAPR_MACHINE(rhel740, "rhel7.4.0", false);
ddf19c
+
ddf19c
+/*
ddf19c
+ * pseries-rhel7.4.0-sxxm
ddf19c
+ *
ddf19c
+ * pseries-rhel7.4.0 with speculative execution exploit mitigations enabled by default
ddf19c
+ */
ddf19c
+
ddf19c
+static void spapr_machine_rhel740sxxm_class_options(MachineClass *mc)
ddf19c
+{
ddf19c
+    SpaprMachineClass *smc = SPAPR_MACHINE_CLASS(mc);
ddf19c
+
ddf19c
+    spapr_machine_rhel740_class_options(mc);
ddf19c
+    smc->default_caps.caps[SPAPR_CAP_CFPC] = SPAPR_CAP_WORKAROUND;
ddf19c
+    smc->default_caps.caps[SPAPR_CAP_SBBC] = SPAPR_CAP_WORKAROUND;
ddf19c
+    smc->default_caps.caps[SPAPR_CAP_IBS] = SPAPR_CAP_FIXED_CCD;
ddf19c
+}
ddf19c
+
ddf19c
+DEFINE_SPAPR_MACHINE(rhel740sxxm, "rhel7.4.0-sxxm", false);
ddf19c
+
ddf19c
+/*
ddf19c
+ * pseries-rhel7.3.0
ddf19c
+ * like spapr_compat_2_6/_2_7/_2_8 but "ddw" has been backported to RHEL7_3
ddf19c
+ */
ddf19c
+GlobalProperty spapr_compat_rhel7_3[] = {
ddf19c
+    { TYPE_SPAPR_PCI_HOST_BRIDGE, "mem_win_size", "0xf80000000" },
ddf19c
+    { TYPE_SPAPR_PCI_HOST_BRIDGE, "mem64_win_size", "0" },
ddf19c
+    { TYPE_POWERPC_CPU, "pre-2.8-migration", "on" },
ddf19c
+    { TYPE_SPAPR_PCI_HOST_BRIDGE, "pre-2.8-migration", "on" },
ddf19c
+    { TYPE_SPAPR_PCI_HOST_BRIDGE, "pcie-extended-configuration-space", "off" },
ddf19c
+};
ddf19c
+const size_t spapr_compat_rhel7_3_len = G_N_ELEMENTS(spapr_compat_rhel7_3);
ddf19c
+
ddf19c
+static void spapr_machine_rhel730_class_options(MachineClass *mc)
ddf19c
+{
ddf19c
+    SpaprMachineClass *smc = SPAPR_MACHINE_CLASS(mc);
ddf19c
+
ddf19c
+    spapr_machine_rhel740_class_options(mc);
ddf19c
+    mc->default_cpu_type = POWERPC_CPU_TYPE_NAME("power7_v2.3");
ddf19c
+    mc->default_machine_opts = "modern-hotplug-events=off";
ddf19c
+    compat_props_add(mc->compat_props, hw_compat_rhel_7_3, hw_compat_rhel_7_3_len);
ddf19c
+    compat_props_add(mc->compat_props, spapr_compat_rhel7_3, spapr_compat_rhel7_3_len);
ddf19c
+
ddf19c
+    smc->phb_placement = phb_placement_2_7;
ddf19c
+}
ddf19c
+
ddf19c
+DEFINE_SPAPR_MACHINE(rhel730, "rhel7.3.0", false);
ddf19c
+
ddf19c
+/*
ddf19c
+ * pseries-rhel7.3.0-sxxm
ddf19c
+ *
ddf19c
+ * pseries-rhel7.3.0 with speculative execution exploit mitigations enabled by default
ddf19c
+ */
ddf19c
+
ddf19c
+static void spapr_machine_rhel730sxxm_class_options(MachineClass *mc)
ddf19c
+{
ddf19c
+    SpaprMachineClass *smc = SPAPR_MACHINE_CLASS(mc);
ddf19c
+
ddf19c
+    spapr_machine_rhel730_class_options(mc);
ddf19c
+    smc->default_caps.caps[SPAPR_CAP_CFPC] = SPAPR_CAP_WORKAROUND;
ddf19c
+    smc->default_caps.caps[SPAPR_CAP_SBBC] = SPAPR_CAP_WORKAROUND;
ddf19c
+    smc->default_caps.caps[SPAPR_CAP_IBS] = SPAPR_CAP_FIXED_CCD;
ddf19c
+}
ddf19c
+
ddf19c
+DEFINE_SPAPR_MACHINE(rhel730sxxm, "rhel7.3.0-sxxm", false);
ddf19c
+
ddf19c
+/*
ddf19c
+ * pseries-rhel7.2.0
ddf19c
+ */
ddf19c
+/* Should be like spapr_compat_2_5 + 2_4 + 2_3, but "dynamic-reconfiguration"
ddf19c
+ * has been backported to RHEL7_2 so we don't need it here.
ddf19c
+ */
ddf19c
+
ddf19c
+GlobalProperty spapr_compat_rhel7_2[] = {
ddf19c
+    { "spapr-vlan", "use-rx-buffer-pools", "off" },
ddf19c
+    { TYPE_SPAPR_PCI_HOST_BRIDGE, "ddw", "off" },
ddf19c
+};
ddf19c
+const size_t spapr_compat_rhel7_2_len = G_N_ELEMENTS(spapr_compat_rhel7_2);
ddf19c
+
ddf19c
+static void spapr_machine_rhel720_class_options(MachineClass *mc)
ddf19c
+{
ddf19c
+    SpaprMachineClass *smc = SPAPR_MACHINE_CLASS(mc);
ddf19c
+
ddf19c
+    spapr_machine_rhel730_class_options(mc);
ddf19c
+    smc->use_ohci_by_default = true;
ddf19c
+    mc->has_hotpluggable_cpus = NULL;
ddf19c
+    compat_props_add(mc->compat_props, hw_compat_rhel_7_2, hw_compat_rhel_7_2_len);
ddf19c
+    compat_props_add(mc->compat_props, spapr_compat_rhel7_2, spapr_compat_rhel7_2_len);
ddf19c
+}
ddf19c
+
ddf19c
+DEFINE_SPAPR_MACHINE(rhel720, "rhel7.2.0", false);
ddf19c
 
ddf19c
 static void spapr_machine_register_types(void)
ddf19c
 {
ddf19c
diff --git a/hw/ppc/spapr_cpu_core.c b/hw/ppc/spapr_cpu_core.c
ff9ada
index 8ba34f6a1d..78eca1c04a 100644
ddf19c
--- a/hw/ppc/spapr_cpu_core.c
ddf19c
+++ b/hw/ppc/spapr_cpu_core.c
ddf19c
@@ -24,6 +24,7 @@
ddf19c
 #include "sysemu/reset.h"
ddf19c
 #include "sysemu/hw_accel.h"
ddf19c
 #include "qemu/error-report.h"
ddf19c
+#include "cpu-models.h"
ddf19c
 
ddf19c
 static void spapr_reset_vcpu(PowerPCCPU *cpu)
ddf19c
 {
ff9ada
@@ -250,6 +251,7 @@ static bool spapr_realize_vcpu(PowerPCCPU *cpu, SpaprMachineState *spapr,
ff9ada
 {
ddf19c
     CPUPPCState *env = &cpu->env;
ddf19c
     CPUState *cs = CPU(cpu);
ddf19c
+    SpaprMachineClass *smc = SPAPR_MACHINE_GET_CLASS(spapr);
ddf19c
 
ff9ada
     if (!qdev_realize(DEVICE(cpu), NULL, errp)) {
ff9ada
         return false;
ff9ada
@@ -261,6 +263,17 @@ static bool spapr_realize_vcpu(PowerPCCPU *cpu, SpaprMachineState *spapr,
ddf19c
     cpu_ppc_set_vhyp(cpu, PPC_VIRTUAL_HYPERVISOR(spapr));
ddf19c
     kvmppc_set_papr(cpu);
ddf19c
 
ddf19c
+    if (!smc->has_power9_support &&
ddf19c
+        (((spapr->max_compat_pvr &&
ddf19c
+           ppc_compat_cmp(spapr->max_compat_pvr,
ddf19c
+                          CPU_POWERPC_LOGICAL_3_00) >= 0)) ||
ddf19c
+          (!spapr->max_compat_pvr &&
ddf19c
+           ppc_check_compat(cpu, CPU_POWERPC_LOGICAL_3_00, 0, 0)))) {
ddf19c
+        error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND,
ddf19c
+                  "POWER9 CPU is not supported by this machine class");
ff9ada
+        return false;
ddf19c
+    }
ddf19c
+
ff9ada
     if (spapr_irq_cpu_intc_create(spapr, cpu, errp) < 0) {
ff9ada
         qdev_unrealize(DEVICE(cpu));
ff9ada
         return false;
ddf19c
diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h
ff9ada
index ee7504b976..37a014d59c 100644
ddf19c
--- a/include/hw/ppc/spapr.h
ddf19c
+++ b/include/hw/ppc/spapr.h
ff9ada
@@ -154,6 +154,7 @@ struct SpaprMachineClass {
ff9ada
     bool pre_5_2_numa_associativity;
ff9ada
     bool pre_6_2_numa_affinity;
ddf19c
 
ddf19c
+    bool has_power9_support;
ff9ada
     bool (*phb_placement)(SpaprMachineState *spapr, uint32_t index,
ff9ada
                           uint64_t *buid, hwaddr *pio,
ddf19c
                           hwaddr *mmio32, hwaddr *mmio64,
ff9ada
@@ -237,6 +238,9 @@ struct SpaprMachineState {
ff9ada
 
ff9ada
     /* Set by -boot */
ff9ada
     char *boot_device;
ff9ada
+ 
ff9ada
+    /* Secure Guest support via x-svm-allowed */
ff9ada
+    bool svm_allowed;
ff9ada
 
ff9ada
     /*< public >*/
ff9ada
     char *kvm_type;
ddf19c
diff --git a/target/ppc/compat.c b/target/ppc/compat.c
ff9ada
index 7949a24f5a..f207a9ba01 100644
ddf19c
--- a/target/ppc/compat.c
ddf19c
+++ b/target/ppc/compat.c
ff9ada
@@ -114,8 +114,19 @@ static const CompatInfo *compat_by_pvr(uint32_t pvr)
ddf19c
     return NULL;
ddf19c
 }
ddf19c
 
ddf19c
+long ppc_compat_cmp(uint32_t pvr1, uint32_t pvr2)
ddf19c
+{
ddf19c
+    const CompatInfo *compat1 = compat_by_pvr(pvr1);
ddf19c
+    const CompatInfo *compat2 = compat_by_pvr(pvr2);
ddf19c
+
ddf19c
+    g_assert(compat1);
ddf19c
+    g_assert(compat2);
ddf19c
+
ddf19c
+    return compat1 - compat2;
ddf19c
+}
ddf19c
+
ddf19c
 static bool pcc_compat(PowerPCCPUClass *pcc, uint32_t compat_pvr,
ddf19c
-                       uint32_t min_compat_pvr, uint32_t max_compat_pvr)
ddf19c
+                      uint32_t min_compat_pvr, uint32_t max_compat_pvr)
ddf19c
 {
ddf19c
     const CompatInfo *compat = compat_by_pvr(compat_pvr);
ddf19c
     const CompatInfo *min = compat_by_pvr(min_compat_pvr);
ddf19c
diff --git a/target/ppc/cpu.h b/target/ppc/cpu.h
ff9ada
index e946da5f3a..23e8b76c85 100644
ddf19c
--- a/target/ppc/cpu.h
ddf19c
+++ b/target/ppc/cpu.h
ff9ada
@@ -1401,6 +1401,7 @@ static inline int cpu_mmu_index(CPUPPCState *env, bool ifetch)
ddf19c
 
ddf19c
 /* Compatibility modes */
ddf19c
 #if defined(TARGET_PPC64)
ddf19c
+long ppc_compat_cmp(uint32_t pvr1, uint32_t pvr2);
ddf19c
 bool ppc_check_compat(PowerPCCPU *cpu, uint32_t compat_pvr,
ddf19c
                       uint32_t min_compat_pvr, uint32_t max_compat_pvr);
ddf19c
 bool ppc_type_check_compat(const char *cputype, uint32_t compat_pvr,
ff9ada
diff --git a/target/ppc/kvm.c b/target/ppc/kvm.c
ff9ada
index dc93b99189..154888cce5 100644
ff9ada
--- a/target/ppc/kvm.c
ff9ada
+++ b/target/ppc/kvm.c
ff9ada
@@ -90,6 +90,7 @@ static int cap_ppc_nested_kvm_hv;
ff9ada
 static int cap_large_decr;
ff9ada
 static int cap_fwnmi;
ff9ada
 static int cap_rpt_invalidate;
ff9ada
+static int cap_ppc_secure_guest;
ff9ada
 
ff9ada
 static uint32_t debug_inst_opcode;
ff9ada
 
ff9ada
@@ -137,6 +138,7 @@ int kvm_arch_init(MachineState *ms, KVMState *s)
ff9ada
     cap_resize_hpt = kvm_vm_check_extension(s, KVM_CAP_SPAPR_RESIZE_HPT);
ff9ada
     kvmppc_get_cpu_characteristics(s);
ff9ada
     cap_ppc_nested_kvm_hv = kvm_vm_check_extension(s, KVM_CAP_PPC_NESTED_HV);
ff9ada
+    cap_ppc_secure_guest = kvm_vm_check_extension(s, KVM_CAP_PPC_SECURE_GUEST);
ff9ada
     cap_large_decr = kvmppc_get_dec_bits();
ff9ada
     cap_fwnmi = kvm_vm_check_extension(s, KVM_CAP_PPC_FWNMI);
ff9ada
     /*
ff9ada
@@ -2563,6 +2565,16 @@ int kvmppc_has_cap_rpt_invalidate(void)
ff9ada
     return cap_rpt_invalidate;
ff9ada
 }
ff9ada
 
ff9ada
+bool kvmppc_has_cap_secure_guest(void)
ff9ada
+{
ff9ada
+    return !!cap_ppc_secure_guest;
ff9ada
+}
ff9ada
+
ff9ada
+int kvmppc_enable_cap_secure_guest(void)
ff9ada
+{
ff9ada
+    return kvm_vm_enable_cap(kvm_state, KVM_CAP_PPC_SECURE_GUEST, 0, 1);
ff9ada
+}
ff9ada
+
ff9ada
 PowerPCCPUClass *kvm_ppc_get_host_cpu_class(void)
ff9ada
 {
ff9ada
     uint32_t host_pvr = mfpvr();
ff9ada
@@ -2959,3 +2971,18 @@ bool kvm_arch_cpu_check_are_resettable(void)
ff9ada
 {
ff9ada
     return true;
ff9ada
 }
ff9ada
+
ff9ada
+void kvmppc_svm_allow(Error **errp)
ff9ada
+{
ff9ada
+    if (!kvm_enabled()) {
ff9ada
+        error_setg(errp, "No PEF support in tcg, try x-svm-allowed=off");
ff9ada
+        return;
ff9ada
+    }
ff9ada
+
ff9ada
+    if (!kvmppc_has_cap_secure_guest()) {
ff9ada
+        error_setg(errp, "KVM implementation does not support secure guests, "
ff9ada
+                   "try x-svm-allowed=off");
ff9ada
+    } else if (kvmppc_enable_cap_secure_guest() < 0) {
ff9ada
+        error_setg(errp, "Error enabling x-svm-allowed, try x-svm-allowed=off");
ff9ada
+    }
ff9ada
+}
ff9ada
diff --git a/target/ppc/kvm_ppc.h b/target/ppc/kvm_ppc.h
ff9ada
index ee9325bf9a..20dbb95989 100644
ff9ada
--- a/target/ppc/kvm_ppc.h
ff9ada
+++ b/target/ppc/kvm_ppc.h
ff9ada
@@ -40,6 +40,7 @@ int kvmppc_booke_watchdog_enable(PowerPCCPU *cpu);
ff9ada
 target_ulong kvmppc_configure_v3_mmu(PowerPCCPU *cpu,
ff9ada
                                      bool radix, bool gtse,
ff9ada
                                      uint64_t proc_tbl);
ff9ada
+void kvmppc_svm_allow(Error **errp);
ff9ada
 #ifndef CONFIG_USER_ONLY
ff9ada
 bool kvmppc_spapr_use_multitce(void);
ff9ada
 int kvmppc_spapr_enable_inkernel_multitce(void);
ff9ada
@@ -74,6 +75,8 @@ int kvmppc_get_cap_large_decr(void);
ff9ada
 int kvmppc_enable_cap_large_decr(PowerPCCPU *cpu, int enable);
ff9ada
 int kvmppc_has_cap_rpt_invalidate(void);
ff9ada
 int kvmppc_enable_hwrng(void);
ff9ada
+bool kvmppc_has_cap_secure_guest(void);
ff9ada
+int kvmppc_enable_cap_secure_guest(void);
ff9ada
 int kvmppc_put_books_sregs(PowerPCCPU *cpu);
ff9ada
 PowerPCCPUClass *kvm_ppc_get_host_cpu_class(void);
ff9ada
 void kvmppc_check_papr_resize_hpt(Error **errp);
ff9ada
@@ -393,6 +396,16 @@ static inline int kvmppc_has_cap_rpt_invalidate(void)
ff9ada
     return false;
ff9ada
 }
ff9ada
 
ff9ada
+static inline bool kvmppc_has_cap_secure_guest(void)
ff9ada
+{
ff9ada
+    return false;
ff9ada
+}
ff9ada
+
ff9ada
+static inline int kvmppc_enable_cap_secure_guest(void)
ff9ada
+{
ff9ada
+    return -1;
ff9ada
+}
ff9ada
+
ff9ada
 static inline int kvmppc_enable_hwrng(void)
ff9ada
 {
ff9ada
     return -1;
ddf19c
-- 
ff9ada
2.27.0
ddf19c