All of lore.kernel.org
 help / color / mirror / Atom feed
From: Nicholas Piggin <npiggin@gmail.com>
To: linuxppc-dev@lists.ozlabs.org, Michael Ellerman <mpe@ellerman.id.au>
Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
Subject: Re: [PATCH v7 39/42] powerpc: move NMI entry/exit code into wrapper
Date: Sun, 07 Feb 2021 22:54:12 +1000	[thread overview]
Message-ID: <1612702361.lm7fqo56re.astroid@bobo.none> (raw)
In-Reply-To: <1612579435.unncvipdys.astroid@bobo.none>

Excerpts from Nicholas Piggin's message of February 6, 2021 12:46 pm:
> Excerpts from Michael Ellerman's message of February 6, 2021 9:38 am:
>> Nicholas Piggin <npiggin@gmail.com> writes:
>>> Excerpts from Michael Ellerman's message of February 4, 2021 8:15 pm:
>>>> Nicholas Piggin <npiggin@gmail.com> writes:
>>>>> This moves the common NMI entry and exit code into the interrupt handler
>>>>> wrappers.
>>>>>
>>>>> This changes the behaviour of soft-NMI (watchdog) and HMI interrupts, and
>>>>> also MCE interrupts on 64e, by adding missing parts of the NMI entry to
>>>>> them.
>>>>>
>>>>> Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
>>>>> ---
>>>>>  arch/powerpc/include/asm/interrupt.h | 28 ++++++++++++++++++++++
>>>>>  arch/powerpc/kernel/mce.c            | 11 ---------
>>>>>  arch/powerpc/kernel/traps.c          | 35 +++++-----------------------
>>>>>  arch/powerpc/kernel/watchdog.c       | 10 ++++----
>>>>>  4 files changed, 38 insertions(+), 46 deletions(-)
>>>> 
>>>> This is unhappy when injecting SLB multi-hits:
>>>> 
>>>>   root@p86-2:~# echo PPC_SLB_MULTIHIT > /sys/kernel/debug/provoke-crash/DIRECT
>>>>   [  312.496026][ T1344] kernel BUG at arch/powerpc/include/asm/interrupt.h:152!
>>>>   [  312.496037][ T1344] Oops: Exception in kernel mode, sig: 5 [#1]
>>>>   [  312.496045][ T1344] LE PAGE_SIZE=64K MMU=Hash SMP NR_CPUS=2048 NUMA pSeries
>>>
>>> pseries hash. Blast!
>> 
>> The worst kind.
>> 
>>>> 147 static inline void interrupt_nmi_exit_prepare(struct pt_regs *regs, struct interrupt_nmi_state *state)
>>>> 148 {
>>>> 149 	if (!IS_ENABLED(CONFIG_PPC_BOOK3S_64) ||
>>>> 150 			!firmware_has_feature(FW_FEATURE_LPAR) ||
>>>> 151 			radix_enabled() || (mfmsr() & MSR_DR))
>>>> 152 		nmi_exit();
>>>> 
>>>> 
>>>> So presumably it's:
>>>> 
>>>> #define __nmi_exit()						\
>>>> 	do {							\
>>>> 		BUG_ON(!in_nmi());				\
>>>
>>> Yes that would be it, pseries machine check enables MMU half way through 
>>> so only one side of this triggers.
>>>
>>> The MSR_DR check is supposed to catch the other NMIs that run with MMU 
>>> on (perf, watchdog, etc). Suppose it could test TRAP(regs) explicitly
>>> although I wonder if we should also do this to keep things balanced
>> 
>> Yeah I think I like that. I'll give it a test.
> 
> The msr restore? Looking closer, pseries_machine_check_realmode may have
> expected mce_handle_error to enable the MMU, because irq_work_queue uses
> some per-cpu variables I think.
> 
> So the code might have to be rearranged a bit more than the patch below.

Here is a patch, it should go anywhere before this patch. Seems to
work with some test MCE injection on pseries hash.

Thanks,
Nick
--

powerpc/pseries/mce: restore msr before returning from handler

The pseries real-mode machine check handler can enable the MMU, and
return from the handler with the MMU still enabled.

This works, but real-mode handler wrapper exit handlers want to rely
on the MMU being in real-mode. So change the pseries handler to
restore the MSR after it has finished virtual mode tasks.

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

diff --git a/arch/powerpc/platforms/pseries/ras.c b/arch/powerpc/platforms/pseries/ras.c
index 2d9f985fd13a..377439e88598 100644
--- a/arch/powerpc/platforms/pseries/ras.c
+++ b/arch/powerpc/platforms/pseries/ras.c
@@ -722,6 +722,7 @@ static int mce_handle_error(struct pt_regs *regs, struct rtas_error_log *errp)
 	struct pseries_errorlog *pseries_log;
 	struct pseries_mc_errorlog *mce_log = NULL;
 	int disposition = rtas_error_disposition(errp);
+	unsigned long msr;
 	u8 error_type;
 
 	if (!rtas_error_extended(errp))
@@ -747,9 +748,21 @@ static int mce_handle_error(struct pt_regs *regs, struct rtas_error_log *errp)
 	 *       SLB multihit is done by now.
 	 */
 out:
-	mtmsr(mfmsr() | MSR_IR | MSR_DR);
+	msr = mfmsr();
+	mtmsr(msr | MSR_IR | MSR_DR);
+
 	disposition = mce_handle_err_virtmode(regs, errp, mce_log,
 					      disposition);
+
+	/*
+	 * Queue irq work to log this rtas event later.
+	 * irq_work_queue uses per-cpu variables, so do this in virt
+	 * mode as well.
+	 */
+	irq_work_queue(&mce_errlog_process_work);
+
+	mtmsr(msr);
+
 	return disposition;
 }
 
@@ -865,10 +878,8 @@ long pseries_machine_check_realmode(struct pt_regs *regs)
 		 * virtual mode.
 		 */
 		disposition = mce_handle_error(regs, errp);
-		fwnmi_release_errinfo();
 
-		/* Queue irq work to log this rtas event later. */
-		irq_work_queue(&mce_errlog_process_work);
+		fwnmi_release_errinfo();
 
 		if (disposition == RTAS_DISP_FULLY_RECOVERED)
 			return 1;
-- 
2.23.0


  reply	other threads:[~2021-02-07 12:57 UTC|newest]

Thread overview: 62+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-30 13:08 [PATCH v7 00/42] powerpc: interrupt wrappers Nicholas Piggin
2021-01-30 13:08 ` [PATCH v7 01/42] powerpc/64s: interrupt exit improve bounding of interrupt recursion Nicholas Piggin
2021-01-30 13:08 ` [PATCH v7 02/42] KVM: PPC: Book3S HV: Context tracking exit guest context before enabling irqs Nicholas Piggin
2021-01-30 13:08 ` [PATCH v7 03/42] powerpc/32s: move DABR match out of handle_page_fault Nicholas Piggin
2021-01-30 13:08 ` [PATCH v7 04/42] powerpc/64s: " Nicholas Piggin
2021-01-30 13:08 ` [PATCH v7 05/42] powerpc/64s: move the hash fault handling logic to C Nicholas Piggin
2021-01-30 13:08 ` [PATCH v7 06/42] powerpc: remove arguments from fault handler functions Nicholas Piggin
2021-01-30 13:08 ` [PATCH v7 07/42] powerpc/fsl_booke/32: CacheLockingException remove args Nicholas Piggin
2021-02-08 10:04   ` Gautham R Shenoy
2021-02-08 11:54     ` Michael Ellerman
2021-01-30 13:08 ` [PATCH v7 08/42] powerpc: do_break get registers from regs Nicholas Piggin
2021-01-30 13:08 ` [PATCH v7 09/42] powerpc: DebugException remove args Nicholas Piggin
2021-01-30 13:08 ` [PATCH v7 10/42] powerpc/32: transfer can avoid saving r4/r5 over trace call Nicholas Piggin
2021-01-30 13:08 ` [PATCH v7 11/42] powerpc: bad_page_fault get registers from regs Nicholas Piggin
2021-01-30 13:08 ` [PATCH v7 12/42] powerpc/64s: add do_bad_page_fault_segv handler Nicholas Piggin
2021-01-30 13:08 ` [PATCH v7 13/42] powerpc: rearrange do_page_fault error case to be inside exception_enter Nicholas Piggin
2021-01-30 13:08 ` [PATCH v7 14/42] powerpc/64s: move bad_page_fault handling to C Nicholas Piggin
2021-01-30 13:08 ` [PATCH v7 15/42] powerpc/64s: split do_hash_fault Nicholas Piggin
2021-01-30 13:08 ` [PATCH v7 16/42] powerpc/mm: Remove stale do_page_fault comment referring to SLB faults Nicholas Piggin
2021-01-30 13:08 ` [PATCH v7 17/42] powerpc/64s: slb comment update Nicholas Piggin
2021-01-30 13:08 ` [PATCH v7 18/42] powerpc/traps: add NOKPROBE_SYMBOL for sreset and mce Nicholas Piggin
2021-01-30 13:08 ` [PATCH v7 19/42] powerpc/perf: move perf irq/nmi handling details into traps.c Nicholas Piggin
2021-01-31 12:30   ` Athira Rajeev
2021-01-30 13:08 ` [PATCH v7 20/42] powerpc/time: move timer_broadcast_interrupt prototype to asm/time.h Nicholas Piggin
2021-01-30 13:08 ` [PATCH v7 21/42] powerpc: add and use unknown_async_exception Nicholas Piggin
2021-01-30 13:08 ` [PATCH v7 22/42] powerpc/cell: tidy up pervasive declarations Nicholas Piggin
2021-01-30 13:08 ` [PATCH v7 23/42] powerpc: introduce die_mce Nicholas Piggin
2021-01-30 13:08 ` [PATCH v7 24/42] powerpc/mce: ensure machine check handler always tests RI Nicholas Piggin
2021-01-30 13:08 ` [PATCH v7 25/42] powerpc: improve handling of unrecoverable system reset Nicholas Piggin
2021-01-30 13:08 ` [PATCH v7 26/42] powerpc: interrupt handler wrapper functions Nicholas Piggin
2021-01-30 13:08 ` [PATCH v7 27/42] powerpc: add interrupt wrapper entry / exit stub functions Nicholas Piggin
2021-01-30 13:08 ` [PATCH v7 28/42] powerpc: convert interrupt handlers to use wrappers Nicholas Piggin
2021-02-03  1:54   ` Nicholas Piggin
2021-02-05  8:09   ` Christophe Leroy
2021-02-06  2:43     ` Nicholas Piggin
2021-02-07 12:56     ` Nicholas Piggin
2021-01-30 13:08 ` [PATCH v7 29/42] powerpc: add interrupt_cond_local_irq_enable helper Nicholas Piggin
2021-01-30 13:08 ` [PATCH v7 30/42] powerpc/64: context tracking remove _TIF_NOHZ Nicholas Piggin
2021-01-30 13:08 ` [PATCH v7 31/42] powerpc/64s/hash: improve context tracking of hash faults Nicholas Piggin
2021-01-30 13:08 ` [PATCH v7 32/42] powerpc/64: context tracking move to interrupt wrappers Nicholas Piggin
2021-02-09  5:49   ` Christophe Leroy
2021-02-09  7:45     ` Nicholas Piggin
2021-01-30 13:08 ` [PATCH v7 33/42] powerpc/64: add context tracking to asynchronous interrupts Nicholas Piggin
2021-01-30 13:08 ` [PATCH v7 34/42] powerpc: handle irq_enter/irq_exit in interrupt handler wrappers Nicholas Piggin
2021-01-30 13:08 ` [PATCH v7 35/42] powerpc/64s: move context tracking exit to interrupt exit path Nicholas Piggin
2021-01-30 13:08 ` [PATCH v7 36/42] powerpc/64s: reconcile interrupts in C Nicholas Piggin
2021-01-30 13:08 ` [PATCH v7 37/42] powerpc/64: move account_stolen_time into its own function Nicholas Piggin
2021-01-30 13:08 ` [PATCH v7 38/42] powerpc/64: entry cpu time accounting in C Nicholas Piggin
2021-01-30 13:08 ` [PATCH v7 39/42] powerpc: move NMI entry/exit code into wrapper Nicholas Piggin
2021-02-04 10:15   ` Michael Ellerman
2021-02-04 11:31     ` Nicholas Piggin
2021-02-05 23:38       ` Michael Ellerman
2021-02-06  2:46         ` Nicholas Piggin
2021-02-07 12:54           ` Nicholas Piggin [this message]
2021-01-30 13:08 ` [PATCH v7 40/42] powerpc/64s: move NMI soft-mask handling to C Nicholas Piggin
2021-01-30 13:08 ` [PATCH v7 41/42] powerpc/64s: runlatch interrupt handling in C Nicholas Piggin
2021-01-30 13:08 ` [PATCH v7 42/42] powerpc/64s: power4 nap fixup " Nicholas Piggin
2021-02-02 10:31   ` Michael Ellerman
2021-02-03  0:35     ` Nicholas Piggin
2021-02-07 12:58     ` Nicholas Piggin
2021-02-02  5:57 ` [PATCH v7 00/42] powerpc: interrupt wrappers Christophe Leroy
2021-02-10 12:57 ` Michael Ellerman

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=1612702361.lm7fqo56re.astroid@bobo.none \
    --to=npiggin@gmail.com \
    --cc=atrajeev@linux.vnet.ibm.com \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=mpe@ellerman.id.au \
    /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 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.