From: Konstantin Khlebnikov <khlebnikov@yandex-team.ru>
To: Petr Mladek <pmladek@suse.com>,
linux-kernel@vger.kernel.org,
Steven Rostedt <rostedt@goodmis.org>,
Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Subject: [PATCH v2] kernel/printk: prevent deadlock at unexpected call kmsg_dump in NMI context
Date: Mon, 15 Jul 2019 11:04:55 +0300 [thread overview]
Message-ID: <156317789553.326.15952579019338825022.stgit@buzz> (raw)
Kernel message dumper - function kmsg_dump() is called on various oops or
panic paths which could happen in unpredictable context including NMI.
Panic in NMI is handled especially by stopping all other cpus with
smp_send_stop() and busting locks in printk_safe_flush_on_panic().
Other less-fatal cases shouldn't happen in NMI and cannot be handled.
But this might happen for example on oops in nmi context. In this case
dumper could deadlock on lockbuf_lock or break internal structures.
This patch catches kmsg_dump() called in NMI context except panic and
prints warning once.
Signed-off-by: Konstantin Khlebnikov <khlebnikov@yandex-team.ru>
Link: https://lore.kernel.org/lkml/156294329676.1745.2620297516210526183.stgit@buzz/ (v1)
---
kernel/printk/printk.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index 1888f6a3b694..e711f64a1843 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -3104,6 +3104,13 @@ void kmsg_dump(enum kmsg_dump_reason reason)
struct kmsg_dumper *dumper;
unsigned long flags;
+ /*
+ * In NMI context only panic could be handled safely:
+ * it stops other cpus and busts logbuf lock.
+ */
+ if (WARN_ON_ONCE(reason != KMSG_DUMP_PANIC && in_nmi()))
+ return;
+
if ((reason > KMSG_DUMP_OOPS) && !always_kmsg_dump)
return;
next reply other threads:[~2019-07-15 8:05 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-07-15 8:04 Konstantin Khlebnikov [this message]
2019-07-16 7:41 ` [PATCH v2] kernel/printk: prevent deadlock at unexpected call kmsg_dump in NMI context Petr Mladek
2019-07-16 7:55 ` Konstantin Khlebnikov
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=156317789553.326.15952579019338825022.stgit@buzz \
--to=khlebnikov@yandex-team.ru \
--cc=linux-kernel@vger.kernel.org \
--cc=pmladek@suse.com \
--cc=rostedt@goodmis.org \
--cc=sergey.senozhatsky@gmail.com \
/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).