Skip to content

Commit 08d7865

Browse files
vittyvktorvalds
authored andcommitted
panic: release stale console lock to always get the logbuf printed out
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. [akpm@linux-foundation.org: tweak comment text] Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com> Cc: HATAYAMA Daisuke <d.hatayama@jp.fujitsu.com> Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com> Cc: Jiri Kosina <jkosina@suse.cz> Cc: Baoquan He <bhe@redhat.com> Cc: Prarit Bhargava <prarit@redhat.com> Cc: Xie XiuQi <xiexiuqi@huawei.com> Cc: Seth Jennings <sjenning@redhat.com> Cc: "K. Y. Srinivasan" <kys@microsoft.com> Cc: Jan Kara <jack@suse.cz> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 7f83064 commit 08d7865

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

kernel/panic.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <linux/sysrq.h>
2424
#include <linux/init.h>
2525
#include <linux/nmi.h>
26+
#include <linux/console.h>
2627

2728
#define PANIC_TIMER_STEP 100
2829
#define PANIC_BLINK_SPD 18
@@ -147,6 +148,15 @@ void panic(const char *fmt, ...)
147148

148149
bust_spinlocks(0);
149150

151+
/*
152+
* We may have ended up stopping the CPU holding the lock (in
153+
* smp_send_stop()) while still having some valuable data in the console
154+
* buffer. Try to acquire the lock then release it regardless of the
155+
* result. The release will also print the buffers out.
156+
*/
157+
console_trylock();
158+
console_unlock();
159+
150160
if (!panic_blink)
151161
panic_blink = no_blink;
152162

0 commit comments

Comments
 (0)