Message ID | 20221107141638.3790965-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 l7csp2078360wru; Mon, 7 Nov 2022 06:20:27 -0800 (PST) X-Google-Smtp-Source: AMsMyM5WZwjGGaXqRgZ6dIpC8svP2HCMCzFYlydJQeRsitS0z0wkJSLtH6HArC1AkOpEb7gMxWr5 X-Received: by 2002:a63:5a41:0:b0:430:673e:1e13 with SMTP id k1-20020a635a41000000b00430673e1e13mr44494214pgm.435.1667830826671; Mon, 07 Nov 2022 06:20:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667830826; cv=none; d=google.com; s=arc-20160816; b=YOXm3JR/gGjrJX3ablXDJPlRS5NV2hphDikMW6HO/Y3pOBvu5Z3RaehOIqny14xC4J LT7yKU1eYQDoSPMGxLmWf2J574jYZ8/FbIZGrIyBhEwRqTit+dFu2syGphkFVAl1v6qz 1u5QiRy1l+Rrev/kKv09W+vuKakSW2L0CsLWOYAi1CUAXfMHoRpOl7eVUAl4gtzX2FQu /W5ZjnSK8L4sfUeByqTs+WD8A9IKvfpVeGvqN9z0jgU1q43zlndJuZ6VbBNOQpWPvkMu EYkDq73PuTqmNmIY1eSZHiWMFn5cn1VsIpSaRzwBbAju3VNEHoUoOwVBdtS7yMqgyWLh dLlQ== 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=4n04ln6Ch/hdvzpbKZeVJtV0DW7GpBDW/64Z1krMb78=; b=QwxZkT00jn7AKTWqevvdMwt3OrfkYTNuT2xBM9M5cy7VK3H5CTWOTTp8pu9cAIeu1N MgsgXT7jOOHvrntb1DdS2VzfoSP1YpmFAb5egM4anurpcXKN3XqxqLAaN/UoX8kkHEvB 5rw2w9EWK02YrxIb084ZMBcVB0qGhkfWlKMeoIWZebuld3+u5fyRnmxMcrLd72gwaOa8 NL9FUANmfZcfRwz/5hxYOP3P+qCE4veNEOuFpCTZi7Wo3E4L3B1CvAw325gxzN4dnV8a 92suq44QprhjJGD2bu/aQ9sP2NeN3zKJN2c7Z+9fkGD/2lCDzJ8a54A0dWEnFzg7XAW+ KGpg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=fjFDBOuE; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=i2mJNvHh; 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 l70-20020a638849000000b0045cbd4e43b8si8136574pgd.511.2022.11.07.06.20.11; Mon, 07 Nov 2022 06:20:26 -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=fjFDBOuE; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=i2mJNvHh; 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 S231809AbiKGORP (ORCPT <rfc822;hjfbswb@gmail.com> + 99 others); Mon, 7 Nov 2022 09:17:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55672 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232095AbiKGOQq (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 7 Nov 2022 09:16:46 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 17CC71CFF6 for <linux-kernel@vger.kernel.org>; Mon, 7 Nov 2022 06:16:45 -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=1667830602; 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=4n04ln6Ch/hdvzpbKZeVJtV0DW7GpBDW/64Z1krMb78=; b=fjFDBOuExj6AkzrBAgwGsZMWcQG7o8pcYxBeiRO9Hv5/MET+Urn/iU0k73K8KQVlMlUNpM FY+dleU7ocJj0ji81DsotW8vyOMG0D5M1iG7cmDJAaecNz7sH9SRPGHJJCmZcQBb+npM5o lJ0doKia/xvyGmtxJ5kwiPyMJtZqOe0h2Z2CxI35d7hqo2qKdthMC3yWtHOGMY88eLckEs 1Tz8RmJZ/H8/5654j9UFU19pDfIJWfawwbZHcQB+sptO2JpX6Oamb+OWlXEAFBWqGuOX3P n7AnRlDjpaJEB/ZcSIAtzUA/p3z/pTCXdt5NGwFbE/98sWE93QhtL7XkWfWFEQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1667830602; 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=4n04ln6Ch/hdvzpbKZeVJtV0DW7GpBDW/64Z1krMb78=; b=i2mJNvHheKNDa4WvDo4khjz/Y4qbCG/JXNJubnpudAH/q8vUufrKnKB9RlhTArcA9d3SNr EtHCyjWatvPZE0AQ== 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 v3 05/40] printk: fix setting first seq for consoles Date: Mon, 7 Nov 2022 15:22:03 +0106 Message-Id: <20221107141638.3790965-6-john.ogness@linutronix.de> In-Reply-To: <20221107141638.3790965-1-john.ogness@linutronix.de> References: <20221107141638.3790965-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?1748847376993271412?= X-GMAIL-MSGID: =?utf-8?q?1748847376993271412?= |
Series |
reduce console_lock scope
|
|
Commit Message
John Ogness
Nov. 7, 2022, 2:16 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 | 16 ++++++++++++++--
1 file changed, 14 insertions(+), 2 deletions(-)
Comments
On Mon 2022-11-07 15:22:03, 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 173f46a29252..8974523f3107 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -3222,14 +3222,26 @@ 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 an enabled boot console is not caught up, start with + * that message instead. That boot console will be + * unregistered shortly and may be the same device. + */ + for_each_console(con) { + if ((con->flags & (CON_BOOT | CON_ENABLED)) == (CON_BOOT | CON_ENABLED) && + con->seq < newcon->seq) { + newcon->seq = con->seq; + } + } } /*