Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp2973246ybc; Thu, 14 Nov 2019 01:58:44 -0800 (PST) X-Google-Smtp-Source: APXvYqzUm5mNgMxffqQNreOCDcwC5DTr5YEe/2eZqAjXfzpMo4fDmVoa+7NKc8CoD0/yeiBDtbvQ X-Received: by 2002:a17:906:948a:: with SMTP id t10mr7453385ejx.110.1573725524818; Thu, 14 Nov 2019 01:58:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573725524; cv=none; d=google.com; s=arc-20160816; b=Lgx/pOEZnsWyC+kOke7akWTeBSHyVohaAi3ZtQuiaXMKJ3h7u7i27StzGFPrjAMrtI z70J7qHcIRvmnT9ONgC+3wBZuyHlw9Rzz2GAKTbk/Ujvf9oU2NW//FEeFCv8g+VMRe4d 1TEZnwG8iXN+YDq9RS3JYm+nhJzTAzIfkBV6abak/jbBCbNaT4zxywRO1hx4saM3/rhY y1hxv/jRC7cng7VYj6eqnGEUw8kGzLkDtccIkodTY3h40f5xMXTdIO/TiUyAiBfWFdkw 9SSROC9LhcQshEGbRzY7Puxp03CDv6O4g/eIu7tq3PQvZuZabdfBhM0PI88F3yJ+d7tW Prig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=ro8iatAniD0TtcNRzrTynzULGnjmM8SdDbcYFFI1eAc=; b=IDBleeE0I6LNA8cUXXnbF2LyaxumedHQ3ABsXThncpT9hv38/PsCHkRjeZbVihQnGg 5W55KMrjBZEl5ouhWR73waVvnN4t9omRTAKVnsjOf6/L3cn4BtQtfK1p4WZ04WKd7ixe VXfTZtvZhaa3vsRVj3QOvnGsuxyRDd5iEqh+lifbQHzBmAdW6uZasn6mgfRVlLp6mZbs Ml7dYH5WeOt9QAwhCHbrnMQzPfnEuvWffOhQ3LpGxQQTMqsNWTsGeFzMYKP5h2ViKO+E i3svg7dsz4JioO5flgwWF/cg4Fy1w6athk4sTXm7ABojG8/uJ3tmuqyM5SHUcApHdO8V DHJw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e19si3184348edr.255.2019.11.14.01.58.19; Thu, 14 Nov 2019 01:58:44 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726276AbfKNJ5l (ORCPT + 99 others); Thu, 14 Nov 2019 04:57:41 -0500 Received: from mx2.suse.de ([195.135.220.15]:41516 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726024AbfKNJ5k (ORCPT ); Thu, 14 Nov 2019 04:57:40 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 59227ADBB; Thu, 14 Nov 2019 09:57:38 +0000 (UTC) Date: Thu, 14 Nov 2019 10:57:37 +0100 From: Petr Mladek To: Jonathan Richardson Cc: gregkh@linuxfoundation.org, jslaby@suse.com, sergey.senozhatsky@gmail.com, linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, Scott Branden , Ray Jui , Srinath Mannam Subject: Re: console output duplicated when registering additional consoles Message-ID: <20191114095737.wl5nvxu3w6p5thfc@pathway.suse.cz> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20170912 (1.9.0) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed 2019-11-13 17:28:45, Jonathan Richardson wrote: > Adding printk maintainers. > This commit seems to have introduced the error: > > commit f92b070f2dc89a8ff1a0cc8b608e20abef894c7d > Author: Petr Mladek > Date: Thu Sep 13 14:34:06 2018 +0200 > > printk: Do not miss new messages when replaying the log > > If I checkout to the commit before > (a06b0c82a049d34d4dc273e8692ed0894458c468), the console output is > normal when registering 2 bootconsoles and 2 normal consoles. I've > added the log for 4.19.0-rc3 for comparison (previous version was > 5.1.0). I don't think this commit took into account that more than one > console could be registered. When the second console is registered, > 'console_seq >= exclusive_console_stop_seq' is true (both are 0) and > exclusive_console is always set to NULL resulting in the log being > replayed again to the uart8250 console: This race should not happen because Both exclusive_console and exclusive_console_stop_seq are manipulated under console_lock. And the log is replayed before console_lock is released. > /* Output to all consoles once old messages replayed. */ > if (unlikely(exclusive_console && > console_seq >= exclusive_console_stop_seq)) { > exclusive_console = NULL; > } > > I'm looking into it but any input is helpful. Thanks. IMHO, the problem is that the log should not be replayed at all. See the following code in register_console(): /* * If we have a bootconsole, and are switching to a real console, * don't print everything out again, since when the boot console, and * the real console are the same physical device, it's annoying to * see the beginning boot messages twice */ if (bcon && ((newcon->flags & (CON_CONSDEV | CON_BOOT)) == CON_CONSDEV)) newcon->flags &= ~CON_PRINTBUFFER; I already see two problems there: 1. CON_PRINTBUFFER is cleared only when the new console has CON_CONSDEV flag set. It is set only for the console that is defined as the last on the command line. It is a so-called preferred console. 2. bcon is set to the first console in console_drivers list. It is the first registered boot console. Sigh, this works for simple configuration. But it fails badly when more different consoles are configured. We should clear CON_PRINTBUFFER flag when the real console replacing an already registered boot console is registered. BTW: Similar bug is also at the end of register_console(). The boot consoles are unregistered only when the preferred console is installed. For a proper solution we would need to match boot and real consoles that write messages into the physical device. But I am afraid that there is no support for this. con->match() callback compares the name defined on the command line. And it has side effects (the matching console is prepared for registration). To be honest I am not much familiar with the device interface. I am not sure if there is a way to detect the two drivers use the same physical hardware. Sigh, it is a huge historical mess. It would needed a lot of work to clean it up. Best Regards, Petr