586cba
From f61b3d7dc000886e23943457ee9baf1d4cae43b4 Mon Sep 17 00:00:00 2001
495e37
From: Miroslav Rezanina <mrezanin@redhat.com>
495e37
Date: Fri, 19 Oct 2018 13:27:13 +0200
495e37
Subject: Add ppc64 machine types
495e37
495e37
Adding changes to add RHEL machine types for ppc64 architecture.
495e37
495e37
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
495e37
586cba
Rebase notes (6.2.0):
495e37
- Fixed rebase conflict relicts
495e37
- Update machine type compat for 6.2 (from MR 66)
495e37
495e37
Merged patches (6.1.0):
495e37
- c438c25ac3 redhat: Define pseries-rhel8.5.0 machine type
495e37
- a3995e2eff Remove RHEL 7.0.0 machine type (only ppc64 changes)
495e37
- ad3190a79b Remove RHEL 7.1.0 machine type (only ppc64 changes)
495e37
- 84bbe15d4e Remove RHEL 7.2.0 machine type (only ppc64 changes)
495e37
- 0215eb3356 Remove RHEL 7.3.0 machine types (only ppc64 changes)
495e37
- af69d1ca6e Remove RHEL 7.4.0 machine types (only ppc64 changes)
495e37
- 8f7a74ab78 Remove RHEL 7.5.0 machine types (only ppc64 changes)
495e37
---
495e37
 hw/ppc/spapr.c          | 243 ++++++++++++++++++++++++++++++++++++++++
495e37
 hw/ppc/spapr_cpu_core.c |  13 +++
495e37
 include/hw/ppc/spapr.h  |   4 +
495e37
 target/ppc/compat.c     |  13 ++-
495e37
 target/ppc/cpu.h        |   1 +
495e37
 target/ppc/kvm.c        |  27 +++++
495e37
 target/ppc/kvm_ppc.h    |  13 +++
495e37
 7 files changed, 313 insertions(+), 1 deletion(-)
495e37
495e37
diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
586cba
index a4372ba189..5fdf8b506d 100644
495e37
--- a/hw/ppc/spapr.c
495e37
+++ b/hw/ppc/spapr.c
586cba
@@ -1622,6 +1622,9 @@ static void spapr_machine_reset(MachineState *machine)
495e37
 
495e37
     pef_kvm_reset(machine->cgs, &error_fatal);
495e37
     spapr_caps_apply(spapr);
495e37
+    if (spapr->svm_allowed) {
495e37
+        kvmppc_svm_allow(&error_fatal);
495e37
+    }
495e37
 
495e37
     first_ppc_cpu = POWERPC_CPU(first_cpu);
495e37
     if (kvm_enabled() && kvmppc_has_cap_mmu_radix() &&
586cba
@@ -3317,6 +3320,20 @@ static void spapr_set_host_serial(Object *obj, const char *value, Error **errp)
495e37
     spapr->host_serial = g_strdup(value);
495e37
 }
495e37
 
495e37
+static bool spapr_get_svm_allowed(Object *obj, Error **errp)
495e37
+{
495e37
+    SpaprMachineState *spapr = SPAPR_MACHINE(obj);
495e37
+
495e37
+    return spapr->svm_allowed;
495e37
+}
495e37
+
495e37
+static void spapr_set_svm_allowed(Object *obj, bool value, Error **errp)
495e37
+{
495e37
+    SpaprMachineState *spapr = SPAPR_MACHINE(obj);
495e37
+
495e37
+    spapr->svm_allowed = value;
495e37
+}
495e37
+
495e37
 static void spapr_instance_init(Object *obj)
495e37
 {
495e37
     SpaprMachineState *spapr = SPAPR_MACHINE(obj);
586cba
@@ -3395,6 +3412,12 @@ static void spapr_instance_init(Object *obj)
495e37
         spapr_get_host_serial, spapr_set_host_serial);
495e37
     object_property_set_description(obj, "host-serial",
495e37
         "Host serial number to advertise in guest device tree");
495e37
+    object_property_add_bool(obj, "x-svm-allowed",
495e37
+                            spapr_get_svm_allowed,
495e37
+                            spapr_set_svm_allowed);
495e37
+    object_property_set_description(obj, "x-svm-allowed",
495e37
+                                    "Allow the guest to become a Secure Guest"
495e37
+                                    " (experimental only)");
495e37
 }
495e37
 
495e37
 static void spapr_machine_finalizefn(Object *obj)
586cba
@@ -4652,6 +4675,7 @@ static void spapr_machine_class_init(ObjectClass *oc, void *data)
495e37
     vmc->client_architecture_support = spapr_vof_client_architecture_support;
495e37
     vmc->quiesce = spapr_vof_quiesce;
495e37
     vmc->setprop = spapr_vof_setprop;
495e37
+    smc->has_power9_support = true;
495e37
 }
495e37
 
495e37
 static const TypeInfo spapr_machine_info = {
586cba
@@ -4703,6 +4727,7 @@ static void spapr_machine_latest_class_options(MachineClass *mc)
495e37
     }                                                                \
495e37
     type_init(spapr_machine_register_##suffix)
495e37
 
495e37
+#if 0 /* Disabled for Red Hat Enterprise Linux */
495e37
 /*
586cba
  * pseries-7.0
495e37
  */
586cba
@@ -4830,6 +4855,7 @@ static void spapr_machine_4_1_class_options(MachineClass *mc)
495e37
 }
495e37
 
495e37
 DEFINE_SPAPR_MACHINE(4_1, "4.1", false);
495e37
+#endif
495e37
 
495e37
 /*
495e37
  * pseries-4.0
586cba
@@ -4849,6 +4875,8 @@ static bool phb_placement_4_0(SpaprMachineState *spapr, uint32_t index,
495e37
     *nv2atsd = 0;
495e37
     return true;
495e37
 }
495e37
+
495e37
+#if 0 /* Disabled for Red Hat Enterprise Linux */
495e37
 static void spapr_machine_4_0_class_options(MachineClass *mc)
495e37
 {
495e37
     SpaprMachineClass *smc = SPAPR_MACHINE_CLASS(mc);
586cba
@@ -5176,6 +5204,221 @@ static void spapr_machine_2_1_class_options(MachineClass *mc)
495e37
     compat_props_add(mc->compat_props, hw_compat_2_1, hw_compat_2_1_len);
495e37
 }
495e37
 DEFINE_SPAPR_MACHINE(2_1, "2.1", false);
495e37
+#endif
495e37
+
495e37
+static void spapr_machine_rhel_default_class_options(MachineClass *mc)
495e37
+{
495e37
+    /*
495e37
+     * Defaults for the latest behaviour inherited from the base class
495e37
+     * can be overriden here for all pseries-rhel* machines.
495e37
+     */
495e37
+
495e37
+    /* Maximum supported VCPU count */
495e37
+    mc->max_cpus = 384;
495e37
+}
495e37
+
495e37
+/*
495e37
+ * pseries-rhel8.5.0
495e37
+ * like pseries-6.0
495e37
+ */
495e37
+
495e37
+static void spapr_machine_rhel850_class_options(MachineClass *mc)
495e37
+{
495e37
+    SpaprMachineClass *smc = SPAPR_MACHINE_CLASS(mc);
495e37
+
495e37
+    /* The default machine type must apply the RHEL specific defaults */
495e37
+    spapr_machine_rhel_default_class_options(mc);
495e37
+    compat_props_add(mc->compat_props, hw_compat_rhel_8_5,
495e37
+                     hw_compat_rhel_8_5_len);
495e37
+    smc->pre_6_2_numa_affinity = true;
495e37
+    mc->smp_props.prefer_sockets = true;
495e37
+}
495e37
+
495e37
+DEFINE_SPAPR_MACHINE(rhel850, "rhel8.5.0", true);
495e37
+
495e37
+/*
495e37
+ * pseries-rhel8.4.0
495e37
+ * like pseries-5.2
495e37
+ */
495e37
+
495e37
+static void spapr_machine_rhel840_class_options(MachineClass *mc)
495e37
+{
495e37
+    spapr_machine_rhel850_class_options(mc);
495e37
+    compat_props_add(mc->compat_props, hw_compat_rhel_8_4,
495e37
+                     hw_compat_rhel_8_4_len);
495e37
+}
495e37
+
495e37
+DEFINE_SPAPR_MACHINE(rhel840, "rhel8.4.0", false);
495e37
+
495e37
+/*
495e37
+ * pseries-rhel8.3.0
495e37
+ * like pseries-5.1
495e37
+ */
495e37
+
495e37
+static void spapr_machine_rhel830_class_options(MachineClass *mc)
495e37
+{
495e37
+    SpaprMachineClass *smc = SPAPR_MACHINE_CLASS(mc);
495e37
+
495e37
+    spapr_machine_rhel840_class_options(mc);
495e37
+    compat_props_add(mc->compat_props, hw_compat_rhel_8_3,
495e37
+                     hw_compat_rhel_8_3_len);
495e37
+
495e37
+    /* from pseries-5.1 */
495e37
+    smc->pre_5_2_numa_associativity = true;
495e37
+}
495e37
+
495e37
+DEFINE_SPAPR_MACHINE(rhel830, "rhel8.3.0", false);
495e37
+
495e37
+/*
495e37
+ * pseries-rhel8.2.0
495e37
+ * like pseries-4.2 + pseries-5.0
495e37
+ * except SPAPR_CAP_CCF_ASSIST that has been backported to pseries-rhel8.1.0
495e37
+ */
495e37
+
495e37
+static void spapr_machine_rhel820_class_options(MachineClass *mc)
495e37
+{
495e37
+    SpaprMachineClass *smc = SPAPR_MACHINE_CLASS(mc);
495e37
+    /* from pseries-5.0 */
495e37
+    static GlobalProperty compat[] = {
495e37
+        { TYPE_SPAPR_PCI_HOST_BRIDGE, "pre-5.1-associativity", "on" },
495e37
+    };
495e37
+
495e37
+    spapr_machine_rhel830_class_options(mc);
495e37
+    compat_props_add(mc->compat_props, hw_compat_rhel_8_2,
495e37
+                     hw_compat_rhel_8_2_len);
495e37
+    compat_props_add(mc->compat_props, compat, G_N_ELEMENTS(compat));
495e37
+
495e37
+    /* from pseries-4.2 */
495e37
+    smc->default_caps.caps[SPAPR_CAP_FWNMI] = SPAPR_CAP_OFF;
495e37
+    smc->rma_limit = 16 * GiB;
495e37
+    mc->nvdimm_supported = false;
495e37
+
495e37
+    /* from pseries-5.0 */
495e37
+    mc->numa_mem_supported = true;
495e37
+    smc->pre_5_1_assoc_refpoints = true;
495e37
+}
495e37
+
495e37
+DEFINE_SPAPR_MACHINE(rhel820, "rhel8.2.0", false);
495e37
+
495e37
+/*
495e37
+ * pseries-rhel8.1.0
495e37
+ * like pseries-4.1
495e37
+ */
495e37
+
495e37
+static void spapr_machine_rhel810_class_options(MachineClass *mc)
495e37
+{
495e37
+    SpaprMachineClass *smc = SPAPR_MACHINE_CLASS(mc);
495e37
+    static GlobalProperty compat[] = {
495e37
+        /* Only allow 4kiB and 64kiB IOMMU pagesizes */
495e37
+        { TYPE_SPAPR_PCI_HOST_BRIDGE, "pgsz", "0x11000" },
495e37
+    };
495e37
+
495e37
+    spapr_machine_rhel820_class_options(mc);
495e37
+
495e37
+    /* from pseries-4.1 */
495e37
+    smc->linux_pci_probe = false;
495e37
+    smc->smp_threads_vsmt = false;
495e37
+    compat_props_add(mc->compat_props, hw_compat_rhel_8_1,
495e37
+                     hw_compat_rhel_8_1_len);
495e37
+    compat_props_add(mc->compat_props, compat, G_N_ELEMENTS(compat));
495e37
+
495e37
+    /* from pseries-4.2 */
495e37
+    smc->default_caps.caps[SPAPR_CAP_CCF_ASSIST] = SPAPR_CAP_OFF;
495e37
+}
495e37
+
495e37
+DEFINE_SPAPR_MACHINE(rhel810, "rhel8.1.0", false);
495e37
+
495e37
+/*
495e37
+ * pseries-rhel8.0.0
495e37
+ * like pseries-3.1 and pseries-4.0
495e37
+ * except SPAPR_CAP_CFPC, SPAPR_CAP_SBBC and SPAPR_CAP_IBS
495e37
+ * that have been backported to pseries-rhel8.0.0
495e37
+ */
495e37
+
495e37
+static void spapr_machine_rhel800_class_options(MachineClass *mc)
495e37
+{
495e37
+    SpaprMachineClass *smc = SPAPR_MACHINE_CLASS(mc);
495e37
+
495e37
+    spapr_machine_rhel810_class_options(mc);
495e37
+    compat_props_add(mc->compat_props, hw_compat_rhel_8_0,
495e37
+                     hw_compat_rhel_8_0_len);
495e37
+
495e37
+    /* pseries-4.0 */
495e37
+    smc->phb_placement = phb_placement_4_0;
495e37
+    smc->irq = &spapr_irq_xics;
495e37
+    smc->pre_4_1_migration = true;
495e37
+
495e37
+    /* pseries-3.1 */
495e37
+    mc->default_cpu_type = POWERPC_CPU_TYPE_NAME("power8_v2.0");
495e37
+    smc->update_dt_enabled = false;
495e37
+    smc->dr_phb_enabled = false;
495e37
+    smc->broken_host_serial_model = true;
495e37
+    smc->default_caps.caps[SPAPR_CAP_LARGE_DECREMENTER] = SPAPR_CAP_OFF;
495e37
+}
495e37
+
495e37
+DEFINE_SPAPR_MACHINE(rhel800, "rhel8.0.0", false);
495e37
+
495e37
+/*
495e37
+ * pseries-rhel7.6.0
495e37
+ * like spapr_compat_2_12 and spapr_compat_3_0
495e37
+ * spapr_compat_0 is empty
495e37
+ */
495e37
+GlobalProperty spapr_compat_rhel7_6[] = {
495e37
+    { TYPE_POWERPC_CPU, "pre-3.0-migration", "on" },
495e37
+    { TYPE_SPAPR_CPU_CORE, "pre-3.0-migration", "on" },
495e37
+};
495e37
+const size_t spapr_compat_rhel7_6_len = G_N_ELEMENTS(spapr_compat_rhel7_6);
495e37
+
495e37
+
495e37
+static void spapr_machine_rhel760_class_options(MachineClass *mc)
495e37
+{
495e37
+    SpaprMachineClass *smc = SPAPR_MACHINE_CLASS(mc);
495e37
+
495e37
+    spapr_machine_rhel800_class_options(mc);
495e37
+    compat_props_add(mc->compat_props, hw_compat_rhel_7_6, hw_compat_rhel_7_6_len);
495e37
+    compat_props_add(mc->compat_props, spapr_compat_rhel7_6, spapr_compat_rhel7_6_len);
495e37
+
495e37
+    /* from spapr_machine_3_0_class_options() */
495e37
+    smc->legacy_irq_allocation = true;
495e37
+    smc->nr_xirqs = 0x400;
495e37
+    smc->irq = &spapr_irq_xics_legacy;
495e37
+
495e37
+    /* from spapr_machine_2_12_class_options() */
495e37
+    /* We depend on kvm_enabled() to choose a default value for the
495e37
+     * hpt-max-page-size capability. Of course we can't do it here
495e37
+     * because this is too early and the HW accelerator isn't initialzed
495e37
+     * yet. Postpone this to machine init (see default_caps_with_cpu()).
495e37
+     */
495e37
+    smc->default_caps.caps[SPAPR_CAP_HPT_MAXPAGESIZE] = 0;
495e37
+
495e37
+    /* SPAPR_CAP_WORKAROUND enabled in pseries-rhel800 by
495e37
+     * f21757edc554
495e37
+     * "Enable mitigations by default for pseries-4.0 machine type")
495e37
+     */
495e37
+    smc->default_caps.caps[SPAPR_CAP_CFPC] = SPAPR_CAP_BROKEN;
495e37
+    smc->default_caps.caps[SPAPR_CAP_SBBC] = SPAPR_CAP_BROKEN;
495e37
+    smc->default_caps.caps[SPAPR_CAP_IBS] = SPAPR_CAP_BROKEN;
495e37
+}
495e37
+
495e37
+DEFINE_SPAPR_MACHINE(rhel760, "rhel7.6.0", false);
495e37
+
495e37
+/*
495e37
+ * pseries-rhel7.6.0-sxxm
495e37
+ *
495e37
+ * pseries-rhel7.6.0 with speculative execution exploit mitigations enabled by default
495e37
+ */
495e37
+
495e37
+static void spapr_machine_rhel760sxxm_class_options(MachineClass *mc)
495e37
+{
495e37
+    SpaprMachineClass *smc = SPAPR_MACHINE_CLASS(mc);
495e37
+
495e37
+    spapr_machine_rhel760_class_options(mc);
495e37
+    smc->default_caps.caps[SPAPR_CAP_CFPC] = SPAPR_CAP_WORKAROUND;
495e37
+    smc->default_caps.caps[SPAPR_CAP_SBBC] = SPAPR_CAP_WORKAROUND;
495e37
+    smc->default_caps.caps[SPAPR_CAP_IBS] = SPAPR_CAP_FIXED_CCD;
495e37
+}
495e37
+
495e37
+DEFINE_SPAPR_MACHINE(rhel760sxxm, "rhel7.6.0-sxxm", false);
495e37
 
495e37
 static void spapr_machine_register_types(void)
495e37
 {
495e37
diff --git a/hw/ppc/spapr_cpu_core.c b/hw/ppc/spapr_cpu_core.c
586cba
index fcb5dfe792..ab8fb5bf62 100644
495e37
--- a/hw/ppc/spapr_cpu_core.c
495e37
+++ b/hw/ppc/spapr_cpu_core.c
586cba
@@ -25,6 +25,7 @@
495e37
 #include "sysemu/reset.h"
495e37
 #include "sysemu/hw_accel.h"
495e37
 #include "qemu/error-report.h"
495e37
+#include "cpu-models.h"
495e37
 
495e37
 static void spapr_reset_vcpu(PowerPCCPU *cpu)
495e37
 {
586cba
@@ -259,6 +260,7 @@ static bool spapr_realize_vcpu(PowerPCCPU *cpu, SpaprMachineState *spapr,
495e37
 {
495e37
     CPUPPCState *env = &cpu->env;
495e37
     CPUState *cs = CPU(cpu);
495e37
+    SpaprMachineClass *smc = SPAPR_MACHINE_GET_CLASS(spapr);
495e37
 
495e37
     if (!qdev_realize(DEVICE(cpu), NULL, errp)) {
495e37
         return false;
586cba
@@ -270,6 +272,17 @@ static bool spapr_realize_vcpu(PowerPCCPU *cpu, SpaprMachineState *spapr,
586cba
     /* Set time-base frequency to 512 MHz. vhyp must be set first. */
586cba
     cpu_ppc_tb_init(env, SPAPR_TIMEBASE_FREQ);
495e37
 
495e37
+    if (!smc->has_power9_support &&
495e37
+        (((spapr->max_compat_pvr &&
495e37
+           ppc_compat_cmp(spapr->max_compat_pvr,
495e37
+                          CPU_POWERPC_LOGICAL_3_00) >= 0)) ||
495e37
+          (!spapr->max_compat_pvr &&
495e37
+           ppc_check_compat(cpu, CPU_POWERPC_LOGICAL_3_00, 0, 0)))) {
495e37
+        error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND,
495e37
+                  "POWER9 CPU is not supported by this machine class");
495e37
+        return false;
495e37
+    }
495e37
+
495e37
     if (spapr_irq_cpu_intc_create(spapr, cpu, errp) < 0) {
495e37
         qdev_unrealize(DEVICE(cpu));
495e37
         return false;
495e37
diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h
586cba
index f5c33dcc86..4a68e0a901 100644
495e37
--- a/include/hw/ppc/spapr.h
495e37
+++ b/include/hw/ppc/spapr.h
495e37
@@ -154,6 +154,7 @@ struct SpaprMachineClass {
495e37
     bool pre_5_2_numa_associativity;
495e37
     bool pre_6_2_numa_affinity;
495e37
 
495e37
+    bool has_power9_support;
495e37
     bool (*phb_placement)(SpaprMachineState *spapr, uint32_t index,
495e37
                           uint64_t *buid, hwaddr *pio,
495e37
                           hwaddr *mmio32, hwaddr *mmio64,
586cba
@@ -241,6 +242,9 @@ struct SpaprMachineState {
495e37
     /* Set by -boot */
495e37
     char *boot_device;
495e37
 
495e37
+    /* Secure Guest support via x-svm-allowed */
495e37
+    bool svm_allowed;
495e37
+
495e37
     /*< public >*/
495e37
     char *kvm_type;
495e37
     char *host_model;
495e37
diff --git a/target/ppc/compat.c b/target/ppc/compat.c
495e37
index 7949a24f5a..f207a9ba01 100644
495e37
--- a/target/ppc/compat.c
495e37
+++ b/target/ppc/compat.c
495e37
@@ -114,8 +114,19 @@ static const CompatInfo *compat_by_pvr(uint32_t pvr)
495e37
     return NULL;
495e37
 }
495e37
 
495e37
+long ppc_compat_cmp(uint32_t pvr1, uint32_t pvr2)
495e37
+{
495e37
+    const CompatInfo *compat1 = compat_by_pvr(pvr1);
495e37
+    const CompatInfo *compat2 = compat_by_pvr(pvr2);
495e37
+
495e37
+    g_assert(compat1);
495e37
+    g_assert(compat2);
495e37
+
495e37
+    return compat1 - compat2;
495e37
+}
495e37
+
495e37
 static bool pcc_compat(PowerPCCPUClass *pcc, uint32_t compat_pvr,
495e37
-                       uint32_t min_compat_pvr, uint32_t max_compat_pvr)
495e37
+                      uint32_t min_compat_pvr, uint32_t max_compat_pvr)
495e37
 {
495e37
     const CompatInfo *compat = compat_by_pvr(compat_pvr);
495e37
     const CompatInfo *min = compat_by_pvr(min_compat_pvr);
495e37
diff --git a/target/ppc/cpu.h b/target/ppc/cpu.h
586cba
index 047b24ba50..79c5ac50b9 100644
495e37
--- a/target/ppc/cpu.h
495e37
+++ b/target/ppc/cpu.h
586cba
@@ -1462,6 +1462,7 @@ static inline int cpu_mmu_index(CPUPPCState *env, bool ifetch)
495e37
 
495e37
 /* Compatibility modes */
495e37
 #if defined(TARGET_PPC64)
495e37
+long ppc_compat_cmp(uint32_t pvr1, uint32_t pvr2);
495e37
 bool ppc_check_compat(PowerPCCPU *cpu, uint32_t compat_pvr,
495e37
                       uint32_t min_compat_pvr, uint32_t max_compat_pvr);
495e37
 bool ppc_type_check_compat(const char *cputype, uint32_t compat_pvr,
495e37
diff --git a/target/ppc/kvm.c b/target/ppc/kvm.c
495e37
index dc93b99189..154888cce5 100644
495e37
--- a/target/ppc/kvm.c
495e37
+++ b/target/ppc/kvm.c
495e37
@@ -90,6 +90,7 @@ static int cap_ppc_nested_kvm_hv;
495e37
 static int cap_large_decr;
495e37
 static int cap_fwnmi;
495e37
 static int cap_rpt_invalidate;
495e37
+static int cap_ppc_secure_guest;
495e37
 
495e37
 static uint32_t debug_inst_opcode;
495e37
 
495e37
@@ -137,6 +138,7 @@ int kvm_arch_init(MachineState *ms, KVMState *s)
495e37
     cap_resize_hpt = kvm_vm_check_extension(s, KVM_CAP_SPAPR_RESIZE_HPT);
495e37
     kvmppc_get_cpu_characteristics(s);
495e37
     cap_ppc_nested_kvm_hv = kvm_vm_check_extension(s, KVM_CAP_PPC_NESTED_HV);
495e37
+    cap_ppc_secure_guest = kvm_vm_check_extension(s, KVM_CAP_PPC_SECURE_GUEST);
495e37
     cap_large_decr = kvmppc_get_dec_bits();
495e37
     cap_fwnmi = kvm_vm_check_extension(s, KVM_CAP_PPC_FWNMI);
495e37
     /*
495e37
@@ -2563,6 +2565,16 @@ int kvmppc_has_cap_rpt_invalidate(void)
495e37
     return cap_rpt_invalidate;
495e37
 }
495e37
 
495e37
+bool kvmppc_has_cap_secure_guest(void)
495e37
+{
495e37
+    return !!cap_ppc_secure_guest;
495e37
+}
495e37
+
495e37
+int kvmppc_enable_cap_secure_guest(void)
495e37
+{
495e37
+    return kvm_vm_enable_cap(kvm_state, KVM_CAP_PPC_SECURE_GUEST, 0, 1);
495e37
+}
495e37
+
495e37
 PowerPCCPUClass *kvm_ppc_get_host_cpu_class(void)
495e37
 {
495e37
     uint32_t host_pvr = mfpvr();
495e37
@@ -2959,3 +2971,18 @@ bool kvm_arch_cpu_check_are_resettable(void)
495e37
 {
495e37
     return true;
495e37
 }
495e37
+
495e37
+void kvmppc_svm_allow(Error **errp)
495e37
+{
495e37
+    if (!kvm_enabled()) {
495e37
+        error_setg(errp, "No PEF support in tcg, try x-svm-allowed=off");
495e37
+        return;
495e37
+    }
495e37
+
495e37
+    if (!kvmppc_has_cap_secure_guest()) {
495e37
+        error_setg(errp, "KVM implementation does not support secure guests, "
495e37
+                   "try x-svm-allowed=off");
495e37
+    } else if (kvmppc_enable_cap_secure_guest() < 0) {
495e37
+        error_setg(errp, "Error enabling x-svm-allowed, try x-svm-allowed=off");
495e37
+    }
495e37
+}
495e37
diff --git a/target/ppc/kvm_ppc.h b/target/ppc/kvm_ppc.h
495e37
index ee9325bf9a..20dbb95989 100644
495e37
--- a/target/ppc/kvm_ppc.h
495e37
+++ b/target/ppc/kvm_ppc.h
495e37
@@ -40,6 +40,7 @@ int kvmppc_booke_watchdog_enable(PowerPCCPU *cpu);
495e37
 target_ulong kvmppc_configure_v3_mmu(PowerPCCPU *cpu,
495e37
                                      bool radix, bool gtse,
495e37
                                      uint64_t proc_tbl);
495e37
+void kvmppc_svm_allow(Error **errp);
495e37
 #ifndef CONFIG_USER_ONLY
495e37
 bool kvmppc_spapr_use_multitce(void);
495e37
 int kvmppc_spapr_enable_inkernel_multitce(void);
495e37
@@ -74,6 +75,8 @@ int kvmppc_get_cap_large_decr(void);
495e37
 int kvmppc_enable_cap_large_decr(PowerPCCPU *cpu, int enable);
495e37
 int kvmppc_has_cap_rpt_invalidate(void);
495e37
 int kvmppc_enable_hwrng(void);
495e37
+bool kvmppc_has_cap_secure_guest(void);
495e37
+int kvmppc_enable_cap_secure_guest(void);
495e37
 int kvmppc_put_books_sregs(PowerPCCPU *cpu);
495e37
 PowerPCCPUClass *kvm_ppc_get_host_cpu_class(void);
495e37
 void kvmppc_check_papr_resize_hpt(Error **errp);
495e37
@@ -393,6 +396,16 @@ static inline int kvmppc_has_cap_rpt_invalidate(void)
495e37
     return false;
495e37
 }
495e37
 
495e37
+static inline bool kvmppc_has_cap_secure_guest(void)
495e37
+{
495e37
+    return false;
495e37
+}
495e37
+
495e37
+static inline int kvmppc_enable_cap_secure_guest(void)
495e37
+{
495e37
+    return -1;
495e37
+}
495e37
+
495e37
 static inline int kvmppc_enable_hwrng(void)
495e37
 {
495e37
     return -1;
495e37
-- 
586cba
2.31.1
495e37