Nested PAPR API (KVM on PowerVM)
v3 cover Nested PAPR API (KVM on PowerVM)
There is an existing Nested-HV API to enable nested guests on powernv machines. However, that is not supported on pseries/PowerVM LPARs. This patch series implements required hcall interfaces to enable nested guests with KVM on PowerVM.
Unlike Nested-HV, with this API, entire L2 state is retained by L0 during guest entry/exit and uses pre-defined Guest State Buffer (GSB) format to communicate guest state between L1 and L2 via L0.
L0 here refers to the phyp/PowerVM, or launching a Qemu TCG L0 with the newly introduced option cap-nested-papr=true.
L1 refers to the LPAR host on PowerVM or Linux booted on Qemu TCG with above mentioned option cap-nested-papr=true.
L2 refers to nested guest running on top of L1 using KVM.
No SW changes needed for Qemu running in L1 Linux as well as L2 Kernel.
Linux Kernel side support is already merged upstream:
---
commit 19d31c5f115754c369c0995df47479c384757f82
Author: Jordan Niethe <[email protected]> Date: Thu Sep 14 13:05:59 2023 +1000
KVM: PPC: Add support for nestedv2 guests
---
For more details, documentation can be referred in either of patch series.
There are scripts available to assist in setting up an environment for testing nested guests at https://github.com/iamjpn/kvm-powervm-test
A tree with this series is available at:
https://github.com/planetharsh/qemu/tree/upstream-0118-v3
Thanks to Michael Neuling, Shivaprasad Bhat, Amit Machhiwal, Kautuk Consul, Vaibhav Jain and Jordan Niethe.
Changelog:
v3: Addressed review comments from Nick on v2 series.
v2: https://lore.kernel.org/qemu-devel/[email protected]/
v1: https://lore.kernel.org/qemu-devel/[email protected]/
Amit Machhiwal (1):
spapr: nested: Set the PCR when logical PVR is set
Harsh Prateek Bora (14):
spapr: nested: register nested-hv api hcalls only for cap-nested-hv
spapr: nested: move nested part of spapr_get_pate into spapr_nested.c
spapr: nested: Introduce SpaprMachineStateNested to store related
info.
spapr: nested: keep nested-hv related code restricted to its API.
spapr: nested: Document Nested PAPR API
spapr: nested: Introduce H_GUEST_[GET|SET]_CAPABILITIES hcalls.
spapr: nested: Introduce H_GUEST_[CREATE|DELETE] hcalls.
spapr: nested: Introduce H_GUEST_CREATE_VCPU hcall.
spapr: nested: Extend nested_ppc_state for nested PAPR API
spapr: nested: Initialize the GSB elements lookup table.
spapr: nested: Introduce H_GUEST_[GET|SET]_STATE hcalls.
spapr: nested: Use correct source for parttbl info for nested PAPR
API.
spapr: nested: Introduce H_GUEST_RUN_VCPU hcall.
spapr: nested: Introduce cap-nested-papr for Nested PAPR API
docs/devel/nested-papr.txt | 500 +++++++++++ include/hw/ppc/spapr.h | 22 +- include/hw/ppc/spapr_nested.h | 431 +++++++++- target/ppc/cpu.h | 4 + hw/ppc/ppc.c | 10 + hw/ppc/spapr.c | 35 +- hw/ppc/spapr_caps.c | 57 ++ hw/ppc/spapr_hcall.c | 2 - hw/ppc/spapr_nested.c | 1527 ++++++++++++++++++++++++++++++++- 9 files changed, 2533 insertions(+), 55 deletions(-) create mode 100644 docs/devel/nested-papr.txt
Signature · 1 line
2.39.3
PATCH v3 1/15 spapr: nested: register nested-hv api hcalls only for cap-nested-hv
Since cap-nested-hv is an optional capability, it makes sense to register api specfic hcalls only when respective capability is enabled.
--- include/hw/ppc/spapr.h | 1 + include/hw/ppc/spapr_nested.h | 1 - hw/ppc/spapr_caps.c | 1 + hw/ppc/spapr_hcall.c | 2 -- hw/ppc/spapr_nested.c | 4 ++-- 5 files changed, 4 insertions(+), 5 deletions(-)
include/hw/ppc/spapr.h +1 -0
@@ -1025,5 +1025,6 @@ void spapr_vof_client_dt_finalize(SpaprMachineState *spapr, void *fdt);/* H_WATCHDOG */ void spapr_watchdog_init (SpaprMachineState *spapr); +void spapr_register_nested_hv (void );#endif /* HW_SPAPR_H */
include/hw/ppc/spapr_nested.h +0 -1
@@ -96,7 +96,6 @@ struct nested_ppc_state { int64_t tb_offset; }; -void spapr_register_nested (void );void spapr_exit_nested (PowerPCCPU *cpu,int excp);#endif /* HW_SPAPR_NESTED_H */
hw/ppc/spapr_caps.c +1 -0
@@ -487,6 +487,7 @@ 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" ); } +spapr_register_nested_hv (); } }
hw/ppc/spapr_hcall.c +0 -2
@@ -1634,8 +1634,6 @@ static void hypercall_register_types(void)spapr_register_hypercall (KVMPPC_H_CAS , h_client_architecture_support);spapr_register_hypercall (KVMPPC_H_UPDATE_DT , h_update_dt); - -spapr_register_nested (); }type_init (hypercall_register_types)
hw/ppc/spapr_nested.c +2 -2
@@ -375,7 +375,7 @@ void spapr_exit_nested(PowerPCCPU *cpu, int excp)address_space_unmap (CPU (cpu)->as, regs, len, len, true); } -void spapr_register_nested (void ) +void spapr_register_nested_hv (void ) {spapr_register_hypercall (KVMPPC_H_SET_PARTITION_TABLE , h_set_ptbl);spapr_register_hypercall (KVMPPC_H_ENTER_NESTED , h_enter_nested);
@@ -388,7 +388,7 @@ void spapr_exit_nested(PowerPCCPU *cpu, int excp)g_assert_not_reached (); } -void spapr_register_nested (void ) +void spapr_register_nested_hv (void ) {/* DO NOTHING */ }
Signature · 1 line
2.39.3
PATCH v3 2/15 spapr: nested: move nested part of spapr_get_pate into spapr_nested.c
In reply to Harsh Prateek BoraMost of the nested code has already been moved to spapr_nested.c This logic inside spapr_get_pate is related to nested guests and better suited for spapr_nested.c, hence moving there.
--- include/hw/ppc/spapr_nested.h | 3 ++- hw/ppc/spapr.c | 28 ++------------------------- hw/ppc/spapr_nested.c | 36 +++++++++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 27 deletions(-)
include/hw/ppc/spapr_nested.h +2 -1
@@ -97,5 +97,6 @@ struct nested_ppc_state { };void spapr_exit_nested (PowerPCCPU *cpu,int excp); - +bool spapr_get_pate_nested_hv (SpaprMachineState *spapr,PowerPCCPU *cpu, +target_ulong lpid,ppc_v3_pate_t *entry);#endif /* HW_SPAPR_NESTED_H */
hw/ppc/spapr.c +2 -26
@@ -1362,7 +1362,6 @@ void spapr_init_all_lpcrs(target_ulong value, target_ulong mask) } } -static bool spapr_get_pate (PPCVirtualHypervisor *vhyp,PowerPCCPU *cpu,target_ulong lpid,ppc_v3_pate_t *entry) {
@@ -1375,33 +1374,10 @@ static bool spapr_get_pate(PPCVirtualHypervisor *vhyp, PowerPCCPU *cpu,/* Copy PATE1:GR into PATE0:HR */ entry->dw0 = spapr->patb_entry &PATE0_HR ; entry->dw1 = spapr->patb_entry; - +return true; }else { -uint64_t patb, pats; - -assert (lpid !=0 ); - - patb = spapr->nested_ptcr &PTCR_PATB ; - pats = spapr->nested_ptcr &PTCR_PATS ; - -/* Check if partition table is properly aligned */ -if (patb &MAKE_64BIT_MASK (0 , pats +12 )) { -return false; - } - -/* Calculate number of entries */ - pats =1ull << (pats +12 -4 ); -if (pats <= lpid) { -return false; - } - -/* Grab entry */ - patb +=16 * lpid; - entry->dw0 =ldq_phys (CPU (cpu)->as, patb); - entry->dw1 =ldq_phys (CPU (cpu)->as, patb +8 ); +return spapr_get_pate_nested_hv (spapr, cpu, lpid, entry); } - -return true; }#define HPTE (_table, _i) (void *)(((uint64_t *)(_table)) + ((_i) * 2))
hw/ppc/spapr_nested.c +36 -0
@@ -6,8 +6,38 @@#include "hw/ppc/spapr.h" #include "hw/ppc/spapr_cpu_core.h" #include "hw/ppc/spapr_nested.h" +#include "mmu-book3s-v3.h" #ifdef CONFIG_TCG + +bool spapr_get_pate_nested_hv (SpaprMachineState *spapr,PowerPCCPU *cpu, +target_ulong lpid,ppc_v3_pate_t *entry) +{ +uint64_t patb, pats; + +assert (lpid !=0 ); + + patb = spapr->nested_ptcr &PTCR_PATB ; + pats = spapr->nested_ptcr &PTCR_PATS ; + +/* Check if partition table is properly aligned */ +if (patb &MAKE_64BIT_MASK (0 , pats +12 )) { +return false; + } + +/* Calculate number of entries */ + pats =1ull << (pats +12 -4 ); +if (pats <= lpid) { +return false; + } + +/* Grab entry */ + patb +=16 * lpid; + entry->dw0 =ldq_phys (CPU (cpu)->as, patb); + entry->dw1 =ldq_phys (CPU (cpu)->as, patb +8 ); +return true; +} +#define PRTS_MASK 0x1f static target_ulong h_set_ptbl(PowerPCCPU *cpu,
@@ -392,4 +422,10 @@ void spapr_register_nested_hv(void) {/* DO NOTHING */ } + +bool spapr_get_pate_nested_hv (SpaprMachineState *spapr,PowerPCCPU *cpu, +target_ulong lpid,ppc_v3_pate_t *entry) +{ +return false; +}#endif
Signature · 1 line
2.39.3
PATCH v3 3/15 spapr: nested: Introduce SpaprMachineStateNested to store related info.
In reply to Harsh Prateek BoraCurrently, nested_ptcr is being used by existing nested-hv API to store nested guest related info. This need to be organised to extend support for the nested PAPR API which would need to store additional info related to nested guests in next series of patches.
--- include/hw/ppc/spapr.h | 3 ++- include/hw/ppc/spapr_nested.h | 5 +++++ hw/ppc/spapr_nested.c | 8 ++++---- 3 files changed, 11 insertions(+), 5 deletions(-)
include/hw/ppc/spapr.h +2 -1
@@ -12,6 +12,7 @@#include "hw/ppc/spapr_xive.h" /* For SpaprXive */ #include "hw/ppc/xics.h" /* For ICSState */ #include "hw/ppc/spapr_tpm_proxy.h" +#include "hw/ppc/spapr_nested.h" /* For SpaprMachineStateNested */ struct SpaprVioBus ;struct SpaprPhbState ;
@@ -213,7 +214,7 @@ struct SpaprMachineState {uint32_t vsmt;/* Virtual SMT mode (KVM's "core stride") */ /* Nested HV support (TCG only) */ -uint64_t nested_ptcr; +SpaprMachineStateNested nested;Notifier epow_notifier; QTAILQ_HEAD(, SpaprEventLogEntry) pending_events;
include/hw/ppc/spapr_nested.h +5 -0
@@ -4,6 +4,10 @@#include "qemu/osdep.h" #include "target/ppc/cpu.h" +typedef struct SpaprMachineStateNested { +uint64_t ptcr; +}SpaprMachineStateNested ; +/* * Register state for entering a nested guest with H_ENTER_NESTED. * New member must be added at the end.
@@ -97,6 +101,7 @@ struct nested_ppc_state { };void spapr_exit_nested (PowerPCCPU *cpu,int excp); +typedef struct SpaprMachineState SpaprMachineState ;bool spapr_get_pate_nested_hv (SpaprMachineState *spapr,PowerPCCPU *cpu,target_ulong lpid,ppc_v3_pate_t *entry);#endif /* HW_SPAPR_NESTED_H */
hw/ppc/spapr_nested.c +4 -4
@@ -17,8 +17,8 @@ bool spapr_get_pate_nested_hv(SpaprMachineState *spapr, PowerPCCPU *cpu,assert (lpid !=0 ); - patb = spapr->nested_ptcr &PTCR_PATB ; - pats = spapr->nested_ptcr &PTCR_PATS ; + patb = spapr->nested.ptcr &PTCR_PATB ; + pats = spapr->nested.ptcr &PTCR_PATS ;/* Check if partition table is properly aligned */ if (patb &MAKE_64BIT_MASK (0 , pats +12 )) {
@@ -55,7 +55,7 @@ static target_ulong h_set_ptbl(PowerPCCPU *cpu,return H_PARAMETER ; } - spapr->nested_ptcr = ptcr;/* Save new partition table */ + spapr->nested.ptcr = ptcr;/* Save new partition table */ return H_SUCCESS ; }
@@ -187,7 +187,7 @@ static target_ulong h_enter_nested(PowerPCCPU *cpu,struct kvmppc_pt_regs *regs;hwaddr len; -if (spapr->nested_ptcr ==0 ) { +if (spapr->nested.ptcr ==0 ) {return H_NOT_AVAILABLE ; }
Signature · 1 line
2.39.3
PATCH v3 4/15 spapr: nested: keep nested-hv related code restricted to its API.
In reply to Harsh Prateek Boraspapr_exit_nested and spapr_get_pate_nested_hv contains code which is specific to nested-hv API. Isolating code flows based on API helps extending it to be used with different API as well.
--- include/hw/ppc/spapr_nested.h | 4 ++++ hw/ppc/spapr.c | 7 ++++++- hw/ppc/spapr_caps.c | 1 + hw/ppc/spapr_nested.c | 27 ++++++++++++++++++++++++--- 4 files changed, 35 insertions(+), 4 deletions(-)
include/hw/ppc/spapr_nested.h +4 -0
@@ -6,6 +6,8 @@typedef struct SpaprMachineStateNested {uint64_t ptcr; +uint8_t api; +#define NESTED_API_KVM_HV 1 }SpaprMachineStateNested ;/*
@@ -104,4 +106,6 @@ void spapr_exit_nested(PowerPCCPU *cpu, int excp);typedef struct SpaprMachineState SpaprMachineState ;bool spapr_get_pate_nested_hv (SpaprMachineState *spapr,PowerPCCPU *cpu,target_ulong lpid,ppc_v3_pate_t *entry); +void spapr_nested_init (SpaprMachineState *spapr); +uint8_t spapr_nested_api (SpaprMachineState *spapr);#endif /* HW_SPAPR_NESTED_H */
hw/ppc/spapr.c +6 -1
@@ -1376,7 +1376,11 @@ static bool spapr_get_pate(PPCVirtualHypervisor *vhyp, PowerPCCPU *cpu, entry->dw1 = spapr->patb_entry;return true; }else { -return spapr_get_pate_nested_hv (spapr, cpu, lpid, entry); +assert (spapr_nested_api (spapr)); +if (spapr_nested_api (spapr) ==NESTED_API_KVM_HV ) { +return spapr_get_pate_nested_hv (spapr, cpu, lpid, entry); + } +return false; } }
@@ -3451,6 +3455,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)
hw/ppc/spapr_caps.c +1 -0
@@ -487,6 +487,7 @@ 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" ); } + spapr->nested.api =NESTED_API_KVM_HV ;spapr_register_nested_hv (); } }
hw/ppc/spapr_nested.c +24 -3
@@ -8,6 +8,16 @@#include "hw/ppc/spapr_nested.h" #include "mmu-book3s-v3.h" +void spapr_nested_init (SpaprMachineState *spapr) +{ + spapr->nested.api =0 ; +} + +uint8_t spapr_nested_api (SpaprMachineState *spapr) +{ +return spapr->nested.api; +} +#ifdef CONFIG_TCG bool spapr_get_pate_nested_hv(SpaprMachineState *spapr, PowerPCCPU *cpu,
@@ -302,7 +312,7 @@ static target_ulong h_enter_nested(PowerPCCPU *cpu,return env->gpr[3 ]; } -void spapr_exit_nested (PowerPCCPU *cpu,int excp) +static void spapr_exit_nested_hv (PowerPCCPU *cpu,int excp) {CPUPPCState *env = &cpu->env;SpaprCpuState *spapr_cpu =spapr_cpu_state (cpu);
@@ -314,8 +324,6 @@ void spapr_exit_nested(PowerPCCPU *cpu, int excp)struct kvmppc_pt_regs *regs;hwaddr len; -assert (spapr_cpu->in_nested); -nested_save_state (&l2_state, cpu); hsrr0 = env->spr[SPR_HSRR0 ]; hsrr1 = env->spr[SPR_HSRR1 ];
@@ -405,6 +413,19 @@ void spapr_exit_nested(PowerPCCPU *cpu, int excp)address_space_unmap (CPU (cpu)->as, regs, len, len, true); } +void spapr_exit_nested (PowerPCCPU *cpu,int excp) +{ +SpaprMachineState *spapr =SPAPR_MACHINE (qdev_get_machine ()); +SpaprCpuState *spapr_cpu =spapr_cpu_state (cpu); + +assert (spapr_cpu->in_nested); +if (spapr_nested_api (spapr) ==NESTED_API_KVM_HV ) { +spapr_exit_nested_hv (cpu, excp); + }else { +g_assert_not_reached (); + } +} +void spapr_register_nested_hv (void ) {spapr_register_hypercall (KVMPPC_H_SET_PARTITION_TABLE , h_set_ptbl);
Signature · 1 line
2.39.3
PATCH v3 5/15 spapr: nested: Document Nested PAPR API
In reply to Harsh Prateek BoraAdding initial documentation about Nested PAPR API to describe the set of APIs and its usage. Also talks about the Guest State Buffer elements and it's format which is used between L0/L1 to communicate L2 state.
--- docs/devel/nested-papr.txt | 500 +++++++++++++++++++++++++++++++++++++ 1 file changed, 500 insertions(+) create mode 100644 docs/devel/nested-papr.txt
docs/devel/nested-papr.txt new file +500 -0
@@ -0,0 +1,500 @@ +Nested PAPR API (aka KVM on PowerVM) +==================================== + +This API aims at providing support to enable nested virtualization with +KVM on PowerVM. While the existing support for nested KVM on PowerNV was +introduced with cap-nested-hv option, however, with a slight design change, +to enable this on papr/pseries, a new cap-nested-papr option is added. eg: + + qemu-system-ppc64 -cpu POWER10 -machine pseries,cap-nested-papr=true ... + +Work by: + Michael Neuling <[email protected]> + Vaibhav Jain <[email protected]> + Jordan Niethe <[email protected]> + Harsh Prateek Bora <[email protected]> + Shivaprasad G Bhat <[email protected]> + Kautuk Consul <[email protected]> + +Below taken from the kernel documentation: + +Introduction +============ + +This document explains how a guest operating system can act as a +hypervisor and run nested guests through the use of hypercalls, if the +hypervisor has implemented them. The terms L0, L1, and L2 are used to +refer to different software entities. L0 is the hypervisor mode entity +that would normally be called the "host" or "hypervisor". L1 is a +guest virtual machine that is directly run under L0 and is initiated +and controlled by L0. L2 is a guest virtual machine that is initiated +and controlled by L1 acting as a hypervisor. A significant design change +wrt existing API is that now the entire L2 state is maintained within L0. + +Existing Nested-HV API +====================== + +Linux/KVM has had support for Nesting as an L0 or L1 since 2018 + +The L0 code was added:: + + commit 8e3f5fc1045dc49fd175b978c5457f5f51e7a2ce + Author: Paul Mackerras <[email protected]> + Date: Mon Oct 8 16:31:03 2018 +1100 + KVM: PPC: Book3S HV: Framework and hcall stubs for nested virtualization + +The L1 code was added:: + + commit 360cae313702cdd0b90f82c261a8302fecef030a + Author: Paul Mackerras <[email protected]> + Date: Mon Oct 8 16:31:04 2018 +1100 + KVM: PPC: Book3S HV: Nested guest entry via hypercall + +This API works primarily using a signal hcall h_enter_nested(). This +call made by the L1 to tell the L0 to start an L2 vCPU with the given +state. The L0 then starts this L2 and runs until an L2 exit condition +is reached. Once the L2 exits, the state of the L2 is given back to +the L1 by the L0. The full L2 vCPU state is always transferred from +and to L1 when the L2 is run. The L0 doesn't keep any state on the L2 +vCPU (except in the short sequence in the L0 on L1 -> L2 entry and L2 +-> L1 exit). + +The only state kept by the L0 is the partition table. The L1 registers +it's partition table using the h_set_partition_table() hcall. All +other state held by the L0 about the L2s is cached state (such as +shadow page tables). + +The L1 may run any L2 or vCPU without first informing the L0. It +simply starts the vCPU using h_enter_nested(). The creation of L2s and +vCPUs is done implicitly whenever h_enter_nested() is called. + +In this document, we call this existing API the v1 API. + +New PAPR API +=============== + +The new PAPR API changes from the v1 API such that the creating L2 and +associated vCPUs is explicit. In this document, we call this the v2 +API. + +h_enter_nested() is replaced with H_GUEST_VCPU_RUN(). Before this can +be called the L1 must explicitly create the L2 using h_guest_create() +and any associated vCPUs() created with h_guest_create_vCPU(). Getting +and setting vCPU state can also be performed using h_guest_{g|s}et +hcall. + +The basic execution flow is for an L1 to create an L2, run it, and +delete it is: + +- L1 and L0 negotiate capabilities with H_GUEST_{G,S}ET_CAPABILITIES() + (normally at L1 boot time). + +- L1 requests the L0 to create an L2 with H_GUEST_CREATE() and receives a token + +- L1 requests the L0 to create an L2 vCPU with H_GUEST_CREATE_VCPU() + +- L1 and L0 communicate the vCPU state using the H_GUEST_{G,S}ET() hcall + +- L1 requests the L0 to run the vCPU using H_GUEST_RUN_VCPU() hcall + +- L1 deletes L2 with H_GUEST_DELETE() + +More details of the individual hcalls follows: + +HCALL Details +============= + +This documentation is provided to give an overall understating of the +API. It doesn't aim to provide full details required to implement +an L1 or L0. Latest PAPR spec shall be referred for more details. + +All these HCALLs are made by the L1 to the L0. + +H_GUEST_GET_CAPABILITIES() +-------------------------- + +This is called to get the capabilities of the L0 nested +hypervisor. This includes capabilities such the CPU versions (eg +POWER9, POWER10) that are supported as L2s. + +H_GUEST_SET_CAPABILITIES() +-------------------------- + +This is called to inform the L0 of the capabilities of the L1 +hypervisor. The set of flags passed here are the same as +H_GUEST_GET_CAPABILITIES() + +Typically, GET will be called first and then SET will be called with a +subset of the flags returned from GET. This process allows the L0 and +L1 to negotiate a agreed set of capabilities. + +H_GUEST_CREATE() +---------------- + +This is called to create a L2. Returned is ID of the L2 created +(similar to an LPID), which can be use on subsequent HCALLs to +identify the L2. + +H_GUEST_CREATE_VCPU() +--------------------- + +This is called to create a vCPU associated with a L2. The L2 id +(returned from H_GUEST_CREATE()) should be passed it. Also passed in +is a unique (for this L2) vCPUid. This vCPUid is allocated by the +L1. + +H_GUEST_SET_STATE() +------------------- + +This is called to set L2 wide or vCPU specific L2 state. This info is +passed via the Guest State Buffer (GSB), details below. + +This can set either L2 wide or vcpu specific information. Examples of +L2 wide is the timebase offset or process scoped page table +info. Examples of vCPU wide are GPRs or VSRs. A bit in the flags +parameter specifies if this call is L2 wide or vCPU specific and the +IDs in the GSB must match this. + +The L1 provides a pointer to the GSB as a parameter to this call. Also +provided is the L2 and vCPU IDs associated with the state to set. + +The L1 writes all values in the GSB and the L0 only reads the GSB for +this call + +H_GUEST_GET_STATE() +------------------- + +This is called to get state associated with a L2 or L2 vCPU. This info +passed via the GSB (details below). + +This can get either L2 wide or vcpu specific information. Examples of +L2 wide is the timebase offset or process scoped page table +info. Examples of vCPU wide are GPRs or VSRs. A bit in the flags +parameter specifies if this call is L2 wide or vCPU specific and the +IDs in the GSB must match this. + +The L1 provides a pointer to the GSB as a parameter to this call. Also +provided is the L2 and vCPU IDs associated with the state to get. + +The L1 writes only the IDs and sizes in the GSB. L0 writes the +associated values for each ID in the GSB. + +H_GUEST_RUN_VCPU() +------------------ + +This is called to run an L2 vCPU. The L2 and vCPU IDs are passed in as +parameters. The vCPU runs with the state set previously using +H_GUEST_SET_STATE(). When the L2 exits, the L1 will resume from this +hcall. + +This hcall also has associated input and output GSBs. Unlike +H_GUEST_{S,G}ET_STATE(), these GSB pointers are not passed in as +parameters to the hcall (This was done in the interest of +performance). The locations of these GSBs must be preregistered using +the H_GUEST_SET_STATE() call with ID 0x0c00 and 0x0c01 (see table later +below). + +The input GSB may contain only VCPU wide elements to be set. This GSB +may also contain zero elements (ie 0 in the first 4 bytes of the GSB) +if nothing needs to be set. + +On exit from the hcall, the output buffer is filled with elements +determined by the L0. The reason for the exit is contained in GPR4 (ie +NIP is put in GPR4). The elements returned depend on the exit +type. For example, if the exit reason is the L2 doing a hcall (GPR4 = +0xc00), then GPR3-12 are provided in the output GSB as this is the +state likely needed to service the hcall. If additional state is +needed, H_GUEST_GET_STATE() may be called by the L1. + +To synthesize interrupts in the L2, when calling H_GUEST_RUN_VCPU() +the L1 may set a flag (as a hcall parameter) and the L0 will +synthesize the interrupt in the L2. Alternatively, the L1 may +synthesize the interrupt itself using H_GUEST_SET_STATE() or the +H_GUEST_RUN_VCPU() input GSB to set the state appropriately. + +H_GUEST_DELETE() +---------------- + +This is called to delete an L2. All associated vCPUs are also +deleted. No specific vCPU delete call is provided. + +A flag may be provided to delete all guests. This is used to reset the +L0 in the case of kdump/kexec. + +Guest State Buffer (GSB) +======================== + +The Guest State Buffer (GSB) is the main method of communicating state +about the L2 between the L1 and L0 via H_GUEST_{G,S}ET() and +H_GUEST_VCPU_RUN() calls. + +State may be associated with a whole L2 (eg timebase offset) or a +specific L2 vCPU (eg. GPR state). Only L2 VCPU state maybe be set by +H_GUEST_VCPU_RUN(). + +All data in the GSB is big endian (as is standard in PAPR) + +The Guest state buffer has a header which gives the number of +elements, followed by the GSB elements themselves. + +GSB header: + ++----------+----------+-------------------------------------------+ +| Offset | Size | Purpose | +| Bytes | Bytes | | ++==========+==========+===========================================+ +| 0 | 4 | Number of elements | ++----------+----------+-------------------------------------------+ +| 4 | | Guest state buffer elements | ++----------+----------+-------------------------------------------+ + +GSB element: + ++----------+----------+-------------------------------------------+ +| Offset | Size | Purpose | +| Bytes | Bytes | | ++==========+==========+===========================================+ +| 0 | 2 | ID | ++----------+----------+-------------------------------------------+ +| 2 | 2 | Size of Value | ++----------+----------+-------------------------------------------+ +| 4 | As above | Value | ++----------+----------+-------------------------------------------+ + +The ID in the GSB element specifies what is to be set. This includes +archtected state like GPRs, VSRs, SPRs, plus also some meta data about +the partition like the timebase offset and partition scoped page +table information. + ++--------+-------+----+--------+----------------------------------+ +| ID | Size | RW | Thread | Details | +| | Bytes | | Guest | | +| | | | Scope | | ++========+=======+====+========+==================================+ +| 0x0000 | | RW | TG | NOP element | ++--------+-------+----+--------+----------------------------------+ +| 0x0001 | 0x08 | R | G | Size of L0 vCPU state | ++--------+-------+----+--------+----------------------------------+ +| 0x0002 | 0x08 | R | G | Size Run vCPU out buffer | ++--------+-------+----+--------+----------------------------------+ +| 0x0003 | 0x04 | RW | G | Logical PVR | ++--------+-------+----+--------+----------------------------------+ +| 0x0004 | 0x08 | RW | G | TB Offset (L1 relative) | ++--------+-------+----+--------+----------------------------------+ +| 0x0005 | 0x18 | RW | G |Partition scoped page tbl info: | +| | | | | | +| | | | |- 0x00 Addr part scope table | +| | | | |- 0x08 Num addr bits | +| | | | |- 0x10 Size root dir | ++--------+-------+----+--------+----------------------------------+ +| 0x0006 | 0x10 | RW | G |Process Table Information: | +| | | | | | +| | | | |- 0x0 Addr proc scope table | +| | | | |- 0x8 Table size. | ++--------+-------+----+--------+----------------------------------+ +| 0x0007-| | | | Reserved | +| 0x0BFF | | | | | ++--------+-------+----+--------+----------------------------------+ +| 0x0C00 | 0x10 | RW | T |Run vCPU Input Buffer: | +| | | | | | +| | | | |- 0x0 Addr of buffer | +| | | | |- 0x8 Buffer Size. | ++--------+-------+----+--------+----------------------------------+ +| 0x0C01 | 0x10 | RW | T |Run vCPU Output Buffer: | +| | | | | | +| | | | |- 0x0 Addr of buffer | +| | | | |- 0x8 Buffer Size. | ++--------+-------+----+--------+----------------------------------+ +| 0x0C02 | 0x08 | RW | T | vCPU VPA Address | ++--------+-------+----+--------+----------------------------------+ +| 0x0C03-| | | | Reserved | +| 0x0FFF | | | | | ++--------+-------+----+--------+----------------------------------+ +| 0x1000-| 0x08 | RW | T | GPR 0-31 | +| 0x101F | | | | | ++--------+-------+----+--------+----------------------------------+ +| 0x1020 | 0x08 | T | T | HDEC expiry TB | ++--------+-------+----+--------+----------------------------------+ +| 0x1021 | 0x08 | RW | T | NIA | ++--------+-------+----+--------+----------------------------------+ +| 0x1022 | 0x08 | RW | T | MSR | ++--------+-------+----+--------+----------------------------------+ +| 0x1023 | 0x08 | RW | T | LR | ++--------+-------+----+--------+----------------------------------+ +| 0x1024 | 0x08 | RW | T | XER | ++--------+-------+----+--------+----------------------------------+ +| 0x1025 | 0x08 | RW | T | CTR | ++--------+-------+----+--------+----------------------------------+ +| 0x1026 | 0x08 | RW | T | CFAR | ++--------+-------+----+--------+----------------------------------+ +| 0x1027 | 0x08 | RW | T | SRR0 | ++--------+-------+----+--------+----------------------------------+ +| 0x1028 | 0x08 | RW | T | SRR1 | ++--------+-------+----+--------+----------------------------------+ +| 0x1029 | 0x08 | RW | T | DAR | ++--------+-------+----+--------+----------------------------------+ +| 0x102A | 0x08 | RW | T | DEC expiry TB | ++--------+-------+----+--------+----------------------------------+ +| 0x102B | 0x08 | RW | T | VTB | ++--------+-------+----+--------+----------------------------------+ +| 0x102C | 0x08 | RW | T | LPCR | ++--------+-------+----+--------+----------------------------------+ +| 0x102D | 0x08 | RW | T | HFSCR | ++--------+-------+----+--------+----------------------------------+ +| 0x102E | 0x08 | RW | T | FSCR | ++--------+-------+----+--------+----------------------------------+ +| 0x102F | 0x08 | RW | T | FPSCR | ++--------+-------+----+--------+----------------------------------+ +| 0x1030 | 0x08 | RW | T | DAWR0 | ++--------+-------+----+--------+----------------------------------+ +| 0x1031 | 0x08 | RW | T | DAWR1 | ++--------+-------+----+--------+----------------------------------+ +| 0x1032 | 0x08 | RW | T | CIABR | ++--------+-------+----+--------+----------------------------------+ +| 0x1033 | 0x08 | RW | T | PURR | ++--------+-------+----+--------+----------------------------------+ +| 0x1034 | 0x08 | RW | T | SPURR | ++--------+-------+----+--------+----------------------------------+ +| 0x1035 | 0x08 | RW | T | IC | ++--------+-------+----+--------+----------------------------------+ +| 0x1036-| 0x08 | RW | T | SPRG 0-3 | +| 0x1039 | | | | | ++--------+-------+----+--------+----------------------------------+ +| 0x103A | 0x08 | W | T | PPR | ++--------+-------+----+--------+----------------------------------+ +| 0x103B | 0x08 | RW | T | MMCR 0-3 | +| 0x103E | | | | | ++--------+-------+----+--------+----------------------------------+ +| 0x103F | 0x08 | RW | T | MMCRA | ++--------+-------+----+--------+----------------------------------+ +| 0x1040 | 0x08 | RW | T | SIER | ++--------+-------+----+--------+----------------------------------+ +| 0x1041 | 0x08 | RW | T | SIER 2 | ++--------+-------+----+--------+----------------------------------+ +| 0x1042 | 0x08 | RW | T | SIER 3 | ++--------+-------+----+--------+----------------------------------+ +| 0x1043 | 0x08 | RW | T | BESCR | ++--------+-------+----+--------+----------------------------------+ +| 0x1044 | 0x08 | RW | T | EBBHR | ++--------+-------+----+--------+----------------------------------+ +| 0x1045 | 0x08 | RW | T | EBBRR | ++--------+-------+----+--------+----------------------------------+ +| 0x1046 | 0x08 | RW | T | AMR | ++--------+-------+----+--------+----------------------------------+ +| 0x1047 | 0x08 | RW | T | IAMR | ++--------+-------+----+--------+----------------------------------+ +| 0x1048 | 0x08 | RW | T | AMOR | ++--------+-------+----+--------+----------------------------------+ +| 0x1049 | 0x08 | RW | T | UAMOR | ++--------+-------+----+--------+----------------------------------+ +| 0x104A | 0x08 | RW | T | SDAR | ++--------+-------+----+--------+----------------------------------+ +| 0x104B | 0x08 | RW | T | SIAR | ++--------+-------+----+--------+----------------------------------+ +| 0x104C | 0x08 | RW | T | DSCR | ++--------+-------+----+--------+----------------------------------+ +| 0x104D | 0x08 | RW | T | TAR | ++--------+-------+----+--------+----------------------------------+ +| 0x104E | 0x08 | RW | T | DEXCR | ++--------+-------+----+--------+----------------------------------+ +| 0x104F | 0x08 | RW | T | HDEXCR | ++--------+-------+----+--------+----------------------------------+ +| 0x1050 | 0x08 | RW | T | HASHKEYR | ++--------+-------+----+--------+----------------------------------+ +| 0x1051 | 0x08 | RW | T | HASHPKEYR | ++--------+-------+----+--------+----------------------------------+ +| 0x1052 | 0x08 | RW | T | CTRL | ++--------+-------+----+--------+----------------------------------+ +| 0x1053-| | | | Reserved | +| 0x1FFF | | | | | ++--------+-------+----+--------+----------------------------------+ +| 0x2000 | 0x04 | RW | T | CR | ++--------+-------+----+--------+----------------------------------+ +| 0x2001 | 0x04 | RW | T | PIDR | ++--------+-------+----+--------+----------------------------------+ +| 0x2002 | 0x04 | RW | T | DSISR | ++--------+-------+----+--------+----------------------------------+ +| 0x2003 | 0x04 | RW | T | VSCR | ++--------+-------+----+--------+----------------------------------+ +| 0x2004 | 0x04 | RW | T | VRSAVE | ++--------+-------+----+--------+----------------------------------+ +| 0x2005 | 0x04 | RW | T | DAWRX0 | ++--------+-------+----+--------+----------------------------------+ +| 0x2006 | 0x04 | RW | T | DAWRX1 | ++--------+-------+----+--------+----------------------------------+ +| 0x2007-| 0x04 | RW | T | PMC 1-6 | +| 0x200c | | | | | ++--------+-------+----+--------+----------------------------------+ +| 0x200D | 0x04 | RW | T | WORT | ++--------+-------+----+--------+----------------------------------+ +| 0x200E | 0x04 | RW | T | PSPB | ++--------+-------+----+--------+----------------------------------+ +| 0x200F-| | | | Reserved | +| 0x2FFF | | | | | ++--------+-------+----+--------+----------------------------------+ +| 0x3000-| 0x10 | RW | T | VSR 0-63 | +| 0x303F | | | | | ++--------+-------+----+--------+----------------------------------+ +| 0x3040-| | | | Reserved | +| 0xEFFF | | | | | ++--------+-------+----+--------+----------------------------------+ +| 0xF000 | 0x08 | R | T | HDAR | ++--------+-------+----+--------+----------------------------------+ +| 0xF001 | 0x04 | R | T | HDSISR | ++--------+-------+----+--------+----------------------------------+ +| 0xF002 | 0x04 | R | T | HEIR | ++--------+-------+----+--------+----------------------------------+ +| 0xF003 | 0x08 | R | T | ASDR | ++--------+-------+----+--------+----------------------------------+ + +Miscellaneous info +================== + +State not in ptregs/hvregs +-------------------------- + +In the v1 API, some state is not in the ptregs/hvstate. This includes +the vector register and some SPRs. For the L1 to set this state for +the L2, the L1 loads up these hardware registers before the +h_enter_nested() call and the L0 ensures they end up as the L2 state +(by not touching them). + +The v2 API removes this and explicitly sets this state via the GSB. + +L1 Implementation details: Caching state +---------------------------------------- + +In the v1 API, all state is sent from the L1 to the L0 and vice versa +on every h_enter_nested() hcall. If the L0 is not currently running +any L2s, the L0 has no state information about them. The only +exception to this is the location of the partition table, registered +via h_set_partition_table(). + +The v2 API changes this so that the L0 retains the L2 state even when +it's vCPUs are no longer running. This means that the L1 only needs to +communicate with the L0 about L2 state when it needs to modify the L2 +state, or when it's value is out of date. This provides an opportunity +for performance optimisation. + +When a vCPU exits from a H_GUEST_RUN_VCPU() call, the L1 internally +marks all L2 state as invalid. This means that if the L1 wants to know +the L2 state (say via a kvm_get_one_reg() call), it needs to call +H_GUEST_GET_STATE() to get that state. Once it's read, it's marked as +valid in L1 until the L2 is run again. + +Also, when an L1 modifies L2 vcpu state, it doesn't need to write it +to the L0 until that L2 vcpu runs again. Hence when the L1 updates +state (say via a kvm_set_one_reg() call), it writes to an internal L1 +copy and only flushes this copy to the L0 when the L2 runs again via +the H_GUEST_VCPU_RUN() input buffer. + +This lazy updating of state by the L1 avoids unnecessary +H_GUEST_{G|S}ET_STATE() calls. + +References +========== + +For more details, please refer: + +[1] Kernel documentation (patches accepted upstream): + https://lore.kernel.org/linuxppc-dev/[email protected]/
Signature · 1 line
2.39.3
PATCH v3 6/15 spapr: nested: Introduce H_GUEST_[GET|SET]_CAPABILITIES hcalls.
In reply to Harsh Prateek BoraIntroduce the nested PAPR hcalls:
- H_GUEST_GET_CAPABILITIES which is used to query the capabilities of the API and the L2 guests it provides.
- H_GUEST_SET_CAPABILITIES which is used to set the Guest API capabilities that the Host Partition supports and may use.
[amachhiw: support for p9 compat mode and return register bug fixes]
--- include/hw/ppc/spapr.h | 5 +- include/hw/ppc/spapr_nested.h | 13 +++++ hw/ppc/spapr_nested.c | 100 ++++++++++++++++++++++++++++++++++ 3 files changed, 117 insertions(+), 1 deletion(-)
include/hw/ppc/spapr.h +4 -1
@@ -364,6 +364,7 @@ struct SpaprMachineState {#define H_NOOP -63#define H_UNSUPPORTED -67#define H_OVERLAP -68 +#define H_STATE -75#define H_UNSUPPORTED_FLAG -256#define H_MULTI_THREADS_ACTIVE -9005
@@ -583,8 +584,10 @@ struct SpaprMachineState {#define H_RPT_INVALIDATE 0x448#define H_SCM_FLUSH 0x44C#define H_WATCHDOG 0x45C +#define H_GUEST_GET_CAPABILITIES 0x460 +#define H_GUEST_SET_CAPABILITIES 0x464 -#define MAX_HCALL_OPCODE H_WATCHDOG +#define MAX_HCALL_OPCODE H_GUEST_SET_CAPABILITIES/* The hcalls above are standardized in PAPR and implemented by pHyp * as well.
include/hw/ppc/spapr_nested.h +13 -0
@@ -8,8 +8,20 @@ typedef struct SpaprMachineStateNested {uint64_t ptcr;uint8_t api;#define NESTED_API_KVM_HV 1 +bool capabilities_set; +uint32_t pvr_base; } SpaprMachineStateNested; +/* Nested PAPR API related macros */ +#define H_GUEST_CAPABILITIES_COPY_MEM 0x8000000000000000 +#define H_GUEST_CAPABILITIES_P9_MODE 0x4000000000000000 +#define H_GUEST_CAPABILITIES_P10_MODE 0x2000000000000000 +#define H_GUEST_CAP_VALID_MASK (H_GUEST_CAPABILITIES_P10_MODE | \ + H_GUEST_CAPABILITIES_P9_MODE) +#define H_GUEST_CAP_COPY_MEM_BMAP 0 +#define H_GUEST_CAP_P9_MODE_BMAP 1 +#define H_GUEST_CAP_P10_MODE_BMAP 2 +/* * Register state for entering a nested guest with H_ENTER_NESTED. * New member must be added at the end.
@@ -108,4 +120,5 @@ bool spapr_get_pate_nested_hv(SpaprMachineState *spapr, PowerPCCPU *cpu, target_ulong lpid, ppc_v3_pate_t *entry);void spapr_nested_init (SpaprMachineState *spapr);uint8_t spapr_nested_api (SpaprMachineState *spapr); +void spapr_register_nested_papr (void );#endif /* HW_SPAPR_NESTED_H */
hw/ppc/spapr_nested.c +100 -0
126 lines not on this page · raw message
Signature · 1 line
2.39.3
PATCH v3 7/15 spapr: nested: Introduce H_GUEST_[CREATE|DELETE] hcalls.
In reply to Harsh Prateek BoraIntroduce the nested PAPR hcalls:
- H_GUEST_CREATE which is used to create and allocate resources for
nested guest being created.
- H_GUEST_DELETE which is used to delete and deallocate resources
for the nested guest being deleted. It also supports deleting all nested guests at once using a deleteAll flag.
[amachhiw: set capabilities check for no guests created before calling]
--- include/hw/ppc/spapr.h | 4 +- include/hw/ppc/spapr_nested.h | 7 +++ hw/ppc/spapr_nested.c | 106 ++++++++++++++++++++++++++++++++++ 3 files changed, 116 insertions(+), 1 deletion(-)
include/hw/ppc/spapr.h +3 -1
@@ -586,8 +586,10 @@ struct SpaprMachineState {#define H_WATCHDOG 0x45C#define H_GUEST_GET_CAPABILITIES 0x460#define H_GUEST_SET_CAPABILITIES 0x464 +#define H_GUEST_CREATE 0x470 +#define H_GUEST_DELETE 0x488 -#define MAX_HCALL_OPCODE H_GUEST_SET_CAPABILITIES +#define MAX_HCALL_OPCODE H_GUEST_DELETE/* The hcalls above are standardized in PAPR and implemented by pHyp * as well.
include/hw/ppc/spapr_nested.h +7 -0
@@ -10,8 +10,13 @@ typedef struct SpaprMachineStateNested {#define NESTED_API_KVM_HV 1bool capabilities_set;uint32_t pvr_base; +GHashTable *guests; } SpaprMachineStateNested; +typedef struct SpaprMachineStateNestedGuest { +uint32_t pvr_logical; +}SpaprMachineStateNestedGuest ; +/* Nested PAPR API related macros */ #define H_GUEST_CAPABILITIES_COPY_MEM 0x8000000000000000#define H_GUEST_CAPABILITIES_P9_MODE 0x4000000000000000
@@ -21,6 +26,8 @@ typedef struct SpaprMachineStateNested {#define H_GUEST_CAP_COPY_MEM_BMAP 0#define H_GUEST_CAP_P9_MODE_BMAP 1#define H_GUEST_CAP_P10_MODE_BMAP 2 +#define PAPR_NESTED_GUEST_MAX 4096 +#define H_GUEST_DELETE_ALL_FLAG 0x8000000000000000ULL/* * Register state for entering a nested guest with H_ENTER_NESTED.
hw/ppc/spapr_nested.c +106 -0
124 lines not on this page · raw message
Signature · 1 line
2.39.3
PATCH v3 8/15 spapr: nested: Introduce H_GUEST_CREATE_VCPU hcall.
In reply to Harsh Prateek BoraIntroduce the nested PAPR hcall H_GUEST_CREATE_VCPU which is used to create and initialize the specified VCPU resource for the previously created guest. Each guest can have multiple VCPUs upto max 2048. All VCPUs for a guest gets deallocated on guest delete.
--- include/hw/ppc/spapr.h | 2 + include/hw/ppc/spapr_nested.h | 10 ++++ hw/ppc/spapr_nested.c | 96 +++++++++++++++++++++++++++++++++++ 3 files changed, 108 insertions(+)
include/hw/ppc/spapr.h +2 -0
@@ -365,6 +365,7 @@ struct SpaprMachineState {#define H_UNSUPPORTED -67#define H_OVERLAP -68#define H_STATE -75 +#define H_IN_USE -77#define H_UNSUPPORTED_FLAG -256#define H_MULTI_THREADS_ACTIVE -9005
@@ -587,6 +588,7 @@ struct SpaprMachineState {#define H_GUEST_GET_CAPABILITIES 0x460#define H_GUEST_SET_CAPABILITIES 0x464#define H_GUEST_CREATE 0x470 +#define H_GUEST_CREATE_VCPU 0x474#define H_GUEST_DELETE 0x488#define MAX_HCALL_OPCODE H_GUEST_DELETE
include/hw/ppc/spapr_nested.h +10 -0
@@ -15,6 +15,8 @@ typedef struct SpaprMachineStateNested {typedef struct SpaprMachineStateNestedGuest {uint32_t pvr_logical; +unsigned long vcpus; +struct SpaprMachineStateNestedGuestVcpu *vcpu; }SpaprMachineStateNestedGuest ;/* Nested PAPR API related macros */
@@ -28,6 +30,7 @@ typedef struct SpaprMachineStateNestedGuest {#define H_GUEST_CAP_P10_MODE_BMAP 2#define PAPR_NESTED_GUEST_MAX 4096#define H_GUEST_DELETE_ALL_FLAG 0x8000000000000000ULL +#define PAPR_NESTED_GUEST_VCPU_MAX 2048/* * Register state for entering a nested guest with H_ENTER_NESTED.
@@ -119,8 +122,15 @@ struct nested_ppc_state {uint64_t ppr;int64_t tb_offset; +/* Nested PAPR API */ +uint64_t pvr; }; +typedef struct SpaprMachineStateNestedGuestVcpu { +bool enabled; +struct nested_ppc_state state; +}SpaprMachineStateNestedGuestVcpu ; +void spapr_exit_nested (PowerPCCPU *cpu,int excp);typedef struct SpaprMachineState SpaprMachineState ; bool spapr_get_pate_nested_hv(SpaprMachineState *spapr, PowerPCCPU *cpu,
hw/ppc/spapr_nested.c +96 -0
120 lines not on this page · raw message
Signature · 1 line
2.39.3
PATCH v3 9/15 spapr: nested: Extend nested_ppc_state for nested PAPR API
In reply to Harsh Prateek BoraCurrently, nested_ppc_state stores a certain set of registers and works with nested_[load|save]_state() for state transfer as reqd for nested-hv API. Extending these with additional registers state as reqd for nested PAPR API.
--- include/hw/ppc/spapr_nested.h | 49 ++++++++++++++++ target/ppc/cpu.h | 2 + hw/ppc/spapr_nested.c | 106 ++++++++++++++++++++++++++++++++++ 3 files changed, 157 insertions(+)
include/hw/ppc/spapr_nested.h +49 -0
@@ -8,6 +8,7 @@ typedef struct SpaprMachineStateNested {uint64_t ptcr;uint8_t api;#define NESTED_API_KVM_HV 1 +#define NESTED_API_PAPR 2bool capabilities_set;uint32_t pvr_base;GHashTable *guests;
@@ -124,6 +125,54 @@ struct nested_ppc_state {int64_t tb_offset;/* Nested PAPR API */ uint64_t pvr; +uint64_t amor; +uint64_t dawr0; +uint64_t dawrx0; +uint64_t ciabr; +uint64_t purr; +uint64_t spurr; +uint64_t ic; +uint64_t vtb; +uint64_t hdar; +uint64_t hdsisr; +uint64_t heir; +uint64_t asdr; +uint64_t dawr1; +uint64_t dawrx1; +uint64_t dexcr; +uint64_t hdexcr; +uint64_t hashkeyr; +uint64_t hashpkeyr; + ppc_vsr_t vsr[64] QEMU_ALIGNED(16); +uint64_t ebbhr; +uint64_t tar; +uint64_t ebbrr; +uint64_t bescr; +uint64_t iamr; +uint64_t amr; +uint64_t uamor; +uint64_t dscr; +uint64_t fscr; +uint64_t pspb; +uint64_t ctrl; +uint64_t vrsave; +uint64_t dar; +uint64_t dsisr; +uint64_t pmc1; +uint64_t pmc2; +uint64_t pmc3; +uint64_t pmc4; +uint64_t pmc5; +uint64_t pmc6; +uint64_t mmcr0; +uint64_t mmcr1; +uint64_t mmcr2; +uint64_t mmcra; +uint64_t sdar; +uint64_t siar; +uint64_t sier; +uint32_t vscr; +uint64_t fpscr; }; typedef struct SpaprMachineStateNestedGuestVcpu {
target/ppc/cpu.h +2 -0
@@ -1737,9 +1737,11 @@ void ppc_compat_add_property(Object *obj, const char *name,#define SPR_PSPB (0x09F)#define SPR_DPDES (0x0B0)#define SPR_DAWR0 (0x0B4) +#define SPR_DAWR1 (0x0B5)#define SPR_RPR (0x0BA)#define SPR_CIABR (0x0BB)#define SPR_DAWRX0 (0x0BC) +#define SPR_DAWRX1 (0x0BD)#define SPR_HFSCR (0x0BE)#define SPR_VRSAVE (0x100)#define SPR_USPRG0 (0x100)
hw/ppc/spapr_nested.c +106 -0
130 lines not on this page · raw message
Signature · 1 line
2.39.3
PATCH v3 10/15 spapr: nested: Initialize the GSB elements lookup table.
In reply to Harsh Prateek BoraNested PAPR API provides a standard Guest State Buffer (GSB) format with unique IDs for each guest state element for which get/set state is supported by the API. Some of the elements are read-only and/or guest-wide. Introducing helper routines for state exchange of each of the nested guest state elements for which get/set state should be supported by the API.
--- include/hw/ppc/spapr_nested.h | 303 +++++++++++++++++++++++ hw/ppc/spapr_nested.c | 442 +++++++++++++++++++++++++++++++++- 2 files changed, 742 insertions(+), 3 deletions(-)
include/hw/ppc/spapr_nested.h +303 -0
@@ -4,6 +4,191 @@#include "qemu/osdep.h" #include "target/ppc/cpu.h" +/* Guest State Buffer Element IDs */ +#define GSB_HV_VCPU_IGNORED_ID 0x0000/* An element whose value is ignored */ +#define GSB_HV_VCPU_STATE_SIZE 0x0001/* HV internal format VCPU state size */ +#define GSB_VCPU_OUT_BUF_MIN_SZ 0x0002/* Min size of the Run VCPU o/p buffer */ +#define GSB_VCPU_LPVR 0x0003/* Logical PVR */ +#define GSB_TB_OFFSET 0x0004/* Timebase Offset */ +#define GSB_PART_SCOPED_PAGETBL 0x0005/* Partition Scoped Page Table */ +#define GSB_PROCESS_TBL 0x0006/* Process Table */ +/* RESERVED 0x0007 - 0x0BFF */ +#define GSB_VCPU_IN_BUFFER 0x0C00/* Run VCPU Input Buffer */ +#define GSB_VCPU_OUT_BUFFER 0x0C01/* Run VCPU Out Buffer */ +#define GSB_VCPU_VPA 0x0C02/* HRA to Guest VCPU VPA */ +/* RESERVED 0x0C03 - 0x0FFF */ +#define GSB_VCPU_GPR0 0x1000 +#define GSB_VCPU_GPR1 0x1001 +#define GSB_VCPU_GPR2 0x1002 +#define GSB_VCPU_GPR3 0x1003 +#define GSB_VCPU_GPR4 0x1004 +#define GSB_VCPU_GPR5 0x1005 +#define GSB_VCPU_GPR6 0x1006 +#define GSB_VCPU_GPR7 0x1007 +#define GSB_VCPU_GPR8 0x1008 +#define GSB_VCPU_GPR9 0x1009 +#define GSB_VCPU_GPR10 0x100A +#define GSB_VCPU_GPR11 0x100B +#define GSB_VCPU_GPR12 0x100C +#define GSB_VCPU_GPR13 0x100D +#define GSB_VCPU_GPR14 0x100E +#define GSB_VCPU_GPR15 0x100F +#define GSB_VCPU_GPR16 0x1010 +#define GSB_VCPU_GPR17 0x1011 +#define GSB_VCPU_GPR18 0x1012 +#define GSB_VCPU_GPR19 0x1013 +#define GSB_VCPU_GPR20 0x1014 +#define GSB_VCPU_GPR21 0x1015 +#define GSB_VCPU_GPR22 0x1016 +#define GSB_VCPU_GPR23 0x1017 +#define GSB_VCPU_GPR24 0x1018 +#define GSB_VCPU_GPR25 0x1019 +#define GSB_VCPU_GPR26 0x101A +#define GSB_VCPU_GPR27 0x101B +#define GSB_VCPU_GPR28 0x101C +#define GSB_VCPU_GPR29 0x101D +#define GSB_VCPU_GPR30 0x101E +#define GSB_VCPU_GPR31 0x101F +#define GSB_VCPU_HDEC_EXPIRY_TB 0x1020 +#define GSB_VCPU_SPR_NIA 0x1021 +#define GSB_VCPU_SPR_MSR 0x1022 +#define GSB_VCPU_SPR_LR 0x1023 +#define GSB_VCPU_SPR_XER 0x1024 +#define GSB_VCPU_SPR_CTR 0x1025 +#define GSB_VCPU_SPR_CFAR 0x1026 +#define GSB_VCPU_SPR_SRR0 0x1027 +#define GSB_VCPU_SPR_SRR1 0x1028 +#define GSB_VCPU_SPR_DAR 0x1029 +#define GSB_VCPU_DEC_EXPIRE_TB 0x102A +#define GSB_VCPU_SPR_VTB 0x102B +#define GSB_VCPU_SPR_LPCR 0x102C +#define GSB_VCPU_SPR_HFSCR 0x102D +#define GSB_VCPU_SPR_FSCR 0x102E +#define GSB_VCPU_SPR_FPSCR 0x102F +#define GSB_VCPU_SPR_DAWR0 0x1030 +#define GSB_VCPU_SPR_DAWR1 0x1031 +#define GSB_VCPU_SPR_CIABR 0x1032 +#define GSB_VCPU_SPR_PURR 0x1033 +#define GSB_VCPU_SPR_SPURR 0x1034 +#define GSB_VCPU_SPR_IC 0x1035 +#define GSB_VCPU_SPR_SPRG0 0x1036 +#define GSB_VCPU_SPR_SPRG1 0x1037 +#define GSB_VCPU_SPR_SPRG2 0x1038 +#define GSB_VCPU_SPR_SPRG3 0x1039 +#define GSB_VCPU_SPR_PPR 0x103A +#define GSB_VCPU_SPR_MMCR0 0x103B +#define GSB_VCPU_SPR_MMCR1 0x103C +#define GSB_VCPU_SPR_MMCR2 0x103D +#define GSB_VCPU_SPR_MMCR3 0x103E +#define GSB_VCPU_SPR_MMCRA 0x103F +#define GSB_VCPU_SPR_SIER 0x1040 +#define GSB_VCPU_SPR_SIER2 0x1041 +#define GSB_VCPU_SPR_SIER3 0x1042 +#define GSB_VCPU_SPR_BESCR 0x1043 +#define GSB_VCPU_SPR_EBBHR 0x1044 +#define GSB_VCPU_SPR_EBBRR 0x1045 +#define GSB_VCPU_SPR_AMR 0x1046 +#define GSB_VCPU_SPR_IAMR 0x1047 +#define GSB_VCPU_SPR_AMOR 0x1048 +#define GSB_VCPU_SPR_UAMOR 0x1049 +#define GSB_VCPU_SPR_SDAR 0x104A +#define GSB_VCPU_SPR_SIAR 0x104B +#define GSB_VCPU_SPR_DSCR 0x104C +#define GSB_VCPU_SPR_TAR 0x104D +#define GSB_VCPU_SPR_DEXCR 0x104E +#define GSB_VCPU_SPR_HDEXCR 0x104F +#define GSB_VCPU_SPR_HASHKEYR 0x1050 +#define GSB_VCPU_SPR_HASHPKEYR 0x1051 +#define GSB_VCPU_SPR_CTRL 0x1052 +/* RESERVED 0x1053 - 0x1FFF */ +#define GSB_VCPU_SPR_CR 0x2000 +#define GSB_VCPU_SPR_PIDR 0x2001 +#define GSB_VCPU_SPR_DSISR 0x2002 +#define GSB_VCPU_SPR_VSCR 0x2003 +#define GSB_VCPU_SPR_VRSAVE 0x2004 +#define GSB_VCPU_SPR_DAWRX0 0x2005 +#define GSB_VCPU_SPR_DAWRX1 0x2006 +#define GSB_VCPU_SPR_PMC1 0x2007 +#define GSB_VCPU_SPR_PMC2 0x2008 +#define GSB_VCPU_SPR_PMC3 0x2009 +#define GSB_VCPU_SPR_PMC4 0x200A +#define GSB_VCPU_SPR_PMC5 0x200B +#define GSB_VCPU_SPR_PMC6 0x200C +#define GSB_VCPU_SPR_WORT 0x200D +#define GSB_VCPU_SPR_PSPB 0x200E +/* RESERVED 0x200F - 0x2FFF */ +#define GSB_VCPU_SPR_VSR0 0x3000 +#define GSB_VCPU_SPR_VSR1 0x3001 +#define GSB_VCPU_SPR_VSR2 0x3002 +#define GSB_VCPU_SPR_VSR3 0x3003 +#define GSB_VCPU_SPR_VSR4 0x3004 +#define GSB_VCPU_SPR_VSR5 0x3005 +#define GSB_VCPU_SPR_VSR6 0x3006 +#define GSB_VCPU_SPR_VSR7 0x3007 +#define GSB_VCPU_SPR_VSR8 0x3008 +#define GSB_VCPU_SPR_VSR9 0x3009 +#define GSB_VCPU_SPR_VSR10 0x300A +#define GSB_VCPU_SPR_VSR11 0x300B +#define GSB_VCPU_SPR_VSR12 0x300C +#define GSB_VCPU_SPR_VSR13 0x300D +#define GSB_VCPU_SPR_VSR14 0x300E +#define GSB_VCPU_SPR_VSR15 0x300F +#define GSB_VCPU_SPR_VSR16 0x3010 +#define GSB_VCPU_SPR_VSR17 0x3011 +#define GSB_VCPU_SPR_VSR18 0x3012 +#define GSB_VCPU_SPR_VSR19 0x3013 +#define GSB_VCPU_SPR_VSR20 0x3014 +#define GSB_VCPU_SPR_VSR21 0x3015 +#define GSB_VCPU_SPR_VSR22 0x3016 +#define GSB_VCPU_SPR_VSR23 0x3017 +#define GSB_VCPU_SPR_VSR24 0x3018 +#define GSB_VCPU_SPR_VSR25 0x3019 +#define GSB_VCPU_SPR_VSR26 0x301A +#define GSB_VCPU_SPR_VSR27 0x301B +#define GSB_VCPU_SPR_VSR28 0x301C +#define GSB_VCPU_SPR_VSR29 0x301D +#define GSB_VCPU_SPR_VSR30 0x301E +#define GSB_VCPU_SPR_VSR31 0x301F +#define GSB_VCPU_SPR_VSR32 0x3020 +#define GSB_VCPU_SPR_VSR33 0x3021 +#define GSB_VCPU_SPR_VSR34 0x3022 +#define GSB_VCPU_SPR_VSR35 0x3023 +#define GSB_VCPU_SPR_VSR36 0x3024 +#define GSB_VCPU_SPR_VSR37 0x3025 +#define GSB_VCPU_SPR_VSR38 0x3026 +#define GSB_VCPU_SPR_VSR39 0x3027 +#define GSB_VCPU_SPR_VSR40 0x3028 +#define GSB_VCPU_SPR_VSR41 0x3029 +#define GSB_VCPU_SPR_VSR42 0x302A +#define GSB_VCPU_SPR_VSR43 0x302B +#define GSB_VCPU_SPR_VSR44 0x302C +#define GSB_VCPU_SPR_VSR45 0x302D +#define GSB_VCPU_SPR_VSR46 0x302E +#define GSB_VCPU_SPR_VSR47 0x302F +#define GSB_VCPU_SPR_VSR48 0x3030 +#define GSB_VCPU_SPR_VSR49 0x3031 +#define GSB_VCPU_SPR_VSR50 0x3032 +#define GSB_VCPU_SPR_VSR51 0x3033 +#define GSB_VCPU_SPR_VSR52 0x3034 +#define GSB_VCPU_SPR_VSR53 0x3035 +#define GSB_VCPU_SPR_VSR54 0x3036 +#define GSB_VCPU_SPR_VSR55 0x3037 +#define GSB_VCPU_SPR_VSR56 0x3038 +#define GSB_VCPU_SPR_VSR57 0x3039 +#define GSB_VCPU_SPR_VSR58 0x303A +#define GSB_VCPU_SPR_VSR59 0x303B +#define GSB_VCPU_SPR_VSR60 0x303C +#define GSB_VCPU_SPR_VSR61 0x303D +#define GSB_VCPU_SPR_VSR62 0x303E +#define GSB_VCPU_SPR_VSR63 0x303F +/* RESERVED 0x3040 - 0xEFFF */ +#define GSB_VCPU_SPR_HDAR 0xF000 +#define GSB_VCPU_SPR_HDSISR 0xF001 +#define GSB_VCPU_SPR_HEIR 0xF002 +#define GSB_VCPU_SPR_ASDR 0xF003 +/* End of list of Guest State Buffer Element IDs */ +#define GSB_LAST GSB_VCPU_SPR_ASDR + typedef struct SpaprMachineStateNested { uint64_t ptcr; uint8_t api;
@@ -17,6 +202,8 @@ typedef struct SpaprMachineStateNested {typedef struct SpaprMachineStateNestedGuest {uint32_t pvr_logical;unsigned long vcpus; +uint64_t parttbl[2 ]; +uint64_t tb_offset;struct SpaprMachineStateNestedGuestVcpu *vcpu; }SpaprMachineStateNestedGuest ;
@@ -32,6 +219,99 @@ typedef struct SpaprMachineStateNestedGuest {#define PAPR_NESTED_GUEST_MAX 4096#define H_GUEST_DELETE_ALL_FLAG 0x8000000000000000ULL#define PAPR_NESTED_GUEST_VCPU_MAX 2048 +#define VCPU_OUT_BUF_MIN_SZ 0x80ULL +#define HVMASK_DEFAULT 0xffffffffffffffff +#define HVMASK_LPCR 0x0070000003820800 +#define HVMASK_MSR 0xEBFFFFFFFFBFEFFF +#define HVMASK_HDEXCR 0x00000000FFFFFFFF +#define HVMASK_TB_OFFSET 0x000000FFFFFFFFFF + +#define GUEST_STATE_ELEMENT (i, sz, s, f, ptr, c) { \ + .id = (i), \ + .size = (sz), \ + .location = ptr, \ + .offset = offsetof(struct s, f), \ + .copy = (c) \ +} + +#define GSBE_NESTED (i, sz, f, c) { \ + .id = (i), \ + .size = (sz), \ + .location = get_guest_ptr, \ + .offset = offsetof(struct SpaprMachineStateNestedGuest, f),\ + .copy = (c), \ + .mask = HVMASK_DEFAULT \ +} + +#define GSBE_NESTED_MSK (i, sz, f, c, m) { \ + .id = (i), \ + .size = (sz), \ + .location = get_guest_ptr, \ + .offset = offsetof(struct SpaprMachineStateNestedGuest, f),\ + .copy = (c), \ + .mask = (m) \ +} + +#define GSBE_NESTED_VCPU (i, sz, f, c) { \ + .id = (i), \ + .size = (sz), \ + .location = get_vcpu_ptr, \ + .offset = offsetof(struct SpaprMachineStateNestedGuestVcpu, f),\ + .copy = (c), \ + .mask = HVMASK_DEFAULT \ +} + +#define GUEST_STATE_ELEMENT_NOP (i, sz) { \ + .id = (i), \ + .size = (sz), \ + .location = NULL, \ + .offset = 0, \ + .copy = NULL, \ + .mask = HVMASK_DEFAULT \ +} + +#define GUEST_STATE_ELEMENT_NOP_DW (i) \ + GUEST_STATE_ELEMENT_NOP(i, 8) +#define GUEST_STATE_ELEMENT_NOP_W (i) \ + GUEST_STATE_ELEMENT_NOP(i, 4) + +#define GUEST_STATE_ELEMENT_BASE (i, s, c) { \ + .id = (i), \ + .size = (s), \ + .location = get_vcpu_state_ptr, \ + .offset = 0, \ + .copy = (c), \ + .mask = HVMASK_DEFAULT \ + } + +#define GUEST_STATE_ELEMENT_OFF (i, s, f, c) { \ + .id = (i), \ + .size = (s), \ + .location = get_vcpu_state_ptr, \ + .offset = offsetof(struct nested_ppc_state, f), \ + .copy = (c), \ + .mask = HVMASK_DEFAULT \ + } + +#define GUEST_STATE_ELEMENT_MSK (i, s, f, c, m) { \ + .id = (i), \ + .size = (s), \ + .location = get_vcpu_state_ptr, \ + .offset = offsetof(struct nested_ppc_state, f), \ + .copy = (c), \ + .mask = (m) \ + } + +#define GUEST_STATE_ELEMENT_ENV_QW (i, f) \ + GUEST_STATE_ELEMENT_OFF(i, 16, f, copy_state_16to16) +#define GUEST_STATE_ELEMENT_ENV_DW (i, f) \ + GUEST_STATE_ELEMENT_OFF(i, 8, f, copy_state_8to8) +#define GUEST_STATE_ELEMENT_ENV_W (i, f) \ + GUEST_STATE_ELEMENT_OFF(i, 4, f, copy_state_4to8) +#define GUEST_STATE_ELEMENT_ENV_WW (i, f) \ + GUEST_STATE_ELEMENT_OFF(i, 4, f, copy_state_4to4) +#define GSE_ENV_DWM (i, f, m) \ + GUEST_STATE_ELEMENT_MSK(i, 8, f, copy_state_8to8, m)/* * Register state for entering a nested guest with H_ENTER_NESTED.
@@ -173,13 +453,35 @@ struct nested_ppc_state {uint64_t sier;uint32_t vscr;uint64_t fpscr; +int64_t dec_expiry_tb; +}; + +struct SpaprMachineStateNestedGuestVcpuRunBuf { +uint64_t addr; +uint64_t size; };typedef struct SpaprMachineStateNestedGuestVcpu {bool enabled;struct nested_ppc_state state; +struct SpaprMachineStateNestedGuestVcpuRunBuf runbufin; +struct SpaprMachineStateNestedGuestVcpuRunBuf runbufout; +int64_t tb_offset; +uint64_t hdecr_expiry_tb; }SpaprMachineStateNestedGuestVcpu ; +struct guest_state_element_type { +uint16_t id; +int size; +#define GUEST_STATE_ELEMENT_TYPE_FLAG_GUEST_WIDE 0x1 +#define GUEST_STATE_ELEMENT_TYPE_FLAG_READ_ONLY 0x2 +uint16_t flags; +void *(*location)(SpaprMachineStateNestedGuest *,target_ulong ); +size_t offset; +void (*copy)(void *,void *,bool ); +uint64_t mask; +}; +void spapr_exit_nested (PowerPCCPU *cpu,int excp);typedef struct SpaprMachineState SpaprMachineState ; bool spapr_get_pate_nested_hv(SpaprMachineState *spapr, PowerPCCPU *cpu,
@@ -187,4 +489,5 @@ bool spapr_get_pate_nested_hv(SpaprMachineState *spapr, PowerPCCPU *cpu,void spapr_nested_init (SpaprMachineState *spapr);uint8_t spapr_nested_api (SpaprMachineState *spapr);void spapr_register_nested_papr (void ); +void spapr_nested_gsb_init (void );#endif /* HW_SPAPR_NESTED_H */
hw/ppc/spapr_nested.c +439 -3
470 lines not on this page · raw message
Signature · 1 line
2.39.3
PATCH v3 11/15 spapr: nested: Introduce H_GUEST_[GET|SET]_STATE hcalls.
In reply to Harsh Prateek BoraIntroduce the nested PAPR hcalls:
- H_GUEST_GET_STATE which is used to get state of a nested guest or a guest VCPU. The value field for each element in the request is ignored and on success, will be updated to reflect current state.
- H_GUEST_SET_STATE which is used to modify the state of a guest or a guest VCPU. On success, guest (or its VCPU) state shall be updated as per the value field for the requested element(s).
--- include/hw/ppc/spapr.h | 3 + include/hw/ppc/spapr_nested.h | 23 +++ hw/ppc/spapr_nested.c | 267 ++++++++++++++++++++++++++++++++++ 3 files changed, 293 insertions(+)
include/hw/ppc/spapr.h +3 -0
@@ -366,6 +366,7 @@ struct SpaprMachineState {#define H_OVERLAP -68#define H_STATE -75#define H_IN_USE -77 +#define H_INVALID_ELEMENT_VALUE -81#define H_UNSUPPORTED_FLAG -256#define H_MULTI_THREADS_ACTIVE -9005
@@ -589,6 +590,8 @@ struct SpaprMachineState {#define H_GUEST_SET_CAPABILITIES 0x464#define H_GUEST_CREATE 0x470#define H_GUEST_CREATE_VCPU 0x474 +#define H_GUEST_GET_STATE 0x478 +#define H_GUEST_SET_STATE 0x47C#define H_GUEST_DELETE 0x488#define MAX_HCALL_OPCODE H_GUEST_DELETE
include/hw/ppc/spapr_nested.h +23 -0
@@ -225,6 +225,10 @@ typedef struct SpaprMachineStateNestedGuest {#define HVMASK_MSR 0xEBFFFFFFFFBFEFFF#define HVMASK_HDEXCR 0x00000000FFFFFFFF#define HVMASK_TB_OFFSET 0x000000FFFFFFFFFF +#define GSB_MAX_BUF_SIZE (1024 * 1024) +#define H_GUEST_GETSET_STATE_FLAG_GUEST_WIDE 0x8000000000000000 +#define GUEST_STATE_REQUEST_GUEST_WIDE 0x1 +#define GUEST_STATE_REQUEST_SET 0x2#define GUEST_STATE_ELEMENT (i, sz, s, f, ptr, c) { \ .id = (i), \
@@ -313,6 +317,25 @@ typedef struct SpaprMachineStateNestedGuest {#define GSE_ENV_DWM (i, f, m) \ GUEST_STATE_ELEMENT_MSK(i, 8, f, copy_state_8to8, m) +struct guest_state_element { +uint16_t id; +uint16_t size; +uint8_t value[]; +}QEMU_PACKED ; + +struct guest_state_buffer { +uint32_t num_elements; +struct guest_state_element elements[]; +}QEMU_PACKED ; + +/* Actual buffer plus some metadata about the request */ +struct guest_state_request { +struct guest_state_buffer *gsb; +int64_t buf; +int64_t len; +uint16_t flags; +}; +/* * Register state for entering a nested guest with H_ENTER_NESTED. * New member must be added at the end.
hw/ppc/spapr_nested.c +267 -0
291 lines not on this page · raw message
Signature · 1 line
2.39.3
PATCH v3 12/15 spapr: nested: Use correct source for parttbl info for nested PAPR API.
In reply to Harsh Prateek BoraFor nested PAPR API, we use SpaprMachineStateNestedGuest struct to store partition table info, use the same in spapr_get_pate_nested() via helper.
--- include/hw/ppc/spapr_nested.h | 4 ++++ hw/ppc/spapr.c | 2 ++ hw/ppc/spapr_nested.c | 20 +++++++++++++++++++- 3 files changed, 25 insertions(+), 1 deletion(-)
include/hw/ppc/spapr_nested.h +4 -0
@@ -513,4 +513,8 @@ void spapr_nested_init(SpaprMachineState *spapr);uint8_t spapr_nested_api (SpaprMachineState *spapr);void spapr_register_nested_papr (void );void spapr_nested_gsb_init (void ); +bool spapr_get_pate_nested_papr (SpaprMachineState *spapr,PowerPCCPU *cpu, +target_ulong lpid,ppc_v3_pate_t *entry); +SpaprMachineStateNestedGuest *spapr_get_nested_guest (SpaprMachineState *spapr, +target_ulong lpid);#endif /* HW_SPAPR_NESTED_H */
hw/ppc/spapr.c +2 -0
@@ -1379,6 +1379,8 @@ static bool spapr_get_pate(PPCVirtualHypervisor *vhyp, PowerPCCPU *cpu,assert (spapr_nested_api (spapr));if (spapr_nested_api (spapr) ==NESTED_API_KVM_HV ) {return spapr_get_pate_nested_hv (spapr, cpu, lpid, entry); + }else if (spapr_nested_api (spapr) ==NESTED_API_PAPR ) { +return spapr_get_pate_nested_papr (spapr, cpu, lpid, entry); }return false; }
hw/ppc/spapr_nested.c +19 -1
@@ -52,6 +52,19 @@ bool spapr_get_pate_nested_hv(SpaprMachineState *spapr, PowerPCCPU *cpu,return true; } +bool spapr_get_pate_nested_papr (SpaprMachineState *spapr,PowerPCCPU *cpu, +target_ulong lpid,ppc_v3_pate_t *entry) +{ +SpaprMachineStateNestedGuest *guest; +assert (lpid !=0 ); + guest =spapr_get_nested_guest (spapr, lpid); +assert (guest !=NULL ); + + entry->dw0 = guest->parttbl[0 ]; + entry->dw1 = guest->parttbl[1 ]; +return true; +} +#define PRTS_MASK 0x1f static target_ulong h_set_ptbl(PowerPCCPU *cpu,
@@ -536,7 +549,6 @@ void spapr_exit_nested(PowerPCCPU *cpu, int excp) } } -static SpaprMachineStateNestedGuest *spapr_get_nested_guest (SpaprMachineState *spapr,target_ulong guestid) {
@@ -1550,6 +1562,12 @@ bool spapr_get_pate_nested_hv(SpaprMachineState *spapr, PowerPCCPU *cpu,return false; } +bool spapr_get_pate_nested_papr (SpaprMachineState *spapr,PowerPCCPU *cpu, +target_ulong lpid,ppc_v3_pate_t *entry) +{ +return false; +} +void spapr_register_nested_papr (void ) {/* DO NOTHING */
Signature · 1 line
2.39.3
PATCH v3 13/15 spapr: nested: Introduce H_GUEST_RUN_VCPU hcall.
In reply to Harsh Prateek BoraThe H_GUEST_RUN_VCPU hcall is used to start execution of a Guest VCPU. The Hypervisor will update the state of the Guest VCPU based on the input buffer, restore the saved Guest VCPU state, and start its execution.
The Guest VCPU can stop running for numerous reasons including HCALLs, hypervisor exceptions, or an outstanding Host Partition Interrupt. The reason that the Guest VCPU stopped running is communicated through R4 and the output buffer will be filled in with any relevant state.
--- include/hw/ppc/spapr.h | 1 + target/ppc/cpu.h | 2 + hw/ppc/ppc.c | 10 ++ hw/ppc/spapr_nested.c | 333 +++++++++++++++++++++++++++++++++++++---- 4 files changed, 316 insertions(+), 30 deletions(-)
include/hw/ppc/spapr.h +1 -0
@@ -592,6 +592,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
target/ppc/cpu.h +2 -0
@@ -1566,6 +1566,8 @@ uint64_t cpu_ppc_load_atbl(CPUPPCState *env);uint32_t cpu_ppc_load_atbu (CPUPPCState *env);void cpu_ppc_store_atbl (CPUPPCState *env,uint32_t value);void cpu_ppc_store_atbu (CPUPPCState *env,uint32_t value); +void cpu_ppc_increase_tb_by_offset (CPUPPCState *env,int64_t offset); +void cpu_ppc_decrease_tb_by_offset (CPUPPCState *env,int64_t offset);uint64_t cpu_ppc_load_vtb (CPUPPCState *env);void cpu_ppc_store_vtb (CPUPPCState *env,uint64_t value);bool ppc_decr_clear_on_delivery (CPUPPCState *env);
hw/ppc/ppc.c +10 -0
@@ -633,6 +633,16 @@ void cpu_ppc_store_atbu (CPUPPCState *env, uint32_t value) ((uint64_t)value << 32) | tb); } +void cpu_ppc_increase_tb_by_offset (CPUPPCState *env,int64_t offset) +{ + env->tb_env->tb_offset += offset; +} + +void cpu_ppc_decrease_tb_by_offset (CPUPPCState *env,int64_t offset) +{ + env->tb_env->tb_offset -= offset; +} +uint64_t cpu_ppc_load_vtb (CPUPPCState *env) {ppc_tb_t *tb_env = env->tb_env;
hw/ppc/spapr_nested.c +303 -30
394 lines not on this page · raw message
Signature · 1 line
2.39.3
PATCH v3 14/15 spapr: nested: Introduce cap-nested-papr for Nested PAPR API
In reply to Harsh Prateek BoraIntroduce 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.
--- include/hw/ppc/spapr.h | 5 +++- hw/ppc/spapr.c | 2 ++ hw/ppc/spapr_caps.c | 55 ++++++++++++++++++++++++++++++++++++++++++ hw/ppc/spapr_nested.c | 2 -- 4 files changed, 61 insertions(+), 3 deletions(-)
include/hw/ppc/spapr.h +4 -1
@@ -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
@@ -993,6 +995,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;
hw/ppc/spapr.c +2 -0
@@ -2120,6 +2120,7 @@ static const VMStateDescription vmstate_spapr = { &vmstate_spapr_cap_fwnmi, &vmstate_spapr_fwnmi, &vmstate_spapr_cap_rpt_invalidate, + &vmstate_spapr_cap_nested_papr, NULL } };
@@ -4696,6 +4697,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 ;
hw/ppc/spapr_caps.c +55 -0
78 lines not on this page · raw message
hw/ppc/spapr_nested.c +0 -2
@@ -13,8 +13,6 @@void spapr_nested_init (SpaprMachineState *spapr) { spapr->nested.api =0 ; - spapr->nested.capabilities_set = false; -spapr_nested_gsb_init (); }uint8_t spapr_nested_api (SpaprMachineState *spapr)
Signature · 1 line
2.39.3
PATCH v3 15/15 spapr: nested: Set the PCR when logical PVR is set
In reply to Harsh Prateek BoraFrom: Amit Machhiwal <[email protected]>
In APIv1, KVM L0 sets the PCR, while in the nested papr APIv2, this doesn't work as the PCR can't be set via the guest state buffer; the logical PVR is set via the GSB though.
This change sets the PCR whenever the logical PVR is set via the GSB. Also, unlike the other registers, the value 1 in a defined bit in the PCR makes the affected resources unavailable and the value 0 makes them available. Hence, the PCR is set accordingly.
--- include/hw/ppc/spapr_nested.h | 9 +++++++++ hw/ppc/spapr_nested.c | 24 ++++++++++++++++++++++++ 2 files changed, 33 insertions(+)
include/hw/ppc/spapr_nested.h +9 -0
@@ -230,6 +230,15 @@ typedef struct SpaprMachineStateNestedGuest {#define GUEST_STATE_REQUEST_GUEST_WIDE 0x1#define GUEST_STATE_REQUEST_SET 0x2 +/* As per ISA v3.1B, following bits are reserved: +* 0:2 +* 4:57 (ISA mentions bit 58 as well but it should be used for P10) +* 61:63 (hence, haven't included PCR bits for v2.06 and v2.05 +* in LOW BITS) +*/ +#define PCR_LOW_BITS (PCR_COMPAT_3_10 | PCR_COMPAT_3_00) +#define HVMASK_PCR ~PCR_LOW_BITS +#define GUEST_STATE_ELEMENT (i, sz, s, f, ptr, c) { \ .id = (i), \ .size = (sz), \
hw/ppc/spapr_nested.c +24 -0
@@ -740,9 +740,11 @@ static void out_buf_min_size(void *a, void *b, bool set)static void copy_logical_pvr (void *a,void *b,bool set) { +SpaprMachineStateNestedGuest *guest;uint32_t *buf;/* 1 word */ uint32_t *pvr_logical_ptr;uint32_t pvr_logical; +target_ulong pcr =0 ; pvr_logical_ptr = a; buf = b;
@@ -755,6 +757,28 @@ static void copy_logical_pvr(void *a, void *b, bool set) pvr_logical =be32_to_cpu (buf[0 ]); *pvr_logical_ptr = pvr_logical; + +if (*pvr_logical_ptr) { +switch (*pvr_logical_ptr) { +case CPU_POWERPC_LOGICAL_3_10 : + pcr =PCR_COMPAT_3_10 |PCR_COMPAT_3_00 ; +break ; +case CPU_POWERPC_LOGICAL_3_00 : + pcr =PCR_COMPAT_3_00 ; +break ; +default : +qemu_log_mask (LOG_GUEST_ERROR , +"Could not set PCR for LPVR=0x%08x\n" , *pvr_logical_ptr); +return ; + } + } + + guest =container_of (pvr_logical_ptr, + struct SpaprMachineStateNestedGuest, + pvr_logical); +for (int i =0 ; i < guest->vcpus; i++) { + guest->vcpu[i].state.pcr = ~pcr |HVMASK_PCR ; + } }static void copy_tb_offset (void *a,void *b,bool set)
Signature · 1 line
2.39.3