Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp365653ybv; Thu, 13 Feb 2020 01:53:48 -0800 (PST) X-Google-Smtp-Source: APXvYqx5ky3NohWHfYzVWZLw/eZ/9xhDHD1wL2ilvjXP0tQmJT9a6VHPeX9hPINeJl/t4vEl2vbI X-Received: by 2002:a9d:4110:: with SMTP id o16mr12740276ote.101.1581587628758; Thu, 13 Feb 2020 01:53:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581587628; cv=none; d=google.com; s=arc-20160816; b=U4eBjzE0Am4hb+W36B9IL5jJVxBDqDLaD0ZGfgngPtyw5oduV6SvcFDXGV0fJ0bRl8 YOIKI0aMMjXTrLKeE1SvRZGhZrVpzAdWhkwD/36AN9bGDNP6MPPmM+J3tVfJR3+nBLA0 4cq9nHE0RoNMvUm30brcMZRqa976wcZwW/aqivjD7h61A0AD1oYTuUVExp+lwrnJgMoJ cnXM3W9r9tthKpy5IzXL6wCKS7B4/b1iznzzCmFGkY4/xH32iiPdQPSlFTS/j63Webvc Hg92g0aTDvaJyuS3ML9AZut7ApcC5Jhi8iVz/4Bnfa4688ElaYeBfwWO+Gp5hlaB6KrJ ZK1Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=eUTeZksDRKqpUJwTkMnDHnu3vXXFTIsR4mnVUxW/0CU=; b=0EghB0TDrC9VIjQuUR714yoT3Rqt98aILYiuzx7ZGEc35WQF7YV512vlCEUGI8ahwl DJCPvVw5B8SMrWY4bh1BAtfZqK+61AQW9/axrhxjxhLVdVNxfqS8WlXGDQM6J6Xbv5PK 5NcJS0s/b65fC/qOaGQlX1/BfOO8qeObQZFSS5qhvXVky3I49zyRfhGAgA7izOTjGfkA lPV8bjSnjXI8PILr7890TdoIYltJTfxxNA4pgBI/njhX/cond6tWr5qQoL3C8E+oyN64 bqPBBs9l1QGG59RLku4Wpcf0G/sfpx7/bSGgEoQMI0VHR+lySq3iMIwuUVg2sONeyg/K bEEA== 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 x16si916502otk.13.2020.02.13.01.53.36; Thu, 13 Feb 2020 01:53:48 -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 S1729845AbgBMJv6 (ORCPT + 99 others); Thu, 13 Feb 2020 04:51:58 -0500 Received: from mx2.suse.de ([195.135.220.15]:41218 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729805AbgBMJv5 (ORCPT ); Thu, 13 Feb 2020 04:51:57 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 381B5B240; Thu, 13 Feb 2020 09:51:56 +0000 (UTC) From: Petr Mladek To: Sergey Senozhatsky , Steven Rostedt , Benjamin Herrenschmidt Cc: Peter Zijlstra , John Ogness , linux-kernel@vger.kernel.org Subject: [PATCH v4 3/3] printk: Correctly set CON_CONSDEV even when preferred console was not registered Date: Thu, 13 Feb 2020 10:51:33 +0100 Message-Id: <20200213095133.23176-4-pmladek@suse.com> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20200213095133.23176-1-pmladek@suse.com> References: <20200213095133.23176-1-pmladek@suse.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Benjamin Herrenschmidt CON_CONSDEV flag was historically used to put/keep the preferred console first in console_drivers list. Where the preferred console is the last on the command line. The ordering is important only when opening /dev/console: + tty_kopen() + tty_lookup_driver() + console_device() The flag was originally an implementation detail. But it was later made accessible from userspace via /proc/consoles. It was used, for example, by the tool "showconsole" to show the real tty accessible via /dev/console, see https://github.com/bitstreamout/showconsole Now, the current code sets CON_CONSDEV only for the preferred console or when a fallback console is added. The flag is not set when the preferred console is defined on the command line but it is not registered from some reasons. Simple solution is to set CON_CONSDEV flag for the first registered console. It will work most of the time because: + Most real consoles have console->device defined. + Boot consoles are removed in printk_late_init(). + unregister_console() moves CON_CONSDEV flag to the next console. Clean solution would require checking con->device when the preferred console is registered and in unregister_console(). Conclusion: Use the simple solution for now. It is better than the current state and good enough. The clean solution is not worth it. It would complicate the already complicated code without too much gain. Instead the code would deserve a complete rewrite. Signed-off-by: Benjamin Herrenschmidt [pmladek@suse.com: Correct reasoning in the commit message, comment update.] Reviewed-by: Petr Mladek --- include/linux/console.h | 2 +- kernel/printk/printk.c | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/include/linux/console.h b/include/linux/console.h index f33016b3a401..57ae2dedb51f 100644 --- a/include/linux/console.h +++ b/include/linux/console.h @@ -134,7 +134,7 @@ static inline int con_debug_leave(void) */ #define CON_PRINTBUFFER (1) -#define CON_CONSDEV (2) /* Last on the command line */ +#define CON_CONSDEV (2) /* Preferred console, /dev/console */ #define CON_ENABLED (4) #define CON_BOOT (8) #define CON_ANYTIME (16) /* Safe to call when cpu is offline */ diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index f76ef3f0efca..cf0ceacdae2f 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -2788,6 +2788,8 @@ void register_console(struct console *newcon) console_drivers = newcon; if (newcon->next) newcon->next->flags &= ~CON_CONSDEV; + /* Ensure this flag is always set for the head of the list */ + newcon->flags |= CON_CONSDEV; } else { newcon->next = console_drivers->next; console_drivers->next = newcon; -- 2.16.4