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