Skip to content

Commit 6d98ce0

Browse files
npigginmpe
authored andcommitted
powerpc/64s: Fix idle wakeup potential to clobber registers
We concluded there may be a window where the idle wakeup code could get to pnv_wakeup_tb_loss() (which clobbers non-volatile GPRs), but the hardware may set SRR1[46:47] to 01b (no state loss) which would result in the wakeup code failing to restore non-volatile GPRs. I was not able to trigger this condition with trivial tests on real hardware or simulator, but the ISA (at least 2.07) seems to allow for it, and Gautham says that it can happen if there is an exception pending when the sleep/winkle instruction is executed. Fixes: 1706567 ("powerpc/kvm: make hypervisor state restore a function") Cc: [email protected] # v4.8+ Signed-off-by: Nicholas Piggin <[email protected]> Acked-by: Gautham R. Shenoy <[email protected]> Signed-off-by: Michael Ellerman <[email protected]>
1 parent 07f5ab6 commit 6d98ce0

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

arch/powerpc/kernel/idle_book3s.S

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -449,9 +449,23 @@ END_FTR_SECTION_IFSET(CPU_FTR_ARCH_300)
449449
_GLOBAL(pnv_wakeup_tb_loss)
450450
ld r1,PACAR1(r13)
451451
/*
452-
* Before entering any idle state, the NVGPRs are saved in the stack
453-
* and they are restored before switching to the process context. Hence
454-
* until they are restored, they are free to be used.
452+
* Before entering any idle state, the NVGPRs are saved in the stack.
453+
* If there was a state loss, or PACA_NAPSTATELOST was set, then the
454+
* NVGPRs are restored. If we are here, it is likely that state is lost,
455+
* but not guaranteed -- neither ISA207 nor ISA300 tests to reach
456+
* here are the same as the test to restore NVGPRS:
457+
* PACA_THREAD_IDLE_STATE test for ISA207, PSSCR test for ISA300,
458+
* and SRR1 test for restoring NVGPRs.
459+
*
460+
* We are about to clobber NVGPRs now, so set NAPSTATELOST to
461+
* guarantee they will always be restored. This might be tightened
462+
* with careful reading of specs (particularly for ISA300) but this
463+
* is already a slow wakeup path and it's simpler to be safe.
464+
*/
465+
li r0,1
466+
stb r0,PACA_NAPSTATELOST(r13)
467+
468+
/*
455469
*
456470
* Save SRR1 and LR in NVGPRs as they might be clobbered in
457471
* opal_call() (called in CHECK_HMI_INTERRUPT). SRR1 is required

0 commit comments

Comments
 (0)