Skip to content

Commit 1945bc4

Browse files
npigginmpe
authored andcommitted
powerpc/64s: Fix POWER9 machine check handler from stop state
The ISA specifies power save wakeup due to a machine check exception can cause a machine check interrupt (rather than the usual system reset interrupt). The machine check handler copes with this by doing low level machine check recovery without restoring full state from idle, then queues up a machine check event for logging, then directly executes the same idle instruction it woke from. This minimises the work done before recovery is performed. The problem is that it requires machine specific instructions and knowledge of the book3s idle code. Currently it only has code to handle POWER8 idle, so POWER9 crashes when trying to execute the P8 idle instructions which don't exist in ISAv3.0B. cpu 0x0: Vector: e40 (Emulation Assist) at [c0000000008f3810] pc: c000000000008380: machine_check_handle_early+0x130/0x2f0 lr: c00000000053a098: stop_loop+0x68/0xd0 sp: c0000000008f3a90 msr: 9000000000081001 current = 0xc0000000008a1080 paca = 0xc00000000ffd0000 softe: 0 irq_happened: 0x01 pid = 0, comm = swapper/0 Instead of going to sleep after recovery, do the usual idle wakeup and state restoration by calling into the normal idle wakeup path. This reuses the normal idle wakeup paths. Reviewed-by: Gautham R. Shenoy <[email protected]> Reviewed-by: Mahesh J Salgaonkar <[email protected]> Signed-off-by: Nicholas Piggin <[email protected]> Signed-off-by: Michael Ellerman <[email protected]>
1 parent 10101aa commit 1945bc4

File tree

3 files changed

+70
-35
lines changed

3 files changed

+70
-35
lines changed

arch/powerpc/include/asm/reg.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,7 @@
659659
#define SRR1_ISI_PROT 0x08000000 /* ISI: Other protection fault */
660660
#define SRR1_WAKEMASK 0x00380000 /* reason for wakeup */
661661
#define SRR1_WAKEMASK_P8 0x003c0000 /* reason for wakeup on POWER8 and 9 */
662+
#define SRR1_WAKEMCE_RESVD 0x003c0000 /* Unused/reserved value used by MCE wakeup to indicate cause to idle wakeup handler */
662663
#define SRR1_WAKESYSERR 0x00300000 /* System error */
663664
#define SRR1_WAKEEE 0x00200000 /* External interrupt */
664665
#define SRR1_WAKEHVI 0x00240000 /* Hypervisor Virtualization Interrupt (P9) */

arch/powerpc/kernel/exceptions-64s.S

Lines changed: 44 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,12 @@ BEGIN_FTR_SECTION
178178
* NOTE: We are here with MSR_ME=0 (off), which means we risk a
179179
* checkstop if we get another machine check exception before we do
180180
* rfid with MSR_ME=1.
181+
*
182+
* This interrupt can wake directly from idle. If that is the case,
183+
* the machine check is handled then the idle wakeup code is called
184+
* to restore state. In that case, the POWER9 DD1 idle PACA workaround
185+
* is not applied in the early machine check code, which will cause
186+
* bugs.
181187
*/
182188
mr r11,r1 /* Save r1 */
183189
lhz r10,PACA_IN_MCE(r13)
@@ -306,6 +312,37 @@ EXC_COMMON_BEGIN(machine_check_common)
306312
/* restore original r1. */ \
307313
ld r1,GPR1(r1)
308314

315+
#ifdef CONFIG_PPC_P7_NAP
316+
/*
317+
* This is an idle wakeup. Low level machine check has already been
318+
* done. Queue the event then call the idle code to do the wake up.
319+
*/
320+
EXC_COMMON_BEGIN(machine_check_idle_common)
321+
bl machine_check_queue_event
322+
323+
/*
324+
* We have not used any non-volatile GPRs here, and as a rule
325+
* most exception code including machine check does not.
326+
* Therefore PACA_NAPSTATELOST does not need to be set. Idle
327+
* wakeup will restore volatile registers.
328+
*
329+
* Load the original SRR1 into r3 for pnv_powersave_wakeup_mce.
330+
*
331+
* Then decrement MCE nesting after finishing with the stack.
332+
*/
333+
ld r3,_MSR(r1)
334+
335+
lhz r11,PACA_IN_MCE(r13)
336+
subi r11,r11,1
337+
sth r11,PACA_IN_MCE(r13)
338+
339+
/* Turn off the RI bit because SRR1 is used by idle wakeup code. */
340+
/* Recoverability could be improved by reducing the use of SRR1. */
341+
li r11,0
342+
mtmsrd r11,1
343+
344+
b pnv_powersave_wakeup_mce
345+
#endif
309346
/*
310347
* Handle machine check early in real mode. We come here with
311348
* ME=1, MMU (IR=0 and DR=0) off and using MC emergency stack.
@@ -318,6 +355,7 @@ EXC_COMMON_BEGIN(machine_check_handle_early)
318355
bl machine_check_early
319356
std r3,RESULT(r1) /* Save result */
320357
ld r12,_MSR(r1)
358+
321359
#ifdef CONFIG_PPC_P7_NAP
322360
/*
323361
* Check if thread was in power saving mode. We come here when any
@@ -328,43 +366,14 @@ EXC_COMMON_BEGIN(machine_check_handle_early)
328366
*
329367
* Go back to nap/sleep/winkle mode again if (b) is true.
330368
*/
331-
rlwinm. r11,r12,47-31,30,31 /* Was it in power saving mode? */
332-
beq 4f /* No, it wasn't */
333-
/* Thread was in power saving mode. Go back to nap again. */
334-
cmpwi r11,2
335-
blt 3f
336-
/* Supervisor/Hypervisor state loss */
337-
li r0,1
338-
stb r0,PACA_NAPSTATELOST(r13)
339-
3: bl machine_check_queue_event
340-
MACHINE_CHECK_HANDLER_WINDUP
341-
GET_PACA(r13)
342-
ld r1,PACAR1(r13)
343-
/*
344-
* Check what idle state this CPU was in and go back to same mode
345-
* again.
346-
*/
347-
lbz r3,PACA_THREAD_IDLE_STATE(r13)
348-
cmpwi r3,PNV_THREAD_NAP
349-
bgt 10f
350-
IDLE_STATE_ENTER_SEQ_NORET(PPC_NAP)
351-
/* No return */
352-
10:
353-
cmpwi r3,PNV_THREAD_SLEEP
354-
bgt 2f
355-
IDLE_STATE_ENTER_SEQ_NORET(PPC_SLEEP)
356-
/* No return */
357-
358-
2:
359-
/*
360-
* Go back to winkle. Please note that this thread was woken up in
361-
* machine check from winkle and have not restored the per-subcore
362-
* state.
363-
*/
364-
IDLE_STATE_ENTER_SEQ_NORET(PPC_WINKLE)
365-
/* No return */
369+
BEGIN_FTR_SECTION
370+
rlwinm. r11,r12,47-31,30,31
371+
beq- 4f
372+
BRANCH_TO_COMMON(r10, machine_check_idle_common)
366373
4:
374+
END_FTR_SECTION_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_206)
367375
#endif
376+
368377
/*
369378
* Check if we are coming from hypervisor userspace. If yes then we
370379
* continue in host kernel in V mode to deliver the MC event.

arch/powerpc/kernel/idle_book3s.S

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,31 @@ power9_dd1_recover_paca:
415415
stb r0,PACA_NAPSTATELOST(r13)
416416
blr
417417

418+
/*
419+
* Called from machine check handler for powersave wakeups.
420+
* Low level machine check processing has already been done. Now just
421+
* go through the wake up path to get everything in order.
422+
*
423+
* r3 - The original SRR1 value.
424+
* Original SRR[01] have been clobbered.
425+
* MSR_RI is clear.
426+
*/
427+
.global pnv_powersave_wakeup_mce
428+
pnv_powersave_wakeup_mce:
429+
/* Set cr3 for pnv_powersave_wakeup */
430+
rlwinm r11,r3,47-31,30,31
431+
cmpwi cr3,r11,2
432+
433+
/*
434+
* Now put the original SRR1 with SRR1_WAKEMCE_RESVD as the wake
435+
* reason into SRR1, which allows reuse of the system reset wakeup
436+
* code without being mistaken for another type of wakeup.
437+
*/
438+
oris r3,r3,SRR1_WAKEMCE_RESVD@h
439+
mtspr SPRN_SRR1,r3
440+
441+
b pnv_powersave_wakeup
442+
418443
/*
419444
* Called from reset vector for powersave wakeups.
420445
* cr3 - set to gt if waking up with partial/complete hypervisor state loss

0 commit comments

Comments
 (0)