From: Nicholas Piggin <npiggin@gmail.com>
To: linuxppc-dev@lists.ozlabs.org
Cc: Nicholas Piggin <npiggin@gmail.com>
Subject: [PATCH 05/10] powerpc/64s: dedicated system reset interrupt stack
Date: Tue, 20 Dec 2016 04:30:06 +1000 [thread overview]
Message-ID: <20161219183011.28310-6-npiggin@gmail.com> (raw)
In-Reply-To: <20161219183011.28310-1-npiggin@gmail.com>
The system reset interrupt is used for crash/debug situations, so it is
desirable to have as little impact on the normal state of the system as
possible.
Currently it uses the current kernel stack to process the exception.
This stores into the stack which may be involved with the crash. The
stack pointer may be corrupted, or it may have overflowed.
Avoid or minimise these problems by creating a dedicated NMI stack for
the system reset interrupt to use.
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
arch/powerpc/include/asm/exception-64s.h | 13 +++++++++++++
arch/powerpc/include/asm/paca.h | 3 ++-
arch/powerpc/kernel/asm-offsets.c | 1 +
arch/powerpc/kernel/exceptions-64s.S | 8 +++++---
arch/powerpc/kernel/setup_64.c | 5 +++++
arch/powerpc/xmon/xmon.c | 1 +
6 files changed, 27 insertions(+), 4 deletions(-)
diff --git a/arch/powerpc/include/asm/exception-64s.h b/arch/powerpc/include/asm/exception-64s.h
index 7e47fb67c696..7884d9263b98 100644
--- a/arch/powerpc/include/asm/exception-64s.h
+++ b/arch/powerpc/include/asm/exception-64s.h
@@ -542,6 +542,19 @@ END_FTR_SECTION_IFSET(CPU_FTR_CTRL)
bl hdlr; \
b ret
+/*
+ * Exception where stack is already set in r1, r1 is saved in r10, and it
+ * continues rather than returns.
+ */
+#define EXCEPTION_COMMON_NORET_STACK(area, trap, label, hdlr, additions) \
+ EXCEPTION_PROLOG_COMMON_1(); \
+ EXCEPTION_PROLOG_COMMON_2(area); \
+ EXCEPTION_PROLOG_COMMON_3(trap); \
+ /* Volatile regs are potentially clobbered here */ \
+ additions; \
+ addi r3,r1,STACK_FRAME_OVERHEAD; \
+ bl hdlr
+
#define STD_EXCEPTION_COMMON(trap, label, hdlr) \
EXCEPTION_COMMON(PACA_EXGEN, trap, label, hdlr, \
ret_from_except, ADD_NVGPRS;ADD_RECONCILE)
diff --git a/arch/powerpc/include/asm/paca.h b/arch/powerpc/include/asm/paca.h
index 98da152b257b..c4887c67157b 100644
--- a/arch/powerpc/include/asm/paca.h
+++ b/arch/powerpc/include/asm/paca.h
@@ -179,7 +179,8 @@ struct paca_struct {
u64 exmc[13]; /* used for machine checks */
#endif
#ifdef CONFIG_PPC_BOOK3S_64
- /* Exclusive emergency stack pointer for machine check exception. */
+ /* Exclusive stacks for system reset and machine check exception. */
+ void *nmi_emergency_sp;
void *mc_emergency_sp;
u16 in_nmi; /* In nmi handler */
diff --git a/arch/powerpc/kernel/asm-offsets.c b/arch/powerpc/kernel/asm-offsets.c
index 893da286ecc3..ba1e3bb09f9f 100644
--- a/arch/powerpc/kernel/asm-offsets.c
+++ b/arch/powerpc/kernel/asm-offsets.c
@@ -242,6 +242,7 @@ int main(void)
#endif /* CONFIG_PPC_STD_MMU_64 */
DEFINE(PACAEMERGSP, offsetof(struct paca_struct, emergency_sp));
#ifdef CONFIG_PPC_BOOK3S_64
+ DEFINE(PACANMIEMERGSP, offsetof(struct paca_struct, nmi_emergency_sp));
DEFINE(PACAMCEMERGSP, offsetof(struct paca_struct, mc_emergency_sp));
DEFINE(PACA_IN_MCE, offsetof(struct paca_struct, in_mce));
DEFINE(PACA_IN_NMI, offsetof(struct paca_struct, in_nmi));
diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
index 4034f7db73b7..59f1a53f45c7 100644
--- a/arch/powerpc/kernel/exceptions-64s.S
+++ b/arch/powerpc/kernel/exceptions-64s.S
@@ -170,10 +170,12 @@ EXC_COMMON_BEGIN(system_reset_common)
li r10,MSR_RI
mtmsrd r10,1
- EXCEPTION_COMMON(PACA_EXNMI, 0x100,
- system_reset, system_reset_exception, 1f,
+ mr r10,r1
+ ld r1,PACANMIEMERGSP(r13)
+ subi r1,r1,INT_FRAME_SIZE
+ EXCEPTION_COMMON_NORET_STACK(PACA_EXNMI, 0x100,
+ system_reset, system_reset_exception,
ADD_NVGPRS;ADD_RECONCILE)
-1: /* EXCEPTION_COMMON continues here */
/*
* The stack is no longer in use, decrement in_nmi.
diff --git a/arch/powerpc/kernel/setup_64.c b/arch/powerpc/kernel/setup_64.c
index 6824157e4d2e..0823064c57c1 100644
--- a/arch/powerpc/kernel/setup_64.c
+++ b/arch/powerpc/kernel/setup_64.c
@@ -573,6 +573,11 @@ void __init emergency_stack_init(void)
paca[i].emergency_sp = (void *)ti + THREAD_SIZE;
#ifdef CONFIG_PPC_BOOK3S_64
+ /* emergency stack for NMI exception handling. */
+ ti = __va(memblock_alloc_base(THREAD_SIZE, THREAD_SIZE, limit));
+ klp_init_thread_info(ti);
+ paca[i].nmi_emergency_sp = (void *)ti + THREAD_SIZE;
+
/* emergency stack for machine check exception handling. */
ti = __va(memblock_alloc_base(THREAD_SIZE, THREAD_SIZE, limit));
klp_init_thread_info(ti);
diff --git a/arch/powerpc/xmon/xmon.c b/arch/powerpc/xmon/xmon.c
index 832cbc097416..77a88319f494 100644
--- a/arch/powerpc/xmon/xmon.c
+++ b/arch/powerpc/xmon/xmon.c
@@ -2227,6 +2227,7 @@ static void dump_one_paca(int cpu)
DUMP(p, kernel_msr, "lx");
DUMP(p, emergency_sp, "p");
#ifdef CONFIG_PPC_BOOK3S_64
+ DUMP(p, nmi_emergency_sp, "p");
DUMP(p, mc_emergency_sp, "p");
DUMP(p, in_nmi, "x");
DUMP(p, in_mce, "x");
--
2.11.0
next prev parent reply other threads:[~2016-12-19 18:30 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-12-19 18:30 [PATCH 00/10] Improving debugging with NMIs Nicholas Piggin
2016-12-19 18:30 ` [PATCH 01/10] powerpc/64s: add exception macro that does not enable RI Nicholas Piggin
2017-05-01 2:58 ` [01/10] " Michael Ellerman
2016-12-19 18:30 ` [PATCH 02/10] powerpc/64s: exception macro for stack frame and initial register save Nicholas Piggin
2016-12-19 18:30 ` [PATCH 03/10] powerpc/64s: fix system reset vs general interrupt reentrancy Nicholas Piggin
2016-12-19 18:30 ` [PATCH 04/10] powerpc/64s: disallow system reset vs system reset reentrancy Nicholas Piggin
2016-12-19 18:30 ` Nicholas Piggin [this message]
2016-12-19 18:30 ` [PATCH 06/10] powerpc: nmi_enter for system reset Nicholas Piggin
2017-02-07 4:06 ` Michael Ellerman
2016-12-19 18:30 ` [PATCH 07/10] powerpc: add NMI IPI infrastructure Nicholas Piggin
2017-02-03 11:45 ` Nicholas Piggin
2017-02-04 2:49 ` Nicholas Piggin
2016-12-19 18:30 ` [PATCH 08/10] powerpc: add struct smp_ops_t.cause_nmi_ipi operation Nicholas Piggin
2016-12-19 18:30 ` [PATCH 09/10] powerpc/pseries: implement NMI IPI with H_SIGNAL_SYS_RESET Nicholas Piggin
2016-12-19 18:30 ` [PATCH 10/10] powerpc: xmon wait for secondaries before sending IPI Nicholas Piggin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20161219183011.28310-6-npiggin@gmail.com \
--to=npiggin@gmail.com \
--cc=linuxppc-dev@lists.ozlabs.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).