KVM: PPC: Book3S PR: Transaction memory support on PR KVM
Subsystems (3)
v2 cover KVM: PPC: Book3S PR: Transaction memory support on PR KVM
From: Simon Guo <[email protected]>
In current days, many OS distributions have utilized transaction memory functionality. In PowerPC, HV KVM supports TM. But PR KVM does not.
The drive for the transaction memory support of PR KVM is the openstack Continuous Integration testing - They runs a HV(hypervisor) KVM(as level 1) and then run PR KVM(as level 2) on top of that.
This patch set add transaction memory support on PR KVM.
v1->v2 changes:
1. Correct a bug in trechkpt emulation: the tm sprs need to be flushed to vcpu before trechkpt.
2. add PR kvm ioctl functionalities for TM.
3. removed save_msr_tm and use kvmppc_get_msr() to determine whether a transaction state need to be restored.
4. Remove "KVM: PPC: Book3S PR: set MSR HV bit accordingly for PPC970 and others." patch.
It will prevent PR KVM to start as L1 hypervisor. Since if we set HV bit to 0 when rfid to guest (who is supposed to run at HV=1 && PR=1), the guest will not be able to access its original memory.
The original code always set HV bits for shadow_msr, it is benign since:
HV bits can only be altered by sc instruction; it can only be set to 0 by rfid/hrfid instruction.
We return to guest with rfid. So:
* if KVM are running as L1 hypervisor, guest physical MSR expects HV=1.
* if KVM are running as L2 hypervisor, rfid cannot update HV =1 so the HV is still 0.
5. add XER register implementation to kvmppc_copyto_vcpu_tm/kvmppc_copyfrom_vcpu_tm()
6. remove unnecessary stack frame in _kvmppc_save/restore_tm().
7. move MSR bits sync into kvmppc_copy_from_svcpu() so that we always see inconsistent shadow_msr/kvmppc_get_msr() even when preemption.
8. doing failure recording in treclaim emulation when TEXASR_FS is 0.
Test cases performed:
linux/tools/testing/selftests/powerpc/tm/tm-syscall linux/tools/testing/selftests/powerpc/tm/tm-fork linux/tools/testing/selftests/powerpc/tm/tm-vmx-unavail linux/tools/testing/selftests/powerpc/tm/tm-tmspr linux/tools/testing/selftests/powerpc/tm/tm-signal-msr-resv linux/tools/testing/selftests/powerpc/math/vsx_preempt linux/tools/testing/selftests/powerpc/math/fpu_signal linux/tools/testing/selftests/powerpc/math/vmx_preempt linux/tools/testing/selftests/powerpc/math/fpu_syscall linux/tools/testing/selftests/powerpc/math/vmx_syscall linux/tools/testing/selftests/powerpc/math/fpu_preempt linux/tools/testing/selftests/powerpc/math/vmx_signal linux/tools/testing/selftests/powerpc/ptrace/ptrace-tm-gpr linux/tools/testing/selftests/powerpc/ptrace/ptrace-tm-spd-gpr linux/tools/testing/selftests/powerpc/ptrace/ptrace-tm-spd-vsx linux/tools/testing/selftests/powerpc/ptrace/ptrace-tm-spr linux/tools/testing/selftests/powerpc/ptrace/ptrace-tm-vsx
https://github.com/justdoitqd/publicFiles/blob/master/test_tbegin_pr.c
https://github.com/justdoitqd/publicFiles/blob/master/test_tabort.c
https://github.com/justdoitqd/publicFiles/blob/master/test_kvm_htm_cap.c
https://github.com/justdoitqd/publicFiles/blob/master/test-tm-mig.c
Simon Guo (30):
powerpc: export symbol msr_check_and_set().
powerpc: add TEXASR related macros
powerpc: export tm_enable()/tm_disable/tm_abort() APIs
KVM: PPC: Book3S PR: Move kvmppc_save_tm/kvmppc_restore_tm to separate
file
KVM: PPC: Book3S PR: add new parameter (guest MSR) for
kvmppc_save_tm()/kvmppc_restore_tm()
KVM: PPC: Book3S PR: turn on FP/VSX/VMX MSR bits in kvmppc_save_tm()
KVM: PPC: Book3S PR: add C function wrapper for
_kvmppc_save/restore_tm()
KVM: PPC: Book3S PR: In PR KVM suspends Transactional state when
inject an interrupt.
KVM: PPC: Book3S PR: PR KVM pass through MSR TM/TS bits to shadow_msr.
KVM: PPC: Book3S PR: Sync TM bits to shadow msr for problem state
guest
KVM: PPC: Book3S PR: implement RFID TM behavior to suppress change
from S0 to N0
KVM: PPC: Book3S PR: prevent TS bits change in kvmppc_interrupt_pr()
KVM: PPC: Book3S PR: adds new
kvmppc_copyto_vcpu_tm/kvmppc_copyfrom_vcpu_tm API for PR KVM.
KVM: PPC: Book3S PR: add kvmppc_save/restore_tm_sprs() APIs
KVM: PPC: Book3S PR: add transaction memory save/restore skeleton for
PR KVM
KVM: PPC: Book3S PR: add math support for PR KVM HTM
KVM: PPC: Book3S PR: make mtspr/mfspr emulation behavior based on
active TM SPRs
KVM: PPC: Book3S PR: always fail transaction in guest privilege state
KVM: PPC: Book3S PR: enable NV reg restore for reading TM SPR at guest
privilege state
KVM: PPC: Book3S PR: adds emulation for treclaim.
KVM: PPC: Book3S PR: add emulation for trechkpt in PR KVM.
KVM: PPC: Book3S PR: add emulation for tabort. for privilege guest
KVM: PPC: Book3S PR: add guard code to prevent returning to guest with
PR=0 and Transactional state
KVM: PPC: Book3S PR: Support TAR handling for PR KVM HTM.
KVM: PPC: Book3S PR: enable HTM for PR KVM for KVM_CHECK_EXTENSION
ioctl
KVM: PPC: move vcpu_load/vcpu_put down to each ioctl case in
kvm_arch_vcpu_ioctl
KVM: PPC: remove load/put vcpu for KVM_GET/SET_ONE_REG ioctl
KVM: PPC: remove load/put vcpu for KVM_GET_REGS/KVM_SET_REGS
KVM: PPC: add KVM_SET_ONE_REG/KVM_GET_ONE_REG to async ioctl
KVM: PPC: Book3S PR: enable kvmppc_get/set_one_reg_pr() for HTM
registers
arch/powerpc/include/asm/asm-prototypes.h | 9 + arch/powerpc/include/asm/kvm_book3s.h | 16 ++ arch/powerpc/include/asm/kvm_host.h | 1 - arch/powerpc/include/asm/reg.h | 25 +- arch/powerpc/include/asm/tm.h | 2 - arch/powerpc/include/uapi/asm/tm.h | 2 +- arch/powerpc/kernel/process.c | 1 + arch/powerpc/kernel/tm.S | 12 + arch/powerpc/kvm/Makefile | 3 + arch/powerpc/kvm/book3s.c | 6 - arch/powerpc/kvm/book3s.h | 6 + arch/powerpc/kvm/book3s_64_mmu.c | 11 +- arch/powerpc/kvm/book3s_emulate.c | 369 ++++++++++++++++++++++++++- arch/powerpc/kvm/book3s_hv_rmhandlers.S | 259 ++----------------- arch/powerpc/kvm/book3s_pr.c | 337 +++++++++++++++++++++++-- arch/powerpc/kvm/book3s_segment.S | 13 + arch/powerpc/kvm/powerpc.c | 23 +- arch/powerpc/kvm/tm.S | 379 ++++++++++++++++++++++++++++ arch/powerpc/mm/hash_utils_64.c | 1 + arch/powerpc/platforms/powernv/copy-paste.h | 3 +- 20 files changed, 1179 insertions(+), 299 deletions(-) create mode 100644 arch/powerpc/kvm/tm.S
Signature · 1 line
1.8.3.1
PATCH v2 1/30 powerpc: export symbol msr_check_and_set().
From: Simon Guo <[email protected]>
PR KVM will need to reuse msr_check_and_set().
This patch exports this API for reuse.
--- arch/powerpc/kernel/process.c | 1 + 1 file changed, 1 insertion(+)
arch/powerpc/kernel/process.c +1 -0
@@ -152,6 +152,7 @@ unsigned long msr_check_and_set(unsigned long bits)return newmsr; } +EXPORT_SYMBOL_GPL (msr_check_and_set);void __msr_check_and_clear (unsigned long bits) {
Signature · 1 line
1.8.3.1
PATCH v2 2/30 powerpc: add TEXASR related macros
In reply to [email protected]From: Simon Guo <[email protected]>
This patches add some macros for CR0/TEXASR bits so that PR KVM TM logic(tbegin./treclaim./tabort.) can make use of them later.
--- arch/powerpc/include/asm/reg.h | 25 ++++++++++++++++++++++++- arch/powerpc/platforms/powernv/copy-paste.h | 3 +-- 2 files changed, 25 insertions(+), 3 deletions(-)
arch/powerpc/include/asm/reg.h +24 -1
@@ -146,6 +146,12 @@#define MSR_64BIT 0#endif +/* Condition Register related */ +#define CR0_SHIFT 28 +#define CR0_MASK 0xF +#define CR0_TBEGIN_FAILURE (0x2 << 28)/* 0b0010 */ + +/* Power Management - Processor Stop Status and Control Register Fields */ #define PSSCR_RL_MASK 0x0000000F/* Requested Level */ #define PSSCR_MTL_MASK 0x000000F0/* Maximum Transition Level */
@@ -237,8 +243,25 @@#define SPRN_TFIAR 0x81/* Transaction Failure Inst Addr */ #define SPRN_TEXASR 0x82/* Transaction EXception & Summary */ #define SPRN_TEXASRU 0x83/* '' '' '' Upper 32 */ -#define TEXASR_FS __MASK(63-36)/* TEXASR Failure Summary */ +#define TEXASR_FC_LG (63 - 7)/* Failure Code */ +#define TEXASR_AB_LG (63 - 31)/* Abort */ +#define TEXASR_SU_LG (63 - 32)/* Suspend */ +#define TEXASR_HV_LG (63 - 34)/* Hypervisor state*/ +#define TEXASR_PR_LG (63 - 35)/* Privilege level */ +#define TEXASR_FS_LG (63 - 36)/* failure summary */ +#define TEXASR_EX_LG (63 - 37)/* TFIAR exact bit */ +#define TEXASR_ROT_LG (63 - 38)/* ROT bit */ +#define TEXASR_FC (ASM_CONST(0xFF) << TEXASR_FC_LG) +#define TEXASR_AB __MASK(TEXASR_AB_LG) +#define TEXASR_SU __MASK(TEXASR_SU_LG) +#define TEXASR_HV __MASK(TEXASR_HV_LG) +#define TEXASR_PR __MASK(TEXASR_PR_LG) +#define TEXASR_FS __MASK(TEXASR_FS_LG) +#define TEXASR_EX __MASK(TEXASR_EX_LG) +#define TEXASR_ROT __MASK(TEXASR_ROT_LG) +#define SPRN_TFHAR 0x80/* Transaction Failure Handler Addr */ +#define SPRN_TIDR 144/* Thread ID register */ #define SPRN_CTRLF 0x088#define SPRN_CTRLT 0x098
arch/powerpc/platforms/powernv/copy-paste.h +1 -2
@@ -7,9 +7,8 @@* 2 of the License, or (at your option) any later version. */ #include <asm/ppc-opcode.h> +#include <asm/reg.h> -#define CR0_SHIFT 28 -#define CR0_MASK 0xF/* * Copy/paste instructions: *
Signature · 1 line
1.8.3.1
PATCH v2 3/30 powerpc: export tm_enable()/tm_disable/tm_abort() APIs
In reply to [email protected]From: Simon Guo <[email protected]>
This patch exports tm_enable()/tm_disable/tm_abort() APIs, which will be used for PR KVM transaction memory logic.
--- arch/powerpc/include/asm/asm-prototypes.h | 3 +++ arch/powerpc/include/asm/tm.h | 2 -- arch/powerpc/kernel/tm.S | 12 ++++++++++++ arch/powerpc/mm/hash_utils_64.c | 1 + 4 files changed, 16 insertions(+), 2 deletions(-)
arch/powerpc/include/asm/asm-prototypes.h +3 -0
@@ -126,4 +126,7 @@ unsigned long __init prom_init(unsigned long r3, unsigned long r4,void _mcount (void );unsigned long prepare_ftrace_return (unsigned long parent,unsigned long ip); +void tm_enable (void ); +void tm_disable (void ); +void tm_abort (uint8_t cause);#endif /* _ASM_POWERPC_ASM_PROTOTYPES_H */
arch/powerpc/include/asm/tm.h +0 -2
@@ -10,12 +10,10 @@#ifndef __ASSEMBLY__ -extern void tm_enable (void );extern void tm_reclaim (struct thread_struct *thread,uint8_t cause);extern void tm_reclaim_current (uint8_t cause);extern void tm_recheckpoint (struct thread_struct *thread); -extern void tm_abort (uint8_t cause);extern void tm_save_sprs (struct thread_struct *thread);extern void tm_restore_sprs (struct thread_struct *thread);
arch/powerpc/kernel/tm.S +12 -0
@@ -12,6 +12,7 @@ #include <asm/ptrace.h> #include <asm/reg.h> #include <asm/bug.h> +#include <asm/export.h> #ifdef CONFIG_VSX /* See fpu.S, this is borrowed from there */
@@ -55,6 +56,16 @@ _GLOBAL(tm_enable) or r4, r4, r3 mtmsrd r4 1: blr +EXPORT_SYMBOL_GPL(tm_enable); + +_GLOBAL(tm_disable) + mfmsr r4 + li r3, MSR_TM >> 32 + sldi r3, r3, 32 + andc r4, r4, r3 + mtmsrd r4 + blr +EXPORT_SYMBOL_GPL(tm_disable); _GLOBAL(tm_save_sprs) mfspr r0, SPRN_TFHAR
@@ -78,6 +89,7 @@ _GLOBAL(tm_restore_sprs) _GLOBAL(tm_abort) TABORT(R3) blr +EXPORT_SYMBOL_GPL(tm_abort); /* void tm_reclaim(struct thread_struct *thread, * uint8_t cause)
arch/powerpc/mm/hash_utils_64.c +1 -0
@@ -63,6 +63,7 @@#include <asm/trace.h> #include <asm/ps3.h> #include <asm/pte-walk.h> +#include <asm/asm-prototypes.h> #ifdef DEBUG #define DBG(fmt...) udbg_printf(fmt)
Signature · 1 line
1.8.3.1
PATCH v2 4/30 KVM: PPC: Book3S PR: Move kvmppc_save_tm/kvmppc_restore_tm to separate file
In reply to [email protected]From: Simon Guo <[email protected]>
It is a simple patch just for moving kvmppc_save_tm/kvmppc_restore_tm() functionalities to tm.S. There is no logic change. The reconstruct of those APIs will be done in later patches to improve readability.
It is for preparation of reusing those APIs on both HV/PR PPC KVM.
--- arch/powerpc/kvm/Makefile | 3 + arch/powerpc/kvm/book3s_hv_rmhandlers.S | 239 ---------------------------- arch/powerpc/kvm/tm.S | 267 ++++++++++++++++++++++++++++++++ 3 files changed, 270 insertions(+), 239 deletions(-) create mode 100644 arch/powerpc/kvm/tm.S
arch/powerpc/kvm/Makefile +3 -0
@@ -63,6 +63,9 @@ kvm-pr-y := \ book3s_64_mmu.o \ book3s_32_mmu.o +kvm-book3s_64-builtin-objs-$(CONFIG_KVM_BOOK3S_64_HANDLER) += \ + tm.o + ifdef CONFIG_KVM_BOOK3S_PR_POSSIBLE kvm-book3s_64-builtin-objs-$(CONFIG_KVM_BOOK3S_64_HANDLER) += \ book3s_rmhandlers.o
arch/powerpc/kvm/book3s_hv_rmhandlers.S +0 -239
251 lines not on this page · raw message
arch/powerpc/kvm/tm.S new file +267 -0
267 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v2 5/30 KVM: PPC: Book3S PR: add new parameter (guest MSR) for kvmppc_save_tm()/kvmppc_restore_tm()
In reply to [email protected]From: Simon Guo <[email protected]>
HV KVM and PR KVM need different MSR source to indicate whether treclaim. or trecheckpoint. is necessary.
This patch add new parameter (guest MSR) for these kvmppc_save_tm/ kvmppc_restore_tm() APIs:
- For HV KVM, it is VCPU_MSR
- For PR KVM, it is current host MSR or VCPU_SHADOW_SRR1
This enhancement enables these 2 APIs to be reused by PR KVM later. And the patch keeps HV KVM logic unchanged.
This patch also reworks kvmppc_save_tm()/kvmppc_restore_tm() to have a clean ABI: r3 for vcpu and r4 for guest_msr.
During kvmppc_save_tm/kvmppc_restore_tm(), the R1 need to be saved or restored. Currently the R1 is saved into HSTATE_HOST_R1. In PR KVM, we are going to add a C function wrapper for kvmppc_save_tm/kvmppc_restore_tm() where the R1 will be incremented with added stackframe and save into HSTATE_HOST_R1. There are several places in HV KVM to load HSTATE_HOST_R1 as R1, and we don't want to bring risk or confusion by TM code.
This patch will use HSTATE_SCRATCH2 to save/restore R1 in kvmppc_save_tm/kvmppc_restore_tm() to avoid future confusion, since the r1 is actually a temporary/scratch value to be saved/stored.
--- arch/powerpc/kvm/book3s_hv_rmhandlers.S | 12 ++++++- arch/powerpc/kvm/tm.S | 61 ++++++++++++++++++--------------- 2 files changed, 45 insertions(+), 28 deletions(-)
arch/powerpc/kvm/book3s_hv_rmhandlers.S +11 -1
@@ -788,7 +788,10 @@ BEGIN_FTR_SECTION /* * NOTE THAT THIS TRASHES ALL NON-VOLATILE REGISTERS INCLUDING CR */ + mr r3, r4 + ld r4, VCPU_MSR(r3) bl kvmppc_restore_tm + ld r4, HSTATE_KVM_VCPU(r13) END_FTR_SECTION_IFSET(CPU_FTR_TM) #endif
@@ -1730,7 +1733,10 @@ BEGIN_FTR_SECTION /* * NOTE THAT THIS TRASHES ALL NON-VOLATILE REGISTERS INCLUDING CR */ + mr r3, r9 + ld r4, VCPU_MSR(r3) bl kvmppc_save_tm + ld r9, HSTATE_KVM_VCPU(r13) END_FTR_SECTION_IFSET(CPU_FTR_TM) #endif
@@ -2588,7 +2594,8 @@ BEGIN_FTR_SECTION /* * NOTE THAT THIS TRASHES ALL NON-VOLATILE REGISTERS INCLUDING CR */ - ld r9, HSTATE_KVM_VCPU(r13) + ld r3, HSTATE_KVM_VCPU(r13) + ld r4, VCPU_MSR(r3) bl kvmppc_save_tm END_FTR_SECTION_IFSET(CPU_FTR_TM) #endif
@@ -2701,7 +2708,10 @@ BEGIN_FTR_SECTION /* * NOTE THAT THIS TRASHES ALL NON-VOLATILE REGISTERS INCLUDING CR */ + mr r3, r4 + ld r4, VCPU_MSR(r3) bl kvmppc_restore_tm + ld r4, HSTATE_KVM_VCPU(r13) END_FTR_SECTION_IFSET(CPU_FTR_TM) #endif
arch/powerpc/kvm/tm.S +34 -27
135 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v2 6/30 KVM: PPC: Book3S PR: turn on FP/VSX/VMX MSR bits in kvmppc_save_tm()
In reply to [email protected]From: Simon Guo <[email protected]>
kvmppc_save_tm() invokes store_fp_state/store_vr_state(). So it is mandatory to turn on FP/VSX/VMX MSR bits for its execution, just like what kvmppc_restore_tm() did.
Previsouly HV KVM has turned the bits on outside of function kvmppc_save_tm(). Now we include this bit change in kvmppc_save_tm() so that the logic is more clean. And PR KVM can reuse it later.
--- arch/powerpc/kvm/tm.S | 2 ++ 1 file changed, 2 insertions(+)
arch/powerpc/kvm/tm.S +2 -0
@@ -43,6 +43,8 @@ _GLOBAL(kvmppc_save_tm) mfmsr r8 li r0, 1 rldimi r8, r0, MSR_TM_LG, 63-MSR_TM_LG + ori r8, r8, MSR_FP + oris r8, r8, (MSR_VEC | MSR_VSX)@h mtmsrd r8 rldicl. r4, r4, 64 - MSR_TS_S_LG, 62
Signature · 1 line
1.8.3.1
PATCH v2 7/30 KVM: PPC: Book3S PR: add C function wrapper for _kvmppc_save/restore_tm()
In reply to [email protected]From: Simon Guo <[email protected]>
Currently _kvmppc_save/restore_tm() APIs can only be invoked from assembly function. This patch adds C function wrappers for them so that they can be safely called from C function.
--- arch/powerpc/include/asm/asm-prototypes.h | 6 ++ arch/powerpc/kvm/book3s_hv_rmhandlers.S | 8 +-- arch/powerpc/kvm/tm.S | 95 ++++++++++++++++++++++++++++++- 3 files changed, 103 insertions(+), 6 deletions(-)
arch/powerpc/include/asm/asm-prototypes.h +6 -0
@@ -126,7 +126,13 @@ unsigned long __init prom_init(unsigned long r3, unsigned long r4,void _mcount (void );unsigned long prepare_ftrace_return (unsigned long parent,unsigned long ip); +/* Transaction memory related */ void tm_enable (void );void tm_disable (void );void tm_abort (uint8_t cause); + +struct kvm_vcpu ; +void _kvmppc_restore_tm_pr (struct kvm_vcpu *vcpu,u64 guest_msr); +void _kvmppc_save_tm_pr (struct kvm_vcpu *vcpu,u64 guest_msr); +#endif /* _ASM_POWERPC_ASM_PROTOTYPES_H */
arch/powerpc/kvm/book3s_hv_rmhandlers.S +4 -4
@@ -790,7 +790,7 @@ BEGIN_FTR_SECTION */ mr r3, r4 ld r4, VCPU_MSR(r3) - bl kvmppc_restore_tm + bl __kvmppc_restore_tm ld r4, HSTATE_KVM_VCPU(r13) END_FTR_SECTION_IFSET(CPU_FTR_TM) #endif
@@ -1735,7 +1735,7 @@ BEGIN_FTR_SECTION */ mr r3, r9 ld r4, VCPU_MSR(r3) - bl kvmppc_save_tm + bl __kvmppc_save_tm ld r9, HSTATE_KVM_VCPU(r13) END_FTR_SECTION_IFSET(CPU_FTR_TM) #endif
@@ -2596,7 +2596,7 @@ BEGIN_FTR_SECTION */ ld r3, HSTATE_KVM_VCPU(r13) ld r4, VCPU_MSR(r3) - bl kvmppc_save_tm + bl __kvmppc_save_tm END_FTR_SECTION_IFSET(CPU_FTR_TM) #endif
@@ -2710,7 +2710,7 @@ BEGIN_FTR_SECTION */ mr r3, r4 ld r4, VCPU_MSR(r3) - bl kvmppc_restore_tm + bl __kvmppc_restore_tm ld r4, HSTATE_KVM_VCPU(r13) END_FTR_SECTION_IFSET(CPU_FTR_TM) #endif
arch/powerpc/kvm/tm.S +93 -2
129 lines not on this page · raw message
Signature · 1 line
1.8.3.1
Re: [PATCH v2 07/30] KVM: PPC: Book3S PR: add C function wrapper for _kvmppc_save/restore_tm()
Quoted 7 lines · On Wed, Feb 28, 2018 at 01:37:14AM +0800, [email protected] wrote:
From: Simon Guo <[email protected]>
Currently _kvmppc_save/restore_tm() APIs can only be invoked from assembly function. This patch adds C function wrappers for them so that they can be safely called from C function.
Signed-off-by Simon Guo <[email protected]>
Some relatively minor comments below:
Quoted 14 lines
arch/powerpc/kvm/tm.S +1
-1@@ -35,7 +35,7 @@ * This can modify all checkpointed registers, but * restores r1, r2 before exit. */ -_GLOBAL(kvmppc_save_tm) +_GLOBAL(__kvmppc_save_tm) mflr r0 std r0, PPC_LR_STKOFF(r1)
arch/powerpc/kvm/tm.S _GLOBAL(kvmppc_save_tm) · line 155
Quoted 7 lines
arch/powerpc/kvm/tm.S +4
-0@@ -149,6 +149,52 @@ _GLOBAL(kvmppc_save_tm) blr /* + * _kvmppc_save_tm() is a wrapper around __kvmppc_save_tm(), so that it can + * be invoked from C function by PR KVM only. + */ +_GLOBAL(_kvmppc_save_tm_pr)
The comment doesn't match the actual function name.
Quoted 55 lines
arch/powerpc/kvm/tm.S +43
-1+ mflr r5 + std r5, PPC_LR_STKOFF(r1) + stdu r1, -SWITCH_FRAME_SIZE(r1) + SAVE_NVGPRS(r1) + + /* save MSR since TM/math bits might be impacted + * by __kvmppc_save_tm(). + */ + mfmsr r5 + SAVE_GPR(5, r1) + + /* also save DSCR/CR so that it can be recovered later */ + mfspr r6, SPRN_DSCR + SAVE_GPR(6, r1) + + mfcr r7 + stw r7, _CCR(r1) + + bl __kvmppc_save_tm + + ld r7, _CCR(r1) + mtcr r7 + + REST_GPR(6, r1) + mtspr SPRN_DSCR, r6 + + /* need preserve current MSR's MSR_TS bits */ + REST_GPR(5, r1) + mfmsr r6 + rldicl r6, r6, 64 - MSR_TS_S_LG, 62 + rldimi r5, r6, MSR_TS_S_LG, 63 - MSR_TS_T_LG + mtmsrd r5 + + REST_NVGPRS(r1) + addi r1, r1, SWITCH_FRAME_SIZE + ld r5, PPC_LR_STKOFF(r1) + mtlr r5 + blr + +EXPORT_SYMBOL_GPL(_kvmppc_save_tm_pr); + +/* * Restore transactional state and TM-related registers. * Called with: * - r3 pointing to the vcpu struct.@@ -158,7 +204,7 @@ _GLOBAL(kvmppc_save_tm) * This potentially modifies all checkpointed registers. * It restores r1, r2 from the PACA. */ -_GLOBAL(kvmppc_restore_tm) +_GLOBAL(__kvmppc_restore_tm) mflr r0 std r0, PPC_LR_STKOFF(r1)
arch/powerpc/kvm/tm.S _GLOBAL(kvmppc_restore_tm) · line 235
Quoted 4 lines
arch/powerpc/kvm/tm.S +1
-0@@ -186,6 +232,7 @@ _GLOBAL(kvmppc_restore_tm) rldicl. r5, r5, 64 - MSR_TS_S_LG, 62 beqlr /* TM not active in guest */ std r1, HSTATE_SCRATCH2(r13) + std r3, HSTATE_SCRATCH1(r13)
Why do we need to save r3 here and restore it below?
Quoted 12 lines
arch/powerpc/kvm/tm.S +1
-0/* Make sure the failure summary is set, otherwise we'll program check * when we trechkpt. It's possible that this might have been not set@@ -262,6 +309,7 @@ _GLOBAL(kvmppc_restore_tm) ld r29, HSTATE_DSCR(r13) mtspr SPRN_DSCR, r29 #endif + ld r3, HSTATE_SCRATCH1(r13) ld r1, HSTATE_SCRATCH2(r13) ld r2, PACATMSCRATCH(r13)
arch/powerpc/kvm/tm.S _GLOBAL(kvmppc_restore_tm) · line 328
Quoted 8 lines
arch/powerpc/kvm/tm.S +5
-0@@ -273,4 +321,47 @@ _GLOBAL(kvmppc_restore_tm) mtlr r0 blr +/* + * _kvmppc_restore_tm() is a wrapper around __kvmppc_restore_tm(), so that it + * can be invoked from C function by PR KVM only. + */ +_GLOBAL(_kvmppc_restore_tm_pr)
Again, comment doesn't match the actual function name.
Quoted 41 lines
arch/powerpc/kvm/tm.S +38
-0+ mflr r5 + std r5, PPC_LR_STKOFF(r1) + stdu r1, -SWITCH_FRAME_SIZE(r1) + SAVE_NVGPRS(r1) + + /* save MSR to avoid TM/math bits change */ + mfmsr r5 + SAVE_GPR(5, r1) + + /* also save DSCR/CR so that it can be recovered later */ + mfspr r6, SPRN_DSCR + SAVE_GPR(6, r1) + + mfcr r7 + stw r7, _CCR(r1) + + bl __kvmppc_restore_tm + + ld r7, _CCR(r1) + mtcr r7 + + REST_GPR(6, r1) + mtspr SPRN_DSCR, r6 + + /* need preserve current MSR's MSR_TS bits */ + REST_GPR(5, r1) + mfmsr r6 + rldicl r6, r6, 64 - MSR_TS_S_LG, 62 + rldimi r5, r6, MSR_TS_S_LG, 63 - MSR_TS_T_LG + mtmsrd r5 + + REST_NVGPRS(r1) + addi r1, r1, SWITCH_FRAME_SIZE + ld r5, PPC_LR_STKOFF(r1) + mtlr r5 + blr + +EXPORT_SYMBOL_GPL(_kvmppc_restore_tm_pr); #endifSignature · 1 line
1.8.3.1
Paul.
Re: [PATCH v2 07/30] KVM: PPC: Book3S PR: add C function wrapper for _kvmppc_save/restore_tm()
Quoted 27 lines · Paul Mackerras
Quoted 7 lines · On Wed, Feb 28, 2018 at 01:37:14AM +0800, [email protected] wrote:
From: Simon Guo <[email protected]>
Currently _kvmppc_save/restore_tm() APIs can only be invoked from assembly function. This patch adds C function wrappers for them so that they can be safely called from C function.
Signed-off-by Simon Guo <[email protected]>Some relatively minor comments below:
Quoted 16 lines
arch/powerpc/kvm/tm.S +1
-1@@ -35,7 +35,7 @@ * This can modify all checkpointed registers, but * restores r1, r2 before exit. */ -_GLOBAL(kvmppc_save_tm) +_GLOBAL(__kvmppc_save_tm) mflr r0 std r0, PPC_LR_STKOFF(r1)@@ -149,6 +149,52 @@ _GLOBAL(kvmppc_save_tm) blr
Quoted 7 lines
arch/powerpc/kvm/tm.S _GLOBAL(kvmppc_save_tm) · line 155
Quoted 5 lines
arch/powerpc/kvm/tm.S +4
-0/* + * _kvmppc_save_tm() is a wrapper around __kvmppc_save_tm(), so that it can + * be invoked from C function by PR KVM only. + */ +_GLOBAL(_kvmppc_save_tm_pr)The comment doesn't match the actual function name.
I will correct that. Thanks for point it out.
Quoted 55 lines
Quoted 55 lines
arch/powerpc/kvm/tm.S +43
-1+ mflr r5 + std r5, PPC_LR_STKOFF(r1) + stdu r1, -SWITCH_FRAME_SIZE(r1) + SAVE_NVGPRS(r1) + + /* save MSR since TM/math bits might be impacted + * by __kvmppc_save_tm(). + */ + mfmsr r5 + SAVE_GPR(5, r1) + + /* also save DSCR/CR so that it can be recovered later */ + mfspr r6, SPRN_DSCR + SAVE_GPR(6, r1) + + mfcr r7 + stw r7, _CCR(r1) + + bl __kvmppc_save_tm + + ld r7, _CCR(r1) + mtcr r7 + + REST_GPR(6, r1) + mtspr SPRN_DSCR, r6 + + /* need preserve current MSR's MSR_TS bits */ + REST_GPR(5, r1) + mfmsr r6 + rldicl r6, r6, 64 - MSR_TS_S_LG, 62 + rldimi r5, r6, MSR_TS_S_LG, 63 - MSR_TS_T_LG + mtmsrd r5 + + REST_NVGPRS(r1) + addi r1, r1, SWITCH_FRAME_SIZE + ld r5, PPC_LR_STKOFF(r1) + mtlr r5 + blr + +EXPORT_SYMBOL_GPL(_kvmppc_save_tm_pr); + +/* * Restore transactional state and TM-related registers. * Called with: * - r3 pointing to the vcpu struct.@@ -158,7 +204,7 @@ _GLOBAL(kvmppc_save_tm) * This potentially modifies all checkpointed registers. * It restores r1, r2 from the PACA. */ -_GLOBAL(kvmppc_restore_tm) +_GLOBAL(__kvmppc_restore_tm) mflr r0 std r0, PPC_LR_STKOFF(r1)
Quoted 7 lines
arch/powerpc/kvm/tm.S _GLOBAL(kvmppc_restore_tm) · line 235
Quoted 5 lines
arch/powerpc/kvm/tm.S +1
-0@@ -186,6 +232,7 @@ _GLOBAL(kvmppc_restore_tm) rldicl. r5, r5, 64 - MSR_TS_S_LG, 62 beqlr /* TM not active in guest */ std r1, HSTATE_SCRATCH2(r13) + std r3, HSTATE_SCRATCH1(r13)Why do we need to save r3 here and restore it below?
I think it is a legacy change when I did TM save/restore on each trap from guest to host. It can be removed now.
Quoted 16 lines
Quoted 16 lines
arch/powerpc/kvm/tm.S +1
-0/* Make sure the failure summary is set, otherwise we'll program check * when we trechkpt. It's possible that this might have been not set@@ -262,6 +309,7 @@ _GLOBAL(kvmppc_restore_tm) ld r29, HSTATE_DSCR(r13) mtspr SPRN_DSCR, r29 #endif + ld r3, HSTATE_SCRATCH1(r13) ld r1, HSTATE_SCRATCH2(r13) ld r2, PACATMSCRATCH(r13)@@ -273,4 +321,47 @@ _GLOBAL(kvmppc_restore_tm) mtlr r0 blr
Quoted 7 lines
arch/powerpc/kvm/tm.S _GLOBAL(kvmppc_restore_tm) · line 328
Quoted 5 lines
arch/powerpc/kvm/tm.S +5
-0+/* + * _kvmppc_restore_tm() is a wrapper around __kvmppc_restore_tm(), so that it + * can be invoked from C function by PR KVM only. + */ +_GLOBAL(_kvmppc_restore_tm_pr)Again, comment doesn't match the actual function name.
I will correct that.
Thanks,
- Simon
PATCH v2 8/30 KVM: PPC: Book3S PR: In PR KVM suspends Transactional state when inject an interrupt.
In reply to [email protected]From: Simon Guo <[email protected]>
This patch simulates interrupt behavior per Power ISA while injecting interrupt in PR KVM:
- When interrupt happens, transactional state should be suspended.
kvmppc_mmu_book3s_64_reset_msr() will be invoked when injecting an interrupt. This patch performs this ISA logic in kvmppc_mmu_book3s_64_reset_msr().
--- arch/powerpc/kvm/book3s_64_mmu.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
arch/powerpc/kvm/book3s_64_mmu.c +10 -1
@@ -38,7 +38,16 @@static void kvmppc_mmu_book3s_64_reset_msr (struct kvm_vcpu *vcpu) { -kvmppc_set_msr (vcpu, vcpu->arch.intr_msr); +unsigned long msr = vcpu->arch.intr_msr; +unsigned long cur_msr =kvmppc_get_msr (vcpu); + +/* If transactional, change to suspend mode on IRQ delivery */ +if (MSR_TM_TRANSACTIONAL (cur_msr)) + msr |=MSR_TS_S ; +else + msr |= cur_msr &MSR_TS_MASK ; + +kvmppc_set_msr (vcpu, msr); } static struct kvmppc_slb *kvmppc_mmu_book3s_64_find_slbe(
Signature · 1 line
1.8.3.1
PATCH v2 9/30 KVM: PPC: Book3S PR: PR KVM pass through MSR TM/TS bits to shadow_msr.
In reply to [email protected]From: Simon Guo <[email protected]>
PowerPC TM functionality needs MSR TM/TS bits support in hardware level. Guest TM functionality can not be emulated with "fake" MSR (msr in magic page) TS bits.
This patch syncs TM/TS bits in shadow_msr with the MSR value in magic page, so that the MSR TS value which guest sees is consistent with actual MSR bits running in guest.
--- arch/powerpc/kvm/book3s_pr.c | 5 +++++ 1 file changed, 5 insertions(+)
arch/powerpc/kvm/book3s_pr.c +5 -0
@@ -323,7 +323,12 @@ static void kvmppc_recalc_shadow_msr(struct kvm_vcpu *vcpu)ulong smsr = guest_msr;/* Guest MSR values */ +#ifdef CONFIG_PPC_TRANSACTIONAL_MEM + smsr &=MSR_FE0 |MSR_FE1 |MSR_SF |MSR_SE |MSR_BE |MSR_LE | +MSR_TM |MSR_TS_MASK ; +#else smsr &=MSR_FE0 |MSR_FE1 |MSR_SF |MSR_SE |MSR_BE |MSR_LE ; +#endif /* Process MSR values */ smsr |=MSR_ME |MSR_RI |MSR_IR |MSR_DR |MSR_PR |MSR_EE ;/* External providers the guest reserved */
Signature · 1 line
1.8.3.1
PATCH v2 10/30 KVM: PPC: Book3S PR: Sync TM bits to shadow msr for problem state guest
In reply to [email protected]From: Simon Guo <[email protected]>
MSR TS bits can be modified with non-privileged instruction like tbegin./tend. That means guest can change MSR value "silently" without notifying host.
It is necessary to sync the TM bits to host so that host can calculate shadow msr correctly.
note privilege guest will always fail transactions so we only take care of problem state guest.
The logic is put into kvmppc_copy_from_svcpu() so that kvmppc_handle_exit_pr() can use correct MSR TM bits even when preemption.
--- arch/powerpc/kvm/book3s_pr.c | 73 ++++++++++++++++++++++++++++++-------------- 1 file changed, 50 insertions(+), 23 deletions(-)
arch/powerpc/kvm/book3s_pr.c +50 -23
@@ -179,10 +179,36 @@ void kvmppc_copy_to_svcpu(struct kvmppc_book3s_shadow_vcpu *svcpu, svcpu->in_use = true; } +static void kvmppc_recalc_shadow_msr (struct kvm_vcpu *vcpu) +{ +ulong guest_msr =kvmppc_get_msr (vcpu); +ulong smsr = guest_msr; + +/* Guest MSR values */ +#ifdef CONFIG_PPC_TRANSACTIONAL_MEM + smsr &=MSR_FE0 |MSR_FE1 |MSR_SF |MSR_SE |MSR_BE |MSR_LE | +MSR_TM |MSR_TS_MASK ; +#else + smsr &=MSR_FE0 |MSR_FE1 |MSR_SF |MSR_SE |MSR_BE |MSR_LE ; +#endif +/* Process MSR values */ + smsr |=MSR_ME |MSR_RI |MSR_IR |MSR_DR |MSR_PR |MSR_EE ; +/* External providers the guest reserved */ + smsr |= (guest_msr & vcpu->arch.guest_owned_ext); +/* 64-bit Process MSR values */ +#ifdef CONFIG_PPC_BOOK3S_64 + smsr |=MSR_ISF |MSR_HV ; +#endif + vcpu->arch.shadow_msr = smsr; +} +/* Copy data touched by real-mode code from shadow vcpu back to vcpu */ void kvmppc_copy_from_svcpu (struct kvm_vcpu *vcpu,struct kvmppc_book3s_shadow_vcpu *svcpu) { +#ifdef CONFIG_PPC_TRANSACTIONAL_MEM +ulong old_msr; +#endif /* * vcpu_put would just call us again because in_use hasn't * been updated yet.
@@ -230,6 +256,30 @@ void kvmppc_copy_from_svcpu(struct kvm_vcpu *vcpu,to_book3s (vcpu)->vtb +=get_vtb () - vcpu->arch.entry_vtb;if (cpu_has_feature (CPU_FTR_ARCH_207S )) vcpu->arch.ic +=mfspr (SPRN_IC ) - vcpu->arch.entry_ic; + +#ifdef CONFIG_PPC_TRANSACTIONAL_MEM +/* +* Unlike other MSR bits, MSR[TS]bits can be changed at guest without +* notifying host: +* modified by unprivileged instructions like "tbegin"/"tend"/ +* "tresume"/"tsuspend" in PR KVM guest. +* +* It is necessary to sync here to calculate a correct shadow_msr. +* +* privileged guest's tbegin will be failed at present. So we +* only take care of problem state guest. +*/ + old_msr =kvmppc_get_msr (vcpu); +if (unlikely ((old_msr &MSR_PR ) && + (vcpu->arch.shadow_srr1 & (MSR_TS_MASK )) != + (old_msr & (MSR_TS_MASK )))) { + old_msr &= ~(MSR_TS_MASK ); + old_msr |= (vcpu->arch.shadow_srr1 & (MSR_TS_MASK )); +kvmppc_set_msr_fast (vcpu, old_msr); +kvmppc_recalc_shadow_msr (vcpu); + } +#endif + svcpu->in_use = false; out:
@@ -317,29 +367,6 @@ static void kvm_set_spte_hva_pr(struct kvm *kvm, unsigned long hva, pte_t pte)/*****************************************/ -static void kvmppc_recalc_shadow_msr (struct kvm_vcpu *vcpu) -{ -ulong guest_msr =kvmppc_get_msr (vcpu); -ulong smsr = guest_msr; - -/* Guest MSR values */ -#ifdef CONFIG_PPC_TRANSACTIONAL_MEM - smsr &=MSR_FE0 |MSR_FE1 |MSR_SF |MSR_SE |MSR_BE |MSR_LE | -MSR_TM |MSR_TS_MASK ; -#else - smsr &=MSR_FE0 |MSR_FE1 |MSR_SF |MSR_SE |MSR_BE |MSR_LE ; -#endif -/* Process MSR values */ - smsr |=MSR_ME |MSR_RI |MSR_IR |MSR_DR |MSR_PR |MSR_EE ; -/* External providers the guest reserved */ - smsr |= (guest_msr & vcpu->arch.guest_owned_ext); -/* 64-bit Process MSR values */ -#ifdef CONFIG_PPC_BOOK3S_64 - smsr |=MSR_ISF |MSR_HV ; -#endif - vcpu->arch.shadow_msr = smsr; -} -static void kvmppc_set_msr_pr (struct kvm_vcpu *vcpu,u64 msr) {ulong old_msr =kvmppc_get_msr (vcpu);
Signature · 1 line
1.8.3.1
Quoted 11 lines · On Wed, Feb 28, 2018 at 01:37:07AM +0800, [email protected] wrote:
From: Simon Guo <[email protected]>
In current days, many OS distributions have utilized transaction memory functionality. In PowerPC, HV KVM supports TM. But PR KVM does not.
The drive for the transaction memory support of PR KVM is the openstack Continuous Integration testing - They runs a HV(hypervisor) KVM(as level 1) and then run PR KVM(as level 2) on top of that.
This patch set add transaction memory support on PR KVM.
This patch set is starting to look pretty nice. I only have a few comments on some of the patches.
Unfortunately, these patches collide with the patches that have gone upstream to add the hypervisor assistance for TM on POWER9, so some of the patches will need to be rebased (in particular patches 2 and 4).
Paul.
Quoted 11 lines · Paul Mackerras
Quoted 10 lines · On Wed, Feb 28, 2018 at 01:37:07AM +0800, [email protected] wrote:
From: Simon Guo <[email protected]>
In current days, many OS distributions have utilized transaction memory functionality. In PowerPC, HV KVM supports TM. But PR KVM does not.
The drive for the transaction memory support of PR KVM is the openstack Continuous Integration testing - They runs a HV(hypervisor) KVM(as level 1) and then run PR KVM(as level 2) on top of that.
Quoted 8 lines
Quoted 1 line
This patch set add transaction memory support on PR KVM.
This patch set is starting to look pretty nice. I only have a few comments on some of the patches.
Unfortunately, these patches collide with the patches that have gone upstream to add the hypervisor assistance for TM on POWER9, so some of the patches will need to be rebased (in particular patches 2 and 4).
Paul,
Thanks for your kind guide/patience during developing this patch set.
I will rebase and rework your comments.
BR,
- Simon