437 lines
15 KiB
Diff
437 lines
15 KiB
Diff
From 078107cb85368f95afc5f48ec7712a3c9213b157 Mon Sep 17 00:00:00 2001
|
|
From: eabdullin <ed.abdullin.1@gmail.com>
|
|
Date: Tue, 26 Nov 2024 13:11:35 +0300
|
|
Subject: [PATCH] Add ppc64 support
|
|
|
|
---
|
|
hw/ppc/spapr.c | 101 ++++++++++++++++++++++++++++++++++++++++
|
|
hw/ppc/spapr_cpu_core.c | 16 +++++++
|
|
include/hw/ppc/spapr.h | 3 ++
|
|
target/ppc/compat.c | 11 +++++
|
|
target/ppc/cpu-models.c | 9 +++-
|
|
target/ppc/cpu.h | 1 +
|
|
target/ppc/kvm.c | 27 +++++++++++
|
|
target/ppc/kvm_ppc.h | 13 ++++++
|
|
8 files changed, 180 insertions(+), 1 deletion(-)
|
|
|
|
diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
|
|
index e9bc97fee..3e1713838 100644
|
|
--- a/hw/ppc/spapr.c
|
|
+++ b/hw/ppc/spapr.c
|
|
@@ -1718,6 +1718,13 @@ static void spapr_machine_reset(MachineState *machine, ShutdownCause reason)
|
|
pef_kvm_reset(machine->cgs, &error_fatal);
|
|
spapr_caps_apply(spapr);
|
|
spapr_nested_reset(spapr);
|
|
+ if (spapr->svm_allowed) {
|
|
+#ifdef CONFIG_KVM
|
|
+ kvmppc_svm_allow(&error_fatal);
|
|
+#else
|
|
+ error_setg(&error_fatal, "No PEF support in tcg, try x-svm-allowed=off");
|
|
+#endif
|
|
+ }
|
|
|
|
first_ppc_cpu = POWERPC_CPU(first_cpu);
|
|
if (kvm_enabled() && kvmppc_has_cap_mmu_radix() &&
|
|
@@ -3421,6 +3428,20 @@ static void spapr_set_host_serial(Object *obj, const char *value, Error **errp)
|
|
spapr->host_serial = g_strdup(value);
|
|
}
|
|
|
|
+static bool spapr_get_svm_allowed(Object *obj, Error **errp)
|
|
+{
|
|
+ SpaprMachineState *spapr = SPAPR_MACHINE(obj);
|
|
+
|
|
+ return spapr->svm_allowed;
|
|
+}
|
|
+
|
|
+static void spapr_set_svm_allowed(Object *obj, bool value, Error **errp)
|
|
+{
|
|
+ SpaprMachineState *spapr = SPAPR_MACHINE(obj);
|
|
+
|
|
+ spapr->svm_allowed = value;
|
|
+}
|
|
+
|
|
static void spapr_instance_init(Object *obj)
|
|
{
|
|
SpaprMachineState *spapr = SPAPR_MACHINE(obj);
|
|
@@ -3499,6 +3520,12 @@ static void spapr_instance_init(Object *obj)
|
|
spapr_get_host_serial, spapr_set_host_serial);
|
|
object_property_set_description(obj, "host-serial",
|
|
"Host serial number to advertise in guest device tree");
|
|
+ object_property_add_bool(obj, "x-svm-allowed",
|
|
+ spapr_get_svm_allowed,
|
|
+ spapr_set_svm_allowed);
|
|
+ object_property_set_description(obj, "x-svm-allowed",
|
|
+ "Allow the guest to become a Secure Guest"
|
|
+ " (experimental only)");
|
|
}
|
|
|
|
static void spapr_machine_finalizefn(Object *obj)
|
|
@@ -4754,6 +4781,7 @@ static void spapr_machine_class_init(ObjectClass *oc, void *data)
|
|
vmc->client_architecture_support = spapr_vof_client_architecture_support;
|
|
vmc->quiesce = spapr_vof_quiesce;
|
|
vmc->setprop = spapr_vof_setprop;
|
|
+ smc->has_power9_support = true;
|
|
}
|
|
|
|
static const TypeInfo spapr_machine_info = {
|
|
@@ -4805,6 +4833,7 @@ static void spapr_machine_latest_class_options(MachineClass *mc)
|
|
} \
|
|
type_init(spapr_machine_register_##suffix)
|
|
|
|
+#if 0 /* Disabled for Red Hat Enterprise Linux */
|
|
/*
|
|
* pseries-9.0
|
|
*/
|
|
@@ -5013,6 +5042,9 @@ static bool phb_placement_4_0(SpaprMachineState *spapr, uint32_t index,
|
|
}
|
|
return true;
|
|
}
|
|
+#endif
|
|
+
|
|
+#if 0 /* Disabled for Red Hat Enterprise Linux */
|
|
static void spapr_machine_4_0_class_options(MachineClass *mc)
|
|
{
|
|
SpaprMachineClass *smc = SPAPR_MACHINE_CLASS(mc);
|
|
@@ -5338,6 +5370,75 @@ static void spapr_machine_2_1_class_options(MachineClass *mc)
|
|
compat_props_add(mc->compat_props, hw_compat_2_1, hw_compat_2_1_len);
|
|
}
|
|
DEFINE_SPAPR_MACHINE(2_1, "2.1", false);
|
|
+#endif /* disabled for RHEL */
|
|
+
|
|
+static void spapr_rhel_machine_default_class_options(MachineClass *mc)
|
|
+{
|
|
+ /*
|
|
+ * Defaults for the latest behaviour inherited from the base class
|
|
+ * can be overriden here for all pseries-rhel* machines.
|
|
+ */
|
|
+
|
|
+ /* Maximum supported VCPU count */
|
|
+ mc->max_cpus = 384;
|
|
+}
|
|
+
|
|
+static void spapr_machine_rhel950_class_options(MachineClass *mc)
|
|
+{
|
|
+ SpaprMachineClass *smc = SPAPR_MACHINE_CLASS(mc);
|
|
+ spapr_rhel_machine_default_class_options(mc);
|
|
+ compat_props_add(mc->compat_props, hw_compat_rhel_9_5,
|
|
+ hw_compat_rhel_9_5_len);
|
|
+ smc->pre_6_2_numa_affinity = true;
|
|
+ mc->smp_props.prefer_sockets = true;
|
|
+}
|
|
+
|
|
+DEFINE_SPAPR_MACHINE(rhel950, "rhel9.5.0", true);
|
|
+
|
|
+static void spapr_machine_rhel940_class_options(MachineClass *mc)
|
|
+{
|
|
+ spapr_machine_rhel950_class_options(mc);
|
|
+ compat_props_add(mc->compat_props, hw_compat_rhel_9_4,
|
|
+ hw_compat_rhel_9_4_len);
|
|
+}
|
|
+
|
|
+DEFINE_SPAPR_MACHINE(rhel940, "rhel9.4.0", false);
|
|
+
|
|
+static void spapr_machine_rhel930_class_options(MachineClass *mc)
|
|
+{
|
|
+ spapr_machine_rhel940_class_options(mc);
|
|
+ compat_props_add(mc->compat_props, hw_compat_rhel_9_3,
|
|
+ hw_compat_rhel_9_3_len);
|
|
+}
|
|
+
|
|
+DEFINE_SPAPR_MACHINE(rhel930, "rhel9.3.0", false);
|
|
+
|
|
+static void spapr_machine_rhel920_class_options(MachineClass *mc)
|
|
+{
|
|
+ spapr_machine_rhel930_class_options(mc);
|
|
+ compat_props_add(mc->compat_props, hw_compat_rhel_9_2,
|
|
+ hw_compat_rhel_9_2_len);
|
|
+}
|
|
+
|
|
+DEFINE_SPAPR_MACHINE(rhel920, "rhel9.2.0", false);
|
|
+
|
|
+static void spapr_machine_rhel910_class_options(MachineClass *mc)
|
|
+{
|
|
+ spapr_machine_rhel920_class_options(mc);
|
|
+ compat_props_add(mc->compat_props, hw_compat_rhel_9_1,
|
|
+ hw_compat_rhel_9_1_len);
|
|
+}
|
|
+
|
|
+DEFINE_SPAPR_MACHINE(rhel910, "rhel9.1.0", false);
|
|
+
|
|
+static void spapr_machine_rhel900_class_options(MachineClass *mc)
|
|
+{
|
|
+ spapr_machine_rhel910_class_options(mc);
|
|
+ compat_props_add(mc->compat_props, hw_compat_rhel_9_0,
|
|
+ hw_compat_rhel_9_0_len);
|
|
+}
|
|
+
|
|
+DEFINE_SPAPR_MACHINE(rhel900, "rhel9.0.0", false);
|
|
|
|
static void spapr_machine_register_types(void)
|
|
{
|
|
diff --git a/hw/ppc/spapr_cpu_core.c b/hw/ppc/spapr_cpu_core.c
|
|
index e7c9edd03..c33c321d1 100644
|
|
--- a/hw/ppc/spapr_cpu_core.c
|
|
+++ b/hw/ppc/spapr_cpu_core.c
|
|
@@ -25,6 +25,7 @@
|
|
#include "sysemu/reset.h"
|
|
#include "sysemu/hw_accel.h"
|
|
#include "qemu/error-report.h"
|
|
+#include "cpu-models.h"
|
|
|
|
static void spapr_reset_vcpu(PowerPCCPU *cpu)
|
|
{
|
|
@@ -264,6 +265,7 @@ static bool spapr_realize_vcpu(PowerPCCPU *cpu, SpaprMachineState *spapr,
|
|
{
|
|
CPUPPCState *env = &cpu->env;
|
|
CPUState *cs = CPU(cpu);
|
|
+ SpaprMachineClass *smc = SPAPR_MACHINE_GET_CLASS(spapr);
|
|
|
|
if (!qdev_realize(DEVICE(cpu), NULL, errp)) {
|
|
return false;
|
|
@@ -280,6 +282,18 @@ static bool spapr_realize_vcpu(PowerPCCPU *cpu, SpaprMachineState *spapr,
|
|
/* Set time-base frequency to 512 MHz. vhyp must be set first. */
|
|
cpu_ppc_tb_init(env, SPAPR_TIMEBASE_FREQ);
|
|
|
|
+ if (!smc->has_power9_support &&
|
|
+ (((spapr->max_compat_pvr &&
|
|
+ ppc_compat_cmp(spapr->max_compat_pvr,
|
|
+ CPU_POWERPC_LOGICAL_3_00) >= 0)) ||
|
|
+ (!spapr->max_compat_pvr &&
|
|
+ ppc_check_compat(cpu, CPU_POWERPC_LOGICAL_3_00, 0, 0)))) {
|
|
+ error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND,
|
|
+ "POWER9 CPU is not supported by this machine class");
|
|
+ return false;
|
|
+ }
|
|
+
|
|
+
|
|
if (spapr_irq_cpu_intc_create(spapr, cpu, errp) < 0) {
|
|
qdev_unrealize(DEVICE(cpu));
|
|
return false;
|
|
@@ -389,10 +403,12 @@ static const TypeInfo spapr_cpu_core_type_infos[] = {
|
|
.instance_size = sizeof(SpaprCpuCore),
|
|
.class_size = sizeof(SpaprCpuCoreClass),
|
|
},
|
|
+#if 0 /* Disabled for Red Hat Enterprise Linux */
|
|
DEFINE_SPAPR_CPU_CORE_TYPE("970_v2.2"),
|
|
DEFINE_SPAPR_CPU_CORE_TYPE("970mp_v1.0"),
|
|
DEFINE_SPAPR_CPU_CORE_TYPE("970mp_v1.1"),
|
|
DEFINE_SPAPR_CPU_CORE_TYPE("power5p_v2.1"),
|
|
+#endif
|
|
DEFINE_SPAPR_CPU_CORE_TYPE("power7_v2.3"),
|
|
DEFINE_SPAPR_CPU_CORE_TYPE("power7p_v2.1"),
|
|
DEFINE_SPAPR_CPU_CORE_TYPE("power8_v2.0"),
|
|
diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h
|
|
index 4aaf23d28..183a13702 100644
|
|
--- a/include/hw/ppc/spapr.h
|
|
+++ b/include/hw/ppc/spapr.h
|
|
@@ -157,6 +157,7 @@ struct SpaprMachineClass {
|
|
bool pre_5_2_numa_associativity;
|
|
bool pre_6_2_numa_affinity;
|
|
|
|
+ bool has_power9_support;
|
|
bool (*phb_placement)(SpaprMachineState *spapr, uint32_t index,
|
|
uint64_t *buid, hwaddr *pio,
|
|
hwaddr *mmio32, hwaddr *mmio64,
|
|
@@ -258,6 +259,8 @@ struct SpaprMachineState {
|
|
|
|
/* Set by -boot */
|
|
char *boot_device;
|
|
+ /* Secure Guest support via x-svm-allowed */
|
|
+ bool svm_allowed;
|
|
|
|
/*< public >*/
|
|
char *kvm_type;
|
|
diff --git a/target/ppc/compat.c b/target/ppc/compat.c
|
|
index ebef2ccce..ab7ed7680 100644
|
|
--- a/target/ppc/compat.c
|
|
+++ b/target/ppc/compat.c
|
|
@@ -114,6 +114,17 @@ static const CompatInfo *compat_by_pvr(uint32_t pvr)
|
|
return NULL;
|
|
}
|
|
|
|
+long ppc_compat_cmp(uint32_t pvr1, uint32_t pvr2)
|
|
+{
|
|
+ const CompatInfo *compat1 = compat_by_pvr(pvr1);
|
|
+ const CompatInfo *compat2 = compat_by_pvr(pvr2);
|
|
+
|
|
+ g_assert(compat1);
|
|
+ g_assert(compat2);
|
|
+
|
|
+ return compat1 - compat2;
|
|
+}
|
|
+
|
|
static bool pcc_compat(PowerPCCPUClass *pcc, uint32_t compat_pvr,
|
|
uint32_t min_compat_pvr, uint32_t max_compat_pvr)
|
|
{
|
|
diff --git a/target/ppc/cpu-models.c b/target/ppc/cpu-models.c
|
|
index f2301b43f..4c38fa517 100644
|
|
--- a/target/ppc/cpu-models.c
|
|
+++ b/target/ppc/cpu-models.c
|
|
@@ -66,6 +66,7 @@
|
|
#define POWERPC_DEF(_name, _pvr, _type, _desc) \
|
|
POWERPC_DEF_SVR(_name, _desc, _pvr, POWERPC_SVR_NONE, _type)
|
|
|
|
+#if 0 /* Embedded and 32-bit CPUs disabled for Red Hat Enterprise Linux */
|
|
/* Embedded PowerPC */
|
|
/* PowerPC 405 family */
|
|
/* PowerPC 405 cores */
|
|
@@ -698,8 +699,10 @@
|
|
"PowerPC 7447A v1.2 (G4)")
|
|
POWERPC_DEF("7457a_v1.2", CPU_POWERPC_74x7A_v12, 7455,
|
|
"PowerPC 7457A v1.2 (G4)")
|
|
+#endif
|
|
/* 64 bits PowerPC */
|
|
#if defined(TARGET_PPC64)
|
|
+#if 0 /* Disabled for Red Hat Enterprise Linux */
|
|
POWERPC_DEF("970_v2.2", CPU_POWERPC_970_v22, 970,
|
|
"PowerPC 970 v2.2")
|
|
POWERPC_DEF("970fx_v1.0", CPU_POWERPC_970FX_v10, 970,
|
|
@@ -718,6 +721,7 @@
|
|
"PowerPC 970MP v1.1")
|
|
POWERPC_DEF("power5p_v2.1", CPU_POWERPC_POWER5P_v21, POWER5P,
|
|
"POWER5+ v2.1")
|
|
+#endif
|
|
POWERPC_DEF("power7_v2.3", CPU_POWERPC_POWER7_v23, POWER7,
|
|
"POWER7 v2.3")
|
|
POWERPC_DEF("power7p_v2.1", CPU_POWERPC_POWER7P_v21, POWER7,
|
|
@@ -895,12 +899,14 @@ PowerPCCPUAlias ppc_cpu_aliases[] = {
|
|
{ "7457a", "7457a_v1.2" },
|
|
{ "apollo7pm", "7457a_v1.0" },
|
|
#if defined(TARGET_PPC64)
|
|
+#if 0 /* Disabled for Red Hat Enterprise Linux */
|
|
{ "970", "970_v2.2" },
|
|
{ "970fx", "970fx_v3.1" },
|
|
{ "970mp", "970mp_v1.1" },
|
|
{ "power5+", "power5p_v2.1" },
|
|
{ "power5+_v2.1", "power5p_v2.1" },
|
|
{ "power5gs", "power5+_v2.1" },
|
|
+#endif
|
|
{ "power7", "power7_v2.3" },
|
|
{ "power7+", "power7p_v2.1" },
|
|
{ "power7+_v2.1", "power7p_v2.1" },
|
|
@@ -910,13 +916,14 @@ PowerPCCPUAlias ppc_cpu_aliases[] = {
|
|
{ "power9", "power9_v2.2" },
|
|
{ "power10", "power10_v2.0" },
|
|
#endif
|
|
-
|
|
+#if 0 /* Disabled for Red Hat Enterprise Linux */
|
|
/* Generic PowerPCs */
|
|
#if defined(TARGET_PPC64)
|
|
{ "ppc64", "970fx_v3.1" },
|
|
#endif
|
|
{ "ppc32", "604" },
|
|
{ "ppc", "604" },
|
|
+#endif
|
|
|
|
{ NULL, NULL }
|
|
};
|
|
diff --git a/target/ppc/cpu.h b/target/ppc/cpu.h
|
|
index 67e6b2eff..11187aeb9 100644
|
|
--- a/target/ppc/cpu.h
|
|
+++ b/target/ppc/cpu.h
|
|
@@ -1655,6 +1655,7 @@ static inline int ppc_env_mmu_index(CPUPPCState *env, bool ifetch)
|
|
|
|
/* Compatibility modes */
|
|
#if defined(TARGET_PPC64)
|
|
+long ppc_compat_cmp(uint32_t pvr1, uint32_t pvr2);
|
|
bool ppc_check_compat(PowerPCCPU *cpu, uint32_t compat_pvr,
|
|
uint32_t min_compat_pvr, uint32_t max_compat_pvr);
|
|
bool ppc_type_check_compat(const char *cputype, uint32_t compat_pvr,
|
|
diff --git a/target/ppc/kvm.c b/target/ppc/kvm.c
|
|
index 8231feb2d..59f640cf7 100644
|
|
--- a/target/ppc/kvm.c
|
|
+++ b/target/ppc/kvm.c
|
|
@@ -89,6 +89,7 @@ static int cap_large_decr;
|
|
static int cap_fwnmi;
|
|
static int cap_rpt_invalidate;
|
|
static int cap_ail_mode_3;
|
|
+static int cap_ppc_secure_guest;
|
|
|
|
static uint32_t debug_inst_opcode;
|
|
|
|
@@ -141,6 +142,7 @@ int kvm_arch_init(MachineState *ms, KVMState *s)
|
|
cap_resize_hpt = kvm_vm_check_extension(s, KVM_CAP_SPAPR_RESIZE_HPT);
|
|
kvmppc_get_cpu_characteristics(s);
|
|
cap_ppc_nested_kvm_hv = kvm_vm_check_extension(s, KVM_CAP_PPC_NESTED_HV);
|
|
+ cap_ppc_secure_guest = kvm_vm_check_extension(s, KVM_CAP_PPC_SECURE_GUEST);
|
|
cap_large_decr = kvmppc_get_dec_bits();
|
|
cap_fwnmi = kvm_vm_check_extension(s, KVM_CAP_PPC_FWNMI);
|
|
/*
|
|
@@ -2564,6 +2566,16 @@ bool kvmppc_supports_ail_3(void)
|
|
return cap_ail_mode_3;
|
|
}
|
|
|
|
+bool kvmppc_has_cap_secure_guest(void)
|
|
+{
|
|
+ return !!cap_ppc_secure_guest;
|
|
+}
|
|
+
|
|
+int kvmppc_enable_cap_secure_guest(void)
|
|
+{
|
|
+ return kvm_vm_enable_cap(kvm_state, KVM_CAP_PPC_SECURE_GUEST, 0, 1);
|
|
+}
|
|
+
|
|
PowerPCCPUClass *kvm_ppc_get_host_cpu_class(void)
|
|
{
|
|
uint32_t host_pvr = mfpvr();
|
|
@@ -2964,3 +2976,18 @@ bool kvm_arch_cpu_check_are_resettable(void)
|
|
void kvm_arch_accel_class_init(ObjectClass *oc)
|
|
{
|
|
}
|
|
+
|
|
+void kvmppc_svm_allow(Error **errp)
|
|
+{
|
|
+ if (!kvm_enabled()) {
|
|
+ error_setg(errp, "No PEF support in tcg, try x-svm-allowed=off");
|
|
+ return;
|
|
+ }
|
|
+
|
|
+ if (!kvmppc_has_cap_secure_guest()) {
|
|
+ error_setg(errp, "KVM implementation does not support secure guests, "
|
|
+ "try x-svm-allowed=off");
|
|
+ } else if (kvmppc_enable_cap_secure_guest() < 0) {
|
|
+ error_setg(errp, "Error enabling x-svm-allowed, try x-svm-allowed=off");
|
|
+ }
|
|
+}
|
|
diff --git a/target/ppc/kvm_ppc.h b/target/ppc/kvm_ppc.h
|
|
index 1975fb5ee..d1017f98b 100644
|
|
--- a/target/ppc/kvm_ppc.h
|
|
+++ b/target/ppc/kvm_ppc.h
|
|
@@ -46,6 +46,7 @@ int kvmppc_booke_watchdog_enable(PowerPCCPU *cpu);
|
|
target_ulong kvmppc_configure_v3_mmu(PowerPCCPU *cpu,
|
|
bool radix, bool gtse,
|
|
uint64_t proc_tbl);
|
|
+void kvmppc_svm_allow(Error **errp);
|
|
bool kvmppc_spapr_use_multitce(void);
|
|
int kvmppc_spapr_enable_inkernel_multitce(void);
|
|
void *kvmppc_create_spapr_tce(uint32_t liobn, uint32_t page_shift,
|
|
@@ -79,6 +80,8 @@ int kvmppc_enable_cap_large_decr(PowerPCCPU *cpu, int enable);
|
|
int kvmppc_has_cap_rpt_invalidate(void);
|
|
bool kvmppc_supports_ail_3(void);
|
|
int kvmppc_enable_hwrng(void);
|
|
+bool kvmppc_has_cap_secure_guest(void);
|
|
+int kvmppc_enable_cap_secure_guest(void);
|
|
int kvmppc_put_books_sregs(PowerPCCPU *cpu);
|
|
PowerPCCPUClass *kvm_ppc_get_host_cpu_class(void);
|
|
void kvmppc_check_papr_resize_hpt(Error **errp);
|
|
@@ -427,6 +430,16 @@ static inline bool kvmppc_supports_ail_3(void)
|
|
return false;
|
|
}
|
|
|
|
+static inline bool kvmppc_has_cap_secure_guest(void)
|
|
+{
|
|
+ return false;
|
|
+}
|
|
+
|
|
+static inline int kvmppc_enable_cap_secure_guest(void)
|
|
+{
|
|
+ return -1;
|
|
+}
|
|
+
|
|
static inline int kvmppc_enable_hwrng(void)
|
|
{
|
|
return -1;
|
|
--
|
|
2.39.5 (Apple Git-154)
|
|
|