All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 00/12] powerpc/64: machine check and system reset fixes
@ 2020-03-25 10:33 Nicholas Piggin
  2020-03-25 10:33 ` [PATCH v2 01/12] powerpc/64s/exceptions: Fix in_mce accounting in unrecoverable path Nicholas Piggin
                   ` (11 more replies)
  0 siblings, 12 replies; 19+ messages in thread
From: Nicholas Piggin @ 2020-03-25 10:33 UTC (permalink / raw)
  To: linuxppc-dev; +Cc: Mahesh Salgaonkar, Ganesh Goudar, Nicholas Piggin

There's a bunch of problems we hit bringing up fwnmi sreset and testing
with mce injection on QEMU. Mostly pseries issues.

This series of fixes applies on top of next-test, the machine
check reconcile patch won't apply cleanly to previous kernels but
it might want to be backported. We can do that after upstreaming.

This doesn't solve all known problems yet, but fwnmi machine check
and system reset injection in QEMU is significantly better. There
will be more to come but these should be ready for review now.

Thanks,
Nick

Nicholas Piggin (12):
  powerpc/64s/exceptions: Fix in_mce accounting in unrecoverable path
  powerpc/64s/exceptions: Change irq reconcile for NMIs from reusing
    _DAR to RESULT
  powerpc/64s/exceptions: machine check reconcile irq state
  powerpc/pseries/ras: avoid calling rtas_token in NMI paths
  powerpc/pseries/ras: FWNMI_VALID off by one
  powerpc/pseries/ras: fwnmi avoid modifying r3 in error case
  powerpc/pseries/ras: fwnmi sreset should not interlock
  powerpc/pseries: limit machine check stack to 4GB
  powerpc/pseries: machine check use rtas_call_unlocked with args on
    stack
  powerpc/64s: machine check interrupt update NMI accounting
  powerpc/64s: machine check do not trace real-mode handler
  powerpc/64s: system reset do not trace

 arch/powerpc/include/asm/firmware.h    |  1 +
 arch/powerpc/kernel/exceptions-64s.S   | 33 +++++++++++---
 arch/powerpc/kernel/mce.c              | 13 +++++-
 arch/powerpc/kernel/process.c          |  2 +-
 arch/powerpc/kernel/setup_64.c         | 15 ++++++-
 arch/powerpc/kernel/traps.c            | 18 +++-----
 arch/powerpc/platforms/pseries/ras.c   | 62 +++++++++++++++++++-------
 arch/powerpc/platforms/pseries/setup.c | 13 ++++--
 8 files changed, 118 insertions(+), 39 deletions(-)

-- 
2.23.0


^ permalink raw reply	[flat|nested] 19+ messages in thread

* [PATCH v2 01/12] powerpc/64s/exceptions: Fix in_mce accounting in unrecoverable path
  2020-03-25 10:33 [PATCH v2 00/12] powerpc/64: machine check and system reset fixes Nicholas Piggin
@ 2020-03-25 10:33 ` Nicholas Piggin
  2020-03-27  3:43   ` Mahesh J Salgaonkar
  2020-03-25 10:34 ` [PATCH v2 02/12] powerpc/64s/exceptions: Change irq reconcile for NMIs from reusing _DAR to RESULT Nicholas Piggin
                   ` (10 subsequent siblings)
  11 siblings, 1 reply; 19+ messages in thread
From: Nicholas Piggin @ 2020-03-25 10:33 UTC (permalink / raw)
  To: linuxppc-dev; +Cc: Mahesh Salgaonkar, Ganesh Goudar, Nicholas Piggin

Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
 arch/powerpc/kernel/exceptions-64s.S | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
index 6a936c9199d6..67cbcb2d0c7f 100644
--- a/arch/powerpc/kernel/exceptions-64s.S
+++ b/arch/powerpc/kernel/exceptions-64s.S
@@ -1335,6 +1335,10 @@ END_FTR_SECTION_IFSET(CPU_FTR_HVMODE)
 	andc	r10,r10,r3
 	mtmsrd	r10
 
+	lhz	r12,PACA_IN_MCE(r13)
+	subi	r12,r12,1
+	sth	r12,PACA_IN_MCE(r13)
+
 	/* Invoke machine_check_exception to print MCE event and panic. */
 	addi	r3,r1,STACK_FRAME_OVERHEAD
 	bl	machine_check_exception
-- 
2.23.0


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH v2 02/12] powerpc/64s/exceptions: Change irq reconcile for NMIs from reusing _DAR to RESULT
  2020-03-25 10:33 [PATCH v2 00/12] powerpc/64: machine check and system reset fixes Nicholas Piggin
  2020-03-25 10:33 ` [PATCH v2 01/12] powerpc/64s/exceptions: Fix in_mce accounting in unrecoverable path Nicholas Piggin
@ 2020-03-25 10:34 ` Nicholas Piggin
  2020-03-25 10:34 ` [PATCH v2 03/12] powerpc/64s/exceptions: machine check reconcile irq state Nicholas Piggin
                   ` (9 subsequent siblings)
  11 siblings, 0 replies; 19+ messages in thread
From: Nicholas Piggin @ 2020-03-25 10:34 UTC (permalink / raw)
  To: linuxppc-dev; +Cc: Mahesh Salgaonkar, Ganesh Goudar, Nicholas Piggin

A spare interrupt stack slot is needed to save irq state when
reconciling NMIs (sreset and decrementer soft-nmi). _DAR is used
for this, but we want to reconcile machine checks as well, which
do use _DAR. Switch to using RESULT instead, as it's used by
system calls.

Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
 arch/powerpc/kernel/exceptions-64s.S | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
index 67cbcb2d0c7f..257d24437130 100644
--- a/arch/powerpc/kernel/exceptions-64s.S
+++ b/arch/powerpc/kernel/exceptions-64s.S
@@ -1011,13 +1011,13 @@ EXC_COMMON_BEGIN(system_reset_common)
 	 * the right thing. We do not want to reconcile because that goes
 	 * through irq tracing which we don't want in NMI.
 	 *
-	 * Save PACAIRQHAPPENED to _DAR (otherwise unused), and set HARD_DIS
+	 * Save PACAIRQHAPPENED to RESULT (otherwise unused), and set HARD_DIS
 	 * as we are running with MSR[EE]=0.
 	 */
 	li	r10,IRQS_ALL_DISABLED
 	stb	r10,PACAIRQSOFTMASK(r13)
 	lbz	r10,PACAIRQHAPPENED(r13)
-	std	r10,_DAR(r1)
+	std	r10,RESULT(r1)
 	ori	r10,r10,PACA_IRQ_HARD_DIS
 	stb	r10,PACAIRQHAPPENED(r13)
 
@@ -1038,7 +1038,7 @@ EXC_COMMON_BEGIN(system_reset_common)
 	/*
 	 * Restore soft mask settings.
 	 */
-	ld	r10,_DAR(r1)
+	ld	r10,RESULT(r1)
 	stb	r10,PACAIRQHAPPENED(r13)
 	ld	r10,SOFTE(r1)
 	stb	r10,PACAIRQSOFTMASK(r13)
@@ -2809,7 +2809,7 @@ EXC_COMMON_BEGIN(soft_nmi_common)
 	li	r10,IRQS_ALL_DISABLED
 	stb	r10,PACAIRQSOFTMASK(r13)
 	lbz	r10,PACAIRQHAPPENED(r13)
-	std	r10,_DAR(r1)
+	std	r10,RESULT(r1)
 	ori	r10,r10,PACA_IRQ_HARD_DIS
 	stb	r10,PACAIRQHAPPENED(r13)
 
@@ -2823,7 +2823,7 @@ EXC_COMMON_BEGIN(soft_nmi_common)
 	/*
 	 * Restore soft mask settings.
 	 */
-	ld	r10,_DAR(r1)
+	ld	r10,RESULT(r1)
 	stb	r10,PACAIRQHAPPENED(r13)
 	ld	r10,SOFTE(r1)
 	stb	r10,PACAIRQSOFTMASK(r13)
-- 
2.23.0


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH v2 03/12] powerpc/64s/exceptions: machine check reconcile irq state
  2020-03-25 10:33 [PATCH v2 00/12] powerpc/64: machine check and system reset fixes Nicholas Piggin
  2020-03-25 10:33 ` [PATCH v2 01/12] powerpc/64s/exceptions: Fix in_mce accounting in unrecoverable path Nicholas Piggin
  2020-03-25 10:34 ` [PATCH v2 02/12] powerpc/64s/exceptions: Change irq reconcile for NMIs from reusing _DAR to RESULT Nicholas Piggin
@ 2020-03-25 10:34 ` Nicholas Piggin
  2020-03-25 10:34 ` [PATCH v2 04/12] powerpc/pseries/ras: avoid calling rtas_token in NMI paths Nicholas Piggin
                   ` (8 subsequent siblings)
  11 siblings, 0 replies; 19+ messages in thread
From: Nicholas Piggin @ 2020-03-25 10:34 UTC (permalink / raw)
  To: linuxppc-dev; +Cc: Mahesh Salgaonkar, Ganesh Goudar, Nicholas Piggin

pseries fwnmi machine check code pops the soft-irq checks in rtas_call
(after the previous patch to remove rtas_token from this call path).
Rather than play whack a mole with these and forever having fragile
code, it seems better to have the early machine check handler perform
the same kind of reconcile as the other NMI interrupts.

  WARNING: CPU: 0 PID: 493 at arch/powerpc/kernel/irq.c:343
  CPU: 0 PID: 493 Comm: a Tainted: G        W
  NIP:  c00000000001ed2c LR: c000000000042c40 CTR: 0000000000000000
  REGS: c0000001fffd38b0 TRAP: 0700   Tainted: G        W
  MSR:  8000000000021003 <SF,ME,RI,LE>  CR: 28000488  XER: 00000000
  CFAR: c00000000001ec90 IRQMASK: 0
  GPR00: c000000000043820 c0000001fffd3b40 c0000000012ba300 0000000000000000
  GPR04: 0000000048000488 0000000000000000 0000000000000000 00000000deadbeef
  GPR08: 0000000000000080 0000000000000000 0000000000000000 0000000000001001
  GPR12: 0000000000000000 c0000000014a0000 0000000000000000 0000000000000000
  GPR16: 0000000000000000 0000000000000000 0000000000000000 0000000000000000
  GPR20: 0000000000000000 0000000000000000 0000000000000000 0000000000000000
  GPR24: 0000000000000000 0000000000000000 0000000000000000 0000000000000000
  GPR28: 0000000000000000 0000000000000001 c000000001360810 0000000000000000
  NIP [c00000000001ed2c] arch_local_irq_restore.part.0+0xac/0x100
  LR [c000000000042c40] unlock_rtas+0x30/0x90
  Call Trace:
  [c0000001fffd3b40] [c000000001360810] 0xc000000001360810 (unreliable)
  [c0000001fffd3b60] [c000000000043820] rtas_call+0x1c0/0x280
  [c0000001fffd3bb0] [c0000000000dc328] fwnmi_release_errinfo+0x38/0x70
  [c0000001fffd3c10] [c0000000000dcd8c] pseries_machine_check_realmode+0x1dc/0x540
  [c0000001fffd3cd0] [c00000000003fe04] machine_check_early+0x54/0x70
  [c0000001fffd3d00] [c000000000008384] machine_check_early_common+0x134/0x1f0
  --- interrupt: 200 at 0x13f1307c8
      LR = 0x7fff888b8528
  Instruction dump:
  60000000 7d2000a6 71298000 41820068 39200002 7d210164 4bffff9c 60000000
  60000000 7d2000a6 71298000 4c820020 <0fe00000> 4e800020 60000000 60000000

Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
 arch/powerpc/kernel/exceptions-64s.S | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
index 257d24437130..687f1389a5e5 100644
--- a/arch/powerpc/kernel/exceptions-64s.S
+++ b/arch/powerpc/kernel/exceptions-64s.S
@@ -1186,11 +1186,30 @@ END_FTR_SECTION_IFSET(CPU_FTR_HVMODE)
 	li	r10,MSR_RI
 	mtmsrd	r10,1
 
+	/*
+	 * Set IRQS_ALL_DISABLED and save PACAIRQHAPPENED (see
+	 * system_reset_common)
+	 */
+	li	r10,IRQS_ALL_DISABLED
+	stb	r10,PACAIRQSOFTMASK(r13)
+	lbz	r10,PACAIRQHAPPENED(r13)
+	std	r10,RESULT(r1)
+	ori	r10,r10,PACA_IRQ_HARD_DIS
+	stb	r10,PACAIRQHAPPENED(r13)
+
 	addi	r3,r1,STACK_FRAME_OVERHEAD
 	bl	machine_check_early
 	std	r3,RESULT(r1)	/* Save result */
 	ld	r12,_MSR(r1)
 
+	/*
+	 * Restore soft mask settings.
+	 */
+	ld	r10,RESULT(r1)
+	stb	r10,PACAIRQHAPPENED(r13)
+	ld	r10,SOFTE(r1)
+	stb	r10,PACAIRQSOFTMASK(r13)
+
 #ifdef CONFIG_PPC_P7_NAP
 	/*
 	 * Check if thread was in power saving mode. We come here when any
-- 
2.23.0


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH v2 04/12] powerpc/pseries/ras: avoid calling rtas_token in NMI paths
  2020-03-25 10:33 [PATCH v2 00/12] powerpc/64: machine check and system reset fixes Nicholas Piggin
                   ` (2 preceding siblings ...)
  2020-03-25 10:34 ` [PATCH v2 03/12] powerpc/64s/exceptions: machine check reconcile irq state Nicholas Piggin
@ 2020-03-25 10:34 ` Nicholas Piggin
  2020-03-27  3:50   ` Mahesh J Salgaonkar
  2020-03-25 10:34 ` [PATCH v2 05/12] powerpc/pseries/ras: FWNMI_VALID off by one Nicholas Piggin
                   ` (7 subsequent siblings)
  11 siblings, 1 reply; 19+ messages in thread
From: Nicholas Piggin @ 2020-03-25 10:34 UTC (permalink / raw)
  To: linuxppc-dev; +Cc: Mahesh Salgaonkar, Ganesh Goudar, Nicholas Piggin

In the interest of reducing code and possible failures in the
machine check and system reset paths, grab the "ibm,nmi-interlock"
token at init time.

Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
 arch/powerpc/include/asm/firmware.h    |  1 +
 arch/powerpc/platforms/pseries/ras.c   |  2 +-
 arch/powerpc/platforms/pseries/setup.c | 13 ++++++++++---
 3 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/arch/powerpc/include/asm/firmware.h b/arch/powerpc/include/asm/firmware.h
index ca33f4ef6cb4..6003c2e533a0 100644
--- a/arch/powerpc/include/asm/firmware.h
+++ b/arch/powerpc/include/asm/firmware.h
@@ -128,6 +128,7 @@ extern void machine_check_fwnmi(void);
 
 /* This is true if we are using the firmware NMI handler (typically LPAR) */
 extern int fwnmi_active;
+extern int ibm_nmi_interlock_token;
 
 extern unsigned int __start___fw_ftr_fixup, __stop___fw_ftr_fixup;
 
diff --git a/arch/powerpc/platforms/pseries/ras.c b/arch/powerpc/platforms/pseries/ras.c
index 1d7f973c647b..c74d5e740922 100644
--- a/arch/powerpc/platforms/pseries/ras.c
+++ b/arch/powerpc/platforms/pseries/ras.c
@@ -458,7 +458,7 @@ static struct rtas_error_log *fwnmi_get_errinfo(struct pt_regs *regs)
  */
 static void fwnmi_release_errinfo(void)
 {
-	int ret = rtas_call(rtas_token("ibm,nmi-interlock"), 0, 1, NULL);
+	int ret = rtas_call(ibm_nmi_interlock_token, 0, 1, NULL);
 	if (ret != 0)
 		printk(KERN_ERR "FWNMI: nmi-interlock failed: %d\n", ret);
 }
diff --git a/arch/powerpc/platforms/pseries/setup.c b/arch/powerpc/platforms/pseries/setup.c
index 17d17f064a2d..c31acd7ce0c0 100644
--- a/arch/powerpc/platforms/pseries/setup.c
+++ b/arch/powerpc/platforms/pseries/setup.c
@@ -83,6 +83,7 @@ unsigned long CMO_PageSize = (ASM_CONST(1) << IOMMU_PAGE_SHIFT_4K);
 EXPORT_SYMBOL(CMO_PageSize);
 
 int fwnmi_active;  /* TRUE if an FWNMI handler is present */
+int ibm_nmi_interlock_token;
 
 static void pSeries_show_cpuinfo(struct seq_file *m)
 {
@@ -113,9 +114,14 @@ static void __init fwnmi_init(void)
 	struct slb_entry *slb_ptr;
 	size_t size;
 #endif
+	int ibm_nmi_register_token;
 
-	int ibm_nmi_register = rtas_token("ibm,nmi-register");
-	if (ibm_nmi_register == RTAS_UNKNOWN_SERVICE)
+	ibm_nmi_register_token = rtas_token("ibm,nmi-register");
+	if (ibm_nmi_register_token == RTAS_UNKNOWN_SERVICE)
+		return;
+
+	ibm_nmi_interlock_token = rtas_token("ibm,nmi-interlock");
+	if (WARN_ON(ibm_nmi_interlock_token == RTAS_UNKNOWN_SERVICE))
 		return;
 
 	/* If the kernel's not linked at zero we point the firmware at low
@@ -123,7 +129,8 @@ static void __init fwnmi_init(void)
 	system_reset_addr  = __pa(system_reset_fwnmi) - PHYSICAL_START;
 	machine_check_addr = __pa(machine_check_fwnmi) - PHYSICAL_START;
 
-	if (0 == rtas_call(ibm_nmi_register, 2, 1, NULL, system_reset_addr,
+	if (0 == rtas_call(ibm_nmi_register_token, 2, 1, NULL,
+				system_reset_addr,
 				machine_check_addr))
 		fwnmi_active = 1;
 
-- 
2.23.0


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH v2 05/12] powerpc/pseries/ras: FWNMI_VALID off by one
  2020-03-25 10:33 [PATCH v2 00/12] powerpc/64: machine check and system reset fixes Nicholas Piggin
                   ` (3 preceding siblings ...)
  2020-03-25 10:34 ` [PATCH v2 04/12] powerpc/pseries/ras: avoid calling rtas_token in NMI paths Nicholas Piggin
@ 2020-03-25 10:34 ` Nicholas Piggin
  2020-03-27  3:51   ` Mahesh J Salgaonkar
  2020-03-25 10:34 ` [PATCH v2 06/12] powerpc/pseries/ras: fwnmi avoid modifying r3 in error case Nicholas Piggin
                   ` (6 subsequent siblings)
  11 siblings, 1 reply; 19+ messages in thread
From: Nicholas Piggin @ 2020-03-25 10:34 UTC (permalink / raw)
  To: linuxppc-dev; +Cc: Mahesh Salgaonkar, Ganesh Goudar, Nicholas Piggin

This was discovered developing qemu fwnmi sreset support. This
off-by-one bug means the last 16 bytes of the rtas area can not
be used for a 16 byte save area.

It's not a serious bug, and QEMU implementation has to retain a
workaround for old kernels, but it's good to tighten it.

Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
 arch/powerpc/platforms/pseries/ras.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/platforms/pseries/ras.c b/arch/powerpc/platforms/pseries/ras.c
index c74d5e740922..9a37bda47468 100644
--- a/arch/powerpc/platforms/pseries/ras.c
+++ b/arch/powerpc/platforms/pseries/ras.c
@@ -395,10 +395,11 @@ static irqreturn_t ras_error_interrupt(int irq, void *dev_id)
 /*
  * Some versions of FWNMI place the buffer inside the 4kB page starting at
  * 0x7000. Other versions place it inside the rtas buffer. We check both.
+ * Minimum size of the buffer is 16 bytes.
  */
 #define VALID_FWNMI_BUFFER(A) \
-	((((A) >= 0x7000) && ((A) < 0x7ff0)) || \
-	(((A) >= rtas.base) && ((A) < (rtas.base + rtas.size - 16))))
+	((((A) >= 0x7000) && ((A) <= 0x8000 - 16)) || \
+	(((A) >= rtas.base) && ((A) <= (rtas.base + rtas.size - 16))))
 
 static inline struct rtas_error_log *fwnmi_get_errlog(void)
 {
-- 
2.23.0


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH v2 06/12] powerpc/pseries/ras: fwnmi avoid modifying r3 in error case
  2020-03-25 10:33 [PATCH v2 00/12] powerpc/64: machine check and system reset fixes Nicholas Piggin
                   ` (4 preceding siblings ...)
  2020-03-25 10:34 ` [PATCH v2 05/12] powerpc/pseries/ras: FWNMI_VALID off by one Nicholas Piggin
@ 2020-03-25 10:34 ` Nicholas Piggin
  2020-03-25 10:34 ` [PATCH v2 07/12] powerpc/pseries/ras: fwnmi sreset should not interlock Nicholas Piggin
                   ` (5 subsequent siblings)
  11 siblings, 0 replies; 19+ messages in thread
From: Nicholas Piggin @ 2020-03-25 10:34 UTC (permalink / raw)
  To: linuxppc-dev; +Cc: Mahesh Salgaonkar, Ganesh Goudar, Nicholas Piggin

If there is some error with the fwnmi save area, r3 has already been
modified which doesn't help with debugging.

Only update r3 when to restore the saved value.

Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
 arch/powerpc/platforms/pseries/ras.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/arch/powerpc/platforms/pseries/ras.c b/arch/powerpc/platforms/pseries/ras.c
index 9a37bda47468..a40598e6e525 100644
--- a/arch/powerpc/platforms/pseries/ras.c
+++ b/arch/powerpc/platforms/pseries/ras.c
@@ -423,18 +423,19 @@ static inline struct rtas_error_log *fwnmi_get_errlog(void)
  */
 static struct rtas_error_log *fwnmi_get_errinfo(struct pt_regs *regs)
 {
+	unsigned long savep_ra;
 	unsigned long *savep;
 	struct rtas_error_log *h;
 
 	/* Mask top two bits */
-	regs->gpr[3] &= ~(0x3UL << 62);
+	savep_ra = regs->gpr[3] & ~(0x3UL << 62);
 
-	if (!VALID_FWNMI_BUFFER(regs->gpr[3])) {
+	if (!VALID_FWNMI_BUFFER(savep_ra)) {
 		printk(KERN_ERR "FWNMI: corrupt r3 0x%016lx\n", regs->gpr[3]);
 		return NULL;
 	}
 
-	savep = __va(regs->gpr[3]);
+	savep = __va(savep_ra);
 	regs->gpr[3] = be64_to_cpu(savep[0]);	/* restore original r3 */
 
 	h = (struct rtas_error_log *)&savep[1];
-- 
2.23.0


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH v2 07/12] powerpc/pseries/ras: fwnmi sreset should not interlock
  2020-03-25 10:33 [PATCH v2 00/12] powerpc/64: machine check and system reset fixes Nicholas Piggin
                   ` (5 preceding siblings ...)
  2020-03-25 10:34 ` [PATCH v2 06/12] powerpc/pseries/ras: fwnmi avoid modifying r3 in error case Nicholas Piggin
@ 2020-03-25 10:34 ` Nicholas Piggin
  2020-03-25 10:34 ` [PATCH v2 08/12] powerpc/pseries: limit machine check stack to 4GB Nicholas Piggin
                   ` (4 subsequent siblings)
  11 siblings, 0 replies; 19+ messages in thread
From: Nicholas Piggin @ 2020-03-25 10:34 UTC (permalink / raw)
  To: linuxppc-dev; +Cc: Mahesh Salgaonkar, Ganesh Goudar, Nicholas Piggin

PAPR does not specify that fwnmi sreset should be interlocked, and
PowerVM (and therefore now QEMU) do not require it.

These "ibm,nmi-interlock" calls are ignored by firmware, but there
is a possibility that the sreset could have interrupted a machine
check and release the machine check's interlock too early, corrupting
it if another machine check came in.

This is an extremely rare case, but it should be fixed for clarity
and reducing the code executed in the sreset path. Firmware also
does not provide error information for the sreset case to look at, so
remove that comment.

Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
 arch/powerpc/platforms/pseries/ras.c | 48 ++++++++++++++++++++--------
 1 file changed, 34 insertions(+), 14 deletions(-)

diff --git a/arch/powerpc/platforms/pseries/ras.c b/arch/powerpc/platforms/pseries/ras.c
index a40598e6e525..833ae34b7fec 100644
--- a/arch/powerpc/platforms/pseries/ras.c
+++ b/arch/powerpc/platforms/pseries/ras.c
@@ -406,6 +406,20 @@ static inline struct rtas_error_log *fwnmi_get_errlog(void)
 	return (struct rtas_error_log *)local_paca->mce_data_buf;
 }
 
+static unsigned long *fwnmi_get_savep(struct pt_regs *regs)
+{
+	unsigned long savep_ra;
+
+	/* Mask top two bits */
+	savep_ra = regs->gpr[3] & ~(0x3UL << 62);
+	if (!VALID_FWNMI_BUFFER(savep_ra)) {
+		printk(KERN_ERR "FWNMI: corrupt r3 0x%016lx\n", regs->gpr[3]);
+		return NULL;
+	}
+
+	return __va(savep_ra);
+}
+
 /*
  * Get the error information for errors coming through the
  * FWNMI vectors.  The pt_regs' r3 will be updated to reflect
@@ -423,20 +437,15 @@ static inline struct rtas_error_log *fwnmi_get_errlog(void)
  */
 static struct rtas_error_log *fwnmi_get_errinfo(struct pt_regs *regs)
 {
-	unsigned long savep_ra;
 	unsigned long *savep;
 	struct rtas_error_log *h;
 
-	/* Mask top two bits */
-	savep_ra = regs->gpr[3] & ~(0x3UL << 62);
-
-	if (!VALID_FWNMI_BUFFER(savep_ra)) {
-		printk(KERN_ERR "FWNMI: corrupt r3 0x%016lx\n", regs->gpr[3]);
+	savep = fwnmi_get_savep(regs);
+	if (!savep)
 		return NULL;
-	}
 
-	savep = __va(savep_ra);
-	regs->gpr[3] = be64_to_cpu(savep[0]);	/* restore original r3 */
+	/* restore original r3 */
+	regs->gpr[3] = be64_to_cpu(savep[0]);
 
 	h = (struct rtas_error_log *)&savep[1];
 	/* Use the per cpu buffer from paca to store rtas error log */
@@ -483,11 +492,22 @@ int pSeries_system_reset_exception(struct pt_regs *regs)
 #endif
 
 	if (fwnmi_active) {
-		struct rtas_error_log *errhdr = fwnmi_get_errinfo(regs);
-		if (errhdr) {
-			/* XXX Should look at FWNMI information */
-		}
-		fwnmi_release_errinfo();
+		unsigned long *savep;
+
+		/*
+		 * Firmware (PowerVM and KVM) saves r3 to a save area like
+		 * machine check, which is not exactly what PAPR (2.9)
+		 * suggests but there is no way to detect otherwise, so this
+		 * is the interface now.
+		 *
+		 * System resets do not save any error log or require an
+		 * "ibm,nmi-interlock" rtas call to release.
+		 */
+
+		savep = fwnmi_get_savep(regs);
+		/* restore original r3 */
+		if (savep)
+			regs->gpr[3] = be64_to_cpu(savep[0]);
 	}
 
 	if (smp_handle_nmi_ipi(regs))
-- 
2.23.0


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH v2 08/12] powerpc/pseries: limit machine check stack to 4GB
  2020-03-25 10:33 [PATCH v2 00/12] powerpc/64: machine check and system reset fixes Nicholas Piggin
                   ` (6 preceding siblings ...)
  2020-03-25 10:34 ` [PATCH v2 07/12] powerpc/pseries/ras: fwnmi sreset should not interlock Nicholas Piggin
@ 2020-03-25 10:34 ` Nicholas Piggin
  2020-03-27  5:24   ` Mahesh J Salgaonkar
  2020-03-25 10:34 ` [PATCH v2 09/12] powerpc/pseries: machine check use rtas_call_unlocked with args on stack Nicholas Piggin
                   ` (3 subsequent siblings)
  11 siblings, 1 reply; 19+ messages in thread
From: Nicholas Piggin @ 2020-03-25 10:34 UTC (permalink / raw)
  To: linuxppc-dev; +Cc: Mahesh Salgaonkar, Ganesh Goudar, Nicholas Piggin

This allows rtas_args to be put on the machine check stack, which
avoids a lot of complications with re-entrancy deadlocks.

Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
 arch/powerpc/kernel/setup_64.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/arch/powerpc/kernel/setup_64.c b/arch/powerpc/kernel/setup_64.c
index 3bf03666ee09..ca1041f8a578 100644
--- a/arch/powerpc/kernel/setup_64.c
+++ b/arch/powerpc/kernel/setup_64.c
@@ -695,6 +695,9 @@ void __init exc_lvl_early_init(void)
 void __init emergency_stack_init(void)
 {
 	u64 limit;
+#ifdef CONFIG_PPC_BOOK3S_64
+	u64 mce_limit;
+#endif
 	unsigned int i;
 
 	/*
@@ -713,6 +716,16 @@ void __init emergency_stack_init(void)
 	 */
 	limit = min(ppc64_bolted_size(), ppc64_rma_size);
 
+	/*
+	 * Machine check on pseries calls rtas, but can't use the static
+	 * rtas_args due to a machine check hitting while the lock is held.
+	 * rtas args have to be under 4GB, so the machine check stack is
+	 * limited to 4GB so args can be put on stack.
+	 */
+	mce_limit = limit;
+	if (firmware_has_feature(FW_FEATURE_LPAR) && mce_limit > 4UL*1024*1024*1024)
+		mce_limit = 4UL*1024*1024*1024;
+
 	for_each_possible_cpu(i) {
 		paca_ptrs[i]->emergency_sp = alloc_stack(limit, i) + THREAD_SIZE;
 
@@ -721,7 +734,7 @@ void __init emergency_stack_init(void)
 		paca_ptrs[i]->nmi_emergency_sp = alloc_stack(limit, i) + THREAD_SIZE;
 
 		/* emergency stack for machine check exception handling. */
-		paca_ptrs[i]->mc_emergency_sp = alloc_stack(limit, i) + THREAD_SIZE;
+		paca_ptrs[i]->mc_emergency_sp = alloc_stack(mce_limit, i) + THREAD_SIZE;
 #endif
 	}
 }
-- 
2.23.0


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH v2 09/12] powerpc/pseries: machine check use rtas_call_unlocked with args on stack
  2020-03-25 10:33 [PATCH v2 00/12] powerpc/64: machine check and system reset fixes Nicholas Piggin
                   ` (7 preceding siblings ...)
  2020-03-25 10:34 ` [PATCH v2 08/12] powerpc/pseries: limit machine check stack to 4GB Nicholas Piggin
@ 2020-03-25 10:34 ` Nicholas Piggin
  2020-03-25 10:34 ` [PATCH v2 10/12] powerpc/64s: machine check interrupt update NMI accounting Nicholas Piggin
                   ` (2 subsequent siblings)
  11 siblings, 0 replies; 19+ messages in thread
From: Nicholas Piggin @ 2020-03-25 10:34 UTC (permalink / raw)
  To: linuxppc-dev; +Cc: Mahesh Salgaonkar, Ganesh Goudar, Nicholas Piggin

With the previous patch, machine checks can use rtas_call_unlocked
which avoids the rtas spinlock which would deadlock if a machine
check hits while making an rtas call.

This also avoids the complex rtas error logging which has more rtas calls
and includes kmalloc (which can return memory beyond RMA, which would
also crash).

Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
 arch/powerpc/platforms/pseries/ras.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/arch/powerpc/platforms/pseries/ras.c b/arch/powerpc/platforms/pseries/ras.c
index 833ae34b7fec..6938261e4569 100644
--- a/arch/powerpc/platforms/pseries/ras.c
+++ b/arch/powerpc/platforms/pseries/ras.c
@@ -469,7 +469,15 @@ static struct rtas_error_log *fwnmi_get_errinfo(struct pt_regs *regs)
  */
 static void fwnmi_release_errinfo(void)
 {
-	int ret = rtas_call(ibm_nmi_interlock_token, 0, 1, NULL);
+	struct rtas_args rtas_args;
+	int ret;
+
+	/*
+	 * On pseries, the machine check stack is limited to under 4GB, so
+	 * args can be on-stack.
+	 */
+	rtas_call_unlocked(&rtas_args, ibm_nmi_interlock_token, 0, 1, NULL);
+	ret = be32_to_cpu(rtas_args.rets[0]);
 	if (ret != 0)
 		printk(KERN_ERR "FWNMI: nmi-interlock failed: %d\n", ret);
 }
-- 
2.23.0


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH v2 10/12] powerpc/64s: machine check interrupt update NMI accounting
  2020-03-25 10:33 [PATCH v2 00/12] powerpc/64: machine check and system reset fixes Nicholas Piggin
                   ` (8 preceding siblings ...)
  2020-03-25 10:34 ` [PATCH v2 09/12] powerpc/pseries: machine check use rtas_call_unlocked with args on stack Nicholas Piggin
@ 2020-03-25 10:34 ` Nicholas Piggin
  2020-03-25 10:34 ` [PATCH v2 11/12] powerpc/64s: machine check do not trace real-mode handler Nicholas Piggin
  2020-03-25 10:34 ` [PATCH v2 12/12] powerpc/64s: system reset do not trace Nicholas Piggin
  11 siblings, 0 replies; 19+ messages in thread
From: Nicholas Piggin @ 2020-03-25 10:34 UTC (permalink / raw)
  To: linuxppc-dev; +Cc: Mahesh Salgaonkar, Ganesh Goudar, Nicholas Piggin

machine_check_early is taken as an NMI, so nmi_enter is used there.
machine_check_exception is no longer taken as an NMI (it's invoked
via irq_work in the case a machine check hits in kernel mode), so
remove the nmi_enter from that case.

In NMI context, hash faults don't try to refill the hash table, which
can lead to crashes accessing non-pinned kernel pages. System reset
still has this potential problem.

Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
 arch/powerpc/kernel/mce.c     |  7 +++++++
 arch/powerpc/kernel/process.c |  2 +-
 arch/powerpc/kernel/traps.c   | 13 +------------
 3 files changed, 9 insertions(+), 13 deletions(-)

diff --git a/arch/powerpc/kernel/mce.c b/arch/powerpc/kernel/mce.c
index 34c1001e9e8b..c1684be0d8b7 100644
--- a/arch/powerpc/kernel/mce.c
+++ b/arch/powerpc/kernel/mce.c
@@ -560,6 +560,9 @@ EXPORT_SYMBOL_GPL(machine_check_print_event_info);
 long machine_check_early(struct pt_regs *regs)
 {
 	long handled = 0;
+	bool nested = in_nmi();
+	if (!nested)
+		nmi_enter();
 
 	hv_nmi_check_nonrecoverable(regs);
 
@@ -568,6 +571,10 @@ long machine_check_early(struct pt_regs *regs)
 	 */
 	if (ppc_md.machine_check_early)
 		handled = ppc_md.machine_check_early(regs);
+
+	if (!nested)
+		nmi_exit();
+
 	return handled;
 }
 
diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
index d27bf367e929..c21344c1a151 100644
--- a/arch/powerpc/kernel/process.c
+++ b/arch/powerpc/kernel/process.c
@@ -1421,7 +1421,7 @@ void show_regs(struct pt_regs * regs)
 		pr_cont("DAR: "REG" DSISR: %08lx ", regs->dar, regs->dsisr);
 #endif
 #ifdef CONFIG_PPC64
-	pr_cont("IRQMASK: %lx ", regs->softe);
+	pr_cont("IRQMASK: %lx IN_NMI:%d IN_MCE:%d", regs->softe, (int)get_paca()->in_nmi, (int)get_paca()->in_mce);
 #endif
 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
 	if (MSR_TM_ACTIVE(regs->msr))
diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
index 82a3438300fd..1845fd7e161a 100644
--- a/arch/powerpc/kernel/traps.c
+++ b/arch/powerpc/kernel/traps.c
@@ -823,9 +823,6 @@ int machine_check_generic(struct pt_regs *regs)
 void machine_check_exception(struct pt_regs *regs)
 {
 	int recover = 0;
-	bool nested = in_nmi();
-	if (!nested)
-		nmi_enter();
 
 	__this_cpu_inc(irq_stat.mce_exceptions);
 
@@ -851,20 +848,12 @@ void machine_check_exception(struct pt_regs *regs)
 	if (check_io_access(regs))
 		goto bail;
 
-	if (!nested)
-		nmi_exit();
-
 	die("Machine check", regs, SIGBUS);
 
+bail:
 	/* Must die if the interrupt is not recoverable */
 	if (!(regs->msr & MSR_RI))
 		nmi_panic(regs, "Unrecoverable Machine check");
-
-	return;
-
-bail:
-	if (!nested)
-		nmi_exit();
 }
 
 void SMIException(struct pt_regs *regs)
-- 
2.23.0


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH v2 11/12] powerpc/64s: machine check do not trace real-mode handler
  2020-03-25 10:33 [PATCH v2 00/12] powerpc/64: machine check and system reset fixes Nicholas Piggin
                   ` (9 preceding siblings ...)
  2020-03-25 10:34 ` [PATCH v2 10/12] powerpc/64s: machine check interrupt update NMI accounting Nicholas Piggin
@ 2020-03-25 10:34 ` Nicholas Piggin
  2020-03-25 10:34 ` [PATCH v2 12/12] powerpc/64s: system reset do not trace Nicholas Piggin
  11 siblings, 0 replies; 19+ messages in thread
From: Nicholas Piggin @ 2020-03-25 10:34 UTC (permalink / raw)
  To: linuxppc-dev; +Cc: Mahesh Salgaonkar, Ganesh Goudar, Nicholas Piggin

Rather than notrace annotations throughout a significant part of the
machine check code across kernel/ pseries/ and powernv/ which can
easily be broken and is infrequently tested, use paca->ftrace_enabled
to blanket-disable tracing of the real-mode non-maskable handler.

Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
 arch/powerpc/kernel/mce.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/arch/powerpc/kernel/mce.c b/arch/powerpc/kernel/mce.c
index c1684be0d8b7..36e99adb8710 100644
--- a/arch/powerpc/kernel/mce.c
+++ b/arch/powerpc/kernel/mce.c
@@ -557,10 +557,13 @@ EXPORT_SYMBOL_GPL(machine_check_print_event_info);
  *
  * regs->nip and regs->msr contains srr0 and ssr1.
  */
-long machine_check_early(struct pt_regs *regs)
+long notrace machine_check_early(struct pt_regs *regs)
 {
 	long handled = 0;
 	bool nested = in_nmi();
+	u8 ftrace_enabled = local_paca->ftrace_enabled;
+
+	local_paca->ftrace_enabled = 0;
 	if (!nested)
 		nmi_enter();
 
@@ -574,6 +577,7 @@ long machine_check_early(struct pt_regs *regs)
 
 	if (!nested)
 		nmi_exit();
+	local_paca->ftrace_enabled = ftrace_enabled;
 
 	return handled;
 }
-- 
2.23.0


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH v2 12/12] powerpc/64s: system reset do not trace
  2020-03-25 10:33 [PATCH v2 00/12] powerpc/64: machine check and system reset fixes Nicholas Piggin
                   ` (10 preceding siblings ...)
  2020-03-25 10:34 ` [PATCH v2 11/12] powerpc/64s: machine check do not trace real-mode handler Nicholas Piggin
@ 2020-03-25 10:34 ` Nicholas Piggin
  2020-03-26 17:23   ` Naveen N. Rao
  11 siblings, 1 reply; 19+ messages in thread
From: Nicholas Piggin @ 2020-03-25 10:34 UTC (permalink / raw)
  To: linuxppc-dev; +Cc: Mahesh Salgaonkar, Ganesh Goudar, Nicholas Piggin

Similarly to the previous patch, do not trace system reset. This code
is used when there is a crash or hang, and tracing disturbs the system
more and has been known to crash in the crash handling path.

Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
 arch/powerpc/kernel/traps.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
index 1845fd7e161a..ed7b7a6e2dc0 100644
--- a/arch/powerpc/kernel/traps.c
+++ b/arch/powerpc/kernel/traps.c
@@ -443,6 +443,9 @@ void system_reset_exception(struct pt_regs *regs)
 	unsigned long hsrr0, hsrr1;
 	bool nested = in_nmi();
 	bool saved_hsrrs = false;
+	u8 ftrace_enabled = local_paca->ftrace_enabled;
+
+	local_paca->ftrace_enabled = 0;
 
 	/*
 	 * Avoid crashes in case of nested NMI exceptions. Recoverability
@@ -524,6 +527,8 @@ void system_reset_exception(struct pt_regs *regs)
 	if (!nested)
 		nmi_exit();
 
+	local_paca->ftrace_enabled = ftrace_enabled;
+
 	/* What should we do here? We could issue a shutdown or hard reset. */
 }
 
-- 
2.23.0


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* Re: [PATCH v2 12/12] powerpc/64s: system reset do not trace
  2020-03-25 10:34 ` [PATCH v2 12/12] powerpc/64s: system reset do not trace Nicholas Piggin
@ 2020-03-26 17:23   ` Naveen N. Rao
  0 siblings, 0 replies; 19+ messages in thread
From: Naveen N. Rao @ 2020-03-26 17:23 UTC (permalink / raw)
  To: linuxppc-dev, Nicholas Piggin; +Cc: Mahesh Salgaonkar, Ganesh Goudar

Nicholas Piggin wrote:
> Similarly to the previous patch, do not trace system reset. This code
> is used when there is a crash or hang, and tracing disturbs the system
> more and has been known to crash in the crash handling path.
> 
> Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
> ---
>  arch/powerpc/kernel/traps.c | 5 +++++
>  1 file changed, 5 insertions(+)

For the ftrace bits:
Acked-by: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>

> 
> diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
> index 1845fd7e161a..ed7b7a6e2dc0 100644
> --- a/arch/powerpc/kernel/traps.c
> +++ b/arch/powerpc/kernel/traps.c
> @@ -443,6 +443,9 @@ void system_reset_exception(struct pt_regs *regs)
>  	unsigned long hsrr0, hsrr1;
>  	bool nested = in_nmi();
>  	bool saved_hsrrs = false;
> +	u8 ftrace_enabled = local_paca->ftrace_enabled;
> +
> +	local_paca->ftrace_enabled = 0;
>  
>  	/*
>  	 * Avoid crashes in case of nested NMI exceptions. Recoverability
> @@ -524,6 +527,8 @@ void system_reset_exception(struct pt_regs *regs)
>  	if (!nested)
>  		nmi_exit();
>  
> +	local_paca->ftrace_enabled = ftrace_enabled;
> +

I suppose we could add helpers to save/restore the state. But, since we 
only have these two users as of now, we can revisit that if the need 
arises.


- Naveen


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH v2 01/12] powerpc/64s/exceptions: Fix in_mce accounting in unrecoverable path
  2020-03-25 10:33 ` [PATCH v2 01/12] powerpc/64s/exceptions: Fix in_mce accounting in unrecoverable path Nicholas Piggin
@ 2020-03-27  3:43   ` Mahesh J Salgaonkar
  0 siblings, 0 replies; 19+ messages in thread
From: Mahesh J Salgaonkar @ 2020-03-27  3:43 UTC (permalink / raw)
  To: Nicholas Piggin; +Cc: Ganesh Goudar, linuxppc-dev, Mahesh Salgaonkar

On 2020-03-25 20:33:59 Wed, Nicholas Piggin wrote:
> Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
> ---
>  arch/powerpc/kernel/exceptions-64s.S | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
> index 6a936c9199d6..67cbcb2d0c7f 100644
> --- a/arch/powerpc/kernel/exceptions-64s.S
> +++ b/arch/powerpc/kernel/exceptions-64s.S
> @@ -1335,6 +1335,10 @@ END_FTR_SECTION_IFSET(CPU_FTR_HVMODE)
>  	andc	r10,r10,r3
>  	mtmsrd	r10
> 
> +	lhz	r12,PACA_IN_MCE(r13)
> +	subi	r12,r12,1
> +	sth	r12,PACA_IN_MCE(r13)
> +

Acked-by: Mahesh Salgaonkar <mahesh@linux.ibm.com>

Thanks,
-Mahesh.


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH v2 04/12] powerpc/pseries/ras: avoid calling rtas_token in NMI paths
  2020-03-25 10:34 ` [PATCH v2 04/12] powerpc/pseries/ras: avoid calling rtas_token in NMI paths Nicholas Piggin
@ 2020-03-27  3:50   ` Mahesh J Salgaonkar
  0 siblings, 0 replies; 19+ messages in thread
From: Mahesh J Salgaonkar @ 2020-03-27  3:50 UTC (permalink / raw)
  To: Nicholas Piggin; +Cc: Ganesh Goudar, linuxppc-dev, Mahesh Salgaonkar

On 2020-03-25 20:34:02 Wed, Nicholas Piggin wrote:
> In the interest of reducing code and possible failures in the
> machine check and system reset paths, grab the "ibm,nmi-interlock"
> token at init time.
> 
> Signed-off-by: Nicholas Piggin <npiggin@gmail.com>

Reviewed-by: Mahesh Salgaonkar <mahesh@linux.ibm.com>

Thanks,
-Mahesh.
> ---
>  arch/powerpc/include/asm/firmware.h    |  1 +
>  arch/powerpc/platforms/pseries/ras.c   |  2 +-
>  arch/powerpc/platforms/pseries/setup.c | 13 ++++++++++---
>  3 files changed, 12 insertions(+), 4 deletions(-)
> 
> diff --git a/arch/powerpc/include/asm/firmware.h b/arch/powerpc/include/asm/firmware.h
> index ca33f4ef6cb4..6003c2e533a0 100644
> --- a/arch/powerpc/include/asm/firmware.h
> +++ b/arch/powerpc/include/asm/firmware.h
> @@ -128,6 +128,7 @@ extern void machine_check_fwnmi(void);
> 
>  /* This is true if we are using the firmware NMI handler (typically LPAR) */
>  extern int fwnmi_active;
> +extern int ibm_nmi_interlock_token;
> 
>  extern unsigned int __start___fw_ftr_fixup, __stop___fw_ftr_fixup;
> 
> diff --git a/arch/powerpc/platforms/pseries/ras.c b/arch/powerpc/platforms/pseries/ras.c
> index 1d7f973c647b..c74d5e740922 100644
> --- a/arch/powerpc/platforms/pseries/ras.c
> +++ b/arch/powerpc/platforms/pseries/ras.c
> @@ -458,7 +458,7 @@ static struct rtas_error_log *fwnmi_get_errinfo(struct pt_regs *regs)
>   */
>  static void fwnmi_release_errinfo(void)
>  {
> -	int ret = rtas_call(rtas_token("ibm,nmi-interlock"), 0, 1, NULL);
> +	int ret = rtas_call(ibm_nmi_interlock_token, 0, 1, NULL);
>  	if (ret != 0)
>  		printk(KERN_ERR "FWNMI: nmi-interlock failed: %d\n", ret);
>  }
> diff --git a/arch/powerpc/platforms/pseries/setup.c b/arch/powerpc/platforms/pseries/setup.c
> index 17d17f064a2d..c31acd7ce0c0 100644
> --- a/arch/powerpc/platforms/pseries/setup.c
> +++ b/arch/powerpc/platforms/pseries/setup.c
> @@ -83,6 +83,7 @@ unsigned long CMO_PageSize = (ASM_CONST(1) << IOMMU_PAGE_SHIFT_4K);
>  EXPORT_SYMBOL(CMO_PageSize);
> 
>  int fwnmi_active;  /* TRUE if an FWNMI handler is present */
> +int ibm_nmi_interlock_token;
> 
>  static void pSeries_show_cpuinfo(struct seq_file *m)
>  {
> @@ -113,9 +114,14 @@ static void __init fwnmi_init(void)
>  	struct slb_entry *slb_ptr;
>  	size_t size;
>  #endif
> +	int ibm_nmi_register_token;
> 
> -	int ibm_nmi_register = rtas_token("ibm,nmi-register");
> -	if (ibm_nmi_register == RTAS_UNKNOWN_SERVICE)
> +	ibm_nmi_register_token = rtas_token("ibm,nmi-register");
> +	if (ibm_nmi_register_token == RTAS_UNKNOWN_SERVICE)
> +		return;
> +
> +	ibm_nmi_interlock_token = rtas_token("ibm,nmi-interlock");
> +	if (WARN_ON(ibm_nmi_interlock_token == RTAS_UNKNOWN_SERVICE))
>  		return;
> 
>  	/* If the kernel's not linked at zero we point the firmware at low
> @@ -123,7 +129,8 @@ static void __init fwnmi_init(void)
>  	system_reset_addr  = __pa(system_reset_fwnmi) - PHYSICAL_START;
>  	machine_check_addr = __pa(machine_check_fwnmi) - PHYSICAL_START;
> 
> -	if (0 == rtas_call(ibm_nmi_register, 2, 1, NULL, system_reset_addr,
> +	if (0 == rtas_call(ibm_nmi_register_token, 2, 1, NULL,
> +				system_reset_addr,
>  				machine_check_addr))
>  		fwnmi_active = 1;
> 
> -- 
> 2.23.0
> 

-- 
Mahesh J Salgaonkar


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH v2 05/12] powerpc/pseries/ras: FWNMI_VALID off by one
  2020-03-25 10:34 ` [PATCH v2 05/12] powerpc/pseries/ras: FWNMI_VALID off by one Nicholas Piggin
@ 2020-03-27  3:51   ` Mahesh J Salgaonkar
  0 siblings, 0 replies; 19+ messages in thread
From: Mahesh J Salgaonkar @ 2020-03-27  3:51 UTC (permalink / raw)
  To: Nicholas Piggin; +Cc: Mahesh Salgaonkar, Ganesh Goudar, linuxppc-dev

On 2020-03-25 20:34:03 Wed, Nicholas Piggin wrote:
> This was discovered developing qemu fwnmi sreset support. This
> off-by-one bug means the last 16 bytes of the rtas area can not
> be used for a 16 byte save area.
> 
> It's not a serious bug, and QEMU implementation has to retain a
> workaround for old kernels, but it's good to tighten it.
> 
> Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
> ---
>  arch/powerpc/platforms/pseries/ras.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/arch/powerpc/platforms/pseries/ras.c b/arch/powerpc/platforms/pseries/ras.c
> index c74d5e740922..9a37bda47468 100644
> --- a/arch/powerpc/platforms/pseries/ras.c
> +++ b/arch/powerpc/platforms/pseries/ras.c
> @@ -395,10 +395,11 @@ static irqreturn_t ras_error_interrupt(int irq, void *dev_id)
>  /*
>   * Some versions of FWNMI place the buffer inside the 4kB page starting at
>   * 0x7000. Other versions place it inside the rtas buffer. We check both.
> + * Minimum size of the buffer is 16 bytes.

Acked-by: Mahesh Salgaonkar <mahesh@linux.ibm.com>

Thanks,
-Mahesh.

>   */
>  #define VALID_FWNMI_BUFFER(A) \
> -	((((A) >= 0x7000) && ((A) < 0x7ff0)) || \
> -	(((A) >= rtas.base) && ((A) < (rtas.base + rtas.size - 16))))
> +	((((A) >= 0x7000) && ((A) <= 0x8000 - 16)) || \
> +	(((A) >= rtas.base) && ((A) <= (rtas.base + rtas.size - 16))))
> 
>  static inline struct rtas_error_log *fwnmi_get_errlog(void)
>  {
> -- 
> 2.23.0
> 

-- 
Mahesh J Salgaonkar


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH v2 08/12] powerpc/pseries: limit machine check stack to 4GB
  2020-03-25 10:34 ` [PATCH v2 08/12] powerpc/pseries: limit machine check stack to 4GB Nicholas Piggin
@ 2020-03-27  5:24   ` Mahesh J Salgaonkar
  2020-04-03 10:24     ` Nicholas Piggin
  0 siblings, 1 reply; 19+ messages in thread
From: Mahesh J Salgaonkar @ 2020-03-27  5:24 UTC (permalink / raw)
  To: Nicholas Piggin; +Cc: Mahesh Salgaonkar, Ganesh Goudar, linuxppc-dev

On 2020-03-25 20:34:06 Wed, Nicholas Piggin wrote:
> This allows rtas_args to be put on the machine check stack, which
> avoids a lot of complications with re-entrancy deadlocks.
> 
> Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
> ---
>  arch/powerpc/kernel/setup_64.c | 15 ++++++++++++++-
>  1 file changed, 14 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/powerpc/kernel/setup_64.c b/arch/powerpc/kernel/setup_64.c
> index 3bf03666ee09..ca1041f8a578 100644
> --- a/arch/powerpc/kernel/setup_64.c
> +++ b/arch/powerpc/kernel/setup_64.c
> @@ -695,6 +695,9 @@ void __init exc_lvl_early_init(void)
>  void __init emergency_stack_init(void)
>  {
>  	u64 limit;
> +#ifdef CONFIG_PPC_BOOK3S_64
> +	u64 mce_limit;
> +#endif
>  	unsigned int i;
> 
>  	/*
> @@ -713,6 +716,16 @@ void __init emergency_stack_init(void)
>  	 */
>  	limit = min(ppc64_bolted_size(), ppc64_rma_size);
> 
> +	/*
> +	 * Machine check on pseries calls rtas, but can't use the static
> +	 * rtas_args due to a machine check hitting while the lock is held.
> +	 * rtas args have to be under 4GB, so the machine check stack is
> +	 * limited to 4GB so args can be put on stack.
> +	 */
> +	mce_limit = limit;
> +	if (firmware_has_feature(FW_FEATURE_LPAR) && mce_limit > 4UL*1024*1024*1024)
> +		mce_limit = 4UL*1024*1024*1024;
> +

Don't you need this as well under CONFIG_PPC_BOOK3S_64 #ifdef ??

Rest looks good.

Reviewed-by: Mahesh Salgaonkar <mahesh@linux.ibm.com>

Thanks,
-Mahesh.


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH v2 08/12] powerpc/pseries: limit machine check stack to 4GB
  2020-03-27  5:24   ` Mahesh J Salgaonkar
@ 2020-04-03 10:24     ` Nicholas Piggin
  0 siblings, 0 replies; 19+ messages in thread
From: Nicholas Piggin @ 2020-04-03 10:24 UTC (permalink / raw)
  To: mahesh; +Cc: linuxppc-dev, Ganesh Goudar, Mahesh Salgaonkar

Mahesh J Salgaonkar's on March 27, 2020 3:24 pm:
> On 2020-03-25 20:34:06 Wed, Nicholas Piggin wrote:
>> This allows rtas_args to be put on the machine check stack, which
>> avoids a lot of complications with re-entrancy deadlocks.
>> 
>> Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
>> ---
>>  arch/powerpc/kernel/setup_64.c | 15 ++++++++++++++-
>>  1 file changed, 14 insertions(+), 1 deletion(-)
>> 
>> diff --git a/arch/powerpc/kernel/setup_64.c b/arch/powerpc/kernel/setup_64.c
>> index 3bf03666ee09..ca1041f8a578 100644
>> --- a/arch/powerpc/kernel/setup_64.c
>> +++ b/arch/powerpc/kernel/setup_64.c
>> @@ -695,6 +695,9 @@ void __init exc_lvl_early_init(void)
>>  void __init emergency_stack_init(void)
>>  {
>>  	u64 limit;
>> +#ifdef CONFIG_PPC_BOOK3S_64
>> +	u64 mce_limit;
>> +#endif
>>  	unsigned int i;
>> 
>>  	/*
>> @@ -713,6 +716,16 @@ void __init emergency_stack_init(void)
>>  	 */
>>  	limit = min(ppc64_bolted_size(), ppc64_rma_size);
>> 
>> +	/*
>> +	 * Machine check on pseries calls rtas, but can't use the static
>> +	 * rtas_args due to a machine check hitting while the lock is held.
>> +	 * rtas args have to be under 4GB, so the machine check stack is
>> +	 * limited to 4GB so args can be put on stack.
>> +	 */
>> +	mce_limit = limit;
>> +	if (firmware_has_feature(FW_FEATURE_LPAR) && mce_limit > 4UL*1024*1024*1024)
>> +		mce_limit = 4UL*1024*1024*1024;
>> +
> 
> Don't you need this as well under CONFIG_PPC_BOOK3S_64 #ifdef ??

Good catch.

Thanks,
Nick

^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2020-04-03 10:26 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-25 10:33 [PATCH v2 00/12] powerpc/64: machine check and system reset fixes Nicholas Piggin
2020-03-25 10:33 ` [PATCH v2 01/12] powerpc/64s/exceptions: Fix in_mce accounting in unrecoverable path Nicholas Piggin
2020-03-27  3:43   ` Mahesh J Salgaonkar
2020-03-25 10:34 ` [PATCH v2 02/12] powerpc/64s/exceptions: Change irq reconcile for NMIs from reusing _DAR to RESULT Nicholas Piggin
2020-03-25 10:34 ` [PATCH v2 03/12] powerpc/64s/exceptions: machine check reconcile irq state Nicholas Piggin
2020-03-25 10:34 ` [PATCH v2 04/12] powerpc/pseries/ras: avoid calling rtas_token in NMI paths Nicholas Piggin
2020-03-27  3:50   ` Mahesh J Salgaonkar
2020-03-25 10:34 ` [PATCH v2 05/12] powerpc/pseries/ras: FWNMI_VALID off by one Nicholas Piggin
2020-03-27  3:51   ` Mahesh J Salgaonkar
2020-03-25 10:34 ` [PATCH v2 06/12] powerpc/pseries/ras: fwnmi avoid modifying r3 in error case Nicholas Piggin
2020-03-25 10:34 ` [PATCH v2 07/12] powerpc/pseries/ras: fwnmi sreset should not interlock Nicholas Piggin
2020-03-25 10:34 ` [PATCH v2 08/12] powerpc/pseries: limit machine check stack to 4GB Nicholas Piggin
2020-03-27  5:24   ` Mahesh J Salgaonkar
2020-04-03 10:24     ` Nicholas Piggin
2020-03-25 10:34 ` [PATCH v2 09/12] powerpc/pseries: machine check use rtas_call_unlocked with args on stack Nicholas Piggin
2020-03-25 10:34 ` [PATCH v2 10/12] powerpc/64s: machine check interrupt update NMI accounting Nicholas Piggin
2020-03-25 10:34 ` [PATCH v2 11/12] powerpc/64s: machine check do not trace real-mode handler Nicholas Piggin
2020-03-25 10:34 ` [PATCH v2 12/12] powerpc/64s: system reset do not trace Nicholas Piggin
2020-03-26 17:23   ` Naveen N. Rao

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.