linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Petr Mladek <pmladek@suse.com>
To: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	John Ogness <john.ogness@linutronix.de>
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
	Guenter Roeck <linux@roeck-us.net>,
	Shreyas Joshi <shreyas.joshi@biamp.com>,
	shreyasjoshi15@gmail.com,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com>,
	linux-kernel@vger.kernel.org, Petr Mladek <pmladek@suse.com>
Subject: [RFC 1/2] printk: Add kernel parameter: mute_console
Date: Thu, 22 Oct 2020 13:42:27 +0200	[thread overview]
Message-ID: <20201022114228.9098-2-pmladek@suse.com> (raw)
In-Reply-To: <20201022114228.9098-1-pmladek@suse.com>

Users use various undocumented ways how to completely disable
console output. It is usually done by passing an invalid console
name, for example, console="", console=null.

It mostly works but just by chance. The console name is added to the list
of preferred consoles and the variable "preferred_console" is set.
As a result, any register_console() fails because the driver name
does not match the invalid name. And the console is not used as
a fallback because "preferred_console" is set.

It stops working, when another console is defined on the command line
or another way, for example, by SPCR or a device tree.

More importantly, the above approach might break the system. /dev/console
is used as stdin, stdout, and stderr for the init process [0]

Why yet another command line option?

console_loglevel is not reliable. It is manipulated also by user space
when it configures log daemons.

People might also want to just disable the kernel messages but still
use the console for login.

[0] https://lore.kernel.org/r/20201006025935.GA597@jagdpanzerIV.localdomain

Suggested-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Signed-off-by: Petr Mladek <pmladek@suse.com>
---
 .../admin-guide/kernel-parameters.txt         |  6 ++++++
 kernel/printk/printk.c                        | 21 ++++++++++++++++++-
 2 files changed, 26 insertions(+), 1 deletion(-)

diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
index 02d4adbf98d2..52b9e7f5468d 100644
--- a/Documentation/admin-guide/kernel-parameters.txt
+++ b/Documentation/admin-guide/kernel-parameters.txt
@@ -2974,6 +2974,12 @@
 			Used for mtrr cleanup. It is spare mtrr entries number.
 			Set to 2 or more if your graphical card needs more.
 
+	mute_console	[KNL]
+			Completely disable printing of kernel messages to
+			the console. It can still be used as stdin, stdout,
+			and stderr for the init process. Also it can be used
+			for login.
+
 	n2=		[NET] SDL Inc. RISCom/N2 synchronous serial card
 
 	netdev=		[NET] Network devices parameters
diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index fe64a49344bf..63fb96630767 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -1207,6 +1207,19 @@ void __init setup_log_buf(int early)
 	memblock_free(__pa(new_log_buf), new_log_buf_len);
 }
 
+static bool mute_console;
+
+static int __init mute_console_setup(char *str)
+{
+	mute_console = true;
+	pr_info("All consoles muted.\n");
+
+	return 0;
+}
+
+early_param("mute_console", mute_console_setup);
+module_param(mute_console, bool, 0644);
+
 static bool __read_mostly ignore_loglevel;
 
 static int __init ignore_loglevel_setup(char *str)
@@ -1224,7 +1237,13 @@ MODULE_PARM_DESC(ignore_loglevel,
 
 static bool suppress_message_printing(int level)
 {
-	return (level >= console_loglevel && !ignore_loglevel);
+	if (unlikely(mute_console))
+		return true;
+
+	if (unlikely(ignore_loglevel))
+		return false;
+
+	return (level >= console_loglevel);
 }
 
 #ifdef CONFIG_BOOT_PRINTK_DELAY
-- 
2.26.2


  reply	other threads:[~2020-10-22 11:42 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-22 11:42 [RFC 0/2] printk: Official way to mute consoles Petr Mladek
2020-10-22 11:42 ` Petr Mladek [this message]
2020-10-22 13:10   ` [RFC 1/2] printk: Add kernel parameter: mute_console John Ogness
2020-10-22 14:15     ` Guenter Roeck
2020-10-22 14:53       ` John Ogness
2020-10-23 11:49         ` Petr Mladek
2020-10-23 14:52           ` Guenter Roeck
2020-10-22 13:45   ` Steven Rostedt
2020-10-22 14:22     ` Guenter Roeck
2020-10-23  9:46     ` Petr Mladek
2020-10-23  0:33   ` Sergey Senozhatsky
2020-10-23 12:11     ` Petr Mladek
2020-10-23 15:59   ` Linus Torvalds
2020-10-22 11:42 ` RFC 2/2] printk: Restore and document obsolete ways to disable console output Petr Mladek
2020-10-22 14:23   ` Guenter Roeck

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201022114228.9098-2-pmladek@suse.com \
    --to=pmladek@suse.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=john.ogness@linutronix.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=rostedt@goodmis.org \
    --cc=sergey.senozhatsky.work@gmail.com \
    --cc=sergey.senozhatsky@gmail.com \
    --cc=shreyas.joshi@biamp.com \
    --cc=shreyasjoshi15@gmail.com \
    --cc=torvalds@linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).