linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] panic: release stale console lock to always get the logbuf printed out
@ 2015-10-07 17:02 Vitaly Kuznetsov
  2015-10-07 22:34 ` Andrew Morton
  0 siblings, 1 reply; 11+ messages in thread
From: Vitaly Kuznetsov @ 2015-10-07 17:02 UTC (permalink / raw)
  To: Andrew Morton
  Cc: HATAYAMA Daisuke, Masami Hiramatsu, Jiri Kosina, Baoquan He,
	Prarit Bhargava, Xie XiuQi, Seth Jennings, linux-kernel,
	K. Y. Srinivasan

In some cases we may end up killing the CPU holding the console lock
while still having valuable data in logbuf. E.g. I'm observing the
following:
- A crash is happening on one CPU and console_unlock() is being called on
  some other.
- console_unlock() tries to print out the buffer before releasing the lock
  and on slow console it takes time.
- in the meanwhile crashing CPU does lots of printk()-s with valuable data
  (which go to the logbuf) and sends IPIs to all other CPUs.
- console_unlock() finishes printing previous chunk and enables interrupts
  before trying to print out the rest, the CPU catches the IPI and never
  releases console lock.
This is not the only possible case: in VT/fb subsystems we have many other
console_lock()/console_unlock() users. Non-masked interrupts (or receiving
NMI in case of extreme slowness) will have the same result. Getting the
whole console buffer printed out on crash should be top priority.

Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
---
 kernel/panic.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/kernel/panic.c b/kernel/panic.c
index 04e91ff..f94525f 100644
--- a/kernel/panic.c
+++ b/kernel/panic.c
@@ -23,6 +23,7 @@
 #include <linux/sysrq.h>
 #include <linux/init.h>
 #include <linux/nmi.h>
+#include <linux/console.h>
 
 #define PANIC_TIMER_STEP 100
 #define PANIC_BLINK_SPD 18
@@ -147,6 +148,15 @@ void panic(const char *fmt, ...)
 
 	bust_spinlocks(0);
 
+	/*
+	 * We may have ended up killing the CPU holding the lock and still have
+	 * some valuable data in console buffer. Try to acquire the lock and
+	 * release it regardless of the result. The release will also print the
+	 * buffers out.
+	 */
+	console_trylock();
+	console_unlock();
+
 	if (!panic_blink)
 		panic_blink = no_blink;
 
-- 
2.4.3


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

end of thread, other threads:[~2015-10-12  3:03 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-10-07 17:02 [PATCH] panic: release stale console lock to always get the logbuf printed out Vitaly Kuznetsov
2015-10-07 22:34 ` Andrew Morton
2015-10-08  9:01   ` Jan Kara
2015-10-08 10:03     ` Vitaly Kuznetsov
2015-10-08 20:56       ` Andrew Morton
2015-10-09 10:10         ` Vitaly Kuznetsov
2015-10-09 12:44           ` Vitaly Kuznetsov
2015-10-12  3:02     ` kbuild test robot
2015-10-08  9:51   ` Vitaly Kuznetsov
2015-10-08 20:54     ` Andrew Morton
2015-10-09 10:09       ` Vitaly Kuznetsov

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).