Re: [PATCH v8 20/21] printk: Deprecate the kernel.printk sysctl interface
From: Petr Mladek
Date: Fri Dec 12 2025 - 10:51:50 EST
Added Joel into Cc for the sysrq API changes.
On Fri 2025-11-28 03:44:33, Chris Down wrote:
> The kernel.printk sysctl interface is deprecated in favour of more
> granular and clearer sysctl interfaces for controlling loglevels, namely
> kernel.console_loglevel and kernel.default_message_loglevel.
>
> kernel.printk has a number of fairly significant usability problems:
>
> - It takes four values in a specific order, which is not intuitive.
> Speaking from personal experience, even people working on printk
> sometimes need to look up the order of these values, which doesn't
> suggest much in the way of perspicuity.
> - There is no validation on the input values, so users can set them to
> invalid or nonsensical values without receiving any errors or
> warnings. This can lead to unpredictable behaviour.
> - One of the four values, default_console_loglevel, is not used in the
> kernel (see below), making it redundant and potentially confusing.
> - Overall, the interface is complex, hard to understand, and combines
> multiple controls into a single sysctl, which is not ideal. It should
> be separated into distinct controls for clarity.
>
> Setting kernel.printk now calls printk_sysctl_deprecated, which emits a
> pr_warn. The warning informs users about the deprecation and suggests
> using the new sysctl interfaces instead.
>
> By deprecating kernel.printk, we aim to:
>
> - Encourage users to adopt the new, dedicated sysctl interfaces
> (kernel.console_loglevel and kernel.default_message_loglevel), which
> are more straightforward and easier to understand.
> - Improve input validation and error handling, ensuring that users
> receive appropriate feedback when setting invalid values.
> - Simplify the configuration of loglevels by exposing only the controls
> that are necessary and relevant.
>
> --- a/kernel/printk/sysctl.c
> +++ b/kernel/printk/sysctl.c
> @@ -7,6 +7,7 @@
> #include <linux/printk.h>
> #include <linux/capability.h>
> #include <linux/ratelimit.h>
> +#include <linux/console.h>
> #include "internal.h"
>
> static const int ten_thousand = 10000;
> @@ -67,13 +68,24 @@ static int proc_dointvec_console_loglevel(const struct ctl_table *table,
> do_proc_dointvec_console_loglevel, NULL);
> }
>
> +static int proc_dointvec_printk_deprecated(const struct ctl_table *table, int write,
> + void *buffer, size_t *lenp, loff_t *ppos)
> +{
> + int res = proc_dointvec(table, write, buffer, lenp, ppos);
> +
> + if (write)
> + pr_warn_once("printk: The kernel.printk sysctl is deprecated. Consider using kernel.console_loglevel or kernel.default_message_loglevel instead.\n");
> +
> + return res;
> +}
> +
> static const struct ctl_table printk_sysctls[] = {
> {
> .procname = "printk",
> .data = &console_loglevel,
> .maxlen = 4*sizeof(int),
> .mode = 0644,
> - .proc_handler = proc_dointvec,
> + .proc_handler = proc_dointvec_printk_deprecated,
> },
> {
> .procname = "printk_ratelimit",
These changes work because the sysctl API changes were backward
compatible. But it would be nice to follow the new parameter names,
...
I propose to do:
+ renamed @write to @dir
+ use SYSCTL_USER_TO_KERN(dir) macro
I mean to do the following changes on top of this patch:
--- a/kernel/printk/sysctl.c
+++ b/kernel/printk/sysctl.c
@@ -73,12 +73,12 @@ static int proc_dointvec_console_loglevel(const struct ctl_table *table,
do_proc_dointvec_console_loglevel);
}
-static int proc_dointvec_printk_deprecated(const struct ctl_table *table, int write,
+static int proc_dointvec_printk_deprecated(const struct ctl_table *table, int dir,
void *buffer, size_t *lenp, loff_t *ppos)
{
- int res = proc_dointvec(table, write, buffer, lenp, ppos);
+ int res = proc_dointvec(table, dir, buffer, lenp, ppos);
- if (write)
+ if (SYSCTL_USER_TO_KERN(dir))
pr_warn_once("printk: The kernel.printk sysctl is deprecated. Consider using kernel.console_loglevel or kernel.default_message_loglevel instead.\n");
return res;
Best Regards,
Petr