Message ID | 20221114162932.141883-6-john.ogness@linutronix.de |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2237828wru; Mon, 14 Nov 2022 08:30:53 -0800 (PST) X-Google-Smtp-Source: AA0mqf4qpsSdIy+Sj9snBMpkGPzpLjBElUebtcHVBkcZ/eh490Qid+MPhYOSaEAw2v0KXu+5M92F X-Received: by 2002:a17:90a:9ce:b0:206:238e:1379 with SMTP id 72-20020a17090a09ce00b00206238e1379mr14269891pjo.180.1668443452710; Mon, 14 Nov 2022 08:30:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668443452; cv=none; d=google.com; s=arc-20160816; b=uRv7exu4F0o2/KbYF0VbZTUsM5Vdf29qiQdXu0v+ETxdH+puzbiYNTtNcZOtafACax JE8TJVQkA7JQP20CSMzOxpR8GeDdGCqYPe8rmngUceAc+d9BJHKzkCaAyg+edu8elH29 T27pLS0dQA70MUD6OtBbqH+HNU1wv7pfkVfbrGKQYhbJDBZk6TKahqOJwWa+gNK3JzN5 GE2asKt9mO8+ieUxdDeacjEHgxIJlO1+D+pkwwdrnuOOFD5vnmqxsF6Fz/KJwyxaB+d2 pq3McZ9AxQWp+rw0aBEXxiNGTkzYLNr8EkAPIOqJBFmieoq/52urTabHzC/ColsXUIN5 T2Ag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:dkim-signature :dkim-signature:from; bh=BhPw3XXoH9XRWJswk/JBlglPwpWkjXWTrlT44qUapxw=; b=hg7H/sga1Iq7g9xtIyNY/NTZwewBLKazwmK1miPPrFMHB9sfbZXGa7PRxnOi2sd99x 0UiQYwhCTW0r0NAMhMeaBlCVootlSfeRUzINbzhMyrBbYq0CkB6nvS8IgzsBy5WTLx+b w6kpYEu5Zp8tcfKQOJjcsHDS8RwaxcS50my0/n0gFOrAGqVqOg6hJYi3iaj6h1Ir3X+q Q2M3aCMKIn1bWrNkbLzHNInj7448byJAaTvYQn3DH+hHujSuPfokXqUbggLb1xHX0Ost zIFrLwvKwQkrkT1pTsfUqVmMlJ0Z1JKErIRBMYIZ2A1hKc8PV7zdF09GPfbsqCyH5lXe PpHg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=Q1SMMXuy; dkim=neutral (no key) header.i=@linutronix.de; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x11-20020a170902b40b00b0017db9b9d54asi9089795plr.300.2022.11.14.08.30.26; Mon, 14 Nov 2022 08:30:52 -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; dkim=pass header.i=@linutronix.de header.s=2020 header.b=Q1SMMXuy; dkim=neutral (no key) header.i=@linutronix.de; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237587AbiKNQaC (ORCPT <rfc822;winker.wchi@gmail.com> + 99 others); Mon, 14 Nov 2022 11:30:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35558 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237520AbiKNQ3j (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 14 Nov 2022 11:29:39 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0FCB01090 for <linux-kernel@vger.kernel.org>; Mon, 14 Nov 2022 08:29:39 -0800 (PST) From: John Ogness <john.ogness@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668443376; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=BhPw3XXoH9XRWJswk/JBlglPwpWkjXWTrlT44qUapxw=; b=Q1SMMXuyxOWvBY4wLKbn6h5Ayn+3VnUgAJcz69djjTklbRksAE1N3c4XVMpOJtSekBo4HY CCmB6g/foSeYLFibrh7Uyxx8C86o3zjranTjmXECfC6cMBJ2aSLX7gB0UizVZVxOv3JvPY J5Ssv+H1AkQYBOXEqsf5JDpMEqWQoQ9PIpE84wRFAeddZvaMYCbj2hcFnKLG/lhdU1N0bH AxeNLePgmpp1h1Ff70eyoEXZ4dingPBZcY2PYsG+2udfVG/P7ad4gxFnURrJdE1vy6G7Ot RQsEcIBFSkvbKkmbMUQFf7H6ujxGmvtL8i3/gJiWZ2sNI60XOKQ1Qsjas0qPtA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668443376; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=BhPw3XXoH9XRWJswk/JBlglPwpWkjXWTrlT44qUapxw=; b=mcYx8biVkymW58t1QdV6MJQytDsSYwFv4bMvSNwMxW/UleRJ4Bh4P2+T+QkcYr7QJUtST6 9S69gAfrZxGJM7AA== To: Petr Mladek <pmladek@suse.com> Cc: Sergey Senozhatsky <senozhatsky@chromium.org>, Steven Rostedt <rostedt@goodmis.org>, Thomas Gleixner <tglx@linutronix.de>, linux-kernel@vger.kernel.org Subject: [PATCH printk v4 05/39] printk: fix setting first seq for consoles Date: Mon, 14 Nov 2022 17:34:58 +0106 Message-Id: <20221114162932.141883-6-john.ogness@linutronix.de> In-Reply-To: <20221114162932.141883-1-john.ogness@linutronix.de> References: <20221114162932.141883-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,INVALID_DATE_TZ_ABSURD, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749489761650071948?= X-GMAIL-MSGID: =?utf-8?q?1749489761650071948?= |
Series |
reduce console_lock scope
|
|
Commit Message
John Ogness
Nov. 14, 2022, 4:28 p.m. UTC
It used to be that all consoles were synchronized with respect to
which message they were printing. After commit a699449bb13b ("printk:
refactor and rework printing logic"), all consoles have their own
@seq for tracking which message they are on. That commit also changed
how the initial sequence number was chosen. Instead of choosing the
next non-printed message, it chose the sequence number of the next
message that will be added to the ringbuffer.
That change created a possibility that a non-boot console taking over
for a boot console might skip messages if the boot console was behind
and did not have a chance to catch up before being unregistered.
Since it is not possible to know which boot console a console is
taking over, use the lowest @seq of all the enabled boot consoles. If
no boot consoles are available/enabled, begin with the next message
that will be added to the ringbuffer.
Also, since boot consoles are meant to be used at boot time, handle
them the same as CON_PRINTBUFFER to ensure that no initial messages
are skipped.
Signed-off-by: John Ogness <john.ogness@linutronix.de>
---
kernel/printk/printk.c | 21 +++++++++++++++++++--
1 file changed, 19 insertions(+), 2 deletions(-)
Comments
On Mon 2022-11-14 17:34:58, John Ogness wrote: > It used to be that all consoles were synchronized with respect to > which message they were printing. After commit a699449bb13b ("printk: > refactor and rework printing logic"), all consoles have their own > @seq for tracking which message they are on. That commit also changed > how the initial sequence number was chosen. Instead of choosing the > next non-printed message, it chose the sequence number of the next > message that will be added to the ringbuffer. > > That change created a possibility that a non-boot console taking over > for a boot console might skip messages if the boot console was behind > and did not have a chance to catch up before being unregistered. > > Since it is not possible to know which boot console a console is > taking over, use the lowest @seq of all the enabled boot consoles. If > no boot consoles are available/enabled, begin with the next message > that will be added to the ringbuffer. > > Also, since boot consoles are meant to be used at boot time, handle > them the same as CON_PRINTBUFFER to ensure that no initial messages > are skipped. > > Signed-off-by: John Ogness <john.ogness@linutronix.de> Reviewed-by: Petr Mladek <pmladek@suse.com> Best Regards, Petr
diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 3d449dfb1ed6..8dbf3461cba0 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -3222,14 +3222,31 @@ void register_console(struct console *newcon) } newcon->dropped = 0; - if (newcon->flags & CON_PRINTBUFFER) { + if (newcon->flags & (CON_PRINTBUFFER | CON_BOOT)) { /* Get a consistent copy of @syslog_seq. */ mutex_lock(&syslog_lock); newcon->seq = syslog_seq; mutex_unlock(&syslog_lock); } else { - /* Begin with next message. */ + /* Begin with next message added to ringbuffer. */ newcon->seq = prb_next_seq(prb); + + /* + * If any enabled boot consoles are due to be unregistered + * shortly, some may not be caught up and may be the same + * device as @newcon. Since it is not known which boot console + * is the same device, start with the message of the enabled + * boot console that is the furthest behind. + */ + if (bootcon_registered && !keep_bootcon) { + for_each_console(con) { + if ((con->flags & CON_BOOT) && + (con->flags & CON_ENABLED) && + con->seq < newcon->seq) { + newcon->seq = con->seq; + } + } + } } /*