Skip to content

Commit 681c617

Browse files
paulusmackmpe
authored andcommitted
KVM: PPC: Book3S HV: Work around TEXASR bug in fake suspend state
This works around a hardware bug in "Nimbus" POWER9 DD2.2 processors, where the contents of the TEXASR can get corrupted while a thread is in fake suspend state. The workaround is for the instruction emulation code to use the value saved at the most recent guest exit in real suspend mode. We achieve this by simply not saving the TEXASR into the vcpu struct on an exit in fake suspend state. We also have to take care to set the orig_texasr field only on guest exit in real suspend state. This also means that on guest entry in fake suspend state, TEXASR will be restored to the value it had on the last exit in real suspend state, effectively counteracting any hardware-caused corruption. This works because TEXASR may not be written in suspend state. With this, the guest might see the wrong values in TEXASR if it reads it while in suspend state, but will see the correct value in non-transactional state (e.g. after a treclaim), and treclaim will work correctly. With this workaround, the code will actually run slightly faster, and will operate correctly on systems without the TEXASR bug (since TEXASR may not be written in suspend state, and is only changed by failure recording, which will have already been done before we get into fake suspend state). Therefore these changes are not made subject to a CPU feature bit. Signed-off-by: Paul Mackerras <[email protected]> Signed-off-by: Michael Ellerman <[email protected]>
1 parent 87a11bb commit 681c617

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

arch/powerpc/kvm/book3s_hv_rmhandlers.S

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3117,10 +3117,6 @@ kvmppc_save_tm:
31173117
li r3, TM_CAUSE_KVM_RESCHED
31183118

31193119
BEGIN_FTR_SECTION
3120-
/* Emulation of the treclaim instruction needs TEXASR before treclaim */
3121-
mfspr r6, SPRN_TEXASR
3122-
std r6, VCPU_ORIG_TEXASR(r9)
3123-
31243120
lbz r0, HSTATE_FAKE_SUSPEND(r13) /* Were we fake suspended? */
31253121
cmpwi r0, 0
31263122
beq 3f
@@ -3130,7 +3126,12 @@ BEGIN_FTR_SECTION_NESTED(96)
31303126
bl pnv_power9_force_smt4_catch
31313127
END_FTR_SECTION_NESTED(CPU_FTR_P9_TM_XER_SO_BUG, CPU_FTR_P9_TM_XER_SO_BUG, 96)
31323128
nop
3129+
b 6f
31333130
3:
3131+
/* Emulation of the treclaim instruction needs TEXASR before treclaim */
3132+
mfspr r6, SPRN_TEXASR
3133+
std r6, VCPU_ORIG_TEXASR(r9)
3134+
6:
31343135
END_FTR_SECTION_IFSET(CPU_FTR_P9_TM_HV_ASSIST)
31353136

31363137
/* Clear the MSR RI since r1, r13 are all going to be foobar. */
@@ -3176,7 +3177,8 @@ END_FTR_SECTION_NESTED(CPU_FTR_P9_TM_XER_SO_BUG, CPU_FTR_P9_TM_XER_SO_BUG, 96)
31763177
andc r3, r3, r0
31773178
mtspr SPRN_PSSCR, r3
31783179
ld r9, HSTATE_KVM_VCPU(r13)
3179-
b 1f
3180+
/* Don't save TEXASR, use value from last exit in real suspend state */
3181+
b 11f
31803182
2:
31813183
END_FTR_SECTION_IFSET(CPU_FTR_P9_TM_HV_ASSIST)
31823184

@@ -3250,12 +3252,13 @@ END_FTR_SECTION_IFSET(CPU_FTR_P9_TM_HV_ASSIST)
32503252
* change these outside of a transaction, so they must always be
32513253
* context switched.
32523254
*/
3255+
mfspr r7, SPRN_TEXASR
3256+
std r7, VCPU_TEXASR(r9)
3257+
11:
32533258
mfspr r5, SPRN_TFHAR
32543259
mfspr r6, SPRN_TFIAR
3255-
mfspr r7, SPRN_TEXASR
32563260
std r5, VCPU_TFHAR(r9)
32573261
std r6, VCPU_TFIAR(r9)
3258-
std r7, VCPU_TEXASR(r9)
32593262

32603263
addi r1, r1, PPC_MIN_STKFRM
32613264
ld r0, PPC_LR_STKOFF(r1)

0 commit comments

Comments
 (0)