public inbox for linux-rt-users@vger.kernel.org
 help / color / mirror / Atom feed
From: John Ogness <john.ogness@linutronix.de>
To: "André Pribil" <Andre.Pribil@hms-networks.com>,
	"linux-rt-users@vger.kernel.org" <linux-rt-users@vger.kernel.org>
Subject: [PATCH] printk/console: Enable console kthreads only when there is no boot console left
Date: Tue, 21 Feb 2023 17:21:08 +0106	[thread overview]
Message-ID: <878rgrro4z.fsf@jogness.linutronix.de> (raw)
In-Reply-To: <87bklnro9j.fsf@jogness.linutronix.de>

The console kthreads uncovered several races in console drivers.
All problems were in situation when a console was being properly
initialized and registered while an early console, using the same
port, was being used.

These problems are pretty hard to debug because they often result
into silent boot crashes. It would be nice to fix them but it
looks like a can of worms.

Prevent these problems by delaying the use of console kthreads
after all early consoles are gone. It might later be optimized.
But let's close this can of worms with a big hammer for now
so that they do not break first impression on the kthreads
that solve other real problems.

Link: https://lore.kernel.org/r/20220619204949.50d9154d@thinkpad
Link: https://lore.kernel.org/r/2a82eae7-a256-f70c-fd82-4e510750906e@samsung.com
Reported-by: Marek Behún <kabel@kernel.org>
Signed-off-by: Petr Mladek <pmladek@suse.com>
Tested-by: Marek Behún <kabel@kernel.org>
[ rebased for 5.10.165-rt81 by john.ogness ]
---
 kernel/printk/printk.c | 31 ++++++++++++++++++++++++++-----
 1 file changed, 26 insertions(+), 5 deletions(-)

diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index d2205872304d..db095bd0f17c 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -2986,6 +2986,21 @@ void __init console_init(void)
 	}
 }
 
+#ifdef CONFIG_PRINTK
+static int __init printk_activate_kthreads(void)
+{
+	struct console *con;
+
+	console_lock();
+	for_each_console(con)
+		printk_start_kthread(con);
+	kthreads_started = true;
+	console_unlock();
+
+	return 0;
+}
+#endif
+
 /*
  * Some boot consoles access data that is in the init section and which will
  * be discarded after the initcalls have been run. To make sure that no code
@@ -3002,6 +3017,7 @@ void __init console_init(void)
  */
 static int __init printk_late_init(void)
 {
+	bool no_bootcon = true;
 	struct console *con;
 	int ret;
 
@@ -3023,15 +3039,20 @@ static int __init printk_late_init(void)
 			pr_warn("bootconsole [%s%d] uses init memory and must be disabled even before the real one is ready\n",
 				con->name, con->index);
 			unregister_console(con);
+			continue;
 		}
+
+		no_bootcon = false;
 	}
 
 #ifdef CONFIG_PRINTK
-	console_lock();
-	for_each_console(con)
-		start_printk_kthread(con);
-	kthreads_started = true;
-	console_unlock();
+	/*
+	 * Some console drivers are not ready to use the same port with
+	 * boot (early) and normal console in parallel. Stay on the safe
+	 * side and enable kthreads only when there is no boot console.
+	 */
+	if (no_bootcon)
+		printk_activate_kthreads();
 #endif
 
 	ret = cpuhp_setup_state_nocalls(CPUHP_PRINTK_DEAD, "printk:dead", NULL,
-- 
2.30.2

  reply	other threads:[~2023-02-21 16:16 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-21 12:38 printk: console output corrupted André Pribil
2023-02-21 16:12 ` John Ogness
2023-02-21 16:15   ` John Ogness [this message]
2023-02-22 10:53     ` [PATCH] printk/console: Enable console kthreads only when there is no boot console left André Pribil
2023-02-22 14:35       ` André Pribil

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=878rgrro4z.fsf@jogness.linutronix.de \
    --to=john.ogness@linutronix.de \
    --cc=Andre.Pribil@hms-networks.com \
    --cc=linux-rt-users@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox