Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp5745138rwb; Mon, 14 Nov 2022 08:54:23 -0800 (PST) X-Google-Smtp-Source: AA0mqf4Kx/nxQQmht/5cCSmiy96Kqdxv2IOHBA8hL/cvcQtwDZEV2/f5h8Yw8vBejpa/SmwhHFL1 X-Received: by 2002:a17:902:bb8f:b0:186:8f1c:ba11 with SMTP id m15-20020a170902bb8f00b001868f1cba11mr119170pls.90.1668444862916; Mon, 14 Nov 2022 08:54:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668444862; cv=none; d=google.com; s=arc-20160816; b=jLx3AopfTp8cTXJkEf/NpvYJkX8zo8M6ng/9SJiKnFdGwh6d/Bua94O5pU7fCBsITc t+GCgat1CkDmoIyVPzhBf2tNhkv/wbgU+U4W4DWENqeUvNe4S49VZtoCag4VP2f9av4O u1yZ8KMdShRcqWHtQ8B3Sn0svhkRFe3e8vd88WWIBl6mICi02vAz/xdV09MY1WIVkGHB iTlVY3Vdeh0V9X60ZvVMlaqdw/SM0RaysFpwHAsvLrpckLYS2/0j3JV2URtovc/2dbWM 3Cee5jcPBkBQxpiKg9V6yhlJiPKDkisykBFXaoDgmTVSsAs8Or4ZT50LxI1Q+jfZwHfk igkQ== 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 header.s=2020e header.b=mcYx8biV; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m21-20020a170902d19500b00186971db5fbsi8907350plb.220.2022.11.14.08.54.11; Mon, 14 Nov 2022 08:54:22 -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 header.s=2020e header.b=mcYx8biV; 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 + 87 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 ); 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 ; Mon, 14 Nov 2022 08:29:39 -0800 (PST) From: John Ogness 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 Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , 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: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- kernel/printk/printk.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) 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; + } + } + } } /* -- 2.30.2