From nobody Fri Oct 2 04:35:59 2026 Received: from out28-197.mail.aliyun.com (out28-197.mail.aliyun.com [115.124.28.197]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 30DF93EB11E for ; Wed, 5 Aug 2026 09:21:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.28.197 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785921668; cv=none; b=tUO7wJVLrAF7wSlQsUxiOloW6O9uMzPsQKWzPmwEBQZLjI15o50No+RRBzfZlFeFC0lY9uO5YlyfZzuna9Q2zh1DasnUxxhUBAaI9mCofshB8wskArRFhWXJI1ySYyj7g+jBhjHahVhlMaBX3KM4MotcZj5yAYmkl772wScZDio= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785921668; c=relaxed/simple; bh=3aLQtRTwtoG0Di4rCKDRH9I+tiEDmL7FodkztCj3fe4=; h=From:To:Cc:Subject:Date:Message-Id; b=tk73fhTCABZfG+Fg5Ym5WDw1XJr7FLvUkRJHVo18FDzCA/0QdCd9jYN/AelUvAexNjFrAq0xoaBF7piKz97at5VijmMltCMUDHlm00aX/f/hXu22lBgoa1Jc2zIZkQ8wPlxYk2yilDBqU2D6ee1n1ukTvMFwEkImEMXWQichelQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=open-hieco.net; spf=pass smtp.mailfrom=open-hieco.net; arc=none smtp.client-ip=115.124.28.197 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=open-hieco.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=open-hieco.net X-Alimail-AntiSpam: AC=CONTINUE;BC=0.07528795|-1;CH=green;DM=|CONTINUE|false|;DS=CONTINUE|ham_system_inform|0.138925-0.000531669-0.860544;FP=3012044126974739583|2|1|1|0|-1|-1|-1;HT=maildocker-contentspam033045220102;MF=lixiaochun@open-hieco.net;NM=1;PH=DS;RN=6;RT=6;SR=0;TI=SMTPD_---.ieQ0UAj_1785921287; Received: from localhost.localdomain(mailfrom:lixiaochun@open-hieco.net fp:SMTPD_---.ieQ0UAj_1785921287 cluster:ay29) by smtp.aliyun-inc.com; Wed, 05 Aug 2026 17:15:33 +0800 From: Xiaochun Li To: pmladek@suse.com Cc: rostedt@goodmis.org, john.ogness@linutronix.de, senozhatsky@chromium.org, linux-kernel@vger.kernel.org, Xiaochun Li Subject: [PATCH v2] printk: Remove remaining boot consoles when a real console exists Date: Wed, 5 Aug 2026 16:48:46 +0800 Message-Id: <20260805084846.1802042-1-lixiaochun@open-hieco.net> X-Mailer: git-send-email 2.18.2 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Boot consoles are temporary and should be removed once a real console is available. However, the late init cleanup currently only unregisters boot consoles that use init section memory. Other boot consoles are expected to be removed when the real preferred console is registered. This does not cover cases where a real console has registered, but the boot console was not removed because the real console did not become the preferred console. For example, with multiple console=3D parameters using the same driver, a real 8250 console may be enabled while the early console remains registered. The result is duplicate printk output from both consoles. In the mailing list discussion, two possible approaches were suggested to fix this problem [1]. This patch implements the first one: during printk_late_init(), check whether at least one real console is already registered. If so, unregister all remaining boot consoles. If no real console exists yet, keep the existing behavior and unregister only boot consoles that reference init section memory, avoiding a period with no console output while waiting for a deferred or modular real console. Suggested-by: Petr Mladek Link: https://lore.kernel.org/lkml/ahBsSW2bB2CRfW-k@pathway.suse.cz/ # [1] Signed-off-by: Xiaochun Li --- kernel/printk/printk.c | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 2fe9a963c823..5a5ec7ac99bd 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -4420,36 +4420,48 @@ void __init console_init(void) * be a brief interval in which no messages are logged to the console, whi= ch * makes it difficult to diagnose problems that occur during this time. * - * To mitigate this problem somewhat, only unregister consoles whose memory - * intersects with the init section. Note that all other boot consoles will - * get unregistered when the real preferred console is registered. + * If a real console has already registered, remove all remaining boot con= soles. + * Otherwise, mitigate the no-console interval by removing only boot conso= les + * whose memory intersects with the init section. */ static int __init printk_late_init(void) { + bool realcon_registered =3D false; struct hlist_node *tmp; struct console *con; int ret; =20 console_list_lock(); + for_each_console(con) { + if (!(con->flags & CON_BOOT)) { + realcon_registered =3D true; + break; + } + } + hlist_for_each_entry_safe(con, tmp, &console_list, node) { if (!(con->flags & CON_BOOT)) continue; =20 - /* Check addresses that might be used for enabled consoles. */ - if (init_section_intersects(con, sizeof(*con)) || - init_section_contains(con->write, 0) || - init_section_contains(con->read, 0) || - init_section_contains(con->device, 0) || - init_section_contains(con->unblank, 0) || - init_section_contains(con->data, 0)) { + if (!realcon_registered) { + /* Check addresses that might be used for enabled consoles. */ + if (!init_section_intersects(con, sizeof(*con)) && + !init_section_contains(con->write, 0) && + !init_section_contains(con->read, 0) && + !init_section_contains(con->device, 0) && + !init_section_contains(con->unblank, 0) && + !init_section_contains(con->data, 0)) + continue; + /* * Please, consider moving the reported consoles out * of the init section. */ 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_locked(con); } + + unregister_console_locked(con); } console_list_unlock(); =20 --=20 2.18.2