All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] printk: Do not miss new messages when replaying the log
@ 2018-09-13 12:34 Petr Mladek
  2018-10-03  9:23 ` Petr Mladek
  0 siblings, 1 reply; 2+ messages in thread
From: Petr Mladek @ 2018-09-13 12:34 UTC (permalink / raw)
  To: Sergey Senozhatsky, Steven Rostedt
  Cc: Peter Zijlstra, Sergey Senozhatsky, linux-kernel, Petr Mladek

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>
Signed-off-by: Petr Mladek <pmladek@suse.com>
Acked-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
---
 kernel/printk/printk.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index e30e5023511b..54dfc441a692 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -421,6 +421,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;
@@ -2007,6 +2008,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;
@@ -2373,6 +2375,12 @@ void console_unlock(void)
 			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,
 				console_msg_format & MSG_FORMAT_SYSLOG,
 				text + len,
@@ -2415,10 +2423,6 @@ void console_unlock(void)
 
 	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();
@@ -2703,6 +2707,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();
-- 
2.13.7


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

* Re: [PATCH] printk: Do not miss new messages when replaying the log
  2018-09-13 12:34 [PATCH] printk: Do not miss new messages when replaying the log Petr Mladek
@ 2018-10-03  9:23 ` Petr Mladek
  0 siblings, 0 replies; 2+ messages in thread
From: Petr Mladek @ 2018-10-03  9:23 UTC (permalink / raw)
  To: Sergey Senozhatsky, Steven Rostedt
  Cc: Peter Zijlstra, Sergey Senozhatsky, linux-kernel

On Thu 2018-09-13 14:34:06, Petr Mladek wrote:
> 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>
> Signed-off-by: Petr Mladek <pmladek@suse.com>
> Acked-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>

JFYI, I have pushed this into printk.git, for-4.20 branch.

Best Regards,
Petr

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

end of thread, other threads:[~2018-10-03  9:23 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-09-13 12:34 [PATCH] printk: Do not miss new messages when replaying the log Petr Mladek
2018-10-03  9:23 ` Petr Mladek

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.