From patchwork Thu Feb 24 04:40:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukas Wunner X-Patchwork-Id: 61121 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp706759wrd; Thu, 23 Feb 2023 21:01:27 -0800 (PST) X-Google-Smtp-Source: AK7set+wnUWAAZWKYPu9hfZ9BcYcRa6dqd/TgcLSGPGTI3NHQTme/H7siBhgQqC58aZ23V9ho/Lu X-Received: by 2002:a17:907:1c8c:b0:8e6:d08d:f5e8 with SMTP id nb12-20020a1709071c8c00b008e6d08df5e8mr11467218ejc.11.1677214887656; Thu, 23 Feb 2023 21:01:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677214887; cv=none; d=google.com; s=arc-20160816; b=bh/U3HMP9MEm6BtKDCQM827HyyzVfz9q62Y8leAAp+puuf5u0ZBeDVKtvGsIXR4t7c KOHdKAb/kz9cd/v7fEngbHtoEcIM4dPOVsr4jzyfte4fhwDKqz2Ux3dbBY4qd/0rDgTt rRjgZkOXMWoQRQrkn1DcadWg43ZUMRWIOJGFD04IruSE+kLsntqt5ZfGOg6JyGsdLUNL REKoULGc5UfUDnSSJC7n0jJXHaschquY+cejtWmtfq8E8xqMAE32as9c2AGautFHfl4/ L+5JwKAf7A2x5hNAf8bYwlObjDjU5GuHftUCZQTcZzffinAKo04n9dnBRcLjPTDH8hoT pFVA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:date:from:message-id; bh=6cZ2JhqRKp5EBEKFOrGpcpM7CcEUL9VFYC3JvGme2kU=; b=iPal6Za73nE55tXOowGfoWDUNovF5GkuV2GKqzjb62OE1fZ4rwsu9VhnBqH2vPPYgm 6uf3osI41tDbwqKyvBIR4ZrGiiy7h+5V+yVhE+3Vs+41QYXeJTibVJ5tTinXaSczXrOc hI4V8935dFjjNmXgsmn3seaQ1A39FELfivUIPgbgrTCBoGVEbOLKSLOp6Y75EsFks7B9 FhEocQ5mIeuGPpP6rfywzWvXvdl8HbuqfmTeVnczLePbptzd1Xib7E+zEOzWuoUvYnkp leXygoM2x9dbQ2Ct0LYiFsqx/Oi22mRyIfW1j193VogTp4dqVDtYmEfrWiOOxR789AiK 8fnQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id fm21-20020a1709072ad500b008b17e1a54edsi20240335ejc.788.2023.02.23.21.00.56; Thu, 23 Feb 2023 21:01:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229478AbjBXEqZ (ORCPT + 99 others); Thu, 23 Feb 2023 23:46:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57318 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229506AbjBXEqW (ORCPT ); Thu, 23 Feb 2023 23:46:22 -0500 X-Greylist: delayed 341 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Thu, 23 Feb 2023 20:46:18 PST Received: from mailout2.hostsharing.net (mailout2.hostsharing.net [IPv6:2a01:37:3000::53df:4ee9:0]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B25E351F87 for ; Thu, 23 Feb 2023 20:46:18 -0800 (PST) Received: from h08.hostsharing.net (h08.hostsharing.net [IPv6:2a01:37:1000::53df:5f1c:0]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "*.hostsharing.net", Issuer "RapidSSL Global TLS RSA4096 SHA256 2022 CA1" (verified OK)) by mailout2.hostsharing.net (Postfix) with ESMTPS id 2C44310189CFC; Fri, 24 Feb 2023 05:40:34 +0100 (CET) Received: from localhost (unknown [89.246.108.87]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by h08.hostsharing.net (Postfix) with ESMTPSA id EA28561CE0A1; Fri, 24 Feb 2023 05:40:33 +0100 (CET) X-Mailbox-Line: From 13e4bdf7677924c689a70d0b7ad970a3255a8d41 Mon Sep 17 00:00:00 2001 Message-Id: <13e4bdf7677924c689a70d0b7ad970a3255a8d41.1677213245.git.lukas@wunner.de> From: Lukas Wunner Date: Fri, 24 Feb 2022 05:40:33 +0100 Subject: [PATCH for-6.4] printk: Unregister boot consoles on register of 1st real console To: Petr Mladek , Sergey Senozhatsky Cc: Steven Rostedt , John Ogness , Lino Sanfilippo , linux-kernel@vger.kernel.org X-Spam-Status: No, score=1.5 required=5.0 tests=BAYES_00,DATE_IN_PAST_96_XX, SPF_HELO_NONE,SPF_NONE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Level: * X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1758687278147696998?= X-GMAIL-MSGID: =?utf-8?q?1758687278147696998?= The code comment preceding register_console() claims that: "There are two types of consoles - bootconsoles (early_printk) and "real" consoles (everything which is not a bootconsole) which are handled differently. [...] As soon as a "real" console is registered, all bootconsoles will be unregistered automatically." But that's not what the code does: The code unregisters bootconsoles only when the *preferred* console registers, i.e. the last one on the command line. If that console's driver never registers (e.g. because it is disabled in the kernel config), bootconsoles stay around indefinitely. Should the command line contain both a bootconsole as well as a real console on the same serial port, all messages are logged twice once the real console registers. Moreover, the log buffer is replayed once the real console registers even though the messages were already emitted by the bootconsole. Amend the code to be congruent with the above-quoted code comment and thereby avoid these issues. Signed-off-by: Lukas Wunner --- kernel/printk/printk.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index fd0c9f913940..f89e865c6b23 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -3423,10 +3423,8 @@ void register_console(struct console *newcon) * the real console are the same physical device, it's annoying to * see the beginning boot messages twice */ - if (bootcon_registered && - ((newcon->flags & (CON_CONSDEV | CON_BOOT)) == CON_CONSDEV)) { + if (bootcon_registered && !(newcon->flags & CON_BOOT)) newcon->flags &= ~CON_PRINTBUFFER; - } newcon->dropped = 0; console_init_seq(newcon, bootcon_registered); @@ -3465,8 +3463,7 @@ void register_console(struct console *newcon) * went to the bootconsole (that they do not see on the real console) */ con_printk(KERN_INFO, newcon, "enabled\n"); - if (bootcon_registered && - ((newcon->flags & (CON_CONSDEV | CON_BOOT)) == CON_CONSDEV) && + if (bootcon_registered && !(newcon->flags & CON_BOOT) && !keep_bootcon) { struct hlist_node *tmp;