diff options
author | Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com> | 2018-04-18 21:42:50 -0400 |
---|---|---|
committer | Petr Mladek <pmladek@suse.com> | 2018-04-25 07:26:02 -0400 |
commit | 43a17111c2553925f65e7be9b9c3f9d90cf29a8b (patch) | |
tree | 3e14a2ad36779608bc6d4d3bfbdb12ef6c5482d2 | |
parent | 357aa6aefebe888c712152cb83c9e700f98eebd1 (diff) |
printk: wake up klogd in vprintk_emit
We wake up klogd very late - only when current console_sem owner
is done pushing pending kernel messages to the serial/net consoles.
In some cases this results in lost syslog messages, because kernel
log buffer is a circular buffer and if we don't wakeup syslog long
enough there are chances that logbuf simply will wrap around.
The patch moves the klogd wake up call to vprintk_emit(), which is
the only legit way for a kernel message to appear in the logbuf,
right after the attempt to handle consoles. As a result, klogd
will get waken either after flushing the new message to consoles
or immediately when consoles are still busy with older messages.
Link: http://lkml.kernel.org/r/20180419014250.5692-1-sergey.senozhatsky@gmail.com
To: Steven Rostedt <rostedt@goodmis.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Tejun Heo <tj@kernel.org>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Signed-off-by: Petr Mladek <pmladek@suse.com>
-rw-r--r-- | kernel/printk/printk.c | 14 |
1 files changed, 2 insertions, 12 deletions
diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 704e55129c3a..fba995b305b1 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c | |||
@@ -1907,6 +1907,7 @@ asmlinkage int vprintk_emit(int facility, int level, | |||
1907 | preempt_enable(); | 1907 | preempt_enable(); |
1908 | } | 1908 | } |
1909 | 1909 | ||
1910 | wake_up_klogd(); | ||
1910 | return printed_len; | 1911 | return printed_len; |
1911 | } | 1912 | } |
1912 | EXPORT_SYMBOL(vprintk_emit); | 1913 | EXPORT_SYMBOL(vprintk_emit); |
@@ -2288,9 +2289,7 @@ void console_unlock(void) | |||
2288 | { | 2289 | { |
2289 | static char ext_text[CONSOLE_EXT_LOG_MAX]; | 2290 | static char ext_text[CONSOLE_EXT_LOG_MAX]; |
2290 | static char text[LOG_LINE_MAX + PREFIX_MAX]; | 2291 | static char text[LOG_LINE_MAX + PREFIX_MAX]; |
2291 | static u64 seen_seq; | ||
2292 | unsigned long flags; | 2292 | unsigned long flags; |
2293 | bool wake_klogd = false; | ||
2294 | bool do_cond_resched, retry; | 2293 | bool do_cond_resched, retry; |
2295 | 2294 | ||
2296 | if (console_suspended) { | 2295 | if (console_suspended) { |
@@ -2334,11 +2333,6 @@ again: | |||
2334 | 2333 | ||
2335 | printk_safe_enter_irqsave(flags); | 2334 | printk_safe_enter_irqsave(flags); |
2336 | raw_spin_lock(&logbuf_lock); | 2335 | raw_spin_lock(&logbuf_lock); |
2337 | if (seen_seq != log_next_seq) { | ||
2338 | wake_klogd = true; | ||
2339 | seen_seq = log_next_seq; | ||
2340 | } | ||
2341 | |||
2342 | if (console_seq < log_first_seq) { | 2336 | if (console_seq < log_first_seq) { |
2343 | len = sprintf(text, "** %u printk messages dropped **\n", | 2337 | len = sprintf(text, "** %u printk messages dropped **\n", |
2344 | (unsigned)(log_first_seq - console_seq)); | 2338 | (unsigned)(log_first_seq - console_seq)); |
@@ -2396,7 +2390,7 @@ skip: | |||
2396 | 2390 | ||
2397 | if (console_lock_spinning_disable_and_check()) { | 2391 | if (console_lock_spinning_disable_and_check()) { |
2398 | printk_safe_exit_irqrestore(flags); | 2392 | printk_safe_exit_irqrestore(flags); |
2399 | goto out; | 2393 | return; |
2400 | } | 2394 | } |
2401 | 2395 | ||
2402 | printk_safe_exit_irqrestore(flags); | 2396 | printk_safe_exit_irqrestore(flags); |
@@ -2428,10 +2422,6 @@ skip: | |||
2428 | 2422 | ||
2429 | if (retry && console_trylock()) | 2423 | if (retry && console_trylock()) |
2430 | goto again; | 2424 | goto again; |
2431 | |||
2432 | out: | ||
2433 | if (wake_klogd) | ||
2434 | wake_up_klogd(); | ||
2435 | } | 2425 | } |
2436 | EXPORT_SYMBOL(console_unlock); | 2426 | EXPORT_SYMBOL(console_unlock); |
2437 | 2427 | ||