KVM: PPC: Nested APIv2 guest support
Subsystems (4)
v4 cover KVM: PPC: Nested APIv2 guest support
A nested-HV API for PAPR has been developed based on the KVM-specific nested-HV API that is upstream in Linux/KVM and QEMU. The PAPR API had to break compatibility to accommodate implementation in other hypervisors and partitioning firmware. The existing KVM-specific API will be known as the Nested APIv1 and the PAPR API will be known as the Nested APIv2.
The control flow and interrupt processing between L0, L1, and L2 in the Nested APIv2 are conceptually unchanged. Where Nested APIv1 is almost stateless, the Nested APIv2 is stateful, with the L1 registering L2 virtual machines and vCPUs with the L0. Supervisor-privileged register switching duty is now the responsibility for the L0, which holds canonical L2 register state and handles all switching. This new register handling motivates the "getters and setters" wrappers to assist in syncing the L2s state in the L1 and the L0.
Broadly, the new hcalls will be used for creating and managing guests by a regular partition in the following way:
- L1 and L0 negotiate capabilities with
H_GUEST_{G,S}ET_CAPABILITIES
- L1 requests the L0 create a L2 with
H_GUEST_CREATE and receives a handle to use in future hcalls
- L1 requests the L0 create a L2 vCPU with
H_GUEST_CREATE_VCPU
- L1 sets up the L2 using H_GUEST_SET and the
H_GUEST_VCPU_RUN input buffer
- L1 requests the L0 runs the L2 vCPU using H_GUEST_VCPU_RUN
- L2 returns to L1 with an exit reason and L1 reads the H_GUEST_VCPU_RUN output buffer populated by the L0
- L1 handles the exit using H_GET_STATE if necessary
- L1 reruns L2 vCPU with H_GUEST_VCPU_RUN
- L1 frees the L2 in the L0 with H_GUEST_DELETE
Further details are available in Documentation/powerpc/kvm-nested.rst.
This series adds KVM support for using this hcall interface as a regular PAPR partition, i.e. the L1. It does not add support for running as the L0.
The new hcalls have been implemented in the spapr qemu model for testing.
This is available at https://github.com/planetharsh/qemu/tree/upstream-0714-kop
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/iamjpn/linux/tree/features/kvm-nestedv2-v4
Thanks to Amit Machhiwal, Kautuk Consul, Vaibhav Jain, Michael Neuling, Shivaprasad Bhat, Harsh Prateek Bora, Paul Mackerras and Nicholas Piggin.
Change overview in v4:
- Split previous "KVM: PPC: Use getters and setters for vcpu register state" into a number of seperate patches
- Remove _hv suffix from VCORE wrappers
- Do not create arch_compat and lpcr setters, use the existing ones
- Use #ifdef ALTIVEC
- KVM: PPC: Rename accessor generator macros
- Fix typo
- KVM: PPC: Book3s HV: Hold LPIDs in an unsigned long
- Use u64
- Change format strings instead of casting
- KVM: PPC: Add support for nestedv2 guests
- Batch H_GUEST_GET calls in kvmhv_nestedv2_reload_ptregs()
- Fix compile without CONFIG_PSERIES
- Fix maybe uninitialized 'trap' in kvmhv_p9_guest_entry()
- Extend existing setters for arch_compat and lpcr
Change overview in v3:
- KVM: PPC: Use getters and setters for vcpu register state
- Do not add a helper for pvr
- Use an expression when declaring variable in case
- Squash in all getters and setters
- Pass vector registers by reference
- KVM: PPC: Rename accessor generator macros
- New to series
- KVM: PPC: Add helper library for Guest State Buffers
- Use EXPORT_SYMBOL_GPL()
- Use the kvmppc namespace
- Move kvmppc_gsb_reset() out of kvmppc_gsm_fill_info()
- Comments for GSID elements
- Pass vector elements by reference
- Remove generic put and get functions
- KVM: PPC: Book3s HV: Hold LPIDs in an unsigned long
- New to series
- KVM: PPC: Add support for nestedv2 guests
- Use EXPORT_SYMBOL_GPL()
- Change to kvmhv_nestedv2 namespace
- Make kvmhv_enable_nested() return -ENODEV on NESTEDv2 L1 hosts
- s/kvmhv_on_papr/kvmhv_is_nestedv2/
- mv book3s_hv_papr.c book3s_hv_nestedv2.c
- Handle shared regs without a guest state id in the same wrapper
- Use a static key for API version
- Add a positive test for NESTEDv1
- Give the amor a static value
- s/struct kvmhv_nestedv2_host/struct kvmhv_nestedv2_io/
- Propagate failure in kvmhv_vcpu_entry_nestedv2()
- WARN if getters and setters fail
- Progagate failure from kvmhv_nestedv2_parse_output()
- Replace delay with sleep in plpar_guest_{create,delete,create_vcpu}()
- Add logical PVR handling
- Replace kvmppc_gse_{get,put} with specific version
- docs: powerpc: Document nested KVM on POWER
- Fix typos
Change overview in v2:
- Rebase on top of kvm ppc prefix instruction support
- Make documentation an individual patch
- Move guest state buffer files from arch/powerpc/lib/ to arch/powerpc/kvm/
- Use kunit for testing guest state buffer
- Fix some build errors
- Change HEIR element from 4 bytes to 8 bytes
Previous revisions:
- v1: https://lore.kernel.org/linuxppc-dev/[email protected]/
- v2: https://lore.kernel.org/linuxppc-dev/[email protected]/
- v3: https://lore.kernel.org/linuxppc-dev/[email protected]/
Jordan Niethe (10):
KVM: PPC: Always use the GPR accessors
KVM: PPC: Introduce FPR/VR accessor functions
KVM: PPC: Rename accessor generator macros
KVM: PPC: Use accessors for VCPU registers
KVM: PPC: Use accessors VCORE registers
KVM: PPC: Book3S HV: Use accessors for VCPU registers
KVM: PPC: Book3S HV: Introduce low level MSR accessor
KVM: PPC: Add helper library for Guest State Buffers
KVM: PPC: Book3s HV: Hold LPIDs in an unsigned long
KVM: PPC: Add support for nestedv2 guests
Michael Neuling (1):
docs: powerpc: Document nested KVM on POWER
Documentation/powerpc/index.rst | 1 + Documentation/powerpc/kvm-nested.rst | 636 +++++++++++ arch/powerpc/Kconfig.debug | 12 + arch/powerpc/include/asm/guest-state-buffer.h | 995 +++++++++++++++++ arch/powerpc/include/asm/hvcall.h | 30 + arch/powerpc/include/asm/kvm_book3s.h | 220 +++- arch/powerpc/include/asm/kvm_book3s_64.h | 8 +- arch/powerpc/include/asm/kvm_booke.h | 10 + arch/powerpc/include/asm/kvm_host.h | 22 +- arch/powerpc/include/asm/kvm_ppc.h | 102 +- arch/powerpc/include/asm/plpar_wrappers.h | 248 ++++- arch/powerpc/kvm/Makefile | 4 + arch/powerpc/kvm/book3s.c | 38 +- arch/powerpc/kvm/book3s_64_mmu_hv.c | 7 +- arch/powerpc/kvm/book3s_64_mmu_radix.c | 31 +- arch/powerpc/kvm/book3s_64_vio.c | 4 +- arch/powerpc/kvm/book3s_hv.c | 358 +++++-- arch/powerpc/kvm/book3s_hv.h | 76 ++ arch/powerpc/kvm/book3s_hv_builtin.c | 11 +- arch/powerpc/kvm/book3s_hv_nested.c | 42 +- arch/powerpc/kvm/book3s_hv_nestedv2.c | 998 ++++++++++++++++++ arch/powerpc/kvm/book3s_hv_p9_entry.c | 4 +- arch/powerpc/kvm/book3s_hv_ras.c | 4 +- arch/powerpc/kvm/book3s_hv_rm_mmu.c | 8 +- arch/powerpc/kvm/book3s_hv_rm_xics.c | 4 +- arch/powerpc/kvm/book3s_hv_uvmem.c | 2 +- arch/powerpc/kvm/book3s_xive.c | 12 +- arch/powerpc/kvm/emulate_loadstore.c | 6 +- arch/powerpc/kvm/guest-state-buffer.c | 621 +++++++++++ arch/powerpc/kvm/powerpc.c | 76 +- arch/powerpc/kvm/test-guest-state-buffer.c | 328 ++++++ 31 files changed, 4655 insertions(+), 263 deletions(-) create mode 100644 Documentation/powerpc/kvm-nested.rst create mode 100644 arch/powerpc/include/asm/guest-state-buffer.h create mode 100644 arch/powerpc/kvm/book3s_hv_nestedv2.c create mode 100644 arch/powerpc/kvm/guest-state-buffer.c create mode 100644 arch/powerpc/kvm/test-guest-state-buffer.c
Signature · 1 line
2.39.3
PATCH v4 1/11 KVM: PPC: Always use the GPR accessors
Always use the GPR accessor functions. This will be important later for Nested APIv2 support which requires additional functionality for accessing and modifying VCPU state.
---
v4:
- Split into unique patch
--- arch/powerpc/kvm/book3s_64_vio.c | 4 ++-- arch/powerpc/kvm/book3s_hv.c | 8 ++++++-- arch/powerpc/kvm/book3s_hv_builtin.c | 6 +++++- arch/powerpc/kvm/book3s_hv_rm_mmu.c | 8 ++++---- arch/powerpc/kvm/book3s_hv_rm_xics.c | 4 ++-- arch/powerpc/kvm/book3s_xive.c | 4 ++-- 6 files changed, 21 insertions(+), 13 deletions(-)
arch/powerpc/kvm/book3s_64_vio.c +2 -2
@@ -786,12 +786,12 @@ long kvmppc_h_get_tce(struct kvm_vcpu *vcpu, unsigned long liobn, idx = (ioba >> stt->page_shift) - stt->offset; page = stt->pages[idx /TCES_PER_PAGE ];if (!page) { - vcpu->arch.regs.gpr[4 ] =0 ; +kvmppc_set_gpr (vcpu,4 ,0 );return H_SUCCESS ; } tbl = (u64 *)page_address (page); - vcpu->arch.regs.gpr[4 ] = tbl[idx %TCES_PER_PAGE ]; +kvmppc_set_gpr (vcpu,4 , tbl[idx %TCES_PER_PAGE ]);return H_SUCCESS ; }
arch/powerpc/kvm/book3s_hv.c +6 -2
@@ -1267,10 +1267,14 @@ int kvmppc_pseries_do_hcall(struct kvm_vcpu *vcpu)return RESUME_HOST ;break ;#endif -case H_RANDOM : -if (!arch_get_random_seed_longs (&vcpu->arch.regs.gpr[4 ],1 )) +case H_RANDOM : { +unsigned long rand; + +if (!arch_get_random_seed_longs (&rand,1 )) ret =H_HARDWARE ; +kvmppc_set_gpr (vcpu,4 , rand);break ; + }case H_RPT_INVALIDATE : ret = kvmppc_h_rpt_invalidate(vcpu, kvmppc_get_gpr(vcpu, 4), kvmppc_get_gpr(vcpu, 5),
arch/powerpc/kvm/book3s_hv_builtin.c +5 -1
@@ -182,9 +182,13 @@ EXPORT_SYMBOL_GPL(kvmppc_hwrng_present);long kvmppc_rm_h_random (struct kvm_vcpu *vcpu) { +unsigned long rand; +if (ppc_md.get_random_seed && - ppc_md.get_random_seed (&vcpu->arch.regs.gpr[4 ])) + ppc_md.get_random_seed (&rand)) { +kvmppc_set_gpr (vcpu,4 , rand);return H_SUCCESS ; + }return H_HARDWARE ; }
arch/powerpc/kvm/book3s_hv_rm_mmu.c +4 -4
@@ -776,8 +776,8 @@ long kvmppc_h_read(struct kvm_vcpu *vcpu, unsigned long flags, r = rev[i].guest_rpte | (r & (HPTE_R_R |HPTE_R_C )); r &= ~HPTE_GR_RESERVED ; } - vcpu->arch.regs.gpr[4 + i *2 ] = v; - vcpu->arch.regs.gpr[5 + i *2 ] = r; +kvmppc_set_gpr (vcpu,4 + i *2 , v); +kvmppc_set_gpr (vcpu,5 + i *2 , r); }return H_SUCCESS ; }
@@ -824,7 +824,7 @@ long kvmppc_h_clear_ref(struct kvm_vcpu *vcpu, unsigned long flags, } } } - vcpu->arch.regs.gpr[4 ] = gr; +kvmppc_set_gpr (vcpu,4 , gr); ret =H_SUCCESS ; out:unlock_hpte (hpte, v & ~HPTE_V_HVLOCK );
@@ -872,7 +872,7 @@ long kvmppc_h_clear_mod(struct kvm_vcpu *vcpu, unsigned long flags,kvmppc_set_dirty_from_hpte (kvm, v, gr); } } - vcpu->arch.regs.gpr[4 ] = gr; +kvmppc_set_gpr (vcpu,4 , gr); ret =H_SUCCESS ; out:unlock_hpte (hpte, v & ~HPTE_V_HVLOCK );
arch/powerpc/kvm/book3s_hv_rm_xics.c +2 -2
@@ -481,7 +481,7 @@ static void icp_rm_down_cppr(struct kvmppc_xics *xics, struct kvmppc_icp *icp,unsigned long xics_rm_h_xirr_x (struct kvm_vcpu *vcpu) { - vcpu->arch.regs.gpr[5 ] =get_tb (); +kvmppc_set_gpr (vcpu,5 ,get_tb ());return xics_rm_h_xirr (vcpu); }
@@ -518,7 +518,7 @@ unsigned long xics_rm_h_xirr(struct kvm_vcpu *vcpu) }while (!icp_rm_try_update (icp, old_state, new_state));/* Return the result in GPR4 */ - vcpu->arch.regs.gpr[4 ] = xirr; +kvmppc_set_gpr (vcpu,4 , xirr);return check_too_hard (xics, icp); }
arch/powerpc/kvm/book3s_xive.c +2 -2
@@ -328,7 +328,7 @@ static unsigned long xive_vm_h_xirr(struct kvm_vcpu *vcpu)*/ /* Return interrupt and old CPPR in GPR4 */ - vcpu->arch.regs.gpr[4 ] = hirq | (old_cppr <<24 ); +kvmppc_set_gpr (vcpu,4 , hirq | (old_cppr <<24 ));return H_SUCCESS ; }
@@ -364,7 +364,7 @@ static unsigned long xive_vm_h_ipoll(struct kvm_vcpu *vcpu, unsigned long server hirq =xive_vm_scan_interrupts (xc, pending, scan_poll);/* Return interrupt and old CPPR in GPR4 */ - vcpu->arch.regs.gpr[4 ] = hirq | (xc->cppr <<24 ); +kvmppc_set_gpr (vcpu,4 , hirq | (xc->cppr <<24 ));return H_SUCCESS ; }
Signature · 1 line
2.39.3
PATCH v4 2/11 KVM: PPC: Introduce FPR/VR accessor functions
In reply to Jordan NietheIntroduce accessor functions for floating point and vector registers like the ones that exist for GPRs. Use these to replace the existing FPR and VR accessor macros.
This will be important later for Nested APIv2 support which requires additional functionality for accessing and modifying VCPU state.
---
v4:
- Split into unique patch
--- arch/powerpc/include/asm/kvm_book3s.h | 55 ++++++++++++++++++++ arch/powerpc/include/asm/kvm_booke.h | 10 ++++ arch/powerpc/kvm/book3s.c | 16 +++--- arch/powerpc/kvm/emulate_loadstore.c | 2 +- arch/powerpc/kvm/powerpc.c | 72 +++++++++++++-------------- 5 files changed, 110 insertions(+), 45 deletions(-)
arch/powerpc/include/asm/kvm_book3s.h +55 -0
@@ -403,6 +403,61 @@ static inline ulong kvmppc_get_fault_dar(struct kvm_vcpu *vcpu)return vcpu->arch.fault_dar; } +static inline u64 kvmppc_get_fpr (struct kvm_vcpu *vcpu,int i) +{ +return vcpu->arch.fp.fpr[i][TS_FPROFFSET ]; +} + +static inline void kvmppc_set_fpr (struct kvm_vcpu *vcpu,int i,u64 val) +{ + vcpu->arch.fp.fpr[i][TS_FPROFFSET ] = val; +} + +static inline u64 kvmppc_get_fpscr (struct kvm_vcpu *vcpu) +{ +return vcpu->arch.fp.fpscr; +} + +static inline void kvmppc_set_fpscr (struct kvm_vcpu *vcpu,u64 val) +{ + vcpu->arch.fp.fpscr = val; +} + + +static inline u64 kvmppc_get_vsx_fpr (struct kvm_vcpu *vcpu,int i,int j) +{ +return vcpu->arch.fp.fpr[i][j]; +} + +static inline void kvmppc_set_vsx_fpr (struct kvm_vcpu *vcpu,int i,int j, +u64 val) +{ + vcpu->arch.fp.fpr[i][j] = val; +} + +#ifdef CONFIG_ALTIVEC +static inline void kvmppc_get_vsx_vr (struct kvm_vcpu *vcpu,int i,vector128 *v) +{ + *v = vcpu->arch.vr.vr[i]; +} + +static inline void kvmppc_set_vsx_vr (struct kvm_vcpu *vcpu,int i, +vector128 *val) +{ + vcpu->arch.vr.vr[i] = *val; +} + +static inline u32 kvmppc_get_vscr (struct kvm_vcpu *vcpu) +{ +return vcpu->arch.vr.vscr.u[3 ]; +} + +static inline void kvmppc_set_vscr (struct kvm_vcpu *vcpu,u32 val) +{ + vcpu->arch.vr.vscr.u[3 ] = val; +} +#endif +/* Expiry time of vcpu DEC relative to host TB */ static inline u64 kvmppc_dec_expires_host_tb (struct kvm_vcpu *vcpu) {
arch/powerpc/include/asm/kvm_booke.h +10 -0
@@ -89,6 +89,16 @@ static inline ulong kvmppc_get_pc(struct kvm_vcpu *vcpu)return vcpu->arch.regs.nip; } +static inline void kvmppc_set_fpr (struct kvm_vcpu *vcpu,int i,u64 val) +{ + vcpu->arch.fp.fpr[i][TS_FPROFFSET ] = val; +} + +static inline u64 kvmppc_get_fpr (struct kvm_vcpu *vcpu,int i) +{ +return vcpu->arch.fp.fpr[i][TS_FPROFFSET ]; +} +#ifdef CONFIG_BOOKE static inline ulong kvmppc_get_fault_dar (struct kvm_vcpu *vcpu) {
arch/powerpc/kvm/book3s.c +8 -8
@@ -636,17 +636,17 @@ int kvmppc_get_one_reg(struct kvm_vcpu *vcpu, u64 id,break ; case KVM_REG_PPC_FPR0 ... KVM_REG_PPC_FPR31: i = id -KVM_REG_PPC_FPR0 ; - *val =get_reg_val (id,VCPU_FPR (vcpu, i)); + *val =get_reg_val (id,kvmppc_get_fpr (vcpu, i));break ;case KVM_REG_PPC_FPSCR : - *val =get_reg_val (id, vcpu->arch.fp.fpscr); + *val =get_reg_val (id,kvmppc_get_fpscr (vcpu));break ;#ifdef CONFIG_VSX case KVM_REG_PPC_VSR0 ... KVM_REG_PPC_VSR31:if (cpu_has_feature (CPU_FTR_VSX )) { i = id -KVM_REG_PPC_VSR0 ; - val->vsxval[0 ] = vcpu->arch.fp.fpr[i][0 ]; - val->vsxval[1 ] = vcpu->arch.fp.fpr[i][1 ]; + val->vsxval[0 ] =kvmppc_get_vsx_fpr (vcpu, i,0 ); + val->vsxval[1 ] =kvmppc_get_vsx_fpr (vcpu, i,1 ); }else { r = -ENXIO ; }
@@ -724,7 +724,7 @@ int kvmppc_set_one_reg(struct kvm_vcpu *vcpu, u64 id,break ; case KVM_REG_PPC_FPR0 ... KVM_REG_PPC_FPR31: i = id -KVM_REG_PPC_FPR0 ; -VCPU_FPR (vcpu, i) =set_reg_val (id, *val); +kvmppc_set_fpr (vcpu, i,set_reg_val (id, *val));break ;case KVM_REG_PPC_FPSCR : vcpu->arch.fp.fpscr =set_reg_val (id, *val);
@@ -733,8 +733,8 @@ int kvmppc_set_one_reg(struct kvm_vcpu *vcpu, u64 id, case KVM_REG_PPC_VSR0 ... KVM_REG_PPC_VSR31:if (cpu_has_feature (CPU_FTR_VSX )) { i = id -KVM_REG_PPC_VSR0 ; - vcpu->arch.fp.fpr[i][0 ] = val->vsxval[0 ]; - vcpu->arch.fp.fpr[i][1 ] = val->vsxval[1 ]; +kvmppc_set_vsx_fpr (vcpu, i,0 , val->vsxval[0 ]); +kvmppc_set_vsx_fpr (vcpu, i,1 , val->vsxval[1 ]); }else { r = -ENXIO ; }
@@ -765,7 +765,7 @@ int kvmppc_set_one_reg(struct kvm_vcpu *vcpu, u64 id,break ;#endif /* CONFIG_KVM_XIVE */ case KVM_REG_PPC_FSCR : - vcpu->arch.fscr =set_reg_val (id, *val); +kvmppc_set_fpscr (vcpu,set_reg_val (id, *val));break ;case KVM_REG_PPC_TAR : vcpu->arch.tar =set_reg_val (id, *val);
arch/powerpc/kvm/emulate_loadstore.c +1 -1
@@ -250,7 +250,7 @@ int kvmppc_emulate_loadstore(struct kvm_vcpu *vcpu) vcpu->arch.mmio_sp64_extend =1 ; emulated =kvmppc_handle_store (vcpu, -VCPU_FPR (vcpu, op.reg), size,1 ); +kvmppc_get_fpr (vcpu, op.reg), size,1 );if ((op.type &UPDATE ) && (emulated !=EMULATE_FAIL ))kvmppc_set_gpr (vcpu, op.update_reg, op.ea);
arch/powerpc/kvm/powerpc.c +36 -36
212 lines not on this page · raw message
Signature · 1 line
2.39.3
PATCH v4 3/11 KVM: PPC: Rename accessor generator macros
In reply to Jordan NietheMore "wrapper" style accessor generating macros will be introduced for the nestedv2 guest support. Rename the existing macros with more descriptive names now so there is a consistent naming convention.
---
v3:
- New to series
v4:
- Fix ACESSOR typo
--- arch/powerpc/include/asm/kvm_ppc.h | 60 +++++++++++++++--------------- 1 file changed, 30 insertions(+), 30 deletions(-)
arch/powerpc/include/asm/kvm_ppc.h +30 -30
@@ -927,19 +927,19 @@ static inline bool kvmppc_shared_big_endian(struct kvm_vcpu *vcpu)#endif } -#define SPRNG_WRAPPER_GET (reg, bookehv_spr) \ +#define KVMPPC_BOOKE_HV_SPRNG_ACCESSOR_GET (reg, bookehv_spr) \ static inline ulong kvmppc_get_##reg(struct kvm_vcpu *vcpu) \ { \ return mfspr(bookehv_spr); \ } \ -#define SPRNG_WRAPPER_SET (reg, bookehv_spr) \ +#define KVMPPC_BOOKE_HV_SPRNG_ACCESSOR_SET (reg, bookehv_spr) \ static inline void kvmppc_set_##reg(struct kvm_vcpu *vcpu, ulong val) \ { \ mtspr(bookehv_spr, val); \ } \ -#define SHARED_WRAPPER_GET (reg, size) \ +#define KVMPPC_VCPU_SHARED_REGS_ACCESSOR_GET (reg, size) \ static inline u##size kvmppc_get_##reg(struct kvm_vcpu *vcpu) \ { \ if (kvmppc_shared_big_endian(vcpu)) \
@@ -948,7 +948,7 @@ static inline u##size kvmppc_get_##reg(struct kvm_vcpu *vcpu) \ return le##size##_to_cpu(vcpu->arch.shared->reg); \ } \ -#define SHARED_WRAPPER_SET (reg, size) \ +#define KVMPPC_VCPU_SHARED_REGS_ACCESSOR_SET (reg, size) \ static inline void kvmppc_set_##reg(struct kvm_vcpu *vcpu, u##size val) \ { \ if (kvmppc_shared_big_endian(vcpu)) \
@@ -957,36 +957,36 @@ static inline void kvmppc_set_##reg(struct kvm_vcpu *vcpu, u##size val) \ vcpu->arch.shared->reg = cpu_to_le##size(val); \ } \ -#define SHARED_WRAPPER (reg, size) \ - SHARED_WRAPPER_GET(reg, size) \ - SHARED_WRAPPER_SET(reg, size) \ +#define KVMPPC_VCPU_SHARED_REGS_ACCESSOR (reg, size) \ + KVMPPC_VCPU_SHARED_REGS_ACCESSOR_GET(reg, size) \ + KVMPPC_VCPU_SHARED_REGS_ACCESSOR_SET(reg, size) \ -#define SPRNG_WRAPPER (reg, bookehv_spr) \ - SPRNG_WRAPPER_GET(reg, bookehv_spr) \ - SPRNG_WRAPPER_SET(reg, bookehv_spr) \ +#define KVMPPC_BOOKE_HV_SPRNG_ACCESSOR (reg, bookehv_spr) \ + KVMPPC_BOOKE_HV_SPRNG_ACCESSOR_GET(reg, bookehv_spr) \ + KVMPPC_BOOKE_HV_SPRNG_ACCESSOR_SET(reg, bookehv_spr) \#ifdef CONFIG_KVM_BOOKE_HV -#define SHARED_SPRNG_WRAPPER (reg, size, bookehv_spr) \ - SPRNG_WRAPPER(reg, bookehv_spr) \ +#define KVMPPC_BOOKE_HV_SPRNG_OR_VCPU_SHARED_REGS_ACCESSOR (reg, size, bookehv_spr) \ + KVMPPC_BOOKE_HV_SPRNG_ACCESSOR(reg, bookehv_spr) \#else -#define SHARED_SPRNG_WRAPPER (reg, size, bookehv_spr) \ - SHARED_WRAPPER(reg, size) \ +#define KVMPPC_BOOKE_HV_SPRNG_OR_VCPU_SHARED_REGS_ACCESSOR (reg, size, bookehv_spr) \ + KVMPPC_VCPU_SHARED_REGS_ACCESSOR(reg, size) \#endif -SHARED_WRAPPER(critical, 64) -SHARED_SPRNG_WRAPPER(sprg0, 64, SPRN_GSPRG0) -SHARED_SPRNG_WRAPPER(sprg1, 64, SPRN_GSPRG1) -SHARED_SPRNG_WRAPPER(sprg2, 64, SPRN_GSPRG2) -SHARED_SPRNG_WRAPPER(sprg3, 64, SPRN_GSPRG3) -SHARED_SPRNG_WRAPPER(srr0, 64, SPRN_GSRR0) -SHARED_SPRNG_WRAPPER(srr1, 64, SPRN_GSRR1) -SHARED_SPRNG_WRAPPER(dar, 64, SPRN_GDEAR) -SHARED_SPRNG_WRAPPER(esr, 64, SPRN_GESR) -SHARED_WRAPPER_GET(msr, 64) +KVMPPC_VCPU_SHARED_REGS_ACCESSOR(critical, 64) +KVMPPC_BOOKE_HV_SPRNG_OR_VCPU_SHARED_REGS_ACCESSOR(sprg0, 64, SPRN_GSPRG0) +KVMPPC_BOOKE_HV_SPRNG_OR_VCPU_SHARED_REGS_ACCESSOR(sprg1, 64, SPRN_GSPRG1) +KVMPPC_BOOKE_HV_SPRNG_OR_VCPU_SHARED_REGS_ACCESSOR(sprg2, 64, SPRN_GSPRG2) +KVMPPC_BOOKE_HV_SPRNG_OR_VCPU_SHARED_REGS_ACCESSOR(sprg3, 64, SPRN_GSPRG3) +KVMPPC_BOOKE_HV_SPRNG_OR_VCPU_SHARED_REGS_ACCESSOR(srr0, 64, SPRN_GSRR0) +KVMPPC_BOOKE_HV_SPRNG_OR_VCPU_SHARED_REGS_ACCESSOR(srr1, 64, SPRN_GSRR1) +KVMPPC_BOOKE_HV_SPRNG_OR_VCPU_SHARED_REGS_ACCESSOR(dar, 64, SPRN_GDEAR) +KVMPPC_BOOKE_HV_SPRNG_OR_VCPU_SHARED_REGS_ACCESSOR(esr, 64, SPRN_GESR) +KVMPPC_VCPU_SHARED_REGS_ACCESSOR_GET(msr, 64)static inline void kvmppc_set_msr_fast (struct kvm_vcpu *vcpu,u64 val) {if (kvmppc_shared_big_endian (vcpu))
@@ -994,12 +994,12 @@ static inline void kvmppc_set_msr_fast(struct kvm_vcpu *vcpu, u64 val)else vcpu->arch.shared->msr =cpu_to_le64 (val); } -SHARED_WRAPPER(dsisr, 32) -SHARED_WRAPPER(int_pending, 32) -SHARED_WRAPPER(sprg4, 64) -SHARED_WRAPPER(sprg5, 64) -SHARED_WRAPPER(sprg6, 64) -SHARED_WRAPPER(sprg7, 64) +KVMPPC_VCPU_SHARED_REGS_ACCESSOR(dsisr, 32) +KVMPPC_VCPU_SHARED_REGS_ACCESSOR(int_pending, 32) +KVMPPC_VCPU_SHARED_REGS_ACCESSOR(sprg4, 64) +KVMPPC_VCPU_SHARED_REGS_ACCESSOR(sprg5, 64) +KVMPPC_VCPU_SHARED_REGS_ACCESSOR(sprg6, 64) +KVMPPC_VCPU_SHARED_REGS_ACCESSOR(sprg7, 64)static inline u32 kvmppc_get_sr (struct kvm_vcpu *vcpu,int nr) {
Signature · 1 line
2.39.3
PATCH v4 4/11 KVM: PPC: Use accessors for VCPU registers
In reply to Jordan NietheIntroduce accessor generator macros for VCPU registers. Use the accessor functions to replace direct accesses to this registers.
This will be important later for Nested APIv2 support which requires additional functionality for accessing and modifying VCPU state.
---
v4:
- Split to unique patch
--- arch/powerpc/include/asm/kvm_book3s.h | 37 +++++++++++++++++++++++++- arch/powerpc/kvm/book3s.c | 22 +++++++-------- arch/powerpc/kvm/book3s_64_mmu_radix.c | 4 +-- arch/powerpc/kvm/book3s_hv.c | 12 ++++----- arch/powerpc/kvm/book3s_hv_p9_entry.c | 4 +-- arch/powerpc/kvm/powerpc.c | 4 +-- 6 files changed, 59 insertions(+), 24 deletions(-)
arch/powerpc/include/asm/kvm_book3s.h +36 -1
@@ -458,10 +458,45 @@ static inline void kvmppc_set_vscr(struct kvm_vcpu *vcpu, u32 val) }#endif +#define KVMPPC_BOOK3S_VCPU_ACCESSOR_SET (reg, size) \ +static inline void kvmppc_set_##reg(struct kvm_vcpu *vcpu, u##size val) \ +{ \ + \ + vcpu->arch.reg = val; \ +} + +#define KVMPPC_BOOK3S_VCPU_ACCESSOR_GET (reg, size) \ +static inline u##size kvmppc_get_##reg(struct kvm_vcpu *vcpu) \ +{ \ + return vcpu->arch.reg; \ +} + +#define KVMPPC_BOOK3S_VCPU_ACCESSOR (reg, size) \ + KVMPPC_BOOK3S_VCPU_ACCESSOR_SET(reg, size) \ + KVMPPC_BOOK3S_VCPU_ACCESSOR_GET(reg, size) \ + +KVMPPC_BOOK3S_VCPU_ACCESSOR(pid, 32) +KVMPPC_BOOK3S_VCPU_ACCESSOR(tar, 64) +KVMPPC_BOOK3S_VCPU_ACCESSOR(ebbhr, 64) +KVMPPC_BOOK3S_VCPU_ACCESSOR(ebbrr, 64) +KVMPPC_BOOK3S_VCPU_ACCESSOR(bescr, 64) +KVMPPC_BOOK3S_VCPU_ACCESSOR(ic, 64) +KVMPPC_BOOK3S_VCPU_ACCESSOR(vrsave, 64) + +static inline u64 kvmppc_get_dec_expires (struct kvm_vcpu *vcpu) +{ +return vcpu->arch.dec_expires; +} + +static inline void kvmppc_set_dec_expires (struct kvm_vcpu *vcpu,u64 val) +{ + vcpu->arch.dec_expires = val; +} +/* Expiry time of vcpu DEC relative to host TB */ static inline u64 kvmppc_dec_expires_host_tb (struct kvm_vcpu *vcpu) { -return vcpu->arch.dec_expires - vcpu->arch.vcore->tb_offset; +return kvmppc_get_dec_expires (vcpu) - vcpu->arch.vcore->tb_offset; }static inline bool is_kvmppc_resume_guest (int r)
arch/powerpc/kvm/book3s.c +11 -11
@@ -565,7 +565,7 @@ int kvm_arch_vcpu_ioctl_get_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs) regs->msr =kvmppc_get_msr (vcpu); regs->srr0 =kvmppc_get_srr0 (vcpu); regs->srr1 =kvmppc_get_srr1 (vcpu); - regs->pid = vcpu->arch.pid; + regs->pid =kvmppc_get_pid (vcpu); regs->sprg0 =kvmppc_get_sprg0 (vcpu); regs->sprg1 =kvmppc_get_sprg1 (vcpu); regs->sprg2 =kvmppc_get_sprg2 (vcpu);
@@ -683,19 +683,19 @@ int kvmppc_get_one_reg(struct kvm_vcpu *vcpu, u64 id, *val =get_reg_val (id, vcpu->arch.fscr);break ;case KVM_REG_PPC_TAR : - *val =get_reg_val (id, vcpu->arch.tar); + *val =get_reg_val (id,kvmppc_get_tar (vcpu));break ;case KVM_REG_PPC_EBBHR : - *val =get_reg_val (id, vcpu->arch.ebbhr); + *val =get_reg_val (id,kvmppc_get_ebbhr (vcpu));break ;case KVM_REG_PPC_EBBRR : - *val =get_reg_val (id, vcpu->arch.ebbrr); + *val =get_reg_val (id,kvmppc_get_ebbrr (vcpu));break ;case KVM_REG_PPC_BESCR : - *val =get_reg_val (id, vcpu->arch.bescr); + *val =get_reg_val (id,kvmppc_get_bescr (vcpu));break ;case KVM_REG_PPC_IC : - *val =get_reg_val (id, vcpu->arch.ic); + *val =get_reg_val (id,kvmppc_get_ic (vcpu));break ;default : r = -EINVAL ;
@@ -768,19 +768,19 @@ int kvmppc_set_one_reg(struct kvm_vcpu *vcpu, u64 id,kvmppc_set_fpscr (vcpu,set_reg_val (id, *val));break ;case KVM_REG_PPC_TAR : - vcpu->arch.tar =set_reg_val (id, *val); +kvmppc_set_tar (vcpu,set_reg_val (id, *val));break ;case KVM_REG_PPC_EBBHR : - vcpu->arch.ebbhr =set_reg_val (id, *val); +kvmppc_set_ebbhr (vcpu,set_reg_val (id, *val));break ;case KVM_REG_PPC_EBBRR : - vcpu->arch.ebbrr =set_reg_val (id, *val); +kvmppc_set_ebbrr (vcpu,set_reg_val (id, *val));break ;case KVM_REG_PPC_BESCR : - vcpu->arch.bescr =set_reg_val (id, *val); +kvmppc_set_bescr (vcpu,set_reg_val (id, *val));break ;case KVM_REG_PPC_IC : - vcpu->arch.ic =set_reg_val (id, *val); +kvmppc_set_ic (vcpu,set_reg_val (id, *val));break ;default : r = -EINVAL ;
arch/powerpc/kvm/book3s_64_mmu_radix.c +2 -2
@@ -96,7 +96,7 @@ static long kvmhv_copy_tofrom_guest_radix(struct kvm_vcpu *vcpu, gva_t eaddr, void *to, void *from, unsigned long n) { int lpid = vcpu->kvm->arch.lpid; -int pid = vcpu->arch.pid; +int pid =kvmppc_get_pid (vcpu);/* This would cause a data segment intr so don't allow the access */ if (eaddr & (0x3FFUL <<52 ))
@@ -270,7 +270,7 @@ int kvmppc_mmu_radix_xlate(struct kvm_vcpu *vcpu, gva_t eaddr,/* Work out effective PID */ switch (eaddr >>62 ) {case 0 : - pid = vcpu->arch.pid; + pid =kvmppc_get_pid (vcpu);break ;case 3 : pid =0 ;
arch/powerpc/kvm/book3s_hv.c +6 -6
@@ -2310,7 +2310,7 @@ static int kvmppc_get_one_reg_hv(struct kvm_vcpu *vcpu, u64 id, *val =get_reg_val (id, vcpu->arch.tcscr);break ;case KVM_REG_PPC_PID : - *val =get_reg_val (id, vcpu->arch.pid); + *val =get_reg_val (id,kvmppc_get_pid (vcpu));break ;case KVM_REG_PPC_ACOP : *val =get_reg_val (id, vcpu->arch.acop);
@@ -2421,7 +2421,7 @@ static int kvmppc_get_one_reg_hv(struct kvm_vcpu *vcpu, u64 id, *val =get_reg_val (id, vcpu->arch.vcore->arch_compat);break ;case KVM_REG_PPC_DEC_EXPIRY : - *val =get_reg_val (id, vcpu->arch.dec_expires); + *val =get_reg_val (id,kvmppc_get_dec_expires (vcpu));break ;case KVM_REG_PPC_ONLINE : *val =get_reg_val (id, vcpu->arch.online);
@@ -2553,7 +2553,7 @@ static int kvmppc_set_one_reg_hv(struct kvm_vcpu *vcpu, u64 id, vcpu->arch.tcscr =set_reg_val (id, *val);break ;case KVM_REG_PPC_PID : - vcpu->arch.pid =set_reg_val (id, *val); +kvmppc_set_pid (vcpu,set_reg_val (id, *val));break ;case KVM_REG_PPC_ACOP : vcpu->arch.acop =set_reg_val (id, *val);
@@ -2606,8 +2606,8 @@ static int kvmppc_set_one_reg_hv(struct kvm_vcpu *vcpu, u64 id,* decrementer, which is better than a large one that * causes a hang. */ -if (!vcpu->arch.dec_expires && tb_offset) - vcpu->arch.dec_expires =get_tb () + tb_offset; +if (!kvmppc_get_dec_expires (vcpu) && tb_offset) +kvmppc_set_dec_expires (vcpu,get_tb () + tb_offset); vcpu->arch.vcore->tb_offset = tb_offset;break ;
@@ -2690,7 +2690,7 @@ static int kvmppc_set_one_reg_hv(struct kvm_vcpu *vcpu, u64 id, r =kvmppc_set_arch_compat (vcpu,set_reg_val (id, *val));break ;case KVM_REG_PPC_DEC_EXPIRY : - vcpu->arch.dec_expires =set_reg_val (id, *val); +kvmppc_set_dec_expires (vcpu,set_reg_val (id, *val));break ;case KVM_REG_PPC_ONLINE : i =set_reg_val (id, *val);
arch/powerpc/kvm/book3s_hv_p9_entry.c +2 -2
@@ -305,7 +305,7 @@ static void switch_mmu_to_guest_radix(struct kvm *kvm, struct kvm_vcpu *vcpu, u6u32 pid; lpid = nested ? nested->shadow_lpid : kvm->arch.lpid; - pid = vcpu->arch.pid; + pid =kvmppc_get_pid (vcpu);/* * Prior memory accesses to host PID Q3 must be completed before we
@@ -330,7 +330,7 @@ static void switch_mmu_to_guest_hpt(struct kvm *kvm, struct kvm_vcpu *vcpu, u64int i; lpid = kvm->arch.lpid; - pid = vcpu->arch.pid; + pid =kvmppc_get_pid (vcpu);/* * See switch_mmu_to_guest_radix. ptesync should not be required here
arch/powerpc/kvm/powerpc.c +2 -2
@@ -1729,7 +1729,7 @@ int kvm_vcpu_ioctl_get_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg) val =get_reg_val (reg->id,kvmppc_get_vscr (vcpu));break ;case KVM_REG_PPC_VRSAVE : - val =get_reg_val (reg->id, vcpu->arch.vrsave); + val =get_reg_val (reg->id,kvmppc_get_vrsave (vcpu));break ;#endif /* CONFIG_ALTIVEC */ default :
@@ -1784,7 +1784,7 @@ int kvm_vcpu_ioctl_set_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg) r = -ENXIO ; break; } - vcpu->arch.vrsave =set_reg_val (reg->id, val); +kvmppc_set_vrsave (vcpu,set_reg_val (reg->id, val));break ;#endif /* CONFIG_ALTIVEC */ default :
Signature · 1 line
2.39.3
PATCH v4 5/11 KVM: PPC: Use accessors VCORE registers
In reply to Jordan NietheIntroduce accessor generator macros for VCORE registers. Use the accessor functions to replace direct accesses to this registers.
This will be important later for Nested APIv2 support which requires additional functionality for accessing and modifying VCPU state.
---
v4:
- Split to unique patch
- Remove _hv suffix
- Do not generate for setter arch_compat and lpcr
--- arch/powerpc/include/asm/kvm_book3s.h | 25 ++++++++++++++++++++++++- arch/powerpc/kvm/book3s_hv.c | 24 ++++++++++++------------ arch/powerpc/kvm/book3s_hv_ras.c | 4 ++-- arch/powerpc/kvm/book3s_xive.c | 4 +--- 4 files changed, 39 insertions(+), 18 deletions(-)
arch/powerpc/include/asm/kvm_book3s.h +24 -1
@@ -483,6 +483,29 @@ KVMPPC_BOOK3S_VCPU_ACCESSOR(bescr, 64) KVMPPC_BOOK3S_VCPU_ACCESSOR(ic, 64) KVMPPC_BOOK3S_VCPU_ACCESSOR(vrsave, 64) + +#define KVMPPC_BOOK3S_VCORE_ACCESSOR_SET (reg, size) \ +static inline void kvmppc_set_##reg(struct kvm_vcpu *vcpu, u##size val) \ +{ \ + vcpu->arch.vcore->reg = val; \ +} + +#define KVMPPC_BOOK3S_VCORE_ACCESSOR_GET (reg, size) \ +static inline u##size kvmppc_get_##reg(struct kvm_vcpu *vcpu) \ +{ \ + return vcpu->arch.vcore->reg; \ +} + +#define KVMPPC_BOOK3S_VCORE_ACCESSOR (reg, size) \ + KVMPPC_BOOK3S_VCORE_ACCESSOR_SET(reg, size) \ + KVMPPC_BOOK3S_VCORE_ACCESSOR_GET(reg, size) \ + + +KVMPPC_BOOK3S_VCORE_ACCESSOR(vtb, 64) +KVMPPC_BOOK3S_VCORE_ACCESSOR(tb_offset, 64) +KVMPPC_BOOK3S_VCORE_ACCESSOR_GET(arch_compat, 32) +KVMPPC_BOOK3S_VCORE_ACCESSOR_GET(lpcr, 64) +static inline u64 kvmppc_get_dec_expires (struct kvm_vcpu *vcpu) {return vcpu->arch.dec_expires;
@@ -496,7 +519,7 @@ static inline void kvmppc_set_dec_expires(struct kvm_vcpu *vcpu, u64 val)/* Expiry time of vcpu DEC relative to host TB */ static inline u64 kvmppc_dec_expires_host_tb (struct kvm_vcpu *vcpu) { -return kvmppc_get_dec_expires (vcpu) - vcpu->arch.vcore->tb_offset; +return kvmppc_get_dec_expires (vcpu) -kvmppc_get_tb_offset (vcpu); }static inline bool is_kvmppc_resume_guest (int r)
arch/powerpc/kvm/book3s_hv.c +12 -12
@@ -794,7 +794,7 @@ static void kvmppc_update_vpa_dispatch(struct kvm_vcpu *vcpu, vpa->enqueue_dispatch_tb =cpu_to_be64 (be64_to_cpu (vpa->enqueue_dispatch_tb) + stolen); -__kvmppc_create_dtl_entry (vcpu, vpa, vc->pcpu, now + vc->tb_offset, stolen); +__kvmppc_create_dtl_entry (vcpu, vpa, vc->pcpu, now +kvmppc_get_tb_offset (vcpu), stolen); vcpu->arch.vpa.dirty = true; }
@@ -845,9 +845,9 @@ static bool kvmppc_doorbell_pending(struct kvm_vcpu *vcpu)static bool kvmppc_power8_compatible (struct kvm_vcpu *vcpu) { -if (vcpu->arch.vcore->arch_compat >=PVR_ARCH_207 ) +if (kvmppc_get_arch_compat (vcpu) >=PVR_ARCH_207 )return true; -if ((!vcpu->arch.vcore->arch_compat) && +if ((!kvmppc_get_arch_compat (vcpu)) &&cpu_has_feature (CPU_FTR_ARCH_207S ))return true;return false;
@@ -2283,7 +2283,7 @@ static int kvmppc_get_one_reg_hv(struct kvm_vcpu *vcpu, u64 id, *val =get_reg_val (id, vcpu->arch.vcore->dpdes);break ;case KVM_REG_PPC_VTB : - *val =get_reg_val (id, vcpu->arch.vcore->vtb); + *val =get_reg_val (id,kvmppc_get_vtb (vcpu));break ;case KVM_REG_PPC_DAWR : *val =get_reg_val (id, vcpu->arch.dawr0);
@@ -2342,11 +2342,11 @@ static int kvmppc_get_one_reg_hv(struct kvm_vcpu *vcpu, u64 id,spin_unlock (&vcpu->arch.vpa_update_lock);break ;case KVM_REG_PPC_TB_OFFSET : - *val =get_reg_val (id, vcpu->arch.vcore->tb_offset); + *val =get_reg_val (id,kvmppc_get_tb_offset (vcpu));break ;case KVM_REG_PPC_LPCR :case KVM_REG_PPC_LPCR_64 : - *val =get_reg_val (id, vcpu->arch.vcore->lpcr); + *val =get_reg_val (id,kvmppc_get_lpcr (vcpu));break ;case KVM_REG_PPC_PPR : *val =get_reg_val (id, vcpu->arch.ppr);
@@ -2418,7 +2418,7 @@ static int kvmppc_get_one_reg_hv(struct kvm_vcpu *vcpu, u64 id,break ;#endif case KVM_REG_PPC_ARCH_COMPAT : - *val =get_reg_val (id, vcpu->arch.vcore->arch_compat); + *val =get_reg_val (id,kvmppc_get_arch_compat (vcpu));break ;case KVM_REG_PPC_DEC_EXPIRY : *val =get_reg_val (id,kvmppc_get_dec_expires (vcpu));
@@ -2523,7 +2523,7 @@ static int kvmppc_set_one_reg_hv(struct kvm_vcpu *vcpu, u64 id, vcpu->arch.vcore->dpdes =set_reg_val (id, *val);break ;case KVM_REG_PPC_VTB : - vcpu->arch.vcore->vtb =set_reg_val (id, *val); +kvmppc_set_vtb (vcpu,set_reg_val (id, *val));break ;case KVM_REG_PPC_DAWR : vcpu->arch.dawr0 =set_reg_val (id, *val);
@@ -2606,10 +2606,11 @@ static int kvmppc_set_one_reg_hv(struct kvm_vcpu *vcpu, u64 id,* decrementer, which is better than a large one that * causes a hang. */ +kvmppc_set_tb_offset (vcpu, tb_offset);if (!kvmppc_get_dec_expires (vcpu) && tb_offset)kvmppc_set_dec_expires (vcpu,get_tb () + tb_offset); - vcpu->arch.vcore->tb_offset = tb_offset; +kvmppc_set_tb_offset (vcpu, tb_offset);break ; }case KVM_REG_PPC_LPCR :
@@ -4042,7 +4043,6 @@ static void vcpu_vpa_increment_dispatch(struct kvm_vcpu *vcpu)/* call our hypervisor to load up HV regs and go */ static int kvmhv_vcpu_entry_p9_nested (struct kvm_vcpu *vcpu,u64 time_limit,unsigned long lpcr,u64 *tb) { -struct kvmppc_vcore *vc = vcpu->arch.vcore;unsigned long host_psscr;unsigned long msr;struct hv_guest_state hvregs;
@@ -4122,7 +4122,7 @@ static int kvmhv_vcpu_entry_p9_nested(struct kvm_vcpu *vcpu, u64 time_limit, unsif (!(lpcr &LPCR_LD ))/* Sign extend if not using large decrementer */ dec = (s32 ) dec; *tb =mftb (); - vcpu->arch.dec_expires = dec + (*tb + vc->tb_offset); + vcpu->arch.dec_expires = dec + (*tb +kvmppc_get_tb_offset (vcpu));timer_rearm_host_dec (*tb);
@@ -4681,7 +4681,7 @@ int kvmhv_run_single_vcpu(struct kvm_vcpu *vcpu, u64 time_limit, tb =mftb (); -kvmppc_update_vpa_dispatch_p9 (vcpu, vc, tb + vc->tb_offset); +kvmppc_update_vpa_dispatch_p9 (vcpu, vc, tb +kvmppc_get_tb_offset (vcpu));trace_kvm_guest_enter (vcpu);
arch/powerpc/kvm/book3s_hv_ras.c +2 -2
@@ -174,14 +174,14 @@ long kvmppc_p9_realmode_hmi_handler(struct kvm_vcpu *vcpu) ppc_md.hmi_exception_early (NULL ); out: -if (vc->tb_offset) { +if (kvmppc_get_tb_offset (vcpu)) {u64 new_tb =mftb () + vc->tb_offset;mtspr (SPRN_TBU40 , new_tb);if ((mftb () &0xffffff ) < (new_tb &0xffffff )) { new_tb +=0x1000000 ;mtspr (SPRN_TBU40 , new_tb); } - vc->tb_offset_applied = vc->tb_offset; + vc->tb_offset_applied =kvmppc_get_tb_offset (vcpu); }return ret;
arch/powerpc/kvm/book3s_xive.c +1 -3
@@ -2779,8 +2779,6 @@ static int kvmppc_xive_create(struct kvm_device *dev, u32 type)int kvmppc_xive_xics_hcall (struct kvm_vcpu *vcpu,u32 req) { -struct kvmppc_vcore *vc = vcpu->arch.vcore; -/* The VM should have configured XICS mode before doing XICS hcalls. */ if (!kvmppc_xics_enabled (vcpu))return H_TOO_HARD ;
@@ -2799,7 +2797,7 @@ int kvmppc_xive_xics_hcall(struct kvm_vcpu *vcpu, u32 req)return xive_vm_h_ipoll (vcpu,kvmppc_get_gpr (vcpu,4 ));case H_XIRR_X :xive_vm_h_xirr (vcpu); -kvmppc_set_gpr (vcpu,5 ,get_tb () + vc->tb_offset); +kvmppc_set_gpr (vcpu,5 ,get_tb () +kvmppc_get_tb_offset (vcpu));return H_SUCCESS ; }
Signature · 1 line
2.39.3
PATCH v4 6/11 KVM: PPC: Book3S HV: Use accessors for VCPU registers
In reply to Jordan NietheIntroduce accessor generator macros for Book3S HV VCPU registers. Use the accessor functions to replace direct accesses to this registers.
This will be important later for Nested APIv2 support which requires additional functionality for accessing and modifying VCPU state.
---
v4:
- Split to unique patch
--- arch/powerpc/kvm/book3s_64_mmu_radix.c | 5 +- arch/powerpc/kvm/book3s_hv.c | 148 +++++++++++++------------ arch/powerpc/kvm/book3s_hv.h | 58 ++++++++++ 3 files changed, 139 insertions(+), 72 deletions(-)
arch/powerpc/kvm/book3s_64_mmu_radix.c +3 -2
@@ -15,6 +15,7 @@#include <asm/kvm_ppc.h> #include <asm/kvm_book3s.h> +#include "book3s_hv.h" #include <asm/page.h> #include <asm/mmu.h> #include <asm/pgalloc.h>
@@ -294,9 +295,9 @@ int kvmppc_mmu_radix_xlate(struct kvm_vcpu *vcpu, gva_t eaddr, }else {if (!(pte & _PAGE_PRIVILEGED)) {/* Check AMR/IAMR to see if strict mode is in force */ -if (vcpu->arch.amr & (1ul <<62 )) +if (kvmppc_get_amr_hv (vcpu) & (1ul <<62 )) gpte->may_read =0 ; -if (vcpu->arch.amr & (1ul <<63 )) +if (kvmppc_get_amr_hv (vcpu) & (1ul <<63 )) gpte->may_write =0 ;if (vcpu->arch.iamr & (1ul <<62 )) gpte->may_execute =0 ;
arch/powerpc/kvm/book3s_hv.c +78 -70
384 lines not on this page · raw message
arch/powerpc/kvm/book3s_hv.h +58 -0
61 lines not on this page · raw message
Signature · 1 line
2.39.3
PATCH v4 7/11 KVM: PPC: Book3S HV: Introduce low level MSR accessor
In reply to Jordan Niethekvmppc_get_msr() and kvmppc_set_msr_fast() serve as accessors for the MSR. However because the MSR is kept in the shared regs they include a conditional check for kvmppc_shared_big_endian() and endian conversion.
Within the Book3S HV specific code there are direct reads and writes of shregs::msr. In preparation for Nested APIv2 these accesses need to be replaced with accessor functions so it is possible to extend their behavior. However, using the kvmppc_get_msr() and kvmppc_set_msr_fast() functions is undesirable because it would introduce a conditional branch and endian conversion that is not currently present.
kvmppc_set_msr_hv() already exists, it is used for the kvmppc_ops::set_msr callback.
Introduce a low level accessor __kvmppc_{s,g}et_msr_hv() that simply gets and sets shregs::msr. This will be extend for Nested APIv2 support.
---
v4:
- New to series
--- arch/powerpc/kvm/book3s_64_mmu_hv.c | 5 ++-- arch/powerpc/kvm/book3s_hv.c | 34 ++++++++++++++-------------- arch/powerpc/kvm/book3s_hv.h | 10 ++++++++ arch/powerpc/kvm/book3s_hv_builtin.c | 5 ++-- 4 files changed, 33 insertions(+), 21 deletions(-)
arch/powerpc/kvm/book3s_64_mmu_hv.c +3 -2
@@ -28,6 +28,7 @@#include <asm/pte-walk.h> #include "book3s.h" +#include "book3s_hv.h" #include "trace_hv.h" //#define DEBUG_RESIZE_HPT 1
@@ -347,7 +348,7 @@ static int kvmppc_mmu_book3s_64_hv_xlate(struct kvm_vcpu *vcpu, gva_t eaddr,unsigned long v, orig_v, gr;__be64 *hptep;long int index; -int virtmode = vcpu->arch.shregs.msr & (data ?MSR_DR :MSR_IR ); +int virtmode =__kvmppc_get_msr_hv (vcpu) & (data ?MSR_DR :MSR_IR );if (kvm_is_radix (vcpu->kvm))return kvmppc_mmu_radix_xlate (vcpu, eaddr, gpte, data, iswrite);
@@ -385,7 +386,7 @@ static int kvmppc_mmu_book3s_64_hv_xlate(struct kvm_vcpu *vcpu, gva_t eaddr,/* Get PP bits and key for permission check */ pp = gr & (HPTE_R_PP0 |HPTE_R_PP ); - key = (vcpu->arch.shregs.msr &MSR_PR ) ?SLB_VSID_KP :SLB_VSID_KS ; + key = (__kvmppc_get_msr_hv (vcpu) &MSR_PR ) ?SLB_VSID_KP :SLB_VSID_KS ; key &= slb_v;/* Calculate permissions */
arch/powerpc/kvm/book3s_hv.c +17 -17
@@ -1374,7 +1374,7 @@ int kvmppc_pseries_do_hcall(struct kvm_vcpu *vcpu)*/ static void kvmppc_cede (struct kvm_vcpu *vcpu) { - vcpu->arch.shregs.msr |=MSR_EE ; +__kvmppc_set_msr_hv (vcpu,__kvmppc_get_msr_hv (vcpu) |MSR_EE ); vcpu->arch.ceded =1 ;smp_mb ();if (vcpu->arch.prodded) {
@@ -1589,7 +1589,7 @@ static int kvmppc_handle_exit_hv(struct kvm_vcpu *vcpu,* That can happen due to a bug, or due to a machine check * occurring at just the wrong time. */ -if (vcpu->arch.shregs.msr &MSR_HV ) { +if (__kvmppc_get_msr_hv (vcpu) &MSR_HV ) {printk (KERN_EMERG "KVM trap in HV mode!\n" ); printk(KERN_EMERG "trap=0x%x | pc=0x%lx | msr=0x%llx\n", vcpu->arch.trap, kvmppc_get_pc(vcpu),
@@ -1640,7 +1640,7 @@ static int kvmppc_handle_exit_hv(struct kvm_vcpu *vcpu,* so that it knows that the machine check occurred. */ if (!vcpu->kvm->arch.fwnmi_enabled) { -ulong flags = (vcpu->arch.shregs.msr &0x083c0000 ) | +ulong flags = (__kvmppc_get_msr_hv (vcpu) &0x083c0000 ) | (kvmppc_get_msr (vcpu) &SRR1_PREFIXED );kvmppc_core_queue_machine_check (vcpu, flags); r =RESUME_GUEST ;
@@ -1670,7 +1670,7 @@ static int kvmppc_handle_exit_hv(struct kvm_vcpu *vcpu,* as a result of a hypervisor emulation interrupt * (e40) getting turned into a 700 by BML RTAS. */ - flags = (vcpu->arch.shregs.msr &0x1f0000ull ) | + flags = (__kvmppc_get_msr_hv (vcpu) &0x1f0000ull ) | (kvmppc_get_msr (vcpu) &SRR1_PREFIXED );kvmppc_core_queue_program (vcpu, flags); r =RESUME_GUEST ;
@@ -1680,7 +1680,7 @@ static int kvmppc_handle_exit_hv(struct kvm_vcpu *vcpu, {int i; -if (unlikely (vcpu->arch.shregs.msr &MSR_PR )) { +if (unlikely (__kvmppc_get_msr_hv (vcpu) &MSR_PR )) {/* * Guest userspace executed sc 1. This can only be * reached by the P9 path because the old path
@@ -1758,7 +1758,7 @@ static int kvmppc_handle_exit_hv(struct kvm_vcpu *vcpu,break ; } -if (!(vcpu->arch.shregs.msr &MSR_DR )) +if (!(__kvmppc_get_msr_hv (vcpu) &MSR_DR )) vsid = vcpu->kvm->arch.vrma_slb_v;else vsid = vcpu->arch.fault_gpa;
@@ -1782,7 +1782,7 @@ static int kvmppc_handle_exit_hv(struct kvm_vcpu *vcpu,long err; vcpu->arch.fault_dar =kvmppc_get_pc (vcpu); - vcpu->arch.fault_dsisr = vcpu->arch.shregs.msr & + vcpu->arch.fault_dsisr =__kvmppc_get_msr_hv (vcpu) &DSISR_SRR1_MATCH_64S ;if (kvm_is_radix (vcpu->kvm) || !cpu_has_feature (CPU_FTR_ARCH_300 )) {/*
@@ -1791,7 +1791,7 @@ static int kvmppc_handle_exit_hv(struct kvm_vcpu *vcpu,* hash fault handling below is v3 only (it uses ASDR * via fault_gpa). */ -if (vcpu->arch.shregs.msr &HSRR1_HISI_WRITE ) +if (__kvmppc_get_msr_hv (vcpu) &HSRR1_HISI_WRITE ) vcpu->arch.fault_dsisr |=DSISR_ISSTORE ; r =RESUME_PAGE_FAULT ;break ;
@@ -1805,7 +1805,7 @@ static int kvmppc_handle_exit_hv(struct kvm_vcpu *vcpu,break ; } -if (!(vcpu->arch.shregs.msr &MSR_IR )) +if (!(__kvmppc_get_msr_hv (vcpu) &MSR_IR )) vsid = vcpu->kvm->arch.vrma_slb_v;else vsid = vcpu->arch.fault_gpa;
@@ -1895,7 +1895,7 @@ static int kvmppc_handle_exit_hv(struct kvm_vcpu *vcpu,kvmppc_dump_regs (vcpu);printk (KERN_EMERG "trap=0x%x | pc=0x%lx | msr=0x%llx\n" , vcpu->arch.trap,kvmppc_get_pc (vcpu), - vcpu->arch.shregs.msr); +__kvmppc_get_msr_hv (vcpu)); run->hw.hardware_exit_reason = vcpu->arch.trap; r =RESUME_HOST ;break ;
@@ -1919,11 +1919,11 @@ static int kvmppc_handle_nested_exit(struct kvm_vcpu *vcpu)* That can happen due to a bug, or due to a machine check * occurring at just the wrong time. */ -if (vcpu->arch.shregs.msr &MSR_HV ) { +if (__kvmppc_get_msr_hv (vcpu) &MSR_HV ) {pr_emerg ("KVM trap in HV mode while nested!\n" );pr_emerg ("trap=0x%x | pc=0x%lx | msr=0x%llx\n" , vcpu->arch.trap,kvmppc_get_pc (vcpu), - vcpu->arch.shregs.msr); +__kvmppc_get_msr_hv (vcpu));kvmppc_dump_regs (vcpu);return RESUME_HOST ; }
@@ -1980,7 +1980,7 @@ static int kvmppc_handle_nested_exit(struct kvm_vcpu *vcpu) vcpu->arch.fault_dar =kvmppc_get_pc (vcpu); vcpu->arch.fault_dsisr =kvmppc_get_msr (vcpu) &DSISR_SRR1_MATCH_64S ; -if (vcpu->arch.shregs.msr &HSRR1_HISI_WRITE ) +if (__kvmppc_get_msr_hv (vcpu) &HSRR1_HISI_WRITE ) vcpu->arch.fault_dsisr |=DSISR_ISSTORE ; srcu_idx =srcu_read_lock (&vcpu->kvm->srcu); r =kvmhv_nested_page_fault (vcpu);
@@ -2940,7 +2940,7 @@ static int kvmppc_core_vcpu_create_hv(struct kvm_vcpu *vcpu)spin_lock_init (&vcpu->arch.vpa_update_lock);spin_lock_init (&vcpu->arch.tbacct_lock); vcpu->arch.busy_preempt =TB_NIL ; - vcpu->arch.shregs.msr =MSR_ME ; +__kvmppc_set_msr_hv (vcpu,MSR_ME ); vcpu->arch.intr_msr =MSR_SF |MSR_ME ;/*
@@ -4188,7 +4188,7 @@ static int kvmhv_p9_guest_entry(struct kvm_vcpu *vcpu, u64 time_limit,__this_cpu_write (cpu_in_guest,NULL );if (trap =BOOK3S_INTERRUPT_SYSCALL && - !(vcpu->arch.shregs.msr &MSR_PR )) { + !(__kvmppc_get_msr_hv (vcpu) &MSR_PR )) {unsigned long req =kvmppc_get_gpr (vcpu,3 );/*
@@ -4667,7 +4667,7 @@ int kvmhv_run_single_vcpu(struct kvm_vcpu *vcpu, u64 time_limit,if (!nested) {kvmppc_core_prepare_to_enter (vcpu); -if (vcpu->arch.shregs.msr &MSR_EE ) { +if (__kvmppc_get_msr_hv (vcpu) &MSR_EE ) {if (xive_interrupt_pending (vcpu))kvmppc_inject_interrupt_hv (vcpu,BOOK3S_INTERRUPT_EXTERNAL ,0 );
@@ -4880,7 +4880,7 @@ static int kvmppc_vcpu_run_hv(struct kvm_vcpu *vcpu)if (run->exit_reason =KVM_EXIT_PAPR_HCALL ) {accumulate_time (vcpu, &vcpu->arch.hcall); -if (WARN_ON_ONCE (vcpu->arch.shregs.msr &MSR_PR )) { +if (WARN_ON_ONCE (__kvmppc_get_msr_hv (vcpu) &MSR_PR )) {/* * These should have been caught reflected * into the guest by now. Final sanity check:
arch/powerpc/kvm/book3s_hv.h +10 -0
@@ -51,6 +51,16 @@ void accumulate_time(struct kvm_vcpu *vcpu, struct kvmhv_tb_accumulator *next);#define end_timing (vcpu) do {} while (0)#endif +static inline void __kvmppc_set_msr_hv (struct kvm_vcpu *vcpu,u64 val) +{ + vcpu->arch.shregs.msr = val; +} + +static inline u64 __kvmppc_get_msr_hv (struct kvm_vcpu *vcpu) +{ +return vcpu->arch.shregs.msr; +} +#define KVMPPC_BOOK3S_HV_VCPU_ACCESSOR_SET (reg, size) \ static inline void kvmppc_set_##reg ##_hv(struct kvm_vcpu *vcpu, u##size val) \ { \
arch/powerpc/kvm/book3s_hv_builtin.c +3 -2
@@ -32,6 +32,7 @@#include "book3s_xics.h" #include "book3s_xive.h" +#include "book3s_hv.h" /* * Hash page table alignment on newer cpus(CPU_FTR_ARCH_206)
@@ -514,7 +515,7 @@ void kvmppc_set_msr_hv(struct kvm_vcpu *vcpu, u64 msr)*/ if ((msr &MSR_TS_MASK ) =MSR_TS_MASK ) msr &= ~MSR_TS_MASK ; - vcpu->arch.shregs.msr = msr; +__kvmppc_set_msr_hv (vcpu, msr);kvmppc_end_cede (vcpu); }EXPORT_SYMBOL_GPL (kvmppc_set_msr_hv);
@@ -552,7 +553,7 @@ static void inject_interrupt(struct kvm_vcpu *vcpu, int vec, u64 srr1_flags)kvmppc_set_srr0 (vcpu, pc);kvmppc_set_srr1 (vcpu, (msr &SRR1_MSR_BITS ) | srr1_flags);kvmppc_set_pc (vcpu, new_pc); - vcpu->arch.shregs.msr = new_msr; +__kvmppc_set_msr_hv (vcpu, new_msr); }void kvmppc_inject_interrupt_hv (struct kvm_vcpu *vcpu,int vec,u64 srr1_flags)
Signature · 1 line
2.39.3
PATCH v4 8/11 KVM: PPC: Add helper library for Guest State Buffers
In reply to Jordan NietheThe PAPR "Nestedv2" guest API introduces the concept of a Guest State Buffer for communication about L2 guests between L1 and L0 hosts.
In the new API, the L0 manages the L2 on behalf of the L1. This means that if the L1 needs to change L2 state (e.g. GPRs, SPRs, partition table...), it must request the L0 perform the modification. If the nested host needs to read L2 state likewise this request must go through the L0.
The Guest State Buffer is a Type-Length-Value style data format defined in the PAPR which assigns all relevant partition state a unique identity. Unlike a typical TLV format the length is redundant as the length of each identity is fixed but is included for checking correctness.
A guest state buffer consists of an element count followed by a stream of elements, where elements are composed of an ID number, data length, then the data:
Header:
<---4 bytes--->
+----------------+----- | Element Count | Elements... +----------------+-----
Element:
<----2 bytes---> <-2 bytes-> <-Length bytes->
+----------------+-----------+----------------+ | Guest State ID | Length | Data | +----------------+-----------+----------------+
Guest State IDs have other attributes defined in the PAPR such as whether they are per thread or per guest, or read-only.
Introduce a library for using guest state buffers. This includes support for actions such as creating buffers, adding elements to buffers, reading the value of elements and parsing buffers. This will be used later by the nestedv2 guest support.
---
v2:
- Add missing #ifdef CONFIG_VSXs
- Move files from lib/ to kvm/
- Guard compilation on CONFIG_KVM_BOOK3S_HV_POSSIBLE
- Use kunit for guest state buffer tests
- Add configuration option for the tests
- Use macros for contiguous id ranges like GPRs
- Add some missing EXPORTs to functions
- HEIR element is a double word not a word
v3:
- Use EXPORT_SYMBOL_GPL()
- Use the kvmppc namespace
- Move kvmppc_gsb_reset() out of kvmppc_gsm_fill_info()
- Comments for GSID elements
- Pass vector elements by reference
- Remove generic put and get functions
--- arch/powerpc/Kconfig.debug | 12 + arch/powerpc/include/asm/guest-state-buffer.h | 904 ++++++++++++++++++ arch/powerpc/kvm/Makefile | 3 + arch/powerpc/kvm/guest-state-buffer.c | 571 +++++++++++ arch/powerpc/kvm/test-guest-state-buffer.c | 328 +++++++ 5 files changed, 1818 insertions(+) create mode 100644 arch/powerpc/include/asm/guest-state-buffer.h create mode 100644 arch/powerpc/kvm/guest-state-buffer.c create mode 100644 arch/powerpc/kvm/test-guest-state-buffer.c
arch/powerpc/Kconfig.debug +12 -0
@@ -82,6 +82,18 @@ config MSI_BITMAP_SELFTEST bool "Run self-tests of the MSI bitmap code" depends on DEBUG_KERNEL +config GUEST_STATE_BUFFER_TEST + def_tristate n + prompt "Enable Guest State Buffer unit tests" + depends on KUNIT + depends on KVM_BOOK3S_HV_POSSIBLE + default KUNIT_ALL_TESTS + help + The Guest State Buffer is a data format specified in the PAPR. + It is by hcalls to communicate the state of L2 guests between + the L1 and L0 hypervisors. Enable unit tests for the library + used to create and use guest state buffers. + config PPC_IRQ_SOFT_MASK_DEBUG bool "Include extra checks for powerpc irq soft masking" depends on PPC64
arch/powerpc/include/asm/guest-state-buffer.h new file +904 -0
904 lines not on this page · raw message
arch/powerpc/kvm/Makefile +3 -0
@@ -87,8 +87,11 @@ kvm-book3s_64-builtin-objs-$(CONFIG_KVM_BOOK3S_64_HANDLER) += \ book3s_hv_ras.o \ book3s_hv_builtin.o \ book3s_hv_p9_perf.o \ + guest-state-buffer.o \ $(kvm-book3s_64-builtin-tm-objs-y) \ $(kvm-book3s_64-builtin-xics-objs-y) + +obj-$(CONFIG_GUEST_STATE_BUFFER_TEST) += test-guest-state-buffer.o endif kvm-book3s_64-objs-$(CONFIG_KVM_XICS) += \
arch/powerpc/kvm/guest-state-buffer.c new file +570 -0
570 lines not on this page · raw message
arch/powerpc/kvm/test-guest-state-buffer.c new file +328 -0
328 lines not on this page · raw message
Signature · 1 line
2.39.3
PATCH v4 9/11 KVM: PPC: Book3s HV: Hold LPIDs in an unsigned long
In reply to Jordan NietheThe LPID register is 32 bits long. The host keeps the lpids for each guest in an unsigned word struct kvm_arch. Currently, LPIDs are already limited by mmu_lpid_bits and KVM_MAX_NESTED_GUESTS_SHIFT.
The nestedv2 API returns a 64 bit "Guest ID" to be used be the L1 host for each L2 guest. This value is used as an lpid, e.g. it is the parameter used by H_RPT_INVALIDATE. To minimize needless special casing it makes sense to keep this "Guest ID" in struct kvm_arch::lpid.
This means that struct kvm_arch::lpid is too small so prepare for this and make it an unsigned long. This is not a problem for the KVM-HV and nestedv1 cases as their lpid values are already limited to valid ranges so in those contexts the lpid can be used as an unsigned word safely as needed.
In the PAPR, the H_RPT_INVALIDATE pid/lpid parameter is already specified as an unsigned long so change pseries_rpt_invalidate() to match that. Update the callers of pseries_rpt_invalidate() to also take an unsigned long if they take an lpid value.
---
v3:
- New to series
v4:
- Use u64
- Change format strings instead of casting
--- arch/powerpc/include/asm/kvm_book3s.h | 10 +++++----- arch/powerpc/include/asm/kvm_book3s_64.h | 2 +- arch/powerpc/include/asm/kvm_host.h | 2 +- arch/powerpc/include/asm/plpar_wrappers.h | 4 ++-- arch/powerpc/kvm/book3s_64_mmu_hv.c | 2 +- arch/powerpc/kvm/book3s_64_mmu_radix.c | 22 +++++++++++----------- arch/powerpc/kvm/book3s_hv_nested.c | 4 ++-- arch/powerpc/kvm/book3s_hv_uvmem.c | 2 +- arch/powerpc/kvm/book3s_xive.c | 4 ++-- 9 files changed, 26 insertions(+), 26 deletions(-)
arch/powerpc/include/asm/kvm_book3s.h +5 -5
@@ -191,14 +191,14 @@ extern int kvmppc_mmu_radix_translate_table(struct kvm_vcpu *vcpu, gva_t eaddr,extern int kvmppc_mmu_radix_xlate (struct kvm_vcpu *vcpu,gva_t eaddr,struct kvmppc_pte *gpte,bool data,bool iswrite);extern void kvmppc_radix_tlbie_page (struct kvm *kvm,unsigned long addr, -unsigned int pshift,unsigned int lpid); +unsigned int pshift,u64 lpid);extern void kvmppc_unmap_pte (struct kvm *kvm,pte_t *pte,unsigned long gpa,unsigned int shift,const struct kvm_memory_slot *memslot, -unsigned int lpid); +u64 lpid);extern bool kvmppc_hv_handle_set_rc (struct kvm *kvm,bool nested,bool writing,unsigned long gpa, -unsigned int lpid); +u64 lpid); extern int kvmppc_book3s_instantiate_page(struct kvm_vcpu *vcpu, unsigned long gpa, struct kvm_memory_slot *memslot,
@@ -207,7 +207,7 @@ extern int kvmppc_book3s_instantiate_page(struct kvm_vcpu *vcpu,extern int kvmppc_init_vm_radix (struct kvm *kvm);extern void kvmppc_free_radix (struct kvm *kvm);extern void kvmppc_free_pgtable_radix (struct kvm *kvm,pgd_t *pgd, -unsigned int lpid); +u64 lpid);extern int kvmppc_radix_init (void );extern void kvmppc_radix_exit (void ); extern void kvm_unmap_radix(struct kvm *kvm, struct kvm_memory_slot *memslot,
@@ -300,7 +300,7 @@ void kvmhv_nested_exit(void);void kvmhv_vm_nested_init (struct kvm *kvm);long kvmhv_set_partition_table (struct kvm_vcpu *vcpu);long kvmhv_copy_tofrom_guest_nested (struct kvm_vcpu *vcpu); -void kvmhv_set_ptbl_entry (unsigned int lpid,u64 dw0,u64 dw1); +void kvmhv_set_ptbl_entry (u64 lpid,u64 dw0,u64 dw1);void kvmhv_release_all_nested (struct kvm *kvm);long kvmhv_enter_nested_guest (struct kvm_vcpu *vcpu);long kvmhv_do_nested_tlbie (struct kvm_vcpu *vcpu);
arch/powerpc/include/asm/kvm_book3s_64.h +1 -1
@@ -624,7 +624,7 @@ static inline void copy_to_checkpoint(struct kvm_vcpu *vcpu)extern int kvmppc_create_pte (struct kvm *kvm,pgd_t *pgtable,pte_t pte,unsigned long gpa,unsigned int level, -unsigned long mmu_seq,unsigned int lpid, +unsigned long mmu_seq,u64 lpid,unsigned long *rmapp,struct rmap_nested **n_rmap);extern void kvmhv_insert_nest_rmap (struct kvm *kvm,unsigned long *rmapp,struct rmap_nested **n_rmap);
arch/powerpc/include/asm/kvm_host.h +1 -1
@@ -276,7 +276,7 @@ struct kvm_resize_hpt;#define KVMPPC_SECURE_INIT_ABORT 0x4/* H_SVM_INIT_ABORT issued */ struct kvm_arch { -unsigned int lpid; +u64 lpid;unsigned int smt_mode;/* # vcpus per virtual core */ unsigned int emul_smt_mode;/* emualted SMT mode, on P9 */ #ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE
arch/powerpc/include/asm/plpar_wrappers.h +2 -2
@@ -355,7 +355,7 @@ static inline long plpar_get_cpu_characteristics(struct h_cpu_char_result *p)* error recovery of killing the process/guest will be eventually * needed. */ -static inline long pseries_rpt_invalidate (u32 pid,u64 target,u64 type, +static inline long pseries_rpt_invalidate (u64 pid,u64 target,u64 type,u64 page_sizes,u64 start,u64 end) {long rc;
@@ -401,7 +401,7 @@ static inline long plpar_pte_read_4(unsigned long flags, unsigned long ptex,return 0 ; } -static inline long pseries_rpt_invalidate (u32 pid,u64 target,u64 type, +static inline long pseries_rpt_invalidate (u64 pid,u64 target,u64 type,u64 page_sizes,u64 start,u64 end) {return 0 ;
arch/powerpc/kvm/book3s_64_mmu_hv.c +1 -1
@@ -121,7 +121,7 @@ void kvmppc_set_hpt(struct kvm *kvm, struct kvm_hpt_info *info) kvm->arch.hpt = *info; kvm->arch.sdr1 =__pa (info->virt) | (info->order -18 ); -pr_debug ("KVM guest htab at %lx (order %ld), LPID %x\n" , +pr_debug ("KVM guest htab at %lx (order %ld), LPID %llx\n" , info->virt, (long )info->order, kvm->arch.lpid); }
arch/powerpc/kvm/book3s_64_mmu_radix.c +11 -11
@@ -308,7 +308,7 @@ int kvmppc_mmu_radix_xlate(struct kvm_vcpu *vcpu, gva_t eaddr, }void kvmppc_radix_tlbie_page (struct kvm *kvm,unsigned long addr, -unsigned int pshift,unsigned int lpid) +unsigned int pshift,u64 lpid) {unsigned long psize =PAGE_SIZE ;int psi;
@@ -345,7 +345,7 @@ void kvmppc_radix_tlbie_page(struct kvm *kvm, unsigned long addr,pr_err ("KVM: TLB page invalidation hcall failed, rc=%ld\n" , rc); } -static void kvmppc_radix_flush_pwc (struct kvm *kvm,unsigned int lpid) +static void kvmppc_radix_flush_pwc (struct kvm *kvm,u64 lpid) {long rc;
@@ -418,7 +418,7 @@ static void kvmppc_pmd_free(pmd_t *pmdp)void kvmppc_unmap_pte (struct kvm *kvm,pte_t *pte,unsigned long gpa,unsigned int shift,const struct kvm_memory_slot *memslot, -unsigned int lpid) +u64 lpid) {unsigned long old;
@@ -469,7 +469,7 @@ void kvmppc_unmap_pte(struct kvm *kvm, pte_t *pte, unsigned long gpa,* (or 4kB) mappings (of sub-pages of the same 2MB page). */ static void kvmppc_unmap_free_pte (struct kvm *kvm,pte_t *pte,bool full, -unsigned int lpid) +u64 lpid) {if (full) {memset (pte,0 ,sizeof (long ) <<RADIX_PTE_INDEX_SIZE );
@@ -490,7 +490,7 @@ static void kvmppc_unmap_free_pte(struct kvm *kvm, pte_t *pte, bool full, }static void kvmppc_unmap_free_pmd (struct kvm *kvm,pmd_t *pmd,bool full, -unsigned int lpid) +u64 lpid) {unsigned long im;pmd_t *p = pmd;
@@ -519,7 +519,7 @@ static void kvmppc_unmap_free_pmd(struct kvm *kvm, pmd_t *pmd, bool full, }static void kvmppc_unmap_free_pud (struct kvm *kvm,pud_t *pud, -unsigned int lpid) +u64 lpid) {unsigned long iu;pud_t *p = pud;
@@ -540,7 +540,7 @@ static void kvmppc_unmap_free_pud(struct kvm *kvm, pud_t *pud,pud_free (kvm->mm, pud); } -void kvmppc_free_pgtable_radix (struct kvm *kvm,pgd_t *pgd,unsigned int lpid) +void kvmppc_free_pgtable_radix (struct kvm *kvm,pgd_t *pgd,u64 lpid) {unsigned long ig;
@@ -567,7 +567,7 @@ void kvmppc_free_radix(struct kvm *kvm) }static void kvmppc_unmap_free_pmd_entry_table (struct kvm *kvm,pmd_t *pmd, -unsigned long gpa,unsigned int lpid) +unsigned long gpa,u64 lpid) {pte_t *pte =pte_offset_kernel (pmd,0 );
@@ -583,7 +583,7 @@ static void kvmppc_unmap_free_pmd_entry_table(struct kvm *kvm, pmd_t *pmd, }static void kvmppc_unmap_free_pud_entry_table (struct kvm *kvm,pud_t *pud, -unsigned long gpa,unsigned int lpid) +unsigned long gpa,u64 lpid) {pmd_t *pmd =pmd_offset (pud,0 );
@@ -609,7 +609,7 @@ static void kvmppc_unmap_free_pud_entry_table(struct kvm *kvm, pud_t *pud,int kvmppc_create_pte (struct kvm *kvm,pgd_t *pgtable,pte_t pte,unsigned long gpa,unsigned int level, -unsigned long mmu_seq,unsigned int lpid, +unsigned long mmu_seq,u64 lpid,unsigned long *rmapp,struct rmap_nested **n_rmap) {pgd_t *pgd;
@@ -786,7 +786,7 @@ int kvmppc_create_pte(struct kvm *kvm, pgd_t *pgtable, pte_t pte, }bool kvmppc_hv_handle_set_rc (struct kvm *kvm,bool nested,bool writing, -unsigned long gpa,unsigned int lpid) +unsigned long gpa,u64 lpid) {unsigned long pgflags;unsigned int shift;
arch/powerpc/kvm/book3s_hv_nested.c +2 -2
@@ -478,7 +478,7 @@ void kvmhv_nested_exit(void) } } -static void kvmhv_flush_lpid (unsigned int lpid) +static void kvmhv_flush_lpid (u64 lpid) {long rc;
@@ -500,7 +500,7 @@ static void kvmhv_flush_lpid(unsigned int lpid)pr_err ("KVM: TLB LPID invalidation hcall failed, rc=%ld\n" , rc); } -void kvmhv_set_ptbl_entry (unsigned int lpid,u64 dw0,u64 dw1) +void kvmhv_set_ptbl_entry (u64 lpid,u64 dw0,u64 dw1) {if (!kvmhv_on_pseries ()) {mmu_partition_table_set_entry (lpid, dw0, dw1, true);
arch/powerpc/kvm/book3s_hv_uvmem.c +1 -1
@@ -857,7 +857,7 @@ unsigned long kvmppc_h_svm_init_done(struct kvm *kvm) } kvm->arch.secure_guest |=KVMPPC_SECURE_INIT_DONE ; -pr_info ("LPID %d went secure\n" , kvm->arch.lpid); +pr_info ("LPID %lld went secure\n" , kvm->arch.lpid); out:srcu_read_unlock (&kvm->srcu, srcu_idx);
arch/powerpc/kvm/book3s_xive.c +2 -2
@@ -884,10 +884,10 @@ int kvmppc_xive_attach_escalation(struct kvm_vcpu *vcpu, u8 prio, }if (single_escalation) - name =kasprintf (GFP_KERNEL ,"kvm-%d-%d" , + name =kasprintf (GFP_KERNEL ,"kvm-%lld-%d" , vcpu->kvm->arch.lpid, xc->server_num);else - name =kasprintf (GFP_KERNEL ,"kvm-%d-%d-%d" , + name =kasprintf (GFP_KERNEL ,"kvm-%lld-%d-%d" , vcpu->kvm->arch.lpid, xc->server_num, prio);if (!name) { pr_err("Failed to allocate escalation irq name for queue %d of VCPU %d\n",
Signature · 1 line
2.39.3
PATCH v4 10/11 KVM: PPC: Add support for nestedv2 guests
In reply to Jordan NietheA series of hcalls have been added to the PAPR which allow a regular guest partition to create and manage guest partitions of its own. KVM already had an interface that allowed this on powernv platforms. This existing interface will now be called "nestedv1". The newly added PAPR interface will be called "nestedv2". PHYP will support the nestedv2 interface. At this time the host side of the nestedv2 interface has not been implemented on powernv but there is no technical reason why it could not be added.
The nestedv1 interface is still supported.
Add support to KVM to utilize these hcalls to enable running nested guests as a pseries guest on PHYP.
Overview of the new hcall usage:
- L1 and L0 negotiate capabilities with
H_GUEST_{G,S}ET_CAPABILITIES()
- L1 requests the L0 create a L2 with
H_GUEST_CREATE() and receives a handle to use in future hcalls
- L1 requests the L0 create a L2 vCPU with
H_GUEST_CREATE_VCPU()
- L1 sets up the L2 using H_GUEST_SET and the
H_GUEST_VCPU_RUN input buffer
- L1 requests the L0 runs the L2 vCPU using H_GUEST_VCPU_RUN()
- L2 returns to L1 with an exit reason and L1 reads the H_GUEST_VCPU_RUN output buffer populated by the L0
- L1 handles the exit using H_GET_STATE if necessary
- L1 reruns L2 vCPU with H_GUEST_VCPU_RUN
- L1 frees the L2 in the L0 with H_GUEST_DELETE()
Support for the new API is determined by trying H_GUEST_GET_CAPABILITIES. On a successful return, use the nestedv2 interface.
Use the vcpu register state setters for tracking modified guest state elements and copy the thread wide values into the H_GUEST_VCPU_RUN input buffer immediately before running a L2. The guest wide elements can not be added to the input buffer so send them with a separate H_GUEST_SET call if necessary.
Make the vcpu register getter load the corresponding value from the real host with H_GUEST_GET. To avoid unnecessarily calling H_GUEST_GET, track which values have already been loaded between H_GUEST_VCPU_RUN calls. If an element is present in the H_GUEST_VCPU_RUN output buffer it also does not need to be loaded again.
---
v2:
- Declare op structs as static
- Guatam: Use expressions in switch case with local variables
- Do not use the PVR for the LOGICAL PVR ID
- Kautuk: Handle emul_inst as now a double word, init correctly
- Use new GPR(), etc macros
- Amit: Determine PAPR nested capabilities from cpu features
v3:
- Use EXPORT_SYMBOL_GPL()
- Change to kvmhv_nestedv2 namespace
- Make kvmhv_enable_nested() return -ENODEV on NESTEDv2 L1 hosts
- s/kvmhv_on_papr/kvmhv_is_nestedv2/
- mv book3s_hv_papr.c book3s_hv_nestedv2.c
- Handle shared regs without a guest state id in the same wrapper
- Vaibhav: Use a static key for API version
- Add a positive test for NESTEDv1
- Give the amor a static value
- s/struct kvmhv_nestedv2_host/struct kvmhv_nestedv2_io/
- Propagate failure in kvmhv_vcpu_entry_nestedv2()
- WARN if getters and setters fail
- Progagate failure from kvmhv_nestedv2_parse_output()
- Replace delay with sleep in plpar_guest_{create,delete,create_vcpu}()
- Amit: Add logical PVR handling
- Replace kvmppc_gse_{get,put} with specific version
v4:
- Batch H_GUEST_GET calls in kvmhv_nestedv2_reload_ptregs()
- Fix compile without CONFIG_PSERIES
- Fix maybe uninitialized trap in kvmhv_p9_guest_entry()
- Extend existing setters for arch_compat and lpcr
--- arch/powerpc/include/asm/guest-state-buffer.h | 91 ++ arch/powerpc/include/asm/hvcall.h | 30 + arch/powerpc/include/asm/kvm_book3s.h | 137 ++- arch/powerpc/include/asm/kvm_book3s_64.h | 6 + arch/powerpc/include/asm/kvm_host.h | 20 + arch/powerpc/include/asm/kvm_ppc.h | 90 +- arch/powerpc/include/asm/plpar_wrappers.h | 244 +++++ arch/powerpc/kvm/Makefile | 1 + arch/powerpc/kvm/book3s_hv.c | 134 ++- arch/powerpc/kvm/book3s_hv.h | 80 +- arch/powerpc/kvm/book3s_hv_nested.c | 38 +- arch/powerpc/kvm/book3s_hv_nestedv2.c | 998 ++++++++++++++++++ arch/powerpc/kvm/emulate_loadstore.c | 4 +- arch/powerpc/kvm/guest-state-buffer.c | 50 + 14 files changed, 1826 insertions(+), 97 deletions(-) create mode 100644 arch/powerpc/kvm/book3s_hv_nestedv2.c
arch/powerpc/include/asm/guest-state-buffer.h +91 -0
@@ -5,6 +5,7 @@#ifndef _ASM_POWERPC_GUEST_STATE_BUFFER_H#define _ASM_POWERPC_GUEST_STATE_BUFFER_H +#include "asm/hvcall.h" #include <linux/gfp.h> #include <linux/bitmap.h> #include <asm/plpar_wrappers.h>
@@ -313,6 +314,8 @@ struct kvmppc_gs_buff *kvmppc_gsb_new(size_t size, unsigned long guest_id, unsigned long vcpu_id, gfp_t flags);void kvmppc_gsb_free (struct kvmppc_gs_buff *gsb);void *kvmppc_gsb_put (struct kvmppc_gs_buff *gsb,size_t size); +int kvmppc_gsb_send (struct kvmppc_gs_buff *gsb,unsigned long flags); +int kvmppc_gsb_recv (struct kvmppc_gs_buff *gsb,unsigned long flags);/** * kvmppc_gsb_header() - the header of a guest state buffer
@@ -901,4 +904,92 @@ static inline void kvmppc_gsm_reset(struct kvmppc_gs_msg *gsm) kvmppc_gsbm_zero(&gsm->bitmap); } +/** +* kvmppc_gsb_receive_data - flexibly update values from a guest state buffer +* @gsb: guest state buffer +* @gsm: guest state message +* +* Requests updated values for the guest state values included in the guest +* state message. The guest state message will then deserialize the guest state +* buffer. +*/ +static inline int kvmppc_gsb_receive_data (struct kvmppc_gs_buff *gsb, +struct kvmppc_gs_msg *gsm) +{ +int rc; + +kvmppc_gsb_reset (gsb); + rc =kvmppc_gsm_fill_info (gsm, gsb); +if (rc <0 ) +return rc; + + rc =kvmppc_gsb_recv (gsb, gsm->flags); +if (rc <0 ) +return rc; + + rc =kvmppc_gsm_refresh_info (gsm, gsb); +if (rc <0 ) +return rc; +return 0 ; +} + +/** +* kvmppc_gsb_recv - receive a single guest state ID +* @gsb: guest state buffer +* @gsm: guest state message +* @iden: guest state identity +*/ +static inline int kvmppc_gsb_receive_datum (struct kvmppc_gs_buff *gsb, +struct kvmppc_gs_msg *gsm,u16 iden) +{ +int rc; + +kvmppc_gsm_include (gsm, iden); + rc =kvmppc_gsb_receive_data (gsb, gsm); +if (rc <0 ) +return rc; +kvmppc_gsm_reset (gsm); +return 0 ; +} + +/** +* kvmppc_gsb_send_data - flexibly send values from a guest state buffer +* @gsb: guest state buffer +* @gsm: guest state message +* +* Sends the guest state values included in the guest state message. +*/ +static inline int kvmppc_gsb_send_data (struct kvmppc_gs_buff *gsb, +struct kvmppc_gs_msg *gsm) +{ +int rc; + +kvmppc_gsb_reset (gsb); + rc =kvmppc_gsm_fill_info (gsm, gsb); +if (rc <0 ) +return rc; + rc =kvmppc_gsb_send (gsb, gsm->flags); + +return rc; +} + +/** +* kvmppc_gsb_recv - send a single guest state ID +* @gsb: guest state buffer +* @gsm: guest state message +* @iden: guest state identity +*/ +static inline int kvmppc_gsb_send_datum (struct kvmppc_gs_buff *gsb, +struct kvmppc_gs_msg *gsm,u16 iden) +{ +int rc; + +kvmppc_gsm_include (gsm, iden); + rc =kvmppc_gsb_send_data (gsb, gsm); +if (rc <0 ) +return rc; +kvmppc_gsm_reset (gsm); +return 0 ; +} +#endif /* _ASM_POWERPC_GUEST_STATE_BUFFER_H */
arch/powerpc/include/asm/hvcall.h +30 -0
@@ -100,6 +100,18 @@#define H_COP_HW -74#define H_STATE -75#define H_IN_USE -77 + +#define H_INVALID_ELEMENT_ID -79 +#define H_INVALID_ELEMENT_SIZE -80 +#define H_INVALID_ELEMENT_VALUE -81 +#define H_INPUT_BUFFER_NOT_DEFINED -82 +#define H_INPUT_BUFFER_TOO_SMALL -83 +#define H_OUTPUT_BUFFER_NOT_DEFINED -84 +#define H_OUTPUT_BUFFER_TOO_SMALL -85 +#define H_PARTITION_PAGE_TABLE_NOT_DEFINED -86 +#define H_GUEST_VCPU_STATE_NOT_HV_OWNED -87 + +#define H_UNSUPPORTED_FLAG_START -256#define H_UNSUPPORTED_FLAG_END -511#define H_MULTI_THREADS_ACTIVE -9005
@@ -381,6 +393,15 @@#define H_ENTER_NESTED 0xF804#define H_TLB_INVALIDATE 0xF808#define H_COPY_TOFROM_GUEST 0xF80C +#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_GET_STATE 0x478 +#define H_GUEST_SET_STATE 0x47C +#define H_GUEST_RUN_VCPU 0x480 +#define H_GUEST_COPY_MEMORY 0x484 +#define H_GUEST_DELETE 0x488/* Flags for H_SVM_PAGE_IN */ #define H_PAGE_IN_SHARED 0x1
@@ -467,6 +488,15 @@#define H_RPTI_PAGE_1G 0x08#define H_RPTI_PAGE_ALL (-1UL) +/* Flags for H_GUEST_{S,G}_STATE */ +#define H_GUEST_FLAGS_WIDE (1UL<<(63-0)) + +/* Flag values used for H_{S,G}SET_GUEST_CAPABILITIES */ +#define H_GUEST_CAP_COPY_MEM (1UL<<(63-0)) +#define H_GUEST_CAP_POWER9 (1UL<<(63-1)) +#define H_GUEST_CAP_POWER10 (1UL<<(63-2)) +#define H_GUEST_CAP_BITMAP2 (1UL<<(63-63)) +#ifndef __ASSEMBLY__#include <linux/types.h>
arch/powerpc/include/asm/kvm_book3s.h +116 -21
307 lines not on this page · raw message
arch/powerpc/include/asm/kvm_book3s_64.h +6 -0
@@ -677,6 +677,12 @@ static inline pte_t *find_kvm_host_pte(struct kvm *kvm, unsigned long mmu_seq,extern pte_t *find_kvm_nested_guest_pte (struct kvm *kvm,unsigned long lpid,unsigned long ea,unsigned *hshift); +int kvmhv_nestedv2_vcpu_create (struct kvm_vcpu *vcpu,struct kvmhv_nestedv2_io *io); +void kvmhv_nestedv2_vcpu_free (struct kvm_vcpu *vcpu,struct kvmhv_nestedv2_io *io); +int kvmhv_nestedv2_flush_vcpu (struct kvm_vcpu *vcpu,u64 time_limit); +int kvmhv_nestedv2_set_ptbl_entry (unsigned long lpid,u64 dw0,u64 dw1); +int kvmhv_nestedv2_parse_output (struct kvm_vcpu *vcpu); +#endif /* CONFIG_KVM_BOOK3S_HV_POSSIBLE */ #endif /* __ASM_KVM_BOOK3S_64_H__ */
arch/powerpc/include/asm/kvm_host.h +20 -0
@@ -25,6 +25,7 @@#include <asm/cacheflush.h> #include <asm/hvcall.h> #include <asm/mce.h> +#include <asm/guest-state-buffer.h> #define __KVM_HAVE_ARCH_VCPU_DEBUGFS
@@ -509,6 +510,23 @@ union xive_tma_w01 {__be64 w01; }; +/* Nestedv2 H_GUEST_RUN_VCPU configuration */ +struct kvmhv_nestedv2_config { +struct kvmppc_gs_buff_info vcpu_run_output_cfg; +struct kvmppc_gs_buff_info vcpu_run_input_cfg; +u64 vcpu_run_output_size; +}; + +/* Nestedv2 L1<->L0 communication state */ +struct kvmhv_nestedv2_io { +struct kvmhv_nestedv2_config cfg; +struct kvmppc_gs_buff *vcpu_run_output; +struct kvmppc_gs_buff *vcpu_run_input; +struct kvmppc_gs_msg *vcpu_message; +struct kvmppc_gs_msg *vcore_message; +struct kvmppc_gs_bitmap valids; +}; +struct kvm_vcpu_arch {ulong host_stack;u32 host_pid;
@@ -829,6 +847,8 @@ struct kvm_vcpu_arch {u64 nested_hfscr;/* HFSCR that the L1 requested for the nested guest */ u32 nested_vcpu_id;gpa_t nested_io_gpr; +/* For nested APIv2 guests*/ +struct kvmhv_nestedv2_io nestedv2_io;#endif #ifdef CONFIG_KVM_BOOK3S_HV_EXIT_TIMING
arch/powerpc/include/asm/kvm_ppc.h +66 -24
138 lines not on this page · raw message
arch/powerpc/include/asm/plpar_wrappers.h +244 -0
262 lines not on this page · raw message
arch/powerpc/kvm/Makefile +1 -0
@@ -87,6 +87,7 @@ kvm-book3s_64-builtin-objs-$(CONFIG_KVM_BOOK3S_64_HANDLER) += \ book3s_hv_ras.o \ book3s_hv_builtin.o \ book3s_hv_p9_perf.o \ + book3s_hv_nestedv2.o \ guest-state-buffer.o \ $(kvm-book3s_64-builtin-tm-objs-y) \ $(kvm-book3s_64-builtin-xics-objs-y)
arch/powerpc/kvm/book3s_hv.c +124 -10
225 lines not on this page · raw message
arch/powerpc/kvm/book3s_hv.h +44 -36
117 lines not on this page · raw message
arch/powerpc/kvm/book3s_hv_nested.c +33 -5
@@ -428,10 +428,12 @@ long kvmhv_enter_nested_guest(struct kvm_vcpu *vcpu)return vcpu->arch.trap; } +unsigned long nested_capabilities; +long kvmhv_nested_init (void ) {long int ptb_order; -unsigned long ptcr; +unsigned long ptcr, host_capabilities;long rc;if (!kvmhv_on_pseries ())
@@ -439,6 +441,27 @@ long kvmhv_nested_init(void)if (!radix_enabled ())return -ENODEV ; + rc =plpar_guest_get_capabilities (0 , &host_capabilities); +if (rc =H_SUCCESS ) { +unsigned long capabilities =0 ; + +if (cpu_has_feature (CPU_FTR_ARCH_31 )) + capabilities |=H_GUEST_CAP_POWER10 ; +if (cpu_has_feature (CPU_FTR_ARCH_300 )) + capabilities |=H_GUEST_CAP_POWER9 ; + + nested_capabilities = capabilities & host_capabilities; + rc =plpar_guest_set_capabilities (0 , nested_capabilities); +if (rc !=H_SUCCESS ) { +pr_err ("kvm-hv: Could not configure parent hypervisor capabilities (rc=%ld)" , + rc); +return -ENODEV ; + } + +static_branch_enable (&__kvmhv_is_nestedv2); +return 0 ; + } +/* Partition table entry is 1<<4 bytes in size, hence the 4. */ ptb_order =KVM_MAX_NESTED_GUESTS_SHIFT +4 ;/* Minimum partition table size is 1<<12 bytes */
@@ -507,10 +530,15 @@ void kvmhv_set_ptbl_entry(u64 lpid, u64 dw0, u64 dw1)return ; } - pseries_partition_tb[lpid].patb0 =cpu_to_be64 (dw0); - pseries_partition_tb[lpid].patb1 =cpu_to_be64 (dw1); -/* L0 will do the necessary barriers */ -kvmhv_flush_lpid (lpid); +if (kvmhv_is_nestedv1 ()) { + pseries_partition_tb[lpid].patb0 =cpu_to_be64 (dw0); + pseries_partition_tb[lpid].patb1 =cpu_to_be64 (dw1); +/* L0 will do the necessary barriers */ +kvmhv_flush_lpid (lpid); + } + +if (kvmhv_is_nestedv2 ()) +kvmhv_nestedv2_set_ptbl_entry (lpid, dw0, dw1); }static void kvmhv_set_nested_ptbl (struct kvm_nested_guest *gp)
arch/powerpc/kvm/book3s_hv_nestedv2.c new file +996 -0
996 lines not on this page · raw message
arch/powerpc/kvm/emulate_loadstore.c +3 -1
@@ -92,7 +92,8 @@ int kvmppc_emulate_loadstore(struct kvm_vcpu *vcpu) vcpu->arch.mmio_host_swabbed =0 ; emulated =EMULATE_FAIL ; - vcpu->arch.regs.msr = vcpu->arch.shared->msr; + vcpu->arch.regs.msr =kvmppc_get_msr (vcpu); +kvmhv_nestedv2_reload_ptregs (vcpu, &vcpu->arch.regs);if (analyse_instr (&op, &vcpu->arch.regs, inst) =0 ) {int type = op.type &INSTR_TYPE_MASK ;int size =GETSIZE (op.type);
@@ -357,6 +358,7 @@ int kvmppc_emulate_loadstore(struct kvm_vcpu *vcpu) }trace_kvm_ppc_instr (ppc_inst_val (inst),kvmppc_get_pc (vcpu), emulated); +kvmhv_nestedv2_mark_dirty_ptregs (vcpu, &vcpu->arch.regs);/* Advance past emulated instruction. */ if (emulated !=EMULATE_FAIL )
arch/powerpc/kvm/guest-state-buffer.c +50 -0
53 lines not on this page · raw message
Signature · 1 line
2.39.3
PATCH v4 11/11 docs: powerpc: Document nested KVM on POWER
In reply to Jordan NietheFrom: Michael Neuling <[email protected]>
Document support for nested KVM on POWER using the existing API as well as the new PAPR API. This includes the new HCALL interface and how it used by KVM.
---
v2:
- Separated into individual patch
v3:
- Fix typos
--- Documentation/powerpc/index.rst | 1 + Documentation/powerpc/kvm-nested.rst | 636 +++++++++++++++++++++++++++ 2 files changed, 637 insertions(+) create mode 100644 Documentation/powerpc/kvm-nested.rst
Documentation/powerpc/index.rst +1 -0
@@ -26,6 +26,7 @@ powerpc isa-versions kaslr-booke32 mpc52xx + kvm-nested papr_hcalls pci_iov_resource_on_powernv pmu-ebb
Documentation/powerpc/kvm-nested.rst new file +631 -0
631 lines not on this page · raw message
Signature · 1 line
2.39.3
Quoted 11 lines · Jordan Niethe
A nested-HV API for PAPR has been developed based on the KVM-specific nested-HV API that is upstream in Linux/KVM and QEMU. The PAPR API had to break compatibility to accommodate implementation in other hypervisors and partitioning firmware. The existing KVM-specific API will be known as the Nested APIv1 and the PAPR API will be known as the Nested APIv2.
I tested the Nested APIv2 support on a Power server. Was able to bringup a L2 guest successfully. Additionally also tested the code with avocado-vt based cpu, guest lifecycle and ras bucket. The test completed successfully.
Based on this testing for patches 1 to 10
- Sachin