powernv: Move IDLE_STATE_ENTER_SEQ macro to cpuidle.h
PATCH v3 1/2 powernv: Move IDLE_STATE_ENTER_SEQ macro to cpuidle.h
From: Mahesh Salgaonkar <[email protected]>
Move IDLE_STATE_ENTER_SEQ macro to cpuidle.h so that MCE handler changes in subsequent patch can use it.
No functionality change.
---
Change in v3:
- Rebase to Linus' master.
--- arch/powerpc/include/asm/cpuidle.h | 13 +++++++++++++ arch/powerpc/kernel/idle_book3s.S | 12 ------------ 2 files changed, 13 insertions(+), 12 deletions(-)
arch/powerpc/include/asm/cpuidle.h +13 -0
@@ -19,4 +19,17 @@ extern u64 pnv_first_deep_stop_state;#endif +/* Idle state entry routines */ +#ifdef CONFIG_PPC_P7_NAP +#define IDLE_STATE_ENTER_SEQ (IDLE_INST ) \ +/* Magic NAP/SLEEP/WINKLE mode enter sequence */ \ + std r0,0(r1); \ + ptesync; \ + ld r0,0(r1); \ +1: cmp cr0,r0,r0; \ + bne 1b; \ + IDLE_INST; \ + b . +#endif /* CONFIG_PPC_P7_NAP */ +#endif
arch/powerpc/kernel/idle_book3s.S +0 -12
@@ -44,18 +44,6 @@ PSSCR_PSLL_MASK | PSSCR_TR_MASK | \ PSSCR_MTL_MASK -/* Idle state entry routines */ - -#define IDLE_STATE_ENTER_SEQ(IDLE_INST) \ - /* Magic NAP/SLEEP/WINKLE mode enter sequence */ \ - std r0,0(r1); \ - ptesync; \ - ld r0,0(r1); \ -1: cmp cr0,r0,r0; \ - bne 1b; \ - IDLE_INST; \ - b . - .text /*
PATCH v3 2/2 powernv: Fix MCE handler to avoid trashing CR0/CR1 registers.
From: Mahesh Salgaonkar <[email protected]>
The current implementation of MCE early handling modifies CR0/1 registers without saving its old values. Fix this by moving early check for powersaving mode to machine_check_handle_early().
The power architecture 2.06 or later allows the possibility of getting machine check while in nap/sleep/winkle. The last bit of HSPRG0 is set to 1, if thread is woken up from winkle. Hence, clear the last bit of HSPRG0 (r13) before MCE handler starts using it as paca pointer.
Also, the current code always puts the thread into nap state irrespective of whatever idle state it woke up from. Fix that by looking at paca->thread_idle_state and put the thread back into same state where it came from.
---
Change in v3:
- Rebase to Linus' master.
Change in v2:
- Call IDLE_STATE_ENTER_SEQ(PPC_NAP) instead of power7_enter_nap_mode() to be consistent with other part of code.
--- arch/powerpc/kernel/exceptions-64s.S | 69 ++++++++++++++++++++-------------- 1 file changed, 40 insertions(+), 29 deletions(-)
arch/powerpc/kernel/exceptions-64s.S +40 -29
@@ -144,29 +144,14 @@ machine_check_pSeries_1: * vector */ SET_SCRATCH0(r13) /* save r13 */ -#ifdef CONFIG_PPC_P7_NAP -BEGIN_FTR_SECTION - /* Running native on arch 2.06 or later, check if we are - * waking up from nap. We only handle no state loss and - * supervisor state loss. We do -not- handle hypervisor - * state loss at this time. + /* + * Running native on arch 2.06 or later, we may wakeup from winkle + * inside machine check. If yes, then last bit of HSPGR0 would be set + * to 1. Hence clear it unconditionally. */ - mfspr r13,SPRN_SRR1 - rlwinm. r13,r13,47-31,30,31 - OPT_GET_SPR(r13, SPRN_CFAR, CPU_FTR_CFAR) - beq 9f - - mfspr r13,SPRN_SRR1 - rlwinm. r13,r13,47-31,30,31 - /* waking up from powersave (nap) state */ - cmpwi cr1,r13,2 - /* Total loss of HV state is fatal. let's just stay stuck here */ - OPT_GET_SPR(r13, SPRN_CFAR, CPU_FTR_CFAR) - bgt cr1,. -9: - OPT_SET_SPR(r13, SPRN_CFAR, CPU_FTR_CFAR) -END_FTR_SECTION_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_206) -#endif /* CONFIG_PPC_P7_NAP */ + GET_PACA(r13) + clrrdi r13,r13,1 + SET_PACA(r13) EXCEPTION_PROLOG_0(PACA_EXMC) BEGIN_FTR_SECTION b machine_check_powernv_early
@@ -1273,25 +1258,51 @@ machine_check_handle_early: * Check if thread was in power saving mode. We come here when any * of the following is true: * a. thread wasn't in power saving mode - * b. thread was in power saving mode with no state loss or - * supervisor state loss + * b. thread was in power saving mode with no state loss, + * supervisor state loss or hypervisor state loss. * - * Go back to nap again if (b) is true. + * Go back to nap/sleep/winkle mode again if (b) is true. */ rlwinm. r11,r12,47-31,30,31 /* Was it in power saving mode? */ beq 4f /* No, it wasn;t */ /* Thread was in power saving mode. Go back to nap again. */ cmpwi r11,2 - bne 3f - /* Supervisor state loss */ + blt 3f + /* Supervisor/Hypervisor state loss */ li r0,1 stb r0,PACA_NAPSTATELOST(r13) 3: bl machine_check_queue_event MACHINE_CHECK_HANDLER_WINDUP GET_PACA(r13) ld r1,PACAR1(r13) - li r3,PNV_THREAD_NAP - b pnv_enter_arch207_idle_mode + /* + * Check what idle state this CPU was in and go back to same mode + * again. + */ + lbz r3,PACA_THREAD_IDLE_STATE(r13) + cmpwi r3,PNV_THREAD_NAP + bgt 10f + IDLE_STATE_ENTER_SEQ(PPC_NAP) + /* No return */ +10: + cmpwi r3,PNV_THREAD_SLEEP + bgt 2f + IDLE_STATE_ENTER_SEQ(PPC_SLEEP) + /* No return */ + +2: + /* + * Go back to winkle. Please note that this thread was woken up in + * machine check from winkle and have not restored the per-subcore + * state. Hence before going back to winkle, set last bit of HSPGR0 + * to 1. This will make sure that if this thread gets woken up + * again at reset vector 0x100 then it will get chance to restore + * the subcore state. + */ + ori r13,r13,1 + SET_PACA(r13) + IDLE_STATE_ENTER_SEQ(PPC_WINKLE) + /* No return */ 4: #endif /*
Re: [PATCH v3 2/2] powernv: Fix MCE handler to avoid trashing CR0/CR1 registers.
Quoted 6 lines · Mahesh J Salgaonkar
From: Mahesh Salgaonkar <[email protected]>
The current implementation of MCE early handling modifies CR0/1 registers
without saving its old values. Fix this by moving early check for powersaving mode tomachine_check_handle_early().
CC stable ?
Quoted 142 lines
The power architecture 2.06 or later allows the possibility of getting
machine check while in nap/sleep/winkle. The last bit of HSPRG0 is set
to 1, if thread is woken up from winkle. Hence, clear the last bit of HSPRG0 (r13) before MCE handler starts using it as paca pointer.Also, the current code always puts the thread into nap state irrespective
of whatever idle state it woke up from. Fix that by looking atpaca->thread_idle_stateand put the thread back into same state where it
came from.Reported-by Paul Mackerras <[email protected]>Signed-off-by Mahesh Salgaonkar <[email protected]>Reviewed-by Shreyas B. Prabhu <[email protected]>---
Change in v3:
- Rebase to Linus' master.Change in v2:
- CallIDLE_STATE_ENTER_SEQ(PPC_NAP)instead ofpower7_enter_nap_mode()
to be consistent with other part of code.
---
arch/powerpc/kernel/exceptions-64s.S | 69 ++++++++++++++++++++--
------------1 file changed, 40 insertions(+), 29 deletions(-)arch/powerpc/kernel/exceptions-64s.S +0
-0@@ -144,29 +144,14 @@ machine_check_pSeries_1: * vector */
SET_SCRATCH0(r13)/* save r13 */arch/powerpc/kernel/exceptions-64s.S +2
-6-#ifdef CONFIG_PPC_P7_NAP -BEGIN_FTR_SECTION - /* Running native on arch 2.06 or later, check if we are - * waking up from nap. We only handle no state loss and - * supervisor state loss. We do -not- handle hypervisor - * state loss at this time. + /* + * Running native on arch 2.06 or later, we may wakeup fromwinkle
arch/powerpc/kernel/exceptions-64s.S +1
-0+ * inside machine check. If yes, then last bit of HSPGR0would be set
arch/powerpc/kernel/exceptions-64s.S +1
-0+ * to 1. Hence clear it unconditionally.*/
arch/powerpc/kernel/exceptions-64s.S +0
-10- mfspr r13,SPRN_SRR1 - rlwinm. r13,r13,47-31,30,31 - OPT_GET_SPR(r13, SPRN_CFAR, CPU_FTR_CFAR) - beq 9f - - mfspr r13,SPRN_SRR1 - rlwinm. r13,r13,47-31,30,31 - /* waking up from powersave (nap) state */ - cmpwi cr1,r13,2 - /* Total loss of HV state is fatal. let's just stay stuckhere */
arch/powerpc/kernel/exceptions-64s.S +3
-6- OPT_GET_SPR(r13, SPRN_CFAR, CPU_FTR_CFAR) - bgt cr1,. -9: - OPT_SET_SPR(r13, SPRN_CFAR, CPU_FTR_CFAR) -END_FTR_SECTION_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_206) -#endif /* CONFIG_PPC_P7_NAP */ + GET_PACA(r13) + clrrdi r13,r13,1 + SET_PACA(r13)
EXCEPTION_PROLOG_0(PACA_EXMC)
BEGIN_FTR_SECTION
bmachine_check_powernv_earlyarch/powerpc/kernel/exceptions-64s.S +0
-0@@ -1273,25 +1258,51 @@ machine_check_handle_early: * Check if thread was in power saving mode. We come herewhen any
* of the following is true:
* a. thread wasn't in power saving modearch/powerpc/kernel/exceptions-64s.S +2
-2- * b. thread was in power saving mode with no state loss or - * supervisor state loss + * b. thread was in power saving mode with no state loss, + * supervisor state loss or hypervisor state loss.*
arch/powerpc/kernel/exceptions-64s.S +1
-1- * Go back to nap again if (b) is true. + * Go back to nap/sleep/winkle mode again if (b) is true.*/
rlwinm. r11,r12,47-31,30,31 /* Was it in power
saving mode? */
beq 4f /* No, it wasn;t */
/* Thread was in power saving mode. Go back to nap again. */
cmpwi r11,2arch/powerpc/kernel/exceptions-64s.S +2
-2- bne 3f - /* Supervisor state loss */ + blt 3f + /* Supervisor/Hypervisor state loss */li r0,1
stb r0,PACA_NAPSTATELOST(r13)
3: blmachine_check_queue_event
MACHINE_CHECK_HANDLER_WINDUP
GET_PACA(r13)
ld r1,PACAR1(r13)arch/powerpc/kernel/exceptions-64s.S +2
-2- li r3,PNV_THREAD_NAP - b pnv_enter_arch207_idle_mode + /* + * Check what idle state this CPU was in and go back to samemode
arch/powerpc/kernel/exceptions-64s.S +16
-0+ * again. + */ + lbz r3,PACA_THREAD_IDLE_STATE(r13) + cmpwi r3,PNV_THREAD_NAP + bgt 10f + IDLE_STATE_ENTER_SEQ(PPC_NAP) + /* No return */ +10: + cmpwi r3,PNV_THREAD_SLEEP + bgt 2f + IDLE_STATE_ENTER_SEQ(PPC_SLEEP) + /* No return */ + +2: + /* + * Go back to winkle. Please note that this thread was wokenup in
arch/powerpc/kernel/exceptions-64s.S +1
-0+ * machine check from winkle and have not restored the per-subcore
arch/powerpc/kernel/exceptions-64s.S +1
-0+ * state. Hence before going back to winkle, set last bit ofHSPGR0
arch/powerpc/kernel/exceptions-64s.S +1
-0+ * to 1. This will make sure that if this thread gets wokenup
arch/powerpc/kernel/exceptions-64s.S +1
-0+ * again at reset vector 0x100 then it will get chance torestore
arch/powerpc/kernel/exceptions-64s.S +6
-0+ * the subcore state. + */ + ori r13,r13,1 + SET_PACA(r13) + IDLE_STATE_ENTER_SEQ(PPC_WINKLE) + /* No return */4:
#endif
/*
Michael Ellerman
AppliedRe: [v3, 2/2] powernv: Fix MCE handler to avoid trashing CR0/CR1 registers.
In reply to Mahesh J SalgaonkarQuoted 11 lines · Mahesh Salgaonkar
From: Mahesh Salgaonkar <[email protected]>
The current implementation of MCE early handling modifies CR0/1 registers without saving its old values. Fix this by moving early check for powersaving mode to
machine_check_handle_early().The power architecture 2.06 or later allows the possibility of getting machine check while in nap/sleep/winkle. The last bit of HSPRG0 is set to 1, if thread is woken up from winkle. Hence, clear the last bit of HSPRG0 (r13) before MCE handler starts using it as paca pointer.
Quoted 8 lines
Also, the current code always puts the thread into nap state irrespective of whatever idle state it woke up from. Fix that by looking at
paca->thread_idle_stateand put the thread back into same state where it came from.Reported-by Paul Mackerras <[email protected]>Signed-off-by Mahesh Salgaonkar <[email protected]>Reviewed-by Shreyas B. Prabhu <[email protected]>
Applied to powerpc fixes, thanks.
https://git.kernel.org/powerpc/c/bc14c49195e49b3231c01e4c44
cheers
Michael Ellerman
AppliedQuoted 8 lines · Mahesh Salgaonkar
From: Mahesh Salgaonkar <[email protected]>
Move
IDLE_STATE_ENTER_SEQmacro tocpuidle.hso that MCE handler changes in subsequent patch can use it.No functionality change.
Signed-off-by Mahesh Salgaonkar <[email protected]>
Applied to powerpc fixes, thanks.
https://git.kernel.org/powerpc/c/98d8821a47f3fd7354d3ab87ad
cheers