* [PATCH v2 1/1] powerpc/crash: Use NMI context for printk when starting to crash
@ 2020-05-12 21:45 Leonardo Bras
2020-05-13 4:36 ` Nicholas Piggin
2020-06-09 5:28 ` Michael Ellerman
0 siblings, 2 replies; 4+ messages in thread
From: Leonardo Bras @ 2020-05-12 21:45 UTC (permalink / raw)
To: Michael Ellerman, Benjamin Herrenschmidt, Paul Mackerras,
Thomas Gleixner, Alexios Zavras, Enrico Weigelt,
Greg Kroah-Hartman, Leonardo Bras, Christophe Leroy
Cc: linuxppc-dev, linux-kernel
Currently, if printk lock (logbuf_lock) is held by other thread during
crash, there is a chance of deadlocking the crash on next printk, and
blocking a possibly desired kdump.
At the start of default_machine_crash_shutdown, make printk enter
NMI context, as it will use per-cpu buffers to store the message,
and avoid locking logbuf_lock.
Suggested-by: Michael Ellerman <mpe@ellerman.id.au>
Signed-off-by: Leonardo Bras <leobras.c@gmail.com>
---
Changes since v1:
- Added in-code comment explaining the need of context change
- Function moved to the start of default_machine_crash_shutdown,
to avoid locking any printk on crashing routine.
- Title was 'Use NMI context for printk after crashing other CPUs'
---
arch/powerpc/kexec/crash.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/arch/powerpc/kexec/crash.c b/arch/powerpc/kexec/crash.c
index d488311efab1..c9a889880214 100644
--- a/arch/powerpc/kexec/crash.c
+++ b/arch/powerpc/kexec/crash.c
@@ -311,6 +311,9 @@ void default_machine_crash_shutdown(struct pt_regs *regs)
unsigned int i;
int (*old_handler)(struct pt_regs *regs);
+ /* Avoid hardlocking with irresponsive CPU holding logbuf_lock */
+ printk_nmi_enter();
+
/*
* This function is only called after the system
* has panicked or is otherwise in a critical state.
--
2.25.4
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v2 1/1] powerpc/crash: Use NMI context for printk when starting to crash
2020-05-12 21:45 [PATCH v2 1/1] powerpc/crash: Use NMI context for printk when starting to crash Leonardo Bras
@ 2020-05-13 4:36 ` Nicholas Piggin
2020-05-13 5:16 ` Leonardo Bras
2020-06-09 5:28 ` Michael Ellerman
1 sibling, 1 reply; 4+ messages in thread
From: Nicholas Piggin @ 2020-05-13 4:36 UTC (permalink / raw)
To: Alexios Zavras, Benjamin Herrenschmidt, Christophe Leroy,
Greg Kroah-Hartman, Enrico Weigelt, Leonardo Bras,
Michael Ellerman, Paul Mackerras, Thomas Gleixner
Cc: linuxppc-dev, linux-kernel
Excerpts from Leonardo Bras's message of May 13, 2020 7:45 am:
> Currently, if printk lock (logbuf_lock) is held by other thread during
> crash, there is a chance of deadlocking the crash on next printk, and
> blocking a possibly desired kdump.
>
> At the start of default_machine_crash_shutdown, make printk enter
> NMI context, as it will use per-cpu buffers to store the message,
> and avoid locking logbuf_lock.
printk_nmi_enter is used in one other place outside nmi_enter.
Is there a different/better way to handle this? What do other
architectures do?
Other subsystems get put into an nmi-mode when we call nmi_enter
(lockdep, ftrace, rcu etc). It seems like those would be useful for
similar reasons, so at least explaining why that is not used in a
comment would be good.
Aside from that, I welcome any effort to make our crashes more reliable
so thanks for working on this stuff.
Thanks,
Nick
>
> Suggested-by: Michael Ellerman <mpe@ellerman.id.au>
> Signed-off-by: Leonardo Bras <leobras.c@gmail.com>
>
> ---
> Changes since v1:
> - Added in-code comment explaining the need of context change
> - Function moved to the start of default_machine_crash_shutdown,
> to avoid locking any printk on crashing routine.
> - Title was 'Use NMI context for printk after crashing other CPUs'
>
> ---
> arch/powerpc/kexec/crash.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/arch/powerpc/kexec/crash.c b/arch/powerpc/kexec/crash.c
> index d488311efab1..c9a889880214 100644
> --- a/arch/powerpc/kexec/crash.c
> +++ b/arch/powerpc/kexec/crash.c
> @@ -311,6 +311,9 @@ void default_machine_crash_shutdown(struct pt_regs *regs)
> unsigned int i;
> int (*old_handler)(struct pt_regs *regs);
>
> + /* Avoid hardlocking with irresponsive CPU holding logbuf_lock */
> + printk_nmi_enter();
> +
> /*
> * This function is only called after the system
> * has panicked or is otherwise in a critical state.
> --
> 2.25.4
>
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2 1/1] powerpc/crash: Use NMI context for printk when starting to crash
2020-05-13 4:36 ` Nicholas Piggin
@ 2020-05-13 5:16 ` Leonardo Bras
0 siblings, 0 replies; 4+ messages in thread
From: Leonardo Bras @ 2020-05-13 5:16 UTC (permalink / raw)
To: Nicholas Piggin, Alexios Zavras, Benjamin Herrenschmidt,
Christophe Leroy, Greg Kroah-Hartman, Enrico Weigelt,
Michael Ellerman, Paul Mackerras, Thomas Gleixner
Cc: linuxppc-dev, linux-kernel
Hello Nick, thanks for your feedback.
Comments inline:
On Wed, 2020-05-13 at 14:36 +1000, Nicholas Piggin wrote:
> Excerpts from Leonardo Bras's message of May 13, 2020 7:45 am:
> > Currently, if printk lock (logbuf_lock) is held by other thread during
> > crash, there is a chance of deadlocking the crash on next printk, and
> > blocking a possibly desired kdump.
> >
> > At the start of default_machine_crash_shutdown, make printk enter
> > NMI context, as it will use per-cpu buffers to store the message,
> > and avoid locking logbuf_lock.
>
> printk_nmi_enter is used in one other place outside nmi_enter.
>
> Is there a different/better way to handle this? What do other
> architectures do?
To be honest, I was unaware of nmi_enter() and I have yet to study what
other architectures do here.
> Other subsystems get put into an nmi-mode when we call nmi_enter
> (lockdep, ftrace, rcu etc). It seems like those would be useful for
> similar reasons, so at least explaining why that is not used in a
> comment would be good.
My reasoning for using printk_nmi_enter() here was only to keep it from
using printk regular buffer (and locking logbuf_lock) at this point of
the crash.
I have yet to see how nmi_enter() extra functions would happen to
interfere with the crash at this point.
(In a quick look at x86, (native_machine_crash_shutdown) I could not
see it using any printk, so it may not be necessary).
> Aside from that, I welcome any effort to make our crashes more reliable
> so thanks for working on this stuff.
>
> Thanks,
> Nick
Thank you, it means a lot.
Leonardo Bras
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2 1/1] powerpc/crash: Use NMI context for printk when starting to crash
2020-05-12 21:45 [PATCH v2 1/1] powerpc/crash: Use NMI context for printk when starting to crash Leonardo Bras
2020-05-13 4:36 ` Nicholas Piggin
@ 2020-06-09 5:28 ` Michael Ellerman
1 sibling, 0 replies; 4+ messages in thread
From: Michael Ellerman @ 2020-06-09 5:28 UTC (permalink / raw)
To: Thomas Gleixner, Greg Kroah-Hartman, Christophe Leroy,
Alexios Zavras, Leonardo Bras, Paul Mackerras,
Benjamin Herrenschmidt, Michael Ellerman, Enrico Weigelt
Cc: linuxppc-dev, linux-kernel
On Tue, 12 May 2020 18:45:35 -0300, Leonardo Bras wrote:
> Currently, if printk lock (logbuf_lock) is held by other thread during
> crash, there is a chance of deadlocking the crash on next printk, and
> blocking a possibly desired kdump.
>
> At the start of default_machine_crash_shutdown, make printk enter
> NMI context, as it will use per-cpu buffers to store the message,
> and avoid locking logbuf_lock.
Applied to powerpc/next.
[1/1] powerpc/crash: Use NMI context for printk when starting to crash
https://git.kernel.org/powerpc/c/af2876b501e42c3fb5174cac9dd02598436f0fdf
cheers
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2020-06-09 6:08 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-12 21:45 [PATCH v2 1/1] powerpc/crash: Use NMI context for printk when starting to crash Leonardo Bras
2020-05-13 4:36 ` Nicholas Piggin
2020-05-13 5:16 ` Leonardo Bras
2020-06-09 5:28 ` Michael Ellerman
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).