Skip to content

Commit 267cdfa

Browse files
npigginmpe
authored andcommitted
KVM: PPC: Book3S HV: Tolerate treclaim. in fake-suspend mode changing registers
POWER9 DD2.2 and 2.3 hardware implements a "fake-suspend" mode where certain TM instructions executed in HV=0 mode cause softpatch interrupts so the hypervisor can emulate them and prevent problematic processor conditions. In this fake-suspend mode, the treclaim. instruction does not modify registers. Unfortunately the rfscv instruction executed by the guest do not generate softpatch interrupts, which can cause the hypervisor to lose track of the fake-suspend mode, and it can execute this treclaim. while not in fake-suspend mode. This modifies GPRs and crashes the hypervisor. It's not trivial to disable scv in the guest with HFSCR now, because they assume a POWER9 has scv available. So this fix saves and restores checkpointed registers across the treclaim. Fixes: 7854f75 ("KVM: PPC: Book3S: Rework TM save/restore code and make it C-callable") Signed-off-by: Nicholas Piggin <[email protected]> Signed-off-by: Michael Ellerman <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent ae7aaec commit 267cdfa

File tree

1 file changed

+34
-2
lines changed

1 file changed

+34
-2
lines changed

arch/powerpc/kvm/book3s_hv_rmhandlers.S

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2536,7 +2536,7 @@ END_FTR_SECTION_IFCLR(CPU_FTR_P9_TM_HV_ASSIST)
25362536
/* The following code handles the fake_suspend = 1 case */
25372537
mflr r0
25382538
std r0, PPC_LR_STKOFF(r1)
2539-
stdu r1, -PPC_MIN_STKFRM(r1)
2539+
stdu r1, -TM_FRAME_SIZE(r1)
25402540

25412541
/* Turn on TM. */
25422542
mfmsr r8
@@ -2551,10 +2551,42 @@ BEGIN_FTR_SECTION
25512551
END_FTR_SECTION_IFSET(CPU_FTR_P9_TM_XER_SO_BUG)
25522552
nop
25532553

2554+
/*
2555+
* It's possible that treclaim. may modify registers, if we have lost
2556+
* track of fake-suspend state in the guest due to it using rfscv.
2557+
* Save and restore registers in case this occurs.
2558+
*/
2559+
mfspr r3, SPRN_DSCR
2560+
mfspr r4, SPRN_XER
2561+
mfspr r5, SPRN_AMR
2562+
/* SPRN_TAR would need to be saved here if the kernel ever used it */
2563+
mfcr r12
2564+
SAVE_NVGPRS(r1)
2565+
SAVE_GPR(2, r1)
2566+
SAVE_GPR(3, r1)
2567+
SAVE_GPR(4, r1)
2568+
SAVE_GPR(5, r1)
2569+
stw r12, 8(r1)
2570+
std r1, HSTATE_HOST_R1(r13)
2571+
25542572
/* We have to treclaim here because that's the only way to do S->N */
25552573
li r3, TM_CAUSE_KVM_RESCHED
25562574
TRECLAIM(R3)
25572575

2576+
GET_PACA(r13)
2577+
ld r1, HSTATE_HOST_R1(r13)
2578+
REST_GPR(2, r1)
2579+
REST_GPR(3, r1)
2580+
REST_GPR(4, r1)
2581+
REST_GPR(5, r1)
2582+
lwz r12, 8(r1)
2583+
REST_NVGPRS(r1)
2584+
mtspr SPRN_DSCR, r3
2585+
mtspr SPRN_XER, r4
2586+
mtspr SPRN_AMR, r5
2587+
mtcr r12
2588+
HMT_MEDIUM
2589+
25582590
/*
25592591
* We were in fake suspend, so we are not going to save the
25602592
* register state as the guest checkpointed state (since
@@ -2582,7 +2614,7 @@ END_FTR_SECTION_IFSET(CPU_FTR_P9_TM_XER_SO_BUG)
25822614
std r5, VCPU_TFHAR(r9)
25832615
std r6, VCPU_TFIAR(r9)
25842616

2585-
addi r1, r1, PPC_MIN_STKFRM
2617+
addi r1, r1, TM_FRAME_SIZE
25862618
ld r0, PPC_LR_STKOFF(r1)
25872619
mtlr r0
25882620
blr

0 commit comments

Comments
 (0)