From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f50.google.com (mail-wm1-f50.google.com [209.85.128.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A4BCF30FF2B for ; Fri, 12 Dec 2025 15:24:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.50 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765553064; cv=none; b=D9xAfcjYMjgI6CiCafp3IVNwXXVEFEtr6TenevPN8x27yI6qmGTEfmWNfTaHwjp70fvuSIbc+Gj4hmjoFJWd8Yk072plW4HeBAfw7oCLq468PQ7n1WtBjc7nyy3FkX4hGvApeXK4L1CzkPBjRSTeiYQeeC9obQFctpH2yltW3Y8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765553064; c=relaxed/simple; bh=zckOGltV30l9VkTIQ74ojrAXoSPkisxAGWi/zyHyID4=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=N1xXVOL7ymJqtjejbzS+TRUO+rrFwKJ36rtfLWaYFV93F2Z25BfEdpiB55KfN7+NGNjwjC+oPoUzk9VimFmbM/LTJCnB9npw+GrBOOT5OGdxBHWDXt3t0JwncvJJasixXNuNZApVjI+IrKwMWWj7i7mkodOQSVP9Y0P/lkzbiDo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=TK6CmpmP; arc=none smtp.client-ip=209.85.128.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="TK6CmpmP" Received: by mail-wm1-f50.google.com with SMTP id 5b1f17b1804b1-47755de027eso9790105e9.0 for ; Fri, 12 Dec 2025 07:24:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1765553060; x=1766157860; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=5PtQGla9jseTsTWnnKHj83CsFuwxcsZAO2LhQikKA2g=; b=TK6CmpmPAKrRubtWXGLOuFPW9Hg0cMZWvalKgq6jYATVdbW6pNEufQ8+rhBH6IUrh8 xEUhpJK69R0+OWh+ga3UEHDrwJNu2DOIbYIMh/kNMFbas97Dk1QggSmeaGHMHV8oLJ36 e6JtYKOTvS0N8q1qXyz3IETzOZBof7CtDtRY9ju6TccAS8pfepmCUlwxwVuEWFplOXUR 0nr61dhmcM2EV/cxgtk5PwvmH7BtGxBcQ0n/pO3Zgyg7zZLhGeVDshZ4Q2fGmejW0hui DsJQHDs8MMlsrplNa9KAJKcjz4z6c9k46k1WrjvmIIG5IE388B/cut9egBLjGu/jXmFi ZJEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765553060; x=1766157860; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5PtQGla9jseTsTWnnKHj83CsFuwxcsZAO2LhQikKA2g=; b=EnSMtp2MMJ3ChRQTXXCOfipa6rky31AVNkF9yuYtQjBcM6jNBweyjorAVstHYD64v3 emmh019GX8uawOPlFTrIZd9lJNM170TfLFgz3EVg3dhjEwwPJys00RHIq1DBMxpN1qmi n919PN8C/ATUw9C6ZOwU+3icjJE3shrK5fwuraHSlogF228vBf2U6U90UE+exyOyfpH2 eCq0qr2Py0Tkx5AgpJ+dYVCsYH1IvcXzlzJVrBlgk0Q3OneCOkQk3z8KJNasuDEHdfe1 +IwPjh6QXuxx2SPA9dpyUVsrUi3K/w6+GID8HTSVRiUeJN6RU2ZG9/Qwy/3EBSxfApFZ pwKA== X-Gm-Message-State: AOJu0YyFNz/a7As41Ki68hBmladyERFY52XMUMlpq2JUMnCHy2G12iRH 9o/9wfsWpM3jdroWejBKxEIIAih+c4xtwHjCpZq/vlnAA1dIwvMUCJtSFKGlBMU2WbU= X-Gm-Gg: AY/fxX7Bx3gFRubzFg90toi55rryGW41v9qc0tubwLQsnGTqWj/M0Q+nsn9IIdC9TIY +ayc74Ihris7MyS9c39c2I5M84PqoQ2M9wOycYU8tnc2IRWpVd223dVblkJ9JYAe7Hx5C0IE0N3 c09Bchha/Bi5s4ygOzMWPEm8QFkNfEUAjR7MMQxCvsonDc4csnh7xesJseWhjJWF8RKFenh1LcC RRoC9FzB5fAg/RjZw1L79QorwQ25tj/RX7PNrdBThwfCl2NAshtYg22+BAUz9I2EiQmlZF/k7Zo txelypuIBPyRh9XyW5rSEMOWmhdp01z9SCX1kL1xEkQ9kr7RnoILAnA6xZSAlCBE1yl9JALkvl2 UV5I+VHdc/Bq7WXzdEubVLyYnlfaqjmLFqzORoNVrUw4fePlrRsitHnro2SwoE1wOAQAbUbNErF 0nNleY9GU356ZsFA== X-Google-Smtp-Source: AGHT+IHJgVh0F0zT/7sV+MDJ1ySB+LMGDiYYG0+Va7u9lMzWgLIDqAXwPm0Qw6qU6DG1p9xMA8J/4Q== X-Received: by 2002:a05:600c:444d:b0:476:84e9:b571 with SMTP id 5b1f17b1804b1-47a8f8c6828mr25510705e9.14.1765553059888; Fri, 12 Dec 2025 07:24:19 -0800 (PST) Received: from pathway ([176.114.240.130]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-47a8f8d9d63sm36137775e9.9.2025.12.12.07.24.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Dec 2025 07:24:19 -0800 (PST) Date: Fri, 12 Dec 2025 16:24:17 +0100 From: Petr Mladek To: Chris Down Cc: linux-kernel@vger.kernel.org, Greg Kroah-Hartman , Sergey Senozhatsky , Steven Rostedt , John Ogness , Geert Uytterhoeven , Joel Granados , Tony Lindgren , kernel-team@fb.com Subject: Re: [PATCH v8 18/21] printk: Deconstruct kernel.printk into discrete sysctl controls Message-ID: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Adding Joel into Cc. Joel, see the original patch at https://lore.kernel.org/all/c3e5cc507eb3fd7db0a002f31d7e47d764cad176.1764272407.git.chris@chrisdown.name/ On Fri 2025-11-28 03:44:25, Chris Down wrote: > 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. > > Reviewed-by: Petr Mladek > Tested-by: Petr Mladek > Signed-off-by: Chris Down This patch requires non-trivial changes when rebased on top of v6.19. There have been some conflicting changes in the sysctl API, see https://lore.kernel.org/lkml/20251016-jag-sysctl_conv-v2-0-a2f16529acc4@kernel.org/ > --- a/include/linux/sysctl.h > +++ b/include/linux/sysctl.h > @@ -235,6 +235,13 @@ extern struct ctl_table_header *register_sysctl_mount_point(const char *path); > > void do_sysctl_args(void); > bool sysctl_is_alias(char *param); > +int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp, int *valp, > + int write, void *data); > +int do_proc_dointvec(const struct ctl_table *table, int write, > + void *buffer, size_t *lenp, loff_t *ppos, > + int (*conv)(bool *negp, unsigned long *lvalp, int *valp, > + int write, void *data), > + void *data); > int do_proc_douintvec(const struct ctl_table *table, int write, > void *buffer, size_t *lenp, loff_t *ppos, > int (*conv)(unsigned long *lvalp, This hunk can be removed in v6.19. There is another interface in 6.19, see below. > diff --git a/kernel/printk/sysctl.c b/kernel/printk/sysctl.c > index da77f3f5c1fe..034739939a61 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,50 @@ static int proc_dointvec_minmax_sysadmin(const struct ctl_table *table, int writ > return proc_dointvec_minmax(table, write, buffer, lenp, ppos); > } The new way is to define the needed helpers using macros. We need this: static SYSCTL_USER_TO_KERN_INT_CONV(, SYSCTL_CONV_IDENTITY) static SYSCTL_KERN_TO_USER_INT_CONV(, SYSCTL_CONV_IDENTITY) static SYSCTL_INT_CONV_CUSTOM(, sysctl_user_to_kern_int_conv, sysctl_kern_to_user_int_conv, false) > +static int do_proc_dointvec_console_loglevel(bool *negp, unsigned long *lvalp, > + int *valp, > + int write, void *data) There parameters have got renamed and @table is passed instead or @data: static int do_proc_dointvec_console_loglevel(bool *negp, unsigned long *u_ptr, int *k_ptr, int dir, const struct ctl_table *table) > +{ > + int level, ret; > + > + /* > + * If writing, first do so via a temporary local int so we can > + * bounds-check it before touching *valp. > + */ > + int *intp = write ? &level : valp; The direction is newly checked by macro: int *int_ptr = SYSCTL_USER_TO_KERN(dir) ? &level : k_ptr; > + ret = do_proc_dointvec_conv(negp, lvalp, intp, write, data); The following helper is defined by the above mentioned macros: ret = do_proc_int_conv(negp, u_ptr, int_ptr, dir, table); > + if (ret) > + return ret; > + > + if (write) { The new way: if (SYSCTL_USER_TO_KERN(dir)) { > + if (level != console_clamp_loglevel(level)) > + return -ERANGE; > + > + /* > + * Honour the administrator-configured minimum console > + * loglevel (third element of kernel.printk). This mirrors > + * the syslog() and sysfs control paths so that once the floor > + * is raised we do not let this sysctl silently bypass it. > + */ > + if (minimum_console_loglevel > CONSOLE_LOGLEVEL_MIN && > + level < minimum_console_loglevel) > + level = minimum_console_loglevel; > + > + WRITE_ONCE(*valp, level); New parameter name: WRITE_ONCE(*k_ptr, level); > + } > + > + return 0; > +} > + > +static int proc_dointvec_console_loglevel(const struct ctl_table *table, > + int write, void *buffer, size_t *lenp, > + loff_t *ppos) > +{ > + return do_proc_dointvec(table, write, buffer, lenp, ppos, > + do_proc_dointvec_console_loglevel, NULL); There is a new function where the last NULL parameter is not longer passed: return proc_dointvec_conv(table, write, buffer, lenp, ppos, do_proc_dointvec_console_loglevel); > +} > + > static const struct ctl_table printk_sysctls[] = { > { > .procname = "printk", Here are the above described changes made by diff: --- a/kernel/printk/sysctl.c +++ b/kernel/printk/sysctl.c @@ -24,9 +24,14 @@ static int proc_dointvec_minmax_sysadmin(const struct ctl_table *table, int writ return proc_dointvec_minmax(table, write, buffer, lenp, ppos); } -static int do_proc_dointvec_console_loglevel(bool *negp, unsigned long *lvalp, - int *valp, - int write, void *data) +static SYSCTL_USER_TO_KERN_INT_CONV(, SYSCTL_CONV_IDENTITY) +static SYSCTL_KERN_TO_USER_INT_CONV(, SYSCTL_CONV_IDENTITY) +static SYSCTL_INT_CONV_CUSTOM(, sysctl_user_to_kern_int_conv, + sysctl_kern_to_user_int_conv, false) + +static int do_proc_dointvec_console_loglevel(bool *negp, unsigned long *u_ptr, + int *k_ptr, int dir, + const struct ctl_table *table) { int level, ret; @@ -34,13 +39,13 @@ static int do_proc_dointvec_console_loglevel(bool *negp, unsigned long *lvalp, * If writing, first do so via a temporary local int so we can * bounds-check it before touching *valp. */ - int *intp = write ? &level : valp; + int *int_ptr = SYSCTL_USER_TO_KERN(dir) ? &level : k_ptr; - ret = do_proc_dointvec_conv(negp, lvalp, intp, write, data); + ret = do_proc_int_conv(negp, u_ptr, int_ptr, dir, table); if (ret) return ret; - if (write) { + if (SYSCTL_USER_TO_KERN(dir)) { if (level != console_clamp_loglevel(level)) return -ERANGE; @@ -54,7 +59,7 @@ static int do_proc_dointvec_console_loglevel(bool *negp, unsigned long *lvalp, level < minimum_console_loglevel) level = minimum_console_loglevel; - WRITE_ONCE(*valp, level); + WRITE_ONCE(*k_ptr, level); } return 0; @@ -64,8 +69,8 @@ static int proc_dointvec_console_loglevel(const struct ctl_table *table, int write, void *buffer, size_t *lenp, loff_t *ppos) { - return do_proc_dointvec(table, write, buffer, lenp, ppos, - do_proc_dointvec_console_loglevel, NULL); + return proc_dointvec_conv(table, write, buffer, lenp, ppos, + do_proc_dointvec_console_loglevel); } static int proc_dointvec_printk_deprecated(const struct ctl_table *table, int write, > void __init printk_sysctl_init(void) > diff --git a/kernel/sysctl.c b/kernel/sysctl.c > index cb6196e3fa99..3ed010b8f6b3 100644 > --- a/kernel/sysctl.c > +++ b/kernel/sysctl.c > @@ -354,9 +354,9 @@ static void proc_put_char(void **buf, size_t *size, char c) > } > } > > -static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp, > - int *valp, > - int write, void *data) > +int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp, > + int *valp, > + int write, void *data) > { > if (write) { > if (*negp) { > @@ -380,6 +380,7 @@ static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp, > } > return 0; > } > +EXPORT_SYMBOL(do_proc_dointvec_conv); > > static int do_proc_douintvec_conv(unsigned long *lvalp, > unsigned int *valp, > @@ -471,15 +472,16 @@ static int __do_proc_dointvec(void *tbl_data, const struct ctl_table *table, > return err; > } > > -static int do_proc_dointvec(const struct ctl_table *table, int write, > - void *buffer, size_t *lenp, loff_t *ppos, > - int (*conv)(bool *negp, unsigned long *lvalp, int *valp, > - int write, void *data), > - void *data) > +int do_proc_dointvec(const struct ctl_table *table, int write, > + void *buffer, size_t *lenp, loff_t *ppos, > + int (*conv)(bool *negp, unsigned long *lvalp, int *valp, > + int write, void *data), > + void *data) > { > return __do_proc_dointvec(table->data, table, write, > buffer, lenp, ppos, conv, data); > } > +EXPORT_SYMBOL(do_proc_dointvec); > > static int do_proc_douintvec_w(unsigned int *tbl_data, > const struct ctl_table *table, Also all these changes in kernel/sysctl.c are not loger needed. Best Regards, Petr