From: Chris Down <chris@chrisdown.name>
To: Petr Mladek <pmladek@suse.com>
Cc: linux-kernel@vger.kernel.org,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Sergey Senozhatsky <senozhatsky@chromium.org>,
Steven Rostedt <rostedt@goodmis.org>,
John Ogness <john.ogness@linutronix.de>,
Geert Uytterhoeven <geert@linux-m68k.org>,
Tony Lindgren <tony.lindgren@linux.intel.com>,
kernel-team@fb.com
Subject: [PATCH v6 09/11] printk: Add sysctl interface to set global loglevels
Date: Mon, 28 Oct 2024 16:45:55 +0000 [thread overview]
Message-ID: <f4aa4bc84a7936080bbd727efbd8b540995c8b27.1730133890.git.chris@chrisdown.name> (raw)
In-Reply-To: <cover.1730133890.git.chris@chrisdown.name>
Introduce two new sysctl interfaces for configuring global loglevels:
- kernel.console_loglevel: Sets the global console loglevel, determining
the minimum priority of messages printed to consoles. Messages with a
loglevel lower than this value will be printed.
- kernel.default_message_loglevel: Sets the default loglevel for
messages that do not specify an explicit loglevel.
The kernel.printk sysctl was previously used to set multiple loglevel
parameters simultaneously, but it was confusing and lacked proper
validation. By introducing these dedicated sysctl interfaces, we provide
a clearer and more granular way to configure the loglevels.
Signed-off-by: Chris Down <chris@chrisdown.name>
---
Documentation/admin-guide/sysctl/kernel.rst | 17 ++++++++-
kernel/printk/sysctl.c | 42 +++++++++++++++++++++
2 files changed, 57 insertions(+), 2 deletions(-)
diff --git a/Documentation/admin-guide/sysctl/kernel.rst b/Documentation/admin-guide/sysctl/kernel.rst
index f8bc1630eba0..8019779b27f6 100644
--- a/Documentation/admin-guide/sysctl/kernel.rst
+++ b/Documentation/admin-guide/sysctl/kernel.rst
@@ -1044,6 +1044,20 @@ otherwise the 'doze' mode will be used.
==============================================================
+Some of these settings may be overridden per-console, see
+Documentation/admin-guide/per-console-loglevel.rst. See ``man 2 syslog`` for
+more information on the different loglevels.
+
+console_loglevel
+================
+
+Messages with a higher priority than this will be printed to consoles.
+
+default_message_loglevel
+========================
+
+Messages without an explicit priority will be printed with this priority.
+
printk
======
@@ -1052,8 +1066,7 @@ The four values in printk denote: ``console_loglevel``,
``default_console_loglevel`` respectively.
These values influence printk() behavior when printing or
-logging error messages. See '``man 2 syslog``' for more info on
-the different loglevels.
+logging error messages.
======================== =====================================
console_loglevel messages with a higher priority than
diff --git a/kernel/printk/sysctl.c b/kernel/printk/sysctl.c
index f5072dc85f7a..3bce8b89dacc 100644
--- a/kernel/printk/sysctl.c
+++ b/kernel/printk/sysctl.c
@@ -11,6 +11,9 @@
static const int ten_thousand = 10000;
+static int min_msg_loglevel = LOGLEVEL_EMERG;
+static int max_msg_loglevel = LOGLEVEL_DEBUG;
+
static int proc_dointvec_minmax_sysadmin(const struct ctl_table *table, int write,
void *buffer, size_t *lenp, loff_t *ppos)
{
@@ -20,6 +23,29 @@ static int proc_dointvec_minmax_sysadmin(const struct ctl_table *table, int writ
return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
}
+static int printk_console_loglevel(const struct ctl_table *table, int write,
+ void *buffer, size_t *lenp, loff_t *ppos)
+{
+ struct ctl_table ltable = *table;
+ int ret, level;
+
+ if (!write)
+ return proc_dointvec(table, write, buffer, lenp, ppos);
+
+ ltable.data = &level;
+
+ ret = proc_dointvec(<able, write, buffer, lenp, ppos);
+ if (ret)
+ return ret;
+
+ if (level != -1 && level != clamp_loglevel(level))
+ return -ERANGE;
+
+ console_loglevel = level;
+
+ return 0;
+}
+
static struct ctl_table printk_sysctls[] = {
{
.procname = "printk",
@@ -76,6 +102,22 @@ static struct ctl_table printk_sysctls[] = {
.extra1 = SYSCTL_ZERO,
.extra2 = SYSCTL_TWO,
},
+ {
+ .procname = "console_loglevel",
+ .data = &console_loglevel,
+ .maxlen = sizeof(int),
+ .mode = 0644,
+ .proc_handler = printk_console_loglevel,
+ },
+ {
+ .procname = "default_message_loglevel",
+ .data = &default_message_loglevel,
+ .maxlen = sizeof(int),
+ .mode = 0644,
+ .proc_handler = proc_dointvec_minmax,
+ .extra1 = &min_msg_loglevel,
+ .extra2 = &max_msg_loglevel,
+ },
};
void __init printk_sysctl_init(void)
--
2.46.0
next prev parent reply other threads:[~2024-10-28 16:45 UTC|newest]
Thread overview: 50+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-28 16:45 [PATCH v6 00/11] printk: console: Per-console loglevels Chris Down
2024-10-28 16:45 ` [PATCH v6 01/11] printk: Avoid delaying messages that aren't solicited by any console Chris Down
2024-10-28 16:45 ` [PATCH v6 02/11] printk: Use struct console for suppression and extended console state Chris Down
2024-11-08 9:57 ` Petr Mladek
2024-11-15 8:30 ` John Ogness
2024-11-20 4:17 ` Chris Down
2024-11-20 12:03 ` Petr Mladek
2024-10-28 16:45 ` [PATCH v6 03/11] printk: console: Implement core per-console loglevel infrastructure Chris Down
2024-11-08 16:10 ` Petr Mladek
2024-11-12 10:25 ` Petr Mladek
2024-11-14 16:51 ` Petr Mladek
2024-10-28 16:45 ` [PATCH v6 04/11] printk: Support toggling per-console loglevel via syslog() and cmdline Chris Down
2024-11-12 10:56 ` Conflict with FORCE_CON: " Petr Mladek
2024-11-14 19:28 ` Chris Down
2024-11-15 11:41 ` Petr Mladek
2024-11-12 12:59 ` Petr Mladek
2024-11-14 17:14 ` syslog warning: was: " Petr Mladek
2024-11-14 18:53 ` Chris Down
2024-11-15 11:36 ` Petr Mladek
2024-10-28 16:45 ` [PATCH v6 05/11] MAINTAINERS: Mark printk-basics.rst as owned by printk subsystem Chris Down
2024-10-28 23:26 ` Thomas Gleixner
2024-10-28 23:52 ` Chris Down
2024-11-12 13:00 ` Petr Mladek
2024-10-28 16:45 ` [PATCH v6 06/11] printk: console: Introduce sysfs interface for per-console loglevels Chris Down
2024-11-13 15:58 ` Petr Mladek
2024-11-13 15:59 ` register_device: was: " Petr Mladek
2024-11-14 18:41 ` Chris Down
2024-11-15 4:08 ` Greg Kroah-Hartman
2024-11-18 15:19 ` Petr Mladek
2024-11-15 4:20 ` Greg Kroah-Hartman
2024-11-15 14:09 ` Petr Mladek
2024-11-20 5:01 ` Chris Down
2024-11-20 8:43 ` John Ogness
2024-11-20 14:54 ` Petr Mladek
2024-11-20 15:29 ` John Ogness
2024-11-20 14:45 ` Petr Mladek
2025-01-10 10:27 ` Joel Granados
2025-01-15 10:31 ` Petr Mladek
2024-10-28 16:45 ` [PATCH v6 07/11] printk: Constrain hardware-addressed console checks to name position Chris Down
2024-10-29 8:26 ` Tony Lindgren
2024-11-13 16:11 ` Petr Mladek
2024-10-28 16:45 ` [PATCH v6 08/11] printk: Support setting initial console loglevel via console= on cmdline Chris Down
2024-11-14 9:11 ` Petr Mladek
2024-10-28 16:45 ` Chris Down [this message]
2024-11-14 16:21 ` [PATCH v6 09/11] printk: Add sysctl interface to set global loglevels Petr Mladek
2025-01-10 10:09 ` Joel Granados
2024-10-28 16:45 ` [PATCH v6 10/11] printk: Deprecate the kernel.printk sysctl interface Chris Down
2024-11-14 16:25 ` Petr Mladek
2024-10-28 16:46 ` [PATCH v6 11/11] printk: Purge default_console_loglevel Chris Down
2024-11-14 16:38 ` Petr Mladek
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=f4aa4bc84a7936080bbd727efbd8b540995c8b27.1730133890.git.chris@chrisdown.name \
--to=chris@chrisdown.name \
--cc=geert@linux-m68k.org \
--cc=gregkh@linuxfoundation.org \
--cc=john.ogness@linutronix.de \
--cc=kernel-team@fb.com \
--cc=linux-kernel@vger.kernel.org \
--cc=pmladek@suse.com \
--cc=rostedt@goodmis.org \
--cc=senozhatsky@chromium.org \
--cc=tony.lindgren@linux.intel.com \
/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
all inboxes | Powered by JetHome®