]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commitdiff
printk: Do not miss new messages when replaying the log
authorPetr Mladek <pmladek@suse.com>
Thu, 13 Sep 2018 12:34:06 +0000 (14:34 +0200)
committerKhalid Elmously <khalid.elmously@canonical.com>
Thu, 28 Nov 2019 04:59:27 +0000 (23:59 -0500)
BugLink: https://bugs.launchpad.net/bugs/1854216
[ Upstream commit f92b070f2dc89a8ff1a0cc8b608e20abef894c7d ]

The variable "exclusive_console" is used to reply all existing messages
on a newly registered console. It is cleared when all messages are out.

The problem is that new messages might appear in the meantime. These
are then visible only on the exclusive console.

The obvious solution is to clear "exclusive_console" after we replay
all messages that were already proceed before we started the reply.

Reported-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Link: http://lkml.kernel.org/r/20180913123406.14378-1-pmladek@suse.com
To: Steven Rostedt <rostedt@goodmis.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com>
Cc: linux-kernel@vger.kernel.org
Acked-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Signed-off-by: Petr Mladek <pmladek@suse.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Khalid Elmously <khalid.elmously@canonical.com>
kernel/printk/printk.c

index 98fb7509f1de759862cf690d54d4bf1bf2893dc1..b22c13c55d0e73a018ed885b0b3afcad9d26775b 100644 (file)
@@ -418,6 +418,7 @@ static u32 log_next_idx;
 /* the next printk record to write to the console */
 static u64 console_seq;
 static u32 console_idx;
+static u64 exclusive_console_stop_seq;
 
 /* the next printk record to read after the last 'clear' command */
 static u64 clear_seq;
@@ -2009,6 +2010,7 @@ static u64 syslog_seq;
 static u32 syslog_idx;
 static u64 console_seq;
 static u32 console_idx;
+static u64 exclusive_console_stop_seq;
 static u64 log_first_seq;
 static u32 log_first_idx;
 static u64 log_next_seq;
@@ -2371,6 +2373,12 @@ skip:
                        goto skip;
                }
 
+               /* Output to all consoles once old messages replayed. */
+               if (unlikely(exclusive_console &&
+                            console_seq >= exclusive_console_stop_seq)) {
+                       exclusive_console = NULL;
+               }
+
                len += msg_print_text(msg, false, text + len, sizeof(text) - len);
                if (nr_ext_console_drivers) {
                        ext_len = msg_print_ext_header(ext_text,
@@ -2410,10 +2418,6 @@ skip:
 
        console_locked = 0;
 
-       /* Release the exclusive_console once it is used */
-       if (unlikely(exclusive_console))
-               exclusive_console = NULL;
-
        raw_spin_unlock(&logbuf_lock);
 
        up_console_sem();
@@ -2702,6 +2706,7 @@ void register_console(struct console *newcon)
                 * the already-registered consoles.
                 */
                exclusive_console = newcon;
+               exclusive_console_stop_seq = console_seq;
        }
        console_unlock();
        console_sysfs_notify();