Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp365733rwb; Fri, 18 Nov 2022 02:35:24 -0800 (PST) X-Google-Smtp-Source: AA0mqf4UVMaQYYrCVH6gcB8na4A/UT8mKqKCbtRaZ6+Y7zmzcEmUfMjpuj//4M4oQXcp78RiFxRF X-Received: by 2002:a17:902:6b4a:b0:186:acb1:891d with SMTP id g10-20020a1709026b4a00b00186acb1891dmr6806414plt.160.1668767724653; Fri, 18 Nov 2022 02:35:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668767724; cv=none; d=google.com; s=arc-20160816; b=okZD0DCugqlVfbVwaOGHfZMqNAvjkCujoy59R+12yP4RrLpNTo8ON9PDuNzVTo4rNu mO55rYk4qEKc7ZJmp9zrn0G1bE/Jr2eD0YOxde7+1UBCVQIrztlM8aa2qytNfKz/zTKB +iW/qQEzjUTw4cOgnp7YQ3Iei4LQaciX1WpmKDkBkUENwmXv0ThDK9iunJWu2ljwEgeJ zksIcJLmR/DRw7g8SmuVl5FuThoDMXdVzo/EKg9BDJ8eb1YkOpeEt9w20i02JBYCqt2s FeNQjZdHjMwEQz6mXLjlm9iWhWRs6bLrmfmQu7fPHJiau+gF0GsIyGrOPmsLdZ+/PJ4d himA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=+iV7qxgfXIas0r1bWwuhYw2vLMjDfUDRt2URAsaMlpU=; b=lvdnMqmj6IRScY4yxnZpqg3DQorE1f2OoXXZx+8HXvyFnEx3g/06MGAZaWxhcjLEdO rjPNMMV0/sT02Zko41NzZ/iKgwdZ/T5JLHKmcFmklSQ2ROemUdWYp3eC8BZmVYpMYHbP WwysIehlcCmCwlxKFITzfZslBPUkGmqvg1LPTP5hjJ5GI50++GajsoqogDLtSCkoqou0 lKFV9MqlL94phgOS6+nvGFFAuYoqtFkPwFYDz2SYbhMvpS0k4VD6TlCz9uePtD1PCBkE +2/TqS3ppwh5qkDT5YYFiG7IIiaZs/RfvzEeDErm7l8EyHiHnidM/3LiGtQag4WFpUhs blVQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=QqCSgMTS; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z18-20020a63e552000000b00476a08c5d68si3602447pgj.822.2022.11.18.02.35.13; Fri, 18 Nov 2022 02:35:24 -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=@suse.com header.s=susede1 header.b=QqCSgMTS; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241657AbiKRKX6 (ORCPT + 91 others); Fri, 18 Nov 2022 05:23:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50328 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241649AbiKRKX4 (ORCPT ); Fri, 18 Nov 2022 05:23:56 -0500 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C25F3F027 for ; Fri, 18 Nov 2022 02:23:54 -0800 (PST) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 8349C1F890; Fri, 18 Nov 2022 10:23:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1668767033; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=+iV7qxgfXIas0r1bWwuhYw2vLMjDfUDRt2URAsaMlpU=; b=QqCSgMTSCXufvadkR2iVDiO5Vqja5qqcCGCAMboJGvDTDNnRTjON9zKeCkswtOYBWXxese 9c5PQRWO2X6nAxOl3Opyj0VGI3kQwDXpgcwVH1wP+En31Ml6HI7aI4ZtVB/ag/B2FOPxSm XpyMKZyLVgqUGGTJSppaZj6OiXVr0E4= Received: from suse.cz (unknown [10.100.201.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id 3AA9E2C141; Fri, 18 Nov 2022 10:23:53 +0000 (UTC) Date: Fri, 18 Nov 2022 11:23:52 +0100 From: Petr Mladek To: John Ogness Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: Re: [PATCH printk v5 06/40] printk: fix setting first seq for consoles Message-ID: References: <20221116162152.193147-1-john.ogness@linutronix.de> <20221116162152.193147-7-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221116162152.193147-7-john.ogness@linutronix.de> X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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 On Wed 2022-11-16 17:27:18, 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 known which boot console is the same device, flush > all consoles and, if necessary, start with the message of the enabled > boot console that is the furthest behind. If no boot consoles are > 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 Reviewed-by: Petr Mladek See one possible improvement below. > --- a/kernel/printk/printk.c > +++ b/kernel/printk/printk.c > @@ -3131,16 +3131,56 @@ static void try_enable_default_console(struct console *newcon) > (con->flags & CON_BOOT) ? "boot" : "", \ > con->name, con->index, ##__VA_ARGS__) > > -static void console_init_seq(struct console *newcon) > +static void console_init_seq(struct console *newcon, bool bootcon_registered) > { > - if (newcon->flags & CON_PRINTBUFFER) { > + struct console *con; > + bool handover; > + > + 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, flush all consoles and, if necessary, > + * start with the message of the enabled boot console that is > + * the furthest behind. > + */ > + if (bootcon_registered && !keep_bootcon) { > + /* > + * Flush all consoles and set the console to start at > + * the next unprinted sequence number. > + */ > + if (!console_flush_all(true, &newcon->seq, &handover)) { > + /* > + * Flushing failed. Just choose the lowest > + * sequence of the enabled boot consoles. > + */ > + > + /* > + * If there was a handover, this context no > + * longer holds the console_lock. > + */ > + if (handover) > + console_lock(); Another improvement might be to disable handover in this case. It would be safe because we are in a sleepable context. It would increase the chance that console_fluhs_all() succeeded. On the other hand, it might cause that this caller gets stuck here because of flood of messages printed by another caller. We could do this later when there are problems with this approach. The problem with the handover has been there even before. I do not want to delay this patchset by discussion this non-critical problem to the death ;-) Best Regards, Petr