Skip to content

Commit

Permalink
spapr: nested: Introduce cap-nested-papr for Nested PAPR API
Browse files Browse the repository at this point in the history
Introduce a SPAPR capability cap-nested-papr which enables nested PAPR
API for nested guests. This new API is to enable support for KVM on PowerVM
and the support in Linux kernel has already merged upstream.

Reviewed-by: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Michael Neuling <mikey@neuling.org>
Signed-off-by: Harsh Prateek Bora <harshpb@linux.ibm.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
  • Loading branch information
Harsh Prateek Bora authored and npiggin committed Mar 12, 2024
1 parent 4977110 commit e1617b8
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 4 deletions.
2 changes: 2 additions & 0 deletions hw/ppc/spapr.c
Original file line number Diff line number Diff line change
Expand Up @@ -2166,6 +2166,7 @@ static const VMStateDescription vmstate_spapr = {
&vmstate_spapr_cap_fwnmi,
&vmstate_spapr_fwnmi,
&vmstate_spapr_cap_rpt_invalidate,
&vmstate_spapr_cap_nested_papr,
NULL
}
};
Expand Down Expand Up @@ -4732,6 +4733,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;
Expand Down
54 changes: 54 additions & 0 deletions hw/ppc/spapr_caps.c
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,50 @@ static void cap_nested_kvm_hv_apply(SpaprMachineState *spapr,
error_append_hint(errp, "Try appending -machine cap-nested-hv=off "
"or use threads=1 with -smp\n");
}
if (spapr_nested_api(spapr) &&
spapr_nested_api(spapr) != NESTED_API_KVM_HV) {
error_setg(errp, "Nested-HV APIs are mutually exclusive");
error_append_hint(errp, "Please use either cap-nested-hv or "
"cap-nested-papr to proceed.\n");
return;
} else {
spapr->nested.api = NESTED_API_KVM_HV;
}
}
}

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 (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;
}
if (spapr_nested_api(spapr) &&
spapr_nested_api(spapr) != NESTED_API_PAPR) {
error_setg(errp, "Nested-HV APIs are mutually exclusive");
error_append_hint(errp, "Please use either cap-nested-hv or "
"cap-nested-papr to proceed.\n");
return;
} else {
spapr->nested.api = NESTED_API_PAPR;
}
} else if (kvm_enabled()) {
error_setg(errp, "KVM implementation does not support Nested-PAPR");
error_append_hint(errp,
"Try appending -machine cap-nested-papr=off\n");
}
}

Expand Down Expand Up @@ -735,6 +779,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",
Expand Down Expand Up @@ -919,6 +972,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);
Expand Down
8 changes: 5 additions & 3 deletions hw/ppc/spapr_nested.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@
void spapr_nested_reset(SpaprMachineState *spapr)
{
if (spapr_get_cap(spapr, SPAPR_CAP_NESTED_KVM_HV)) {
spapr->nested.api = NESTED_API_KVM_HV;
spapr_unregister_nested_hv();
spapr_register_nested_hv();
} else {
spapr->nested.api = 0;
} else if (spapr_get_cap(spapr, SPAPR_CAP_NESTED_PAPR)) {
spapr->nested.capabilities_set = false;
spapr_unregister_nested_papr();
spapr_register_nested_papr();
spapr_nested_gsb_init();
} else {
spapr->nested.api = 0;
}
}

Expand Down
6 changes: 5 additions & 1 deletion include/hw/ppc/spapr.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -592,6 +594,7 @@ struct SpaprMachineState {
#define H_GUEST_CREATE_VCPU 0x474
#define H_GUEST_GET_STATE 0x478
#define H_GUEST_SET_STATE 0x47C
#define H_GUEST_RUN_VCPU 0x480
#define H_GUEST_DELETE 0x488

#define MAX_HCALL_OPCODE H_GUEST_DELETE
Expand Down Expand Up @@ -996,6 +999,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;
Expand Down

0 comments on commit e1617b8

Please sign in to comment.