[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2 04/14] spapr: nested: Introduce cap-nested-papr for Nested PAP
From: |
Harsh Prateek Bora |
Subject: |
[PATCH v2 04/14] spapr: nested: Introduce cap-nested-papr for Nested PAPR API |
Date: |
Thu, 12 Oct 2023 16:19:41 +0530 |
Introduce a SPAPR capability cap-nested-papr which provides a nested
HV facility to the guest. This is similar to cap-nested-hv, but uses
a different (incompatible) API and so they are mutually exclusive.
This new API is to enable support for KVM on PowerVM and recently the
Linux kernel side patches have been accepted upstream as well [1].
Support for related hcalls is being added in next set of patches.
[1]
https://lore.kernel.org/linuxppc-dev/169528846875.874757.8861595746180557787.b4-ty@ellerman.id.au/
Signed-off-by: Michael Neuling <mikey@neuling.org>
Signed-off-by: Harsh Prateek Bora <harshpb@linux.ibm.com>
---
hw/ppc/spapr.c | 9 +++++-
hw/ppc/spapr_caps.c | 61 +++++++++++++++++++++++++++++++++++
hw/ppc/spapr_nested.c | 15 +++++++++
include/hw/ppc/spapr.h | 5 ++-
include/hw/ppc/spapr_nested.h | 5 +++
5 files changed, 93 insertions(+), 2 deletions(-)
diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
index a2c69d0f4f..14196fdd11 100644
--- a/hw/ppc/spapr.c
+++ b/hw/ppc/spapr.c
@@ -1355,7 +1355,11 @@ static bool spapr_get_pate(PPCVirtualHypervisor *vhyp,
PowerPCCPU *cpu,
entry->dw1 = spapr->patb_entry;
return true;
} else {
- return spapr_get_pate_nested(spapr, cpu, lpid, entry);
+ assert(spapr->nested.api);
+ if (spapr->nested.api == NESTED_API_KVM_HV) {
+ return spapr_get_pate_nested(spapr, cpu, lpid, entry);
+ }
+ return false;
}
}
@@ -2093,6 +2097,7 @@ static const VMStateDescription vmstate_spapr = {
&vmstate_spapr_cap_fwnmi,
&vmstate_spapr_fwnmi,
&vmstate_spapr_cap_rpt_invalidate,
+ &vmstate_spapr_cap_nested_papr,
NULL
}
};
@@ -3437,6 +3442,7 @@ 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");
+ spapr_nested_init(spapr);
}
static void spapr_machine_finalizefn(Object *obj)
@@ -4675,6 +4681,7 @@ static void spapr_machine_class_init(ObjectClass *oc,
void *data)
smc->default_caps.caps[SPAPR_CAP_IBS] = SPAPR_CAP_WORKAROUND;
smc->default_caps.caps[SPAPR_CAP_HPT_MAXPAGESIZE] = 16; /* 64kiB */
smc->default_caps.caps[SPAPR_CAP_NESTED_KVM_HV] = SPAPR_CAP_OFF;
+ smc->default_caps.caps[SPAPR_CAP_NESTED_PAPR] = SPAPR_CAP_OFF;
smc->default_caps.caps[SPAPR_CAP_LARGE_DECREMENTER] = SPAPR_CAP_ON;
smc->default_caps.caps[SPAPR_CAP_CCF_ASSIST] = SPAPR_CAP_ON;
smc->default_caps.caps[SPAPR_CAP_FWNMI] = SPAPR_CAP_ON;
diff --git a/hw/ppc/spapr_caps.c b/hw/ppc/spapr_caps.c
index 5a0755d34f..9b53f19ec8 100644
--- a/hw/ppc/spapr_caps.c
+++ b/hw/ppc/spapr_caps.c
@@ -454,6 +454,14 @@ static void cap_nested_kvm_hv_apply(SpaprMachineState
*spapr,
return;
}
+ if (!spapr->nested.api) {
+ spapr->nested.api = NESTED_API_KVM_HV;
+ } else {
+ error_setg(errp, "Nested-HV APIs are mutually exclusive/incompatible");
+ error_append_hint(errp, "Please use either cap-nested-hv or "
+ "cap-nested-papr to proceed.\n");
+ return;
+ }
if (kvm_enabled()) {
if (!ppc_check_compat(cpu, CPU_POWERPC_LOGICAL_3_00, 0,
spapr->max_compat_pvr)) {
@@ -490,6 +498,49 @@ static void cap_nested_kvm_hv_apply(SpaprMachineState
*spapr,
}
}
+static void cap_nested_papr_apply(SpaprMachineState *spapr,
+ uint8_t val, Error **errp)
+{
+ ERRP_GUARD();
+ PowerPCCPU *cpu = POWERPC_CPU(first_cpu);
+ CPUPPCState *env = &cpu->env;
+
+ if (!val) {
+ /* capability disabled by default */
+ return;
+ }
+
+ if (!spapr->nested.api) {
+ spapr->nested.api = NESTED_API_PAPR;
+ spapr_register_nested_papr();
+ } else {
+ error_setg(errp, "Nested-HV APIs are mutually exclusive/incompatible");
+ error_append_hint(errp, "Please use either cap-nested-hv or "
+ "cap-nested-papr to proceed.\n");
+ return;
+ }
+
+ if (tcg_enabled()) {
+ if (!(env->insns_flags2 & PPC2_ISA300)) {
+ error_setg(errp, "Nested-PAPR only supported on POWER9 and later");
+ error_append_hint(errp,
+ "Try appending -machine cap-nested-papr=off\n");
+ return;
+ }
+ } else if (kvm_enabled()) {
+ /*
+ * this gets executed in L1 qemu when L2 is launched,
+ * needs kvm-hv support in L1 kernel.
+ */
+ if (!kvmppc_has_cap_nested_kvm_hv()) {
+ error_setg(errp,
+ "KVM implementation does not support Nested-HV");
+ } else if (kvmppc_set_cap_nested_kvm_hv(val) < 0) {
+ error_setg(errp, "Error enabling Nested-HV with KVM");
+ }
+ }
+}
+
static void cap_large_decr_apply(SpaprMachineState *spapr,
uint8_t val, Error **errp)
{
@@ -735,6 +786,15 @@ SpaprCapabilityInfo capability_table[SPAPR_CAP_NUM] = {
.type = "bool",
.apply = cap_nested_kvm_hv_apply,
},
+ [SPAPR_CAP_NESTED_PAPR] = {
+ .name = "nested-papr",
+ .description = "Allow Nested HV (PAPR API)",
+ .index = SPAPR_CAP_NESTED_PAPR,
+ .get = spapr_cap_get_bool,
+ .set = spapr_cap_set_bool,
+ .type = "bool",
+ .apply = cap_nested_papr_apply,
+ },
[SPAPR_CAP_LARGE_DECREMENTER] = {
.name = "large-decr",
.description = "Allow Large Decrementer",
@@ -919,6 +979,7 @@ SPAPR_CAP_MIG_STATE(sbbc, SPAPR_CAP_SBBC);
SPAPR_CAP_MIG_STATE(ibs, SPAPR_CAP_IBS);
SPAPR_CAP_MIG_STATE(hpt_maxpagesize, SPAPR_CAP_HPT_MAXPAGESIZE);
SPAPR_CAP_MIG_STATE(nested_kvm_hv, SPAPR_CAP_NESTED_KVM_HV);
+SPAPR_CAP_MIG_STATE(nested_papr, SPAPR_CAP_NESTED_PAPR);
SPAPR_CAP_MIG_STATE(large_decr, SPAPR_CAP_LARGE_DECREMENTER);
SPAPR_CAP_MIG_STATE(ccf_assist, SPAPR_CAP_CCF_ASSIST);
SPAPR_CAP_MIG_STATE(fwnmi, SPAPR_CAP_FWNMI);
diff --git a/hw/ppc/spapr_nested.c b/hw/ppc/spapr_nested.c
index db47c1196f..87a0db22a5 100644
--- a/hw/ppc/spapr_nested.c
+++ b/hw/ppc/spapr_nested.c
@@ -8,6 +8,11 @@
#include "hw/ppc/spapr_nested.h"
#include "mmu-book3s-v3.h"
+void spapr_nested_init(SpaprMachineState *spapr)
+{
+ spapr->nested.api = 0;
+}
+
bool spapr_get_pate_nested(SpaprMachineState *spapr, PowerPCCPU *cpu,
target_ulong lpid, ppc_v3_pate_t *entry)
{
@@ -411,6 +416,11 @@ void spapr_register_nested(void)
spapr_register_hypercall(KVMPPC_H_TLB_INVALIDATE, h_tlb_invalidate);
spapr_register_hypercall(KVMPPC_H_COPY_TOFROM_GUEST, h_copy_tofrom_guest);
}
+
+void spapr_register_nested_papr(void)
+{
+ /* register hcalls here */
+}
#else
void spapr_exit_nested(PowerPCCPU *cpu, int excp)
{
@@ -421,4 +431,9 @@ void spapr_register_nested(void)
{
/* DO NOTHING */
}
+
+void spapr_register_nested_papr(void)
+{
+ /* DO NOTHING */
+}
#endif
diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h
index 3e825f2787..e33ee87ba4 100644
--- a/include/hw/ppc/spapr.h
+++ b/include/hw/ppc/spapr.h
@@ -81,8 +81,10 @@ typedef enum {
#define SPAPR_CAP_RPT_INVALIDATE 0x0B
/* Support for AIL modes */
#define SPAPR_CAP_AIL_MODE_3 0x0C
+/* Nested PAPR */
+#define SPAPR_CAP_NESTED_PAPR 0x0D
/* Num Caps */
-#define SPAPR_CAP_NUM (SPAPR_CAP_AIL_MODE_3 + 1)
+#define SPAPR_CAP_NUM (SPAPR_CAP_NESTED_PAPR + 1)
/*
* Capability Values
@@ -982,6 +984,7 @@ extern const VMStateDescription vmstate_spapr_cap_sbbc;
extern const VMStateDescription vmstate_spapr_cap_ibs;
extern const VMStateDescription vmstate_spapr_cap_hpt_maxpagesize;
extern const VMStateDescription vmstate_spapr_cap_nested_kvm_hv;
+extern const VMStateDescription vmstate_spapr_cap_nested_papr;
extern const VMStateDescription vmstate_spapr_cap_large_decr;
extern const VMStateDescription vmstate_spapr_cap_ccf_assist;
extern const VMStateDescription vmstate_spapr_cap_fwnmi;
diff --git a/include/hw/ppc/spapr_nested.h b/include/hw/ppc/spapr_nested.h
index 0722b999cd..efdfc78200 100644
--- a/include/hw/ppc/spapr_nested.h
+++ b/include/hw/ppc/spapr_nested.h
@@ -6,6 +6,9 @@
typedef struct SpaprMachineStateNested {
uint64_t ptcr;
+ uint8_t api;
+#define NESTED_API_KVM_HV 1
+#define NESTED_API_PAPR 2
} SpaprMachineStateNested;
/*
@@ -105,4 +108,6 @@ void spapr_exit_nested(PowerPCCPU *cpu, int excp);
typedef struct SpaprMachineState SpaprMachineState;
bool spapr_get_pate_nested(SpaprMachineState *spapr, PowerPCCPU *cpu,
target_ulong lpid, ppc_v3_pate_t *entry);
+void spapr_register_nested_papr(void);
+void spapr_nested_init(SpaprMachineState *spapr);
#endif /* HW_SPAPR_NESTED_H */
--
2.39.3
- [PATCH v2 00/14] Nested PAPR API (KVM on PowerVM), Harsh Prateek Bora, 2023/10/12
- [PATCH v2 01/14] spapr: nested: move nested part of spapr_get_pate into spapr_nested.c, Harsh Prateek Bora, 2023/10/12
- [PATCH v2 04/14] spapr: nested: Introduce cap-nested-papr for Nested PAPR API,
Harsh Prateek Bora <=
- [PATCH v2 03/14] spapr: nested: Document Nested PAPR API, Harsh Prateek Bora, 2023/10/12
- [PATCH v2 06/14] spapr: nested: Introduce H_GUEST_[GET|SET]_CAPABILITIES hcalls., Harsh Prateek Bora, 2023/10/12
- [PATCH v2 02/14] spapr: nested: Introduce SpaprMachineStateNested to store related info., Harsh Prateek Bora, 2023/10/12
- [PATCH v2 08/14] spapr: nested: Introduce H_GUEST_CREATE_VPCU hcall., Harsh Prateek Bora, 2023/10/12
- [PATCH v2 09/14] spapr: nested: Initialize the GSB elements lookup table., Harsh Prateek Bora, 2023/10/12
- [PATCH v2 05/14] spapr: nested: register nested-hv api hcalls only for cap-nested-hv, Harsh Prateek Bora, 2023/10/12
- [PATCH v2 11/14] spapr: nested: Use correct source for parttbl info for nested PAPR API., Harsh Prateek Bora, 2023/10/12
- [PATCH v2 13/14] spapr: nested: keep nested-hv exit code restricted to its API., Harsh Prateek Bora, 2023/10/12
- [PATCH v2 10/14] spapr: nested: Introduce H_GUEST_[GET|SET]_STATE hcalls., Harsh Prateek Bora, 2023/10/12
- [PATCH v2 07/14] spapr: nested: Introduce H_GUEST_[CREATE|DELETE] hcalls., Harsh Prateek Bora, 2023/10/12