From patchwork Thu Apr 30 16:14:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alper Nebi Yasak X-Patchwork-Id: 11520847 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C9996913 for ; Thu, 30 Apr 2020 16:16:48 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A005420873 for ; Thu, 30 Apr 2020 16:16:48 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="IO1epTC7"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="sosUSrAu" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A005420873 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=lC/+rsUbM2+sUOIirPBytShJsGIZjCR59tpSpD/9CpM=; b=IO1epTC79M/DTU d/KAIDA7OPnX1jeQ4X3iBa3F9CuvUFlgtkYTCEEa+T9EhoZhe6yY2gdeQtXlDUEhCz5Sf7MdrRhxn OE1TZjvTLeJ1eF6RQoVTLy5iw9IjNZNViFp+GHGmKBlgkMRlWIlz17XqV6igGyC4pT7lxVCSKrHi+ 7uAzlm1xcTzw60mttZ9TaVbR9/cVIYFrh9uoQSErv9WHXiYsD5QGJqz46pFSZeoY+z8gW8Soi9B7E xMFdLCg85lFn+BCXltxGyigrub9vIB7IrkfBZ66oUzhq+4XOt2NN7lKqoqWJ+DMrEgMGsMO5gDx1R ta8/9bqoYElSrfesJSSQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jUBrZ-0002KY-Dn; Thu, 30 Apr 2020 16:16:37 +0000 Received: from mail-lj1-x242.google.com ([2a00:1450:4864:20::242]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jUBrV-0002F3-NM for linux-arm-kernel@lists.infradead.org; Thu, 30 Apr 2020 16:16:35 +0000 Received: by mail-lj1-x242.google.com with SMTP id a21so7070493ljj.11 for ; Thu, 30 Apr 2020 09:16:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=dcawBkXikPYOd9gFykEVGPuWXUWfQrJeZCwUFjbXlT4=; b=sosUSrAuUHwXK5OEpDrkqaJHrO0GGy0Ln5+fNdN+gN6s5xxybYMfk62DTRz82hFfDW 3WsUtL5mZtTtjasdrGDXuLX2ENo0nhL8CRdGd74HWHwz3Y/lLcmgVn8w01cgM9gIYSWy 1ClW/qZfGqJQKSpQZiLtz7DccWTt1sbgjnej1CuSydRY/DBLa+BQdaaVd4SgxYuTZAc+ 2YgxHtxvdynliAeIBWW300Rq2M7JTEnyXdt/G4CdzegQM8ORS3/eBubBGzy2nENr9s66 tMOSZY6mY7hx0HwZufKzxtYA8dCj2iV167701I6iC3ADwXddcvMiFgS2X52N8DC6+Luj 21rA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=dcawBkXikPYOd9gFykEVGPuWXUWfQrJeZCwUFjbXlT4=; b=ePkh2lu8poDcyFCtbpxlqqxR9yqkczf6q0jTppF3Hde1Vn9WCLzslmzs8NiDQBkNMy bPzzRY1oVRuJdqSHHab/7bZf02eYCkWz+wwPjpEbMB8zeVY2xdd2WXO53xjeWwXEQ5AP C4TvFg6R+e7G+imSILlBFn5+0NJe4fGM/hAF6a/r1A5qlJpLJOVPgqu2MJOZMCh1n593 aN/QS+EBWiN1EJ5cYKjVt3XcNdQBnltU+122OruYkmgxwCIfMVRKPAepicRvCrXn/sQO 1oQgu7VqKKO6gIgr0oBLp9+blR9lKeMgEpPJgZXZIRZKM52r17DcJ+1XYc1OuN8mH0Rf 9MJA== X-Gm-Message-State: AGi0PuY2asijGS/iK6rUtgUGsj5JDD4DyCTKOOVBHYs+gkueQoC+OIZj QcF5/EHaEifkHRIq6xY5gf4= X-Google-Smtp-Source: APiQypJlHPjg7i2J2gTNDSPTCeeNvzQBhsBhfepNh86Pej0Lou55gA4cVl+9dZI3HWGt3Ys5ggHMhQ== X-Received: by 2002:a2e:b012:: with SMTP id y18mr44709ljk.238.1588263391301; Thu, 30 Apr 2020 09:16:31 -0700 (PDT) Received: from localhost.localdomain ([178.233.178.9]) by smtp.gmail.com with ESMTPSA id k6sm60638lfm.91.2020.04.30.09.16.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Apr 2020 09:16:30 -0700 (PDT) From: Alper Nebi Yasak To: Greg Kroah-Hartman , Jiri Slaby , Petr Mladek , Sergey Senozhatsky Subject: [RFC PATCH v2 1/3] printk: Add function to set console to preferred console's driver Date: Thu, 30 Apr 2020 19:14:35 +0300 Message-Id: <20200430161438.17640-2-alpernebiyasak@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200430161438.17640-1-alpernebiyasak@gmail.com> References: <20200430161438.17640-1-alpernebiyasak@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200430_091633_837619_8EED5D92 X-CRM114-Status: GOOD ( 20.85 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.4 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:242 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [alpernebiyasak[at]gmail.com] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Arvind Sankar , Benjamin Herrenschmidt , linux-kernel@vger.kernel.org, Steven Rostedt , Alper Nebi Yasak , linux-serial@vger.kernel.org, Andrew Morton , Andy Shevchenko , Feng Tang , "David S. Miller" , linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org Currently, add_preferred_console sets a preferred console, but doesn't actually change /dev/console to match it. That part is handled within register_device, where a newly registered console driver will be set as /dev/console if it matches the preferred console. However, if the relevant driver is already registered, the only way to set it as /dev/console is by un-registering and re-registering it. An example is the xenfb_make_preferred_console() function: console_lock(); for_each_console(c) { if (!strcmp(c->name, "tty") && c->index == 0) break; } console_unlock(); if (c) { unregister_console(c); c->flags |= CON_CONSDEV; c->flags &= ~CON_PRINTBUFFER; /* don't print again */ register_console(c); } The code above was introduced in commit 9e124fe16ff2 ("xen: Enable console tty by default in domU if it's not a dummy"). In short, it's aim is to set VT as the preferred console only after a working framebuffer is registered and thus VT is not the dummy device. This patch introduces an update_console_to_preferred function that handles the necessary /dev/console change. With this change, the example above can be replaced with: console_lock(); add_preferred_console("tty", 0, NULL); update_console_to_preferred(); console_unlock(); More importantly, these two calls can be moved to vt.c in order to bump its priority when a non-dummy backend for it is introduced, solving that problem in general. Signed-off-by: Alper Nebi Yasak --- Changes in v2: - Use the correct format when referencing a commit include/linux/console.h | 1 + kernel/printk/printk.c | 56 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/include/linux/console.h b/include/linux/console.h index 75dd20650fbe..4b3fa34be245 100644 --- a/include/linux/console.h +++ b/include/linux/console.h @@ -172,6 +172,7 @@ enum con_flush_mode { }; extern int add_preferred_console(char *name, int idx, char *options); +extern int update_console_to_preferred(void); extern void register_console(struct console *); extern int unregister_console(struct console *); extern struct console *console_drivers; diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 6ede4a7222e6..efda422203e4 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -2240,12 +2240,68 @@ __setup("console=", console_setup); * be used by arch-specific code either to override the user or more * commonly to provide a default console (ie from PROM variables) when * the user has not supplied one. + * + * Preferences set by this function don't take effect until the next + * time a matching driver for the preferred console is registered. If a + * matching driver was already registered, @update_console_to_preferred + * function can be used to set that as the preferred console driver. */ int add_preferred_console(char *name, int idx, char *options) { return __add_preferred_console(name, idx, options, NULL, false); } +/** + * update_console_to_preferred - set console to the preferred console's driver. + * + * Updates console_drivers and CON_CONSDEV flags so that an already + * registered and enabled console driver matching the preferred console + * is used as /dev/console. + * + * Must be called within console_lock();. + */ +int update_console_to_preferred(void) +{ + struct console_cmdline *c = NULL; + struct console *con = NULL; + struct console *tmp = NULL; + + if (preferred_console >= 0) + c = &console_cmdline[preferred_console]; + + if (!c || !c->name[0]) + return 0; + + for_each_console(con) { + if (!con->next || !(con->next->flags & CON_ENABLED)) + continue; + if (strcmp(c->name, con->next->name) != 0) + continue; + if (con->next->index >= 0 && + con->next->index != c->index) + continue; + break; + } + + if (!con) + return -ENODEV; + + pr_info("switching to console [%s%d]\n", + con->next->name, con->next->index); + + tmp = con->next; + con->next = con->next->next; + tmp->next = console_drivers; + console_drivers = tmp; + + if (console_drivers->next) + console_drivers->next->flags &= ~CON_CONSDEV; + console_drivers->flags |= CON_CONSDEV; + has_preferred_console = true; + + return 0; +} + bool console_suspend_enabled = true; EXPORT_SYMBOL(console_suspend_enabled); From patchwork Thu Apr 30 16:14:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alper Nebi Yasak X-Patchwork-Id: 11520855 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C47A7912 for ; Thu, 30 Apr 2020 16:17:12 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A1F2D208C3 for ; Thu, 30 Apr 2020 16:17:12 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="Z8ie9TX9"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="f+ltUI3k" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A1F2D208C3 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Vwu0bYIuFYjS1nF5/tjpdjsRZdDv9BQVCrr8756q0tY=; b=Z8ie9TX95rdDuy nrAEX+oGtCgONmuyZsbURw0RLsEWySZJFzxIM6NK4gOQwpUoTmyV4K/1qZ7FJBK/uIRZlgCeaigfk 4I8igXbSSYndiDEwdTot1+YLht1A+bXbcy+r86Mbn0tnju5DM9MV5h6DGOZF9oPfZFOxRJzSMhhY/ eqTIkLYPb7UOv5F6r8gaCR+PGJZFJID+hLOxNY/AaMUMTL+9sr8J/fjTEhG741S4uj+Ga7NtCWbs1 AYCJPHfo3inQS65wI074TXplZVj4FKy/9AuB17CSQRKZa0wrGWzOnYnV9PMO/Puc3E5z17EoS6QtH 3snIYCQ0SQXQsrhP92nQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jUBs4-0002i1-HT; Thu, 30 Apr 2020 16:17:08 +0000 Received: from mail-lf1-x141.google.com ([2a00:1450:4864:20::141]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jUBrc-0002Lh-Se for linux-arm-kernel@lists.infradead.org; Thu, 30 Apr 2020 16:16:42 +0000 Received: by mail-lf1-x141.google.com with SMTP id l11so1713743lfc.5 for ; Thu, 30 Apr 2020 09:16:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=f4TIH8T2iwoy55Ek+4uzhpC1K3VxmoO9RghZLrsLIIU=; b=f+ltUI3klX7y7558UAfiJcLaATEoefw+BMqDr8OH8fF8pzj+J2m70msHpKH57IMN/G CeFOpjAq9DVo8HCD85cPTH1DNF/I1uGD2I4dSPwfDg9FZVFOF8CPw3PQqKYM4RLjavnU SVeUbxBJiXKOKzdIkvmfdLeFLEjE4UjMRoyzzP8nAMdD0St8Ge5acgahuYKIAgNnXqxG u1Wyrl/CU7E7J0lgVSfiGGxSNsvA7RncjakrnyQEoaaVu9xIDTem5xeJj/cZcH+cDABx VIMA2YSzihLF6GVMffFXG8Tkq+EJfXpesZnUK/avHiN/rXxGlskNz86CVExnyw27nXPX Cmgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=f4TIH8T2iwoy55Ek+4uzhpC1K3VxmoO9RghZLrsLIIU=; b=YNB+tt72dbSu+5kOUY+NAjutZNa0AhrNCtBcoRzqAG7MuChekzNMPzvKG6PZF60KWh SA5LcUUKIZKCkl27hYKmxa0tks6qN/Iv47mNlbWOmUESO1zxRbFsJB3mKdHFkvgptCrL wdIC5moU8AH5vpOrMk9+C55ckWYXI6NJv9UIo/Y0JuvSRABA6qnFxiD7TDhAs8SwjANz Tx4W0rHN0i9x5EilPAbB+vwv752v+4B53O0+jdxhN043+rjnZ+Ewul7QSF4y9KuyG74y pHKvPzACwy+Y9y4OIM3COGA0329oRXfo1v3DclRxu8PtOD7jxYxkBW8p2CZcLwMajbWM kLAQ== X-Gm-Message-State: AGi0PuYCi1/s+JYCp2wvGoiaOsmFRCRPSjHY+AxAdJ/luAaPXSgU69TI njJ6lZlI3CE8LxEcMkNO7ns= X-Google-Smtp-Source: APiQypKW0OOMGsBaRso8KpIF88W8pneAiyKgyjSDkdDS+lc6s6+VB6QTd8CG5k93j4XxhkCbFMDS7g== X-Received: by 2002:ac2:4105:: with SMTP id b5mr2763461lfi.94.1588263397052; Thu, 30 Apr 2020 09:16:37 -0700 (PDT) Received: from localhost.localdomain ([178.233.178.9]) by smtp.gmail.com with ESMTPSA id k6sm60638lfm.91.2020.04.30.09.16.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Apr 2020 09:16:36 -0700 (PDT) From: Alper Nebi Yasak To: Greg Kroah-Hartman , Jiri Slaby , Petr Mladek , Sergey Senozhatsky Subject: [RFC PATCH v2 2/3] vt: Set as preferred console when a non-dummy backend is bound Date: Thu, 30 Apr 2020 19:14:36 +0300 Message-Id: <20200430161438.17640-3-alpernebiyasak@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200430161438.17640-1-alpernebiyasak@gmail.com> References: <20200430161438.17640-1-alpernebiyasak@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200430_091640_938282_BC16E221 X-CRM114-Status: GOOD ( 17.43 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.4 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:141 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [alpernebiyasak[at]gmail.com] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Eric Biggers , Daniel Vetter , Nicolas Pitre , linux-kernel@vger.kernel.org, Steven Rostedt , Alper Nebi Yasak , Grzegorz Halat , linux-serial@vger.kernel.org, Lukas Wunner , Sam Ravnborg , linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org When a machine's device-tree has a "chosen" node with a "stdout-path" property that specified console is added as the preferred console by of_console_check via an add_preferred_console call. The property is quite common in kernel device-tree definitions. As far as I can tell, it is set to provide a reasonable default value for earlycon, and the (usually serial) console is set as preferred to avoid output going to VT's dummy backend instead of a working console. However, a chosen stdout-path property is included even in device-trees of systems that are designed to be used with a built-in display, e.g. several ARM Chromebooks. In these cases where CONFIG_VT_CONSOLE is enabled and no console argument is given on the kernel commandline, tty0 is still registered (presumably based on the order of of_console_check and vt's register_console calls) but ends up not being the preferred console. As a result, it is possible for early userspace prompts (encryption passphrase requests, emergency shells) to end up in a console that the user doesn't expect or even have access to. This patch tries to set tty0 as the /dev/console whenever a non-dummy backend tries to register as its default, unless the preferred console was set from the kernel commandline arguments. On a Samsung Chromebook Plus (Google Kevin, rk3399-gru-kevin.dts), boot messages are still visible on the framebuffer without this patch, but it isn't the preferred console due to the device-tree having a stdout-path property (from rk3399-gru.dtsi): # Without earlycon: $ sudo dmesg | grep -i "console\|printk\|tty[0-9a-z]" | grep -v systemd [ 0.001447] Console: colour dummy device 80x25 [ 0.001820] printk: console [tty0] enabled [ 3.012303] ff1a0000.serial: ttyS2 at MMIO 0xff1a0000 (irq = 39, base_baud = 1500000) is a 16550A [ 4.326549] printk: console [ttyS2] enabled [ 5.521780] dw-apb-uart ff1a0000.serial: forbid DMA for kernel console [ 6.359706] Console: switching to colour frame buffer device 300x100 $ cat /proc/consoles ttyS2 -W- (EC p a) 4:66 tty0 -WU (E p ) 4:7 # With earlycon: $ sudo dmesg | grep -i "console\|printk\|tty[0-9a-z]" | grep -v systemd [ 0.000000] printk: bootconsole [uart0] enabled [ 0.010257] Console: colour dummy device 80x25 [ 0.015131] printk: console [tty0] enabled [ 0.019625] printk: bootconsole [uart0] disabled [ 3.034305] ff1a0000.serial: ttyS2 at MMIO 0xff1a0000 (irq = 39, base_baud = 1500000) is a 16550A [ 4.367601] printk: console [ttyS2] enabled [ 5.576519] dw-apb-uart ff1a0000.serial: forbid DMA for kernel console [ 6.435612] Console: switching to colour frame buffer device 300x100 $ cat /proc/consoles ttyS2 -W- (EC p a) 4:66 tty0 -WU (E ) 4:7 And on the same machine, with this patch: # Without earlycon: $ sudo dmesg | grep -i "console\|printk\|tty[0-9a-z]" | grep -v systemd [ 0.001451] Console: colour dummy device 80x25 [ 0.001821] printk: console [tty0] enabled [ 3.013821] ff1a0000.serial: ttyS2 at MMIO 0xff1a0000 (irq = 39, base_baud = 1500000) is a 16550A [ 4.328053] printk: console [ttyS2] enabled [ 5.509658] dw-apb-uart ff1a0000.serial: forbid DMA for kernel console [ 6.309330] Console: switching to colour frame buffer device 300x100 [ 6.378862] printk: switching to console [tty0] $ cat /proc/consoles tty0 -WU (EC p ) 4:7 ttyS2 -W- (E p a) 4:66 # With earlycon: $ sudo dmesg | grep -i "console\|printk\|tty[0-9a-z]" | grep -v systemd [ 0.000000] printk: bootconsole [uart0] enabled [ 0.010259] Console: colour dummy device 80x25 [ 0.015135] printk: console [tty0] enabled [ 0.019628] printk: bootconsole [uart0] disabled [ 3.037677] ff1a0000.serial: ttyS2 at MMIO 0xff1a0000 (irq = 39, base_baud = 1500000) is a 16550A [ 4.370985] printk: console [ttyS2] enabled [ 5.549226] dw-apb-uart ff1a0000.serial: forbid DMA for kernel console [ 6.364818] Console: switching to colour frame buffer device 300x100 [ 6.417589] printk: switching to console [tty0] $ cat /proc/consoles tty0 -WU (EC ) 4:7 ttyS2 -W- (E p a) 4:66 Signed-off-by: Alper Nebi Yasak --- Changes in v2: - Refresh dmesg outputs with/without earlycon for next-20200430 drivers/tty/vt/vt.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/tty/vt/vt.c b/drivers/tty/vt/vt.c index e5ffed795e4c..218171dca711 100644 --- a/drivers/tty/vt/vt.c +++ b/drivers/tty/vt/vt.c @@ -3588,6 +3588,13 @@ static int do_bind_con_driver(const struct consw *csw, int first, int last, pr_cont("to %s\n", desc); } +#ifdef CONFIG_VT_CONSOLE + if (!console_set_on_cmdline && deflt && conswitchp != &dummy_con) { + add_preferred_console("tty", 0, NULL); + update_console_to_preferred(); + } +#endif + retval = 0; err: module_put(owner); From patchwork Thu Apr 30 16:14:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alper Nebi Yasak X-Patchwork-Id: 11520857 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F2C1F912 for ; Thu, 30 Apr 2020 16:17:24 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id BCDC020873 for ; Thu, 30 Apr 2020 16:17:24 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="aBz4Ju1H"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ut+QscvU" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BCDC020873 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=vVNDv+e162GeZw9Lv2ccN89+XGihsOIsxzxPdyzsei4=; b=aBz4Ju1HeOP660 bDqgmtp4cJjveO4EYcQGfDlhb4zsUWNcv57Tv3nSj23zxPxx1H9JVhHM75j0oO4I7OWX7lzUzYPMj f95IUZSQJv8b+JFL/yUako8fAzR7CFpYs7bi8LbZS+0hTUP5bZ3m8QWwzL5cRhUc2pliYxssuUlOZ z8geIBGRw2IbBvhApiMTPRlUDXegyqmBGDUV/uM82Fraf/QvY+Yeq1fE7iEWqkPGQ8012+m7WBick vQ3Wq9g8JZh2N2dkR0Qi1dUPQAbNE8Ebbfts6mxNy2cfBethhoc1/TzU0iaBeuYbHIQvmpAhO/vIh I52N+9RioSPaudzVgTsg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jUBsI-0002wZ-8M; Thu, 30 Apr 2020 16:17:22 +0000 Received: from mail-lj1-x242.google.com ([2a00:1450:4864:20::242]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jUBrf-0002Qk-ON for linux-arm-kernel@lists.infradead.org; Thu, 30 Apr 2020 16:16:49 +0000 Received: by mail-lj1-x242.google.com with SMTP id y4so7102226ljn.7 for ; Thu, 30 Apr 2020 09:16:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=8h7c5xM9KdrcmFCqTV2onQc6DhtZm7K0Uq18xje81Wc=; b=ut+QscvUUbBbBNa/WL+wGEGeS6FwdRtAH9e4SF8KFy4VBSOrFqJ7zF/QgHmMzpquyc 7CR59WjbtwZirwn2GLq2Wz6GF4iMjx9ppczRswAzNIMwPkj47IDPxOTuo7nq8G2mlScm T9FwkRpWpepH2OiJr4yWdMyxWG/LaBUF9uL/fX66XeNyl0OTjgguO4n1Hmv7LvqxZHMA Vb6aIV4J7iOtlCX7z0bV+4neuEiA3GZ0D6BLmZEkDyOXcPEONZe0+m/vdScwgOjsqJrl LIYQjWZ63bLItDsp59jL9XwLoR9O8yLfuSLPU6F7gLJml0zo9qWzMqOQxtCMg1/sj+K2 BHNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=8h7c5xM9KdrcmFCqTV2onQc6DhtZm7K0Uq18xje81Wc=; b=J/VNT9YRf8qy+7goVvx1Au/Zc92JcTEgqyYU8oa8TcqOEsrgcvhLKVxQmDvHpUxgvd pMrfly/sRJrxAu+FzNEdNg4+UjoQUnFdkRMr9YBM6WQa51pgXGHESi0tgfWd/NL41ppI crQpWOspw/iySP1vCEFwIJ7ewkpDFKEaaNR8bZuHI+t4W5lNo0nibSrZGZmEzF/bVFjv kS+vq9lpcACuwNpMAg3y64TnthmG0LBsvi4vTTYXXUXSQdVMdLyemTXIlPuVQg1MpLap w6Tlgcc6sTtBdgnjFAlLzhfRHSHJ3TAnkWsQ1souXGO7QXPSDVT1i957ppv1ZsIbPWos EcsQ== X-Gm-Message-State: AGi0Pubq352EbReRbFSY6KaulGuu8P6CZf9fOccVg3HUjv0lf6bEtirQ 8UuIs8uvT/NdnQZSJslE7Qo= X-Google-Smtp-Source: APiQypLVsApo9iHgMhuxkN2ZlgYWUMp4fhV4J7W4bsnT2jgzRR8RuWaxI89+qS7fAKHE8DyFsSWe0Q== X-Received: by 2002:a2e:96cd:: with SMTP id d13mr18383ljj.219.1588263402185; Thu, 30 Apr 2020 09:16:42 -0700 (PDT) Received: from localhost.localdomain ([178.233.178.9]) by smtp.gmail.com with ESMTPSA id k6sm60638lfm.91.2020.04.30.09.16.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Apr 2020 09:16:41 -0700 (PDT) From: Alper Nebi Yasak To: Greg Kroah-Hartman , Jiri Slaby , Petr Mladek , Sergey Senozhatsky Subject: [RFC PATCH v2 3/3] printk: Preset tty0 as a pseudo-preferred console Date: Thu, 30 Apr 2020 19:14:37 +0300 Message-Id: <20200430161438.17640-4-alpernebiyasak@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200430161438.17640-1-alpernebiyasak@gmail.com> References: <20200430161438.17640-1-alpernebiyasak@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200430_091646_914288_1627AEB0 X-CRM114-Status: GOOD ( 17.47 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.4 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:242 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [alpernebiyasak[at]gmail.com] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arm-kernel@lists.infradead.org, Alper Nebi Yasak , Steven Rostedt , linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org The ACPI SPCR (Serial Port Console Redirection) table from a machine's firmware can specify a serial console which can be used for earlycon. However, in at least ARM64 systems the same device is also set up as the preferred console. Presumably due to the order of acpi_parse_spcr and VT's register_device calls, setting the specified console as the preferred one can prevent registering VT as a console. This might look appropriate for machines which do not have or need working graphics and whose users most likely have access to a serial port. However, the use of SPCR tables may not be limited these. For example, ARM64 QEMU virtual machines include a SPCR table regardless of the existence of a graphics output or even the nonexistence of a serial console. Or server hardware which has a SPCR table can be repurposed into a workstation with the addition of a graphics card. As a result, boot messages and early userspace prompts can go to an unexpected console. This patch presets tty0 as a pseudo-preferred console at compile-time to ensure that CONFIG_VT_CONSOLE always results in the VT console getting registered. With this, VT can get registered, these other consoles are preferred when VT is a dummy, but we can also bump up VTs preference when working graphics are available. Without this patch, an ARM64 QEMU virtual machine has roughly the following order of console events and consoles: # Without earlycon: $ sudo dmesg | grep -i "console\|printk\|tty[0-9a-z]" | grep -v systemd [ 0.000000] ACPI: SPCR: console: pl011,mmio,0x9000000,9600 [ 0.000250] Console: colour dummy device 80x25 [ 0.140955] ARMH0011:00: ttyAMA0 at MMIO 0x9000000 (irq = 4, base_baud = 0) is a SBSA [ 0.317189] printk: console [ttyAMA0] enabled [ 3.540272] Console: switching to colour frame buffer device 150x42 $ cat /proc/consoles ttyAMA0 -W- (EC p a) 204:64 # With earlycon: $ sudo dmesg | grep -i "console\|printk\|tty[0-9a-z]" | grep -v systemd [ 0.000000] ACPI: SPCR: console: pl011,mmio,0x9000000,9600 [ 0.000000] printk: bootconsole [pl11] enabled [ 0.002064] Console: colour dummy device 80x25 [ 0.324415] ARMH0011:00: ttyAMA0 at MMIO 0x9000000 (irq = 4, base_baud = 0) is a SBSA [ 0.327047] printk: console [ttyAMA0] enabled [ 0.329139] printk: bootconsole [pl11] disabled [ 3.704937] Console: switching to colour frame buffer device 150x42 $ cat /proc/consoles ttyAMA0 -W- (EC a) 204:64 In addition, boot messages aren't printed to the framebuffer (as tty0 is not registered). With this patch, boot messages are visible on the framebuffer and the information above becomes: # Without earlycon: $ sudo dmesg | grep -i "console\|printk\|tty[0-9a-z]" | grep -v systemd [ 0.000000] ACPI: SPCR: console: pl011,mmio,0x9000000,9600 [ 0.000058] Console: colour dummy device 80x25 [ 0.000266] printk: console [tty0] enabled [ 0.144615] ARMH0011:00: ttyAMA0 at MMIO 0x9000000 (irq = 4, base_baud = 0) is a SBSA [ 0.299031] printk: console [ttyAMA0] enabled [ 3.320333] Console: switching to colour frame buffer device 150x42 [ 3.329386] printk: switching to console [tty0] $ cat /proc/consoles tty0 -WU (EC p ) 4:7 ttyAMA0 -W- (E p a) 204:64 # With earlycon: $ sudo dmesg | grep -i "console\|printk\|tty[0-9a-z]" | grep -v systemd [ 0.000000] ACPI: SPCR: console: pl011,mmio,0x9000000,9600 [ 0.000000] printk: bootconsole [pl11] enabled [ 0.002326] Console: colour dummy device 80x25 [ 0.003545] printk: console [tty0] enabled [ 0.236824] ARMH0011:00: ttyAMA0 at MMIO 0x9000000 (irq = 4, base_baud = 0) is a SBSA [ 0.239243] printk: console [ttyAMA0] enabled [ 0.241324] printk: bootconsole [pl11] disabled [ 3.715086] Console: switching to colour frame buffer device 150x42 [ 3.742923] printk: switching to console [tty0] $ cat /proc/consoles tty0 -WU (EC p ) 4:7 ttyAMA0 -W- (E a) 204:64 Signed-off-by: Alper Nebi Yasak --- Changes in v2: - Fix #elif to #else (Reported-by: kbuild test robot ) - Refresh dmesg outputs with/without earlycon for next-20200430 kernel/printk/printk.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index efda422203e4..aa9f9f16860f 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -277,7 +277,19 @@ static struct console *exclusive_console; #define MAX_CMDLINECONSOLES 8 +/* + * The preferred_console and has_preferred_console variables are + * intentionally not modified to reflect this so that the first + * registered console is still used as the preferred console. + */ +#ifdef CONFIG_VT_CONSOLE +static struct console_cmdline console_cmdline[MAX_CMDLINECONSOLES] = { + [0].name = "tty", + [0].index = 0, +}; +#else static struct console_cmdline console_cmdline[MAX_CMDLINECONSOLES]; +#endif static int preferred_console = -1; static bool has_preferred_console;