From nobody Tue Dec 2 02:31:07 2025 Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) (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 BABBA285072 for ; Tue, 18 Nov 2025 19:06:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763492814; cv=none; b=HefajxU6/ZLlSwNMidN6YeuFTkes7EXVtYZu7H6KMBqMwhYdPDsiVoE0xl+6pu3Hli/Kfz1tK5Wwm7iN9qZOqnFAShE34gIaJGLzyw4/Fd9CQGuQ3bc78mSC0GZUnF/pY1u3+T2jlQ9Fubyn+wTcot3CYjHYcy61PC6kYi8XXQg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763492814; c=relaxed/simple; bh=xuwn1pZBhIDzoYVPK9/i985xFFkGQIASAQtoC93SKOE=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=kmzaaQguOu5AXCh4r2D6epyewYkEuykNU+Q99wfQwhNGEqgmZTkSV8dZCz/onPdOzZcFfS8SmKnZenGxl5nk5wmLUyxAC0ZGRwi5H8O7jelJgpMBFTp89XdNNzsijSWPiECzFmVEawzg1V6PaSqe7cAVXGuzSlzZ8JdbFMvFMhY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=chrisdown.name; spf=pass smtp.mailfrom=chrisdown.name; dkim=pass (1024-bit key) header.d=chrisdown.name header.i=@chrisdown.name header.b=qrMaSaso; arc=none smtp.client-ip=209.85.214.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=chrisdown.name Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chrisdown.name Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chrisdown.name header.i=@chrisdown.name header.b="qrMaSaso" Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-29558061c68so68508715ad.0 for ; Tue, 18 Nov 2025 11:06:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chrisdown.name; s=google; t=1763492812; x=1764097612; darn=vger.kernel.org; h=user-agent: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=Kvs/7NJ9gNsl4oHgNuED0+c8hh3bhE53eU6duv0IyxI=; b=qrMaSasoUeRM1HPsM+J5P3IiBG/8yR5TtU9DGadtBQTLy+QaSyTl4TauENqQ3jRrkM Vq7cQ9f3BrvKgMuflopmRksGnszsVHFlN8VbT1F+OJN52J+LLfZAmmc17Gxc4hq33gfA hikO4kUFOL6cc2n5eAUaKa77Jtl5bsNIrcBpA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763492812; x=1764097612; h=user-agent: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=Kvs/7NJ9gNsl4oHgNuED0+c8hh3bhE53eU6duv0IyxI=; b=gR1l7kXRik0DpVP79acEKdJyQLA4b8l76SRvaPaiwU/lGeVOvc9v3JY1Dk4W71Y8tV 6pWyJ2m0nWNmFVFRKS915zb/7T3L4wFTu5xOo3971UOhiW82q4qEvaYjwWUR66uXeBYd SqF08IWqHLZb5PbzXx/KqVXcPBr7u3hq0pVh4RuQID+Zr50ecVeXi9qF3j2PyLCwODXb CBDvQeS9yStAQ41ojaZhT92PTVAQ1gBFrE7zUiQIxldJtyKTStMGOm/0hiiEC0YPvR73 kRwrrT6m4RJBWAg6t12DRSHmXV6/cwUPzaeLp+uW2GjYqyoCS3jS0HZdILXGw//bpQDO crdg== X-Gm-Message-State: AOJu0Yw/ffW2A49GuLGY1f6I9eml50F9eQw8G+j5/tfMRwTep7aQkhC8 cgtc6uG2BKHo2+Zy0aZlxFkreeH+/K6Yi5vNkvn9gco26OXzQpkcDMZdGKitUNpVDNs= X-Gm-Gg: ASbGncu0or2Vt6Gncpqaw2/tbdNZoLnSMvKfx6Qa9QVvjI00Ojj7vbk2yi/MOss0kbq 65ovniTeeuZN6XulKaU5NASLg68YKvCR9X7qVWRbRyWwZjrIKtn1+vmdozTyuEQJ3MMuxbOHPsS nx0XT/tw/HRJgXHMQsQiJ/wF8f+9bSNHW9WwnHLFB2CmQdW3nADxIZkPVJk/562jvvhJwlLxSZf zqeLcd/SkW+GJmiUWZtsWSoHBwLYptpZTic+v7EnDE8IucKnSBJAxtWXyJZ+lEHK1M6wfzstlm+ OKLcvwbMAXacuJa1qtqDeksggtLO/EZjNmv5J/mlAQrUjyT38dH9M9YDQh7V8enGGlRZGjITxHn 9mVj8Lb1DSChePT4LKdCIg/ORdNquysbNn+eB3A+LSY6QobJo0JeBkkOEBcmhXWnD4gMdfKRGFZ tNbzp8b/AX X-Google-Smtp-Source: AGHT+IG6e1rUO2FUiGqax9tqkk5ipw7TrtLsg6hgYwrhL9gj+0FkKJHdY9X80xVZknM3cWhK+EINaQ== X-Received: by 2002:a17:903:124b:b0:295:9cb5:ae12 with SMTP id d9443c01a7336-29a0540d482mr1454985ad.25.1763492811909; Tue, 18 Nov 2025 11:06:51 -0800 (PST) Received: from localhost ([116.86.198.140]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7b927150b13sm17152641b3a.46.2025.11.18.11.06.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Nov 2025 11:06:51 -0800 (PST) Date: Wed, 19 Nov 2025 03:06:50 +0800 From: Chris Down To: Petr Mladek Cc: linux-kernel@vger.kernel.org, Greg Kroah-Hartman , Sergey Senozhatsky , Steven Rostedt , John Ogness , Geert Uytterhoeven , Tony Lindgren , kernel-team@fb.com Subject: [PATCH v7 01/13] printk: Avoid delaying messages that aren't solicited by any console Message-ID: <8c69a5fccc15a512e5ba6385f3c933e3d2f8a96b.1763492585.git.chris@chrisdown.name> References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/2.2.15 (2b349c5e) (2025-10-02) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" printk_delay() may introduce delays even when no console wants to emit the message, which is unnecessary and may hold back messages we actually care about. Add a check in printk_delay() to determine if any console will print the message to avoid introducing unnecessary delays. This change aligns with the existing behaviour of boot-delayed printk messages, which already have a similar check. Reviewed-by: Petr Mladek Signed-off-by: Chris Down --- kernel/printk/printk.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 5aee9ffb16b9..ff8b6dbb29a7 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -1307,14 +1307,12 @@ static int __init boot_delay_setup(char *str) } early_param("boot_delay", boot_delay_setup); =20 -static void boot_delay_msec(int level) +static void boot_delay_msec(void) { unsigned long long k; unsigned long timeout; - bool suppress =3D !is_printk_force_console() && - suppress_message_printing(level); =20 - if ((boot_delay =3D=3D 0 || system_state >=3D SYSTEM_RUNNING) || suppress) + if (boot_delay =3D=3D 0 || system_state >=3D SYSTEM_RUNNING) return; =20 k =3D (unsigned long long)loops_per_msec * boot_delay; @@ -1334,7 +1332,7 @@ static void boot_delay_msec(int level) } } #else -static inline void boot_delay_msec(int level) +static inline void boot_delay_msec(void) { } #endif @@ -2116,7 +2114,11 @@ int printk_delay_msec __read_mostly; =20 static inline void printk_delay(int level) { - boot_delay_msec(level); + /* If the message is forced (e.g. panic), we must delay */ + if (!is_printk_force_console() && suppress_message_printing(level)) + return; + + boot_delay_msec(); =20 if (unlikely(printk_delay_msec)) { int m =3D printk_delay_msec; --=20 2.51.2 From nobody Tue Dec 2 02:31:07 2025 Received: from mail-pf1-f172.google.com (mail-pf1-f172.google.com [209.85.210.172]) (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 5EACB2ED148 for ; Tue, 18 Nov 2025 19:07:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763492823; cv=none; b=Hg+a4oY9mDAlfLgUaprt+9n6xC4wMuEz6O+DCqWygae3msLwbAAH21sUPGHZY0wKMFMIHydxK4uGwW7pNnmPdYKY0RfcdCoF2oMNq1mHc7qkIVdXqcUqLLkQc1cdFyYLCsutEokhOuaVgS006LesHX6v7QVvtSCCJt7J+XJQgM8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763492823; c=relaxed/simple; bh=xoQj4Z9WUsqfKseK89ZMboGKd4HYyTDV4ENe8JpPi1o=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=teN35e7a/3skOgRRrxJNlKzHieM4Mfqy0S7I/Dk1YM+TeCTBHLhCBkjUvl7UN9JkFHgmK79Y+recrKZtXnQ4aSe67PEac27BH6g/+AIvD6pmm9ERFUnCAakdHXfQmnlhyNH5jArHanE/NK2krLC9yKlJrg3ECuL19mUQEaRUeuQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=chrisdown.name; spf=pass smtp.mailfrom=chrisdown.name; dkim=pass (1024-bit key) header.d=chrisdown.name header.i=@chrisdown.name header.b=BBEfsOjF; arc=none smtp.client-ip=209.85.210.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=chrisdown.name Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chrisdown.name Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chrisdown.name header.i=@chrisdown.name header.b="BBEfsOjF" Received: by mail-pf1-f172.google.com with SMTP id d2e1a72fcca58-7b86e0d9615so5907261b3a.0 for ; Tue, 18 Nov 2025 11:07:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chrisdown.name; s=google; t=1763492820; x=1764097620; darn=vger.kernel.org; h=user-agent: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=gvwKsdpYaPiic0MVQyPTRwFXWhfv8k4oseUdbUMwfLo=; b=BBEfsOjFHKbmuT46dt7eAkC4m+2kqyMmgGORSFdqD+gfMK2hZoWMxUa0ZRC7/fmfYK tyLgE/h+rcNXRvSByIa9fU3MPduujWl9XIDOsWE2Vl6njKOxsthq2DiZJMEIVPiTPZ11 2lrCz8EVpRJKv6fnyLSpI+08mTKohc6xS4ZWY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763492820; x=1764097620; h=user-agent: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=gvwKsdpYaPiic0MVQyPTRwFXWhfv8k4oseUdbUMwfLo=; b=PFf2yBsV3oBc0rbqnrTCK4TdMgXxRtzW4d5PL1PDwQYRcnKs4BdCxHHCAgmq/pmTLY czCkcuQNhdA3+E7HM8VL3uChaAvgFptj6RvT+rRPmfzpq0QroD+VNkEGsykhVzmOBOgl RLjQ2Ak5cUhurcTe1QLEgraCKL7jdQeMJBENVPfUdL9YPj6vHNXngalmaZm4kO1bHHFw MjV+ThbKoJPZKxvdKUgEae0OHqPFdc7T3/MFDKF5hE1IfM/hVJ3/aY45eCR63McwRiGZ +yuaIPANRkb6IFOxh2cP3XbscvV1GCvDEB94hq131JM3BGLvXuiXOnDy+rtnAm+sFiO9 EgAQ== X-Gm-Message-State: AOJu0Yx1KP6TRe1+tz/enoRb3/TMt5WBLgLbyrgMlrK0ICo8yWuhcyHQ JU+U3XPYRV1sjAzyfZpbQAwQsraxTnM3R4MXsn0v0TwoJEAoIc9WCXj64uSb/E3VcNc= X-Gm-Gg: ASbGncuIKhLeOS2wIOLfQxjrcMiSGrEyEdM3x9PjRxJFekW2E6EKVu88ypmgD7ELccJ igKaC7IaUnzKz/RE3tGWoCDQ0uZNBUwFOFp6Rx5Yepb1890T+dTJl4ximkRpnAKoKircoHR6DDq m9yz1dMkXcRtI+/eZP4ncdxJYLCo6FMqBmwS2G/GIaCpiQIPrIAHHuuwqy7lQdZLZRFU8uJoP2f j+RIwxcE7QazQQlR6X8pIiAnEpiIo2UGBDgUtpWufgnWCSx7DKFWgtfQgh4Exxp5zZcMGJwsD4N IQRkMDDSvijxweXP6W0C6kiIwtnBPjPuPSQkZPr0D8ndIA1tkdyC1T1CcEL7v85IUsxkQ/0JHWt A4/JntBQdV/ow1oIO4lrkLftfeo0oTjZKKBSe1/r9mzC4ndCXKfZ2WEKZudaxT7NXUJ9scKythR eGzsSkzlPS X-Google-Smtp-Source: AGHT+IEAaFa9R2zF/kAbo4SEJ4qguoCz1SGypMyZE51q5lbd4mkt0Y1+b83MKVqm6D1r9vgfU5Aarw== X-Received: by 2002:a05:6a20:7349:b0:35d:5d40:6d65 with SMTP id adf61e73a8af0-35d5d4074e4mr14622922637.5.1763492820510; Tue, 18 Nov 2025 11:07:00 -0800 (PST) Received: from localhost ([116.86.198.140]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7b9250d32e8sm17338142b3a.24.2025.11.18.11.06.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Nov 2025 11:07:00 -0800 (PST) Date: Wed, 19 Nov 2025 03:06:58 +0800 From: Chris Down To: Petr Mladek Cc: linux-kernel@vger.kernel.org, Greg Kroah-Hartman , Sergey Senozhatsky , Steven Rostedt , John Ogness , Geert Uytterhoeven , Tony Lindgren , kernel-team@fb.com Subject: [PATCH v7 02/13] printk: Use effective loglevel for suppression and extended console state Message-ID: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/2.2.15 (2b349c5e) (2025-10-02) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" In preparation for supporting per-console loglevels, modify printk_get_next_message() to accept the effective console loglevel instead of individual arguments that mimic console fields. This keeps the function console-agnostic and lockless as intended, while still allowing per-console loglevel support to be added in later patches. devkmsg_read() uses CONSOLE_LOGLEVEL_MOTORMOUTH to never suppress messages. All other consoles pass their effective loglevel (currently console_loglevel, will be per-console in later patches). Reviewed-by: Petr Mladek Signed-off-by: Chris Down --- kernel/printk/internal.h | 2 +- kernel/printk/nbcon.c | 2 +- kernel/printk/printk.c | 22 +++++++++++++--------- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/kernel/printk/internal.h b/kernel/printk/internal.h index f72bbfa266d6..1ed86577896c 100644 --- a/kernel/printk/internal.h +++ b/kernel/printk/internal.h @@ -333,7 +333,7 @@ struct printk_message { }; =20 bool printk_get_next_message(struct printk_message *pmsg, u64 seq, - bool is_extended, bool may_supress); + bool is_extended, int con_eff_level); =20 #ifdef CONFIG_PRINTK void console_prepend_dropped(struct printk_message *pmsg, unsigned long dr= opped); diff --git a/kernel/printk/nbcon.c b/kernel/printk/nbcon.c index 558ef3177976..eb4c8faa213d 100644 --- a/kernel/printk/nbcon.c +++ b/kernel/printk/nbcon.c @@ -993,7 +993,7 @@ static bool nbcon_emit_next_record(struct nbcon_write_c= ontext *wctxt, bool use_a if (!nbcon_context_enter_unsafe(ctxt)) return false; =20 - ctxt->backlog =3D printk_get_next_message(&pmsg, ctxt->seq, is_extended, = true); + ctxt->backlog =3D printk_get_next_message(&pmsg, ctxt->seq, is_extended, = console_loglevel); if (!ctxt->backlog) return nbcon_context_exit_unsafe(ctxt); =20 diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index ff8b6dbb29a7..745f89a18189 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -807,7 +807,8 @@ static ssize_t devkmsg_read(struct file *file, char __u= ser *buf, if (ret) return ret; =20 - if (!printk_get_next_message(&pmsg, atomic64_read(&user->seq), true, fals= e)) { + if (!printk_get_next_message(&pmsg, atomic64_read(&user->seq), true, + CONSOLE_LOGLEVEL_MOTORMOUTH)) { if (file->f_flags & O_NONBLOCK) { ret =3D -EAGAIN; goto out; @@ -825,7 +826,7 @@ static ssize_t devkmsg_read(struct file *file, char __u= ser *buf, */ ret =3D wait_event_interruptible(log_wait, printk_get_next_message(&pmsg, atomic64_read(&user->seq), true, - false)); /* LMM(devkmsg_read:A) */ + CONSOLE_LOGLEVEL_MOTORMOUTH)); /* LMM(devkmsg_read:A) */ if (ret) goto out; } @@ -1279,9 +1280,9 @@ module_param(ignore_loglevel, bool, S_IRUGO | S_IWUSR= ); MODULE_PARM_DESC(ignore_loglevel, "ignore loglevel setting (prints all kernel messages to the console)"); =20 -static bool suppress_message_printing(int level) +static bool suppress_message_printing(int level, int con_eff_level) { - return (level >=3D console_loglevel && !ignore_loglevel); + return (level >=3D con_eff_level && !ignore_loglevel); } =20 #ifdef CONFIG_BOOT_PRINTK_DELAY @@ -2115,7 +2116,7 @@ int printk_delay_msec __read_mostly; static inline void printk_delay(int level) { /* If the message is forced (e.g. panic), we must delay */ - if (!is_printk_force_console() && suppress_message_printing(level)) + if (!is_printk_force_console() && suppress_message_printing(level, consol= e_loglevel)) return; =20 boot_delay_msec(); @@ -2946,14 +2947,15 @@ void console_prepend_replay(struct printk_message *= pmsg) * @is_extended specifies if the message should be formatted for extended * console output. * - * @may_supress specifies if records may be skipped based on loglevel. + * @con_eff_level is the effective console loglevel to use for suppression + * checks. * * Returns false if no record is available. Otherwise true and all fields * of @pmsg are valid. (See the documentation of struct printk_message * for information about the @pmsg fields.) */ bool printk_get_next_message(struct printk_message *pmsg, u64 seq, - bool is_extended, bool may_suppress) + bool is_extended, int con_eff_level) { struct printk_buffers *pbufs =3D pmsg->pbufs; const size_t scratchbuf_sz =3D sizeof(pbufs->scratchbuf); @@ -2982,13 +2984,14 @@ bool printk_get_next_message(struct printk_message = *pmsg, u64 seq, =20 pmsg->seq =3D r.info->seq; pmsg->dropped =3D r.info->seq - seq; + force_con =3D r.info->flags & LOG_FORCE_CON; =20 /* * Skip records that are not forced to be printed on consoles and that * has level above the console loglevel. */ - if (!force_con && may_suppress && suppress_message_printing(r.info->level= )) + if (!force_con && suppress_message_printing(r.info->level, con_eff_level)) goto out; =20 if (is_extended) { @@ -3064,7 +3067,8 @@ static bool console_emit_next_record(struct console *= con, bool *handover, int co =20 *handover =3D false; =20 - if (!printk_get_next_message(&pmsg, con->seq, is_extended, true)) + if (!printk_get_next_message(&pmsg, con->seq, is_extended, + console_loglevel)) return false; =20 con->dropped +=3D pmsg.dropped; --=20 2.51.2 From nobody Tue Dec 2 02:31:07 2025 Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) (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 E0ADB2E8B7A for ; Tue, 18 Nov 2025 19:07:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763492830; cv=none; b=NKIBX9sOXs4GEk9yFai1lg2uJJJo0cRZjIzv8MdrzNagu6DSHtYzDkVfw7en60BOt802M/T6mNUVNn1ozLgHwwd4MBzXc9DmKvmBNRmem64XGg0+OYIHO8Nk5NcrEm7z0Q7J1lvRHgiZa4Pt3y/BgQD4RsbPdLJbdiOJWl99K1s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763492830; c=relaxed/simple; bh=xKVNnbeSNKrfKn7uvYZI0vYR/Nskc/8flt3OsP8sohw=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=cWdsRSTsserTgs8ofYkdo9JIWl8Flqwbw3S70PRGnhhQUWffAyo64tS+QMTBohRNWiyl/nPk/OFXWiPrefy/bsHkhztkJwMk9+I9r7GjwsP3vO1rfxNc3LlXllC8+Wm10JDpJ563N83iRPgzBPoLxux90KHgVphHgJ4hHRFfcUs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=chrisdown.name; spf=pass smtp.mailfrom=chrisdown.name; dkim=pass (1024-bit key) header.d=chrisdown.name header.i=@chrisdown.name header.b=xTQQLhvT; arc=none smtp.client-ip=209.85.214.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=chrisdown.name Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chrisdown.name Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chrisdown.name header.i=@chrisdown.name header.b="xTQQLhvT" Received: by mail-pl1-f178.google.com with SMTP id d9443c01a7336-297dc3e299bso56912515ad.1 for ; Tue, 18 Nov 2025 11:07:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chrisdown.name; s=google; t=1763492828; x=1764097628; darn=vger.kernel.org; h=user-agent: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=fAXEIOdrPjlE+zwRCMVbogwTJwQnlb80CC1vQLcEkoA=; b=xTQQLhvTmPctEIUzBXfUzRe3RTCYx8LsQZGVU25W/IDA2EzoCkuKOyi+H+PQFnfutB 8cA6ZLbj4LDWFlU+67e79wHrp4xlfO27Q5yPoMn8+7x1MYnU9HvRS/4LJ/jTRDn8DZIW z666IPXhmIlnlJVzMZYOffOzS4bELFO4/wZNA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763492828; x=1764097628; h=user-agent: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=fAXEIOdrPjlE+zwRCMVbogwTJwQnlb80CC1vQLcEkoA=; b=LPLG91n0WtNzdavEu8Z0PQbLbO9LE89v2s3jFisbUSwQAfUEz/yHcUSc+t6Y5em8CD mfn9bEiNSqWIKiHcqwJAftS2R6ahqKKddAnseiKe81Z5WElHgcCe1Uv0Mz9SW6iwfzdt V2umKjY/cqL0pfh0NaZD0f2JX/z9ZrZGxKu5HadOE29dHBMggGVY5GiTW/2dKtYgA18r C+rF7wREnMMwaSjCW5wdb4JvHXxG0EpT5iPTKKISBF23yaV9yr4HF1Mwn2vzEK4lVJw6 keiDwLgS44jkI87b3jNkIgOEFGmd08cTALPZ4oS8RiVw4ollzpPNNx/5tXQsvUrPEVxM OXoQ== X-Gm-Message-State: AOJu0YzNXX5Vn4q7v5lRvaXCn04AopE4A9jwUaVTMJab+0iIjGEuNPlj ixjndhRDHIqw/RjUAt5TtG6/Ue9jRcdjFRJibgztacfboTnn433VhN9PJ3EByxd5GtE= X-Gm-Gg: ASbGncsHGsBltpZqLHuxA0kPq8wTDq5sEEqFyChmalo3shFHDivpUpEfRIphI+g/19l byKvtaGpgjzC8qGgyf0M47SWj8BeV2qyG7eaNAqXUYpYiNSTayPm6FeKZRB9Owrh/n2WWztxAC7 WQSoJ7HHl9SYx783y7MF1BI0uvS6la5difQkIi/QzEf0/3HLCsO/2XLvNNSbV61TkbUc/keKkOO Imb5jUgDn33PzPQnMkLGStaM1IHzo55Ivyo8rq4PMg9PaPxgsFtTvATD+EOXTtV5HT70y3svbiT HOVPagqJT+MdFnZ6aPjpHw0UzDPeAdteKaplGuYhIX1VeAVDHFp8ajDYjaBMrNGCzxeSGzEVRop wSn7Pn6dbLI4DV8jo8rL6tnvFZpaI4JgZOzfTUkxfF1dQR1E6UzVMwyv1soxoXry0DxeaCsBBlC ma/grkUYcnOx4HIFUkWbE= X-Google-Smtp-Source: AGHT+IFvsO86VAhPM6CptdlIPVzNT0Q89ybPGqkJA89h5VTASkSdKVDNQOnLXSJRqu2YJ+p9FRN0yQ== X-Received: by 2002:a17:903:3b87:b0:297:f8d9:aad7 with SMTP id d9443c01a7336-2986a74ba2fmr183918315ad.50.1763492827872; Tue, 18 Nov 2025 11:07:07 -0800 (PST) Received: from localhost ([116.86.198.140]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2985c2346c3sm179898925ad.4.2025.11.18.11.07.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Nov 2025 11:07:07 -0800 (PST) Date: Wed, 19 Nov 2025 03:07:06 +0800 From: Chris Down To: Petr Mladek Cc: linux-kernel@vger.kernel.org, Greg Kroah-Hartman , Sergey Senozhatsky , Steven Rostedt , John Ogness , Geert Uytterhoeven , Tony Lindgren , kernel-team@fb.com Subject: [PATCH v7 03/13] printk: console: Implement core per-console loglevel infrastructure Message-ID: <201aa88f5c476ba56aa23183d74643275f8b2b41.1763492585.git.chris@chrisdown.name> References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/2.2.15 (2b349c5e) (2025-10-02) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Consoles can have vastly different latencies and throughputs. For example, writing a message to the serial console can take on the order of tens of milliseconds to get the UART to successfully write a message. While this might be fine for a single, one-off message, this can cause significant application-level stalls in situations where the kernel writes large amounts of information to the console. This means that while you might want to send at least INFO level messages to (for example) netconsole, which is relatively fast, you may only want to send at least WARN level messages to the serial console. Such an implementation would permit debugging using the serial console in cases that netconsole doesn't receive messages during particularly bad system issues, while still keeping the noise low enough to avoid inducing latency in userspace applications. To mitigate this, add such an interface, extending the existing console loglevel controls to allow each console to have its own loglevel. One can't just disable the serial console, because one may actually need it in situations where the machine is in a bad enough state that nothing is received on netconsole. One also can't just bump the loglevel at runtime after the issue, because usually the machine is already so wedged by this point that it isn't responsive to such requests. This commit adds the internal infrastructure to support per-console log levels, which will be configurable through sysfs and the kernel command line in future commits. The global console_loglevel is preserved and used as the default log level for all consoles. Each console can override this global level with its own specific log level stored in struct console. To override the global level, the per-console log level must be greater than 0; otherwise, the default value of LOGLEVEL_DEFAULT (-1) ensures the global level is used. The existing ignore_loglevel command line parameter will override both the global and per-console log levels. Signed-off-by: Chris Down Reviewed-by: Petr Mladek --- include/linux/console.h | 41 +++++++++-- include/linux/printk.h | 6 +- kernel/printk/internal.h | 12 ++++ kernel/printk/nbcon.c | 4 +- kernel/printk/printk.c | 150 ++++++++++++++++++++++++++++++++++++++- 5 files changed, 203 insertions(+), 10 deletions(-) diff --git a/include/linux/console.h b/include/linux/console.h index 8f10d0a85bb4..c0749a48fc3f 100644 --- a/include/linux/console.h +++ b/include/linux/console.h @@ -314,6 +314,8 @@ struct nbcon_write_context { * @match: Callback for matching a console (Optional) * @flags: Console flags. See enum cons_flags * @index: Console index, e.g. port number + * @level: Per-console loglevel. -1 means use global console_loglevel, + * values > 0 specify console-specific filtering level * @cflag: TTY control mode flags * @ispeed: TTY input speed * @ospeed: TTY output speed @@ -342,6 +344,7 @@ struct console { int (*match)(struct console *co, char *name, int idx, char *options); short flags; short index; + int level; int cflag; uint ispeed; uint ospeed; @@ -518,11 +521,6 @@ extern struct hlist_head console_list; static inline short console_srcu_read_flags(const struct console *con) { WARN_ON_ONCE(!console_srcu_read_lock_is_held()); - - /* - * The READ_ONCE() matches the WRITE_ONCE() when @flags are modified - * for registered consoles with console_srcu_write_flags(). - */ return data_race(READ_ONCE(con->flags)); } =20 @@ -544,6 +542,39 @@ static inline void console_srcu_write_flags(struct con= sole *con, short flags) WRITE_ONCE(con->flags, flags); } =20 +/** + * console_srcu_read_loglevel - Locklessly read the console specific logle= vel + * of a possibly registered console + * @con: struct console pointer of console to read loglevel from + * + * Locklessly reading @con->level provides a consistent read value because + * there is at most one CPU modifying @con->level and that CPU is using on= ly + * read-modify-write operations to do so. + * + * Requires console_srcu_read_lock to be held, which implies that @con mig= ht + * be a registered console. The purpose of holding console_srcu_read_lock = is + * to guarantee that the console state is valid (CON_SUSPENDED/CON_ENABLED) + * and that no exit/cleanup routines will run if the console is currently + * undergoing unregistration. + * + * If the caller is holding the console_list_lock or it is _certain_ that + * @con is not and will not become registered, the caller may read + * @con->level directly instead. + * + * Context: Any context. + * Return: The current value of the @con->level field. + */ +static inline int console_srcu_read_loglevel(const struct console *con) +{ + WARN_ON_ONCE(!console_srcu_read_lock_is_held()); + + /* + * The READ_ONCE() matches the WRITE_ONCE() when @level is modified + * for registered consoles. + */ + return data_race(READ_ONCE(con->level)); +} + /* Variant of console_is_registered() when the console_list_lock is held. = */ static inline bool console_is_registered_locked(const struct console *con) { diff --git a/include/linux/printk.h b/include/linux/printk.h index 45c663124c9b..644584edf3e9 100644 --- a/include/linux/printk.h +++ b/include/linux/printk.h @@ -209,6 +209,7 @@ void printk_legacy_allow_panic_sync(void); extern bool nbcon_device_try_acquire(struct console *con); extern void nbcon_device_release(struct console *con); void nbcon_atomic_flush_unsafe(void); +bool has_per_console_loglevel(const struct console *con); bool pr_flush(int timeout_ms, bool reset_on_progress); #else static inline __printf(1, 0) @@ -322,7 +323,10 @@ static inline void nbcon_device_release(struct console= *con) static inline void nbcon_atomic_flush_unsafe(void) { } - +static inline bool has_per_console_loglevel(const struct console *con) +{ + return false; +} static inline bool pr_flush(int timeout_ms, bool reset_on_progress) { return true; diff --git a/kernel/printk/internal.h b/kernel/printk/internal.h index 1ed86577896c..41e37b44778f 100644 --- a/kernel/printk/internal.h +++ b/kernel/printk/internal.h @@ -15,6 +15,18 @@ int devkmsg_sysctl_set_loglvl(const struct ctl_table *ta= ble, int write, #define printk_sysctl_init() do { } while (0) #endif =20 +enum loglevel_source { + LLS_GLOBAL, + LLS_LOCAL, + LLS_IGNORE_LOGLEVEL, +}; + +int console_clamp_loglevel(int level); + +enum loglevel_source +console_effective_loglevel_source(int con_level); +int console_effective_loglevel(int con_level); + #define con_printk(lvl, con, fmt, ...) \ printk(lvl pr_fmt("%s%sconsole [%s%d] " fmt), \ (con->flags & CON_NBCON) ? "" : "legacy ", \ diff --git a/kernel/printk/nbcon.c b/kernel/printk/nbcon.c index eb4c8faa213d..fb99aaa8c5d8 100644 --- a/kernel/printk/nbcon.c +++ b/kernel/printk/nbcon.c @@ -961,6 +961,7 @@ static bool nbcon_emit_next_record(struct nbcon_write_c= ontext *wctxt, bool use_a struct nbcon_context *ctxt =3D &ACCESS_PRIVATE(wctxt, ctxt); struct console *con =3D ctxt->console; bool is_extended =3D console_srcu_read_flags(con) & CON_EXTENDED; + int con_level =3D console_srcu_read_loglevel(con); struct printk_message pmsg =3D { .pbufs =3D ctxt->pbufs, }; @@ -993,7 +994,8 @@ static bool nbcon_emit_next_record(struct nbcon_write_c= ontext *wctxt, bool use_a if (!nbcon_context_enter_unsafe(ctxt)) return false; =20 - ctxt->backlog =3D printk_get_next_message(&pmsg, ctxt->seq, is_extended, = console_loglevel); + ctxt->backlog =3D printk_get_next_message(&pmsg, ctxt->seq, is_extended, + console_effective_loglevel(con_level)); if (!ctxt->backlog) return nbcon_context_exit_unsafe(ctxt); =20 diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 745f89a18189..928d77c56c77 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -197,6 +197,24 @@ static int __init control_devkmsg(char *str) } __setup("printk.devkmsg=3D", control_devkmsg); =20 +/** + * console_clamp_loglevel - Clamp a loglevel to valid console loglevel ran= ge + * + * @level: The loglevel to clamp + * + * Console loglevels must be within the range [LOGLEVEL_ALERT, LOGLEVEL_DE= BUG + 1]. + * This function clamps a given level to this valid range. + * + * Note: This does not allow LOGLEVEL_EMERG (0) for per-console loglevels,= as + * level 0 is reserved for emergency messages that should always go to all= consoles. + * + * Return: The clamped loglevel value + */ +int console_clamp_loglevel(int level) +{ + return clamp(level, LOGLEVEL_ALERT, LOGLEVEL_DEBUG + 1); +} + char devkmsg_log_str[DEVKMSG_STR_MAX_SIZE] =3D "ratelimit"; #if defined(CONFIG_PRINTK) && defined(CONFIG_SYSCTL) int devkmsg_sysctl_set_loglvl(const struct ctl_table *table, int write, @@ -1280,11 +1298,120 @@ module_param(ignore_loglevel, bool, S_IRUGO | S_IW= USR); MODULE_PARM_DESC(ignore_loglevel, "ignore loglevel setting (prints all kernel messages to the console)"); =20 +bool has_per_console_loglevel(const struct console *con) +{ + return con && (console_srcu_read_loglevel(con) > 0); +} + +/** + * is_valid_per_console_loglevel - Check if a loglevel is valid for per-co= nsole + * + * @con_level: The loglevel to check + * + * Per-console loglevels must be strictly positive (> 0). Level 0 (KERN_EM= ERG) + * is reserved for emergency messages that should go to all consoles (and = so is + * disallowed), and -1 (LOGLEVEL_DEFAULT) means use the global console_log= level. + * + * Return: true if con_level is a valid per-console loglevel (> 0), false + * otherwise + */ +static bool is_valid_per_console_loglevel(int con_level) +{ + return (con_level > 0); +} + +/** + * console_effective_loglevel_source - Determine the source of effective l= oglevel + * + * @con_level: The console's per-console loglevel value + * + * This function determines which loglevel authority is in effect for a co= nsole, + * based on the hierarchy of controls: + * + * 1. ignore_loglevel (overrides everything - prints all messages) + * 2. per-console loglevel (if set and not ignored) + * 3. global console_loglevel (fallback) + * + * Return: The loglevel source (LLS_IGNORE_LOGLEVEL, LLS_LOCAL, or LLS_GLO= BAL) + */ +enum loglevel_source +console_effective_loglevel_source(int con_level) +{ + if (ignore_loglevel) + return LLS_IGNORE_LOGLEVEL; + + if (is_valid_per_console_loglevel(con_level)) + return LLS_LOCAL; + + return LLS_GLOBAL; +} + +/** + * console_effective_loglevel - Get the effective loglevel for a console + * + * @con_level: The console's per-console loglevel value + * + * This function returns the actual loglevel value that should be used for + * message filtering for a console, taking into account all loglevel contr= ols + * (global, per-console, and ignore_loglevel). + * + * The effective loglevel is used to determine which messages get printed = to + * the console. Messages with priority less than the effective level are p= rinted. + * + * Return: The effective loglevel value to use for filtering + */ +int console_effective_loglevel(int con_level) +{ + enum loglevel_source source; + int level; + + source =3D console_effective_loglevel_source(con_level); + + switch (source) { + case LLS_IGNORE_LOGLEVEL: + level =3D CONSOLE_LOGLEVEL_MOTORMOUTH; + break; + case LLS_LOCAL: + level =3D con_level; + break; + case LLS_GLOBAL: + level =3D console_loglevel; + break; + default: + pr_warn("Unhandled console loglevel source: %d", source); + level =3D console_loglevel; + break; + } + + return level; +} + static bool suppress_message_printing(int level, int con_eff_level) { return (level >=3D con_eff_level && !ignore_loglevel); } =20 +static bool suppress_message_printing_everywhere(int level) +{ + bool suppress_everywhere =3D true; + struct console *con; + int cookie; + + cookie =3D console_srcu_read_lock(); + + for_each_console_srcu(con) { + int con_level =3D console_srcu_read_loglevel(con); + + if (!suppress_message_printing(level, console_effective_loglevel(con_lev= el))) { + suppress_everywhere =3D false; + break; + } + } + console_srcu_read_unlock(cookie); + + return suppress_everywhere; +} + #ifdef CONFIG_BOOT_PRINTK_DELAY =20 static int boot_delay; /* msecs delay after each printk during bootup */ @@ -2116,7 +2243,8 @@ int printk_delay_msec __read_mostly; static inline void printk_delay(int level) { /* If the message is forced (e.g. panic), we must delay */ - if (!is_printk_force_console() && suppress_message_printing(level, consol= e_loglevel)) + if (!is_printk_force_console() && + suppress_message_printing_everywhere(level)) return; =20 boot_delay_msec(); @@ -3059,6 +3187,7 @@ struct printk_buffers printk_shared_pbufs; static bool console_emit_next_record(struct console *con, bool *handover, = int cookie) { bool is_extended =3D console_srcu_read_flags(con) & CON_EXTENDED; + int con_level =3D console_srcu_read_loglevel(con); char *outbuf =3D &printk_shared_pbufs.outbuf[0]; struct printk_message pmsg =3D { .pbufs =3D &printk_shared_pbufs, @@ -3068,7 +3197,7 @@ static bool console_emit_next_record(struct console *= con, bool *handover, int co *handover =3D false; =20 if (!printk_get_next_message(&pmsg, con->seq, is_extended, - console_loglevel)) + console_effective_loglevel(con_level))) return false; =20 con->dropped +=3D pmsg.dropped; @@ -3817,6 +3946,9 @@ static int try_enable_preferred_console(struct consol= e *newcon, if (newcon->index < 0) newcon->index =3D c->index; =20 + /* TODO: will be configurable in a later patch */ + newcon->level =3D LOGLEVEL_DEFAULT; + if (_braille_register_console(newcon, c)) return 0; =20 @@ -3835,8 +3967,12 @@ static int try_enable_preferred_console(struct conso= le *newcon, * without matching. Accept the pre-enabled consoles only when match() * and setup() had a chance to be called. */ - if (newcon->flags & CON_ENABLED && c->user_specified =3D=3D user_specifie= d) + if (newcon->flags & CON_ENABLED && c->user_specified =3D=3D user_specifie= d) { + /* Ensure level is initialized for pre-enabled consoles */ + if (newcon->level =3D=3D 0) + newcon->level =3D LOGLEVEL_DEFAULT; return 0; + } =20 return -ENOENT; } @@ -4039,6 +4175,14 @@ void register_console(struct console *newcon) } =20 newcon->dropped =3D 0; + + /* + * Don't unconditionally overwrite, it may have been set on the command + * line already. + */ + if (newcon->level =3D=3D 0) + newcon->level =3D LOGLEVEL_DEFAULT; + init_seq =3D get_init_console_seq(newcon, bootcon_registered); =20 if (newcon->flags & CON_NBCON) { --=20 2.51.2 From nobody Tue Dec 2 02:31:07 2025 Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) (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 75EBB30C601 for ; Tue, 18 Nov 2025 19:07:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763492836; cv=none; b=utXGSDA1sIvQsnFoMJXzdOZpbMExViXqm0T8uQilPduEEM+oBsNbZWFcx82gtQ40N0ZtVVr++3X46jrp90QxF6sVqYTHftuvUTDhPMexQ/DIicYe1TC5NsclefYEuhTZo4iHB6FRFkeOtFWwEoMX6j0Yq5hv9+yjLwpQV7Kctwk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763492836; c=relaxed/simple; bh=DM4Rsh00uOMahlI77s4+jULSF4hwa42Y/OVFP30/iJk=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=R7pIRXBJ8deo4zZeE0A7m8t8Y0XEk4aqL7xtH/sukN+uzBgLOKAYdTe9B6UJ2rBRixseIzTgBembigOYGBdU9cpESmTX+S6foaKzQTSeGQeSeIycjzs2WLvHdWOfykIZ4B6yCbgl2nOFtpTC49L1b27ubvRdzCnoUm7aziMhAz0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=chrisdown.name; spf=pass smtp.mailfrom=chrisdown.name; dkim=pass (1024-bit key) header.d=chrisdown.name header.i=@chrisdown.name header.b=buUYwnLK; arc=none smtp.client-ip=209.85.214.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=chrisdown.name Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chrisdown.name Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chrisdown.name header.i=@chrisdown.name header.b="buUYwnLK" Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-29558061c68so68511685ad.0 for ; Tue, 18 Nov 2025 11:07:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chrisdown.name; s=google; t=1763492834; x=1764097634; darn=vger.kernel.org; h=user-agent: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=7w23/gxbhgAeaCdz9QEozAtVsIwOWUg75eHcu4ZwLfs=; b=buUYwnLK/xXCOS7fTT4+V03rXNuHFDUiZDV8S2Y+yHI3rKpC9+bBHUrqs7VIeJ8pre z2zPO9YtzERJ+e6Dd9edg5HcrzcETY/K2JU9ExGjl3j6py8jzme9IIwIfqDdzOFY/itw 869zinF+mXZJ4uIYiDvA7VWE29TKEEb/mffT8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763492834; x=1764097634; h=user-agent: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=7w23/gxbhgAeaCdz9QEozAtVsIwOWUg75eHcu4ZwLfs=; b=on1YIbmWQonEboq4NYhroful8NNgn354ZUdCgMNQ+5E6ue3l1hM1LPmGNSzywYdzmS WoWdv0np1pInQkHY11Ph+VBHi5PYknjBw1vb4EkNo8E8D47TaWjzAkIQLKFfRW5SNI3g etPrWpLbV+Tyzrqr/T51yPlIwycoGk0TuU4Os8L0djd6bGlORSgktSvnKUW0nQfdyghq OHNbIBJ7FyoR3aFFojOeOnag0FfINtGlPOqtdcmGElEG6Sb0fv5Lf8Qy0WNLmslVpZoo duIOY3+NkckWDj6DnkkO7ncvOp9HJaLa7OdutgI5wWrZxOPc9Zx1EWP5BcwkSyXH+7nn oqvw== X-Gm-Message-State: AOJu0YzP15NykjAXTgI3AxM/8/WgFGudPmPhdaPbTX2OO9itvQzinvmv m7fqfjlalZpNlGpeXZJijRmf9RvERW9IoSnhSVJOJzdE+ORYKe2UmKy8ZWAAMYLXyRA= X-Gm-Gg: ASbGncueBfIbqTsEnpBL8A0Itfzn1Mn1+M4QBGRbWiZFD3Q7LuXySaIOlgaHdjemRUO UZukTmwaZYvXs6h/mCOzy30/srkrtsmfNaByLZdbdwB45Y15u5TafB+H40zVzP9iwuELSy7GOaq kHNF2thNtkL7IsY/O8cCWRJZ4dCj6z77AcN+ijLPyxJrrCxm8AouVqL5APD2L3DrQiguy/1mjaB 2UmUA2tUPM7Y55dxVdmxr/DsWKs790kWbkNNbdd8ZQjaVLDthfloHTe9qzILtpTi0n1BC96Npai 8JfUqNF/XjdERYiN2kMvnSm1S0r/5D8XQw7KNap+IpqQG6irKzL7WfiNXVvt75fijPgdBIWfeev PHLJ/j1f6rppd7Y4oHdc3VRVkT3/jUcVQzWA/eeYRp9XE5STTJAsICxVZeXZux4V6DXLljQrU2m Yqap1iwr7i X-Google-Smtp-Source: AGHT+IFFlqxwQAND+MQlamI3f7hPFF3Clj7ilbDnRtwby2AvpQ5cBl9jC7lC5VagvmpwxoOwaFfwQA== X-Received: by 2002:a17:903:2409:b0:298:4ee2:19f3 with SMTP id d9443c01a7336-29a054c1d3fmr957385ad.49.1763492833653; Tue, 18 Nov 2025 11:07:13 -0800 (PST) Received: from localhost ([116.86.198.140]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2985c2bf158sm183369615ad.91.2025.11.18.11.07.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Nov 2025 11:07:13 -0800 (PST) Date: Wed, 19 Nov 2025 03:07:11 +0800 From: Chris Down To: Petr Mladek Cc: linux-kernel@vger.kernel.org, Greg Kroah-Hartman , Sergey Senozhatsky , Steven Rostedt , John Ogness , Geert Uytterhoeven , Tony Lindgren , kernel-team@fb.com Subject: [PATCH v7 04/13] printk: Ignore per-console loglevel in sysrq Message-ID: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/2.2.15 (2b349c5e) (2025-10-02) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" When the global console loglevel is changed via sysrq, clear any per-console loglevels that may have been set. This ensures that the sysrq loglevel change takes effect immediately across all consoles. Warn once if any per-console loglevels were being overridden. Signed-off-by: Chris Down Reviewed-by: Petr Mladek --- drivers/tty/sysrq.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c index 97f8a9a52285..1763eaefd581 100644 --- a/drivers/tty/sysrq.c +++ b/drivers/tty/sysrq.c @@ -51,6 +51,7 @@ #include #include #include +#include =20 #include #include @@ -101,10 +102,25 @@ __setup("sysrq_always_enabled", sysrq_always_enabled_= setup); static void sysrq_handle_loglevel(u8 key) { u8 loglevel =3D key - '0'; + int cookie; + struct console *con; =20 console_loglevel =3D CONSOLE_LOGLEVEL_DEFAULT; pr_info("Loglevel set to %u\n", loglevel); console_loglevel =3D loglevel; + + /* + * When changing loglevel via sysrq, override all per-console loglevels + * to ensure the new global loglevel takes effect immediately and all + * consoles see the messages. + */ + cookie =3D console_srcu_read_lock(); + for_each_console_srcu(con) { + if (has_per_console_loglevel(con)) + pr_warn_once("Overriding per-console loglevel from sysrq\n"); + WRITE_ONCE(con->level, LOGLEVEL_DEFAULT); + } + console_srcu_read_unlock(cookie); } static const struct sysrq_key_op sysrq_loglevel_op =3D { .handler =3D sysrq_handle_loglevel, --=20 2.51.2 From nobody Tue Dec 2 02:31:07 2025 Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) (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 F09453A8D46 for ; Tue, 18 Nov 2025 19:07:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763492841; cv=none; b=c7KlpQPSb4+hD2HHu5LsqLnHv1h3Oz6vLs/AHh3GUqY4wSxsrUCn1hVetwSuYB3dCY2FGLTqtlaep2PF6nAyiuj89qGnk8h+0GVSE2jIRzZznGgQTjy4ryMJX21x5Y7vPVYhUi8nygjMFtVCIR+UrNpGwIl62BF7cgqCZtaO9y8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763492841; c=relaxed/simple; bh=+crBFLHD4uzzdS3kUxZ6kWF8cNYQioALQNc6kWRg1TU=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=igrDRkamjZS6/wj6TD1fQZSo8j92Wjphbq8PhlG0c+bZPB5kyEeWs0O7yY6szhFV/uj4saQegInL2xeiBqg+A6Z9l8qNLgk185mT++F8cWxSZ/KhI4ndqEQYEkh+uJ/vsGHUFeboJZ69X/Ki8puTnRPEmMj1WAl5zHjJ9PVSORI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=chrisdown.name; spf=pass smtp.mailfrom=chrisdown.name; dkim=pass (1024-bit key) header.d=chrisdown.name header.i=@chrisdown.name header.b=EmkyGBiy; arc=none smtp.client-ip=209.85.214.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=chrisdown.name Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chrisdown.name Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chrisdown.name header.i=@chrisdown.name header.b="EmkyGBiy" Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-297f35be2ffso82068875ad.2 for ; Tue, 18 Nov 2025 11:07:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chrisdown.name; s=google; t=1763492839; x=1764097639; darn=vger.kernel.org; h=user-agent: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=J+zURS8KdG3v8ioTH9loBh6ECN6LbjDg1avPcG73OYw=; b=EmkyGBiyDGaafrqOJkHNbtVJtGZS271hYMKJOWyfnrKurAcoDJO7HOkhphSSg010Ii aN5t/3Mk1CGKF+FepN1H5DPXe88qYm3a24uPdLKIv06l/yBsm0wTvHihAiTj6Y3rkziF fDX/tIJDBveYZxklYzrp1qyg4r1owIcgG14bs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763492839; x=1764097639; h=user-agent: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=J+zURS8KdG3v8ioTH9loBh6ECN6LbjDg1avPcG73OYw=; b=BqJYLFPynOHO77v+W6x231/lv647zSDS+PwUzg4M7onoWA4DIFAl9u5pIUg9lX9SUj iiU1Nygv+yUSOKhS1UohpKz2C+T8zQ52PKh9zcJgODaaVAK0moq5zbJ/xeSxPW7GcbXw jFOPqa0+19UqA5m7JP3K1RYOWU2AGCXpxbmjmKYtXE34kb4b5QSKtX9EFUrlJbOIfo4R Wo+hXLAq2dJmLIX610gp52mA4MFCaLBKGa33CA3DW3TyyyOC2RiHNk8rvnLvu079jgky EPQnM1TeFx9FmTIrpN5AT2gG8Jjy67CUeTC2Blq7KsMRlHYqsDlGSTtEkjFYDCjPpIlI +q7Q== X-Gm-Message-State: AOJu0Yz89E0FtVnYDrXSNuuu4oVZN16trV01fI/s2yzdDN3Hww7YWZts Lj7ahIzYz5AqW+xjxL30rDBZKXGkaneiqzLCCPJRTJql6+/6KfZNpXo+rY8nH92kZrQ= X-Gm-Gg: ASbGncvUxej5CGSQavCoIj7caLfN+pLg/IOb90q/oV/j0I7ybDRxiJdR2KMIRzUgKrh 7QeWZpjnbvkklTmv0lCTZ6Kvji1h+4lGSML0KbS3beXP6tJeH9t33quhzdVIDRF2r4unGosyP6R SX3AOove8l/X/Az08xc077Lv5cGBuO335GCqYa3mIKPk4cLsI6zgEpwSTgiTFl1eYOPPUl9fmrV kZU2GzYNQefQRNXFBRcFy3qayyi5feXRPa3pC3k5nx4fbIHCt6C4yAIx8yez7uqtNbcKglMyp7q 5cx5ThoiugpJYRvDfeUpKGXY43RyyjkU1CkJmJgus9KzK1mEWxuozFIpYz3hZRmUqTLKVII6CcA dXUqJHhhA+5IgSOlVGtqbCPEsNy7RVrL/z9ql6D/CYY+KEszFneNb4/eogs3cRmscWGWOGnGurh Tj5M5XqFFB X-Google-Smtp-Source: AGHT+IGjWd9F+bZl0TH8YK9pYMJNAzfqSXPMiXJO+xy0WefaX33lf3ddAp9iG3YxRdyStsJRKUyy6g== X-Received: by 2002:a17:903:904:b0:295:2276:6704 with SMTP id d9443c01a7336-2986a76821bmr173480585ad.51.1763492839305; Tue, 18 Nov 2025 11:07:19 -0800 (PST) Received: from localhost ([116.86.198.140]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2985c242003sm179764525ad.24.2025.11.18.11.07.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Nov 2025 11:07:18 -0800 (PST) Date: Wed, 19 Nov 2025 03:07:17 +0800 From: Chris Down To: Petr Mladek Cc: linux-kernel@vger.kernel.org, Greg Kroah-Hartman , Sergey Senozhatsky , Steven Rostedt , John Ogness , Geert Uytterhoeven , Tony Lindgren , kernel-team@fb.com Subject: [PATCH v7 05/13] printk: Add synchronisation for concurrent console state changes Message-ID: <9ffc0801a64e5f7d0685c263c1908a34cf89d1a5.1763492585.git.chris@chrisdown.name> References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/2.2.15 (2b349c5e) (2025-10-02) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The syslog actions SYSLOG_ACTION_CONSOLE_OFF and SYSLOG_ACTION_CONSOLE_ON currently run without any locking. This creates a race condition if two processes attempt to toggle the console state simultaneously. While this race has existed for donkey's years, it was previously somewhat tolerable because it involved only a single integer variable (saved_console_loglevel). However, upcoming changes will introduce a second piece of state (saved_ignore_per_console_loglevel) to be saved and restored. With two variables, this can result in saved state getting lost. Here is a demonstration: CPU 0 (SYSLOG_ACTION_CONSOLE_OFF) CPU 1 (SYSLOG_ACTION_CONSOLE_ON) --------------------------------- -------------------------------- // saved_console_loglevel is DEFAULT if (saved =3D=3D DEFAULT) (True) saved =3D console_loglevel (7) // Race triggers here if (saved !=3D DEFAULT) (True) loglevel =3D saved (7) saved =3D DEFAULT // CPU 0 continues, unaware saved // was just reset by CPU 1 loglevel =3D minimum_console_loglevel (1) The result is that the console is now set to the minimum loglevel, but saved_console_loglevel is LOGLEVEL_DEFAULT. A subsequent CONSOLE_ON call will see saved =3D=3D LOGLEVEL_DEFAULT and thus refuse to restore the original loglevel. The console is effectively stuck in quiet mode until manually reset via sysctl. Oh dear. The callers of do_syslog are syscalls (so user context) or procfs write handlers. These contexts are allowed to sleep, so acquiring a mutex is safe. We also already make use of syslog_lock in SYSLOG_ACTION_SIZE_UNREAD and SYSLOG_ACTION_READ, so this is consistent. Signed-off-by: Chris Down Reviewed-by: Petr Mladek --- kernel/printk/printk.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 928d77c56c77..b8679b0da42f 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -1903,16 +1903,20 @@ int do_syslog(int type, char __user *buf, int len, = int source) break; /* Disable logging to console */ case SYSLOG_ACTION_CONSOLE_OFF: + mutex_lock(&syslog_lock); if (saved_console_loglevel =3D=3D LOGLEVEL_DEFAULT) saved_console_loglevel =3D console_loglevel; console_loglevel =3D minimum_console_loglevel; + mutex_unlock(&syslog_lock); break; /* Enable logging to console */ case SYSLOG_ACTION_CONSOLE_ON: + mutex_lock(&syslog_lock); if (saved_console_loglevel !=3D LOGLEVEL_DEFAULT) { console_loglevel =3D saved_console_loglevel; saved_console_loglevel =3D LOGLEVEL_DEFAULT; } + mutex_unlock(&syslog_lock); break; /* Set level of messages printed to console */ case SYSLOG_ACTION_CONSOLE_LEVEL: --=20 2.51.2 From nobody Tue Dec 2 02:31:07 2025 Received: from mail-pf1-f170.google.com (mail-pf1-f170.google.com [209.85.210.170]) (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 379193A8D46 for ; Tue, 18 Nov 2025 19:07:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763492847; cv=none; b=qpn1RpcK/J8v/+BSVK9GhfaHuoIU09SeGI6xqCVTKkdIT1LL9Xt8mD14ixVWiAA8h0ezA1d9tsv7dn4rnCwcxRaogJ2xdKw25QOwsZDGBJ2WZRBO3fEtsAvs1bsN2Fsa4pLs6ifR5ckvBETDlNO603TMLP2M4Fya5kSq+tvKSLo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763492847; c=relaxed/simple; bh=qbm+00Q0+MW5M7XDzk/uCTDsFeWU8UuoWfP/WdNt55A=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=jWL3OSkj9Fg+pcw5JA34ljSRhwf4/yupWnjhw5b4xydaksRcJrL1OTly5tt9CZ7ugluWHV/+zi8JGOEscPisAIqRoQNTn1hFDTuFK0o8UuyQoJTFQQ+tlmcWtJO151w4LCz9ct00CMjGqVI4K1/d6yElgx4HOQDb3uuw1uDNoh4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=chrisdown.name; spf=pass smtp.mailfrom=chrisdown.name; dkim=pass (1024-bit key) header.d=chrisdown.name header.i=@chrisdown.name header.b=MJmc4YjV; arc=none smtp.client-ip=209.85.210.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=chrisdown.name Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chrisdown.name Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chrisdown.name header.i=@chrisdown.name header.b="MJmc4YjV" Received: by mail-pf1-f170.google.com with SMTP id d2e1a72fcca58-7b9215e55e6so3824686b3a.2 for ; Tue, 18 Nov 2025 11:07:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chrisdown.name; s=google; t=1763492844; x=1764097644; darn=vger.kernel.org; h=user-agent: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=hZF4plzNtVV8hXnk1XlbxrXJNMMIMw3IrXz8MfwBF8U=; b=MJmc4YjVENVxlZdWyp0plmoYbtl+/nGPifYJ7iDPWy1eVqlEg6OP+SDiKUBIq0TjQA ZGeepDn2jg7xT5eg1ngXVfghwmjFxAGajiJ3fczaNLNL+1JVKUEmqTjmYVscKPABy/vZ vtslz9zjST/98Yr3hKzENn2mNGN6vWlHAIJu0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763492844; x=1764097644; h=user-agent: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=hZF4plzNtVV8hXnk1XlbxrXJNMMIMw3IrXz8MfwBF8U=; b=xKflPdeky2qSkKBLFEtW2yeBw428hfNJUsTmT18DCI876fINSErA6ZuIAedPmy8PBB z/ke1EtfHicQyFGF9wyb+STiFBrO/so0ihZwadd7Ulpd3A5qfB/MiPREytpnI34SnAM8 MVDAHBCYxSNnWTiW0G+cp+4EAC66/FZp9cQ4GPJEikOLubkD5YfTcmVqQT+03QLcIo2F 7rNsi+7KIxkDsUZl212/nPohuPjHplWPYkCUXkXFDCE0RSiNmdcSzMiP6KqHGq/fKftY ad2Q4bYqUTpewtlmP6ACAbZLVhvwjCVM2L+KJ8cT2ONXjpzvXObYxdGYm/AVmWeCSBNa W19w== X-Gm-Message-State: AOJu0YwEttrY/0AMQeA1YhzeJQhTTND9nuXg6ndI1OVrfPKMlEtOWAf0 BF/ewTuQ0USJBCMIMvhIv6c73ee84YREAeqv4krA2ZEHBVfoIIiuA2RoN7ML2s+4+RQ= X-Gm-Gg: ASbGnct7LfOLxvFbZVeOkzGkGIDcyrdGLfo+Zfo+FBZrsuUI5oZf1A8T8z8Lt3h+knA 4KOu44uczYnZYe2KTSQjDK5Ecw2yHTKS44sW42HLQnMpr5GzwOlOJX9oTADkUIpuxiX8WlkCcgD l2qo4gs0wzV+h0iR9dw4m3DJS1/u5EV06QP2m2BzXVgaV3VmUY2yulCxf65PcFwKVQtZItssodd oNXWe3YN0xxLiNj/hkVtWOjRyThNEgLyaDzlCtkt9Jyb8ig0OidIPyk4LJ/b2nVeyymDKN2XEMN L9nOsZunjBvPj54Ke3prPwpILLO+gKPr/uEXdt0lqrJu82xdkutv353W7wgNtqJGXfOi8P0r1NK UyDtjeMHC4RtaazBDohmOcSWGYikYnzDIGwhpl3I8FEvK3L4DU3Nuk0R/J+J4c2WA+1FZUpcVGR xCc5DCFyyoUBX1QUTcFi0= X-Google-Smtp-Source: AGHT+IHHWcUsp7/rgUihcSI+AhlUWpfYBXVY1d279K2O0BnxymRMN9yYqq/Yb+6+gywkoEHssoCmvg== X-Received: by 2002:a05:6a20:3d1c:b0:35d:a2c1:3a15 with SMTP id adf61e73a8af0-35da2c1d84bmr11884810637.4.1763492844165; Tue, 18 Nov 2025 11:07:24 -0800 (PST) Received: from localhost ([116.86.198.140]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-bc36db2242esm16530128a12.6.2025.11.18.11.07.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Nov 2025 11:07:23 -0800 (PST) Date: Wed, 19 Nov 2025 03:07:22 +0800 From: Chris Down To: Petr Mladek Cc: linux-kernel@vger.kernel.org, Greg Kroah-Hartman , Sergey Senozhatsky , Steven Rostedt , John Ogness , Geert Uytterhoeven , Tony Lindgren , kernel-team@fb.com Subject: [PATCH v7 06/13] printk: Support toggling per-console loglevel via syslog() and cmdline Message-ID: <1c368ffff850a00b81d4b67c15c38b826251e27d.1763492585.git.chris@chrisdown.name> References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/2.2.15 (2b349c5e) (2025-10-02) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" A new module parameter (ignore_per_console_loglevel) is added, which can be set via the kernel command line or at runtime through /sys/module/printk/parameters/ignore_per_console_loglevel. When set, the per-console loglevels are ignored, and the global console loglevel (console_loglevel) is used for all consoles. During sysrq, we temporarily disable per-console loglevels to ensure all requisite messages are printed to the console. This is necessary because sysrq is often used in dire circumstances where access to /sys/class/console may not be trivially possible. Additionally, the syslog actions SYSLOG_ACTION_CONSOLE_ON and SYSLOG_ACTION_CONSOLE_OFF are augmented to save and restore the state of ignore_per_console_loglevel. This allows administrators to enable or disable per-console loglevels dynamically using the syslog() system call, as supported in userspace by things like dmesg. This is useful when debugging issues with message emission, or when needing to quickly break glass and revert to global loglevel only. Signed-off-by: Chris Down Reviewed-by: Petr Mladek --- Documentation/admin-guide/index.rst | 1 + .../admin-guide/kernel-parameters.txt | 7 ++ .../admin-guide/per-console-loglevel.rst | 71 +++++++++++++++++++ MAINTAINERS | 1 + drivers/tty/sysrq.c | 6 ++ include/linux/printk.h | 2 + kernel/printk/printk.c | 29 +++++++- 7 files changed, 114 insertions(+), 3 deletions(-) create mode 100644 Documentation/admin-guide/per-console-loglevel.rst diff --git a/Documentation/admin-guide/index.rst b/Documentation/admin-guid= e/index.rst index 259d79fbeb94..5f0ae9c4017b 100644 --- a/Documentation/admin-guide/index.rst +++ b/Documentation/admin-guide/index.rst @@ -155,6 +155,7 @@ How to configure your hardware within your Linux system. media/index nvme-multipath parport + per-console-loglevel pnp rapidio rtc diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentatio= n/admin-guide/kernel-parameters.txt index 3edc5ce0e2a3..7b62a99489b8 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -2177,6 +2177,13 @@ could change it dynamically, usually by /sys/module/printk/parameters/ignore_loglevel. =20 + ignore_per_console_loglevel [KNL,EARLY] + Ignore all per-console loglevel settings + and use only the global console_loglevel for all + consoles. This can also be set at runtime via + /sys/module/printk/parameters/ignore_per_console_loglevel. + See Documentation/admin-guide/per-console-loglevel.rst. + ignore_rlimit_data Ignore RLIMIT_DATA setting for data mappings, print warning at first misuse. Can be changed via diff --git a/Documentation/admin-guide/per-console-loglevel.rst b/Documenta= tion/admin-guide/per-console-loglevel.rst new file mode 100644 index 000000000000..1f8f1eabc75c --- /dev/null +++ b/Documentation/admin-guide/per-console-loglevel.rst @@ -0,0 +1,71 @@ +.. SPDX-License-Identifier: GPL-2.0 + +.. _per_console_loglevel: + +Per-console loglevel support +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D + +Motivation +---------- + +Consoles can have vastly different latencies and throughputs. For example, +writing a message to the serial console can take on the order of tens of +milliseconds to get the UART to successfully write a message. While this m= ight +be fine for a single, one-off message, this can cause significant +application-level stalls in situations where the kernel writes large amoun= ts of +information to the console. + +This means that while you might want to send at least INFO level messages = to +(for example) netconsole, which is relatively fast, you may only want to s= end at +least WARN level messages to the serial console. This permits debugging +using the serial console in cases that netconsole doesn't receive messages +during particularly bad system issues, while still keeping the noise low e= nough +to avoid inducing latency in userspace applications. + +Loglevel +-------- + +Kernel loglevels are defined thus: + ++---+--------------+-----------------------------------+ +| 0 | KERN_EMERG | system is unusable | ++---+--------------+-----------------------------------+ +| 1 | KERN_ALERT | action must be taken immediately | ++---+--------------+-----------------------------------+ +| 2 | KERN_CRIT | critical conditions | ++---+--------------+-----------------------------------+ +| 3 | KERN_ERR | error conditions | ++---+--------------+-----------------------------------+ +| 4 | KERN_WARNING | warning conditions | ++---+--------------+-----------------------------------+ +| 5 | KERN_NOTICE | normal but significant condition | ++---+--------------+-----------------------------------+ +| 6 | KERN_INFO | informational | ++---+--------------+-----------------------------------+ +| 7 | KERN_DEBUG | debug-level messages | ++---+--------------+-----------------------------------+ + +Tunables +-------- + +In order to allow tuning per-console loglevels, the following controls exi= st: + +Global +~~~~~~ + +The global loglevel is set by the ``kernel.console_loglevel`` sysctl, whic= h can +also be set as ``loglevel=3D`` on the kernel command line. + +The printk module also takes two parameters which modify this behaviour +further: + +* ``ignore_loglevel`` on the kernel command line or set in printk paramete= rs: + Emit all messages. All other controls are ignored if this is present. + +* ``ignore_per_console_loglevel`` on the kernel command line or set in pri= ntk + parameters: Ignore all per-console loglevels and use the global loglevel. + +The default value for ``kernel.console_loglevel`` comes from +``CONFIG_CONSOLE_LOGLEVEL_DEFAULT``, or ``CONFIG_CONSOLE_LOGLEVEL_QUIET`` = if +``quiet`` is passed on the kernel command line. + diff --git a/MAINTAINERS b/MAINTAINERS index e56494c7a956..8018a4db2d9f 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -20505,6 +20505,7 @@ R: John Ogness R: Sergey Senozhatsky S: Maintained T: git git://git.kernel.org/pub/scm/linux/kernel/git/printk/linux.git +F: Documentation/admin-guide/per-console-loglevel.rst F: Documentation/core-api/printk-basics.rst F: include/linux/printk.h F: kernel/printk/ diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c index 1763eaefd581..6cd2750e962b 100644 --- a/drivers/tty/sysrq.c +++ b/drivers/tty/sysrq.c @@ -52,6 +52,7 @@ #include #include #include +#include =20 #include #include @@ -599,12 +600,16 @@ static void __sysrq_put_key_op(u8 key, const struct s= ysrq_key_op *op_p) void __handle_sysrq(u8 key, bool check_mask) { const struct sysrq_key_op *op_p; + bool orig_ignore_per_console_loglevel; int orig_suppress_printk; int i; =20 orig_suppress_printk =3D suppress_printk; suppress_printk =3D 0; =20 + orig_ignore_per_console_loglevel =3D ignore_per_console_loglevel; + ignore_per_console_loglevel =3D true; + rcu_sysrq_start(); rcu_read_lock(); /* @@ -650,6 +655,7 @@ void __handle_sysrq(u8 key, bool check_mask) rcu_read_unlock(); rcu_sysrq_end(); =20 + ignore_per_console_loglevel =3D orig_ignore_per_console_loglevel; suppress_printk =3D orig_suppress_printk; } =20 diff --git a/include/linux/printk.h b/include/linux/printk.h index 644584edf3e9..e36cae1805b2 100644 --- a/include/linux/printk.h +++ b/include/linux/printk.h @@ -73,6 +73,8 @@ extern int console_printk[]; #define minimum_console_loglevel (console_printk[2]) #define default_console_loglevel (console_printk[3]) =20 +extern bool ignore_per_console_loglevel; + extern void console_verbose(void); =20 /* strlen("ratelimit") + 1 */ diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index b8679b0da42f..80204cbb7bc8 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -104,6 +104,9 @@ DEFINE_STATIC_SRCU(console_srcu); */ int __read_mostly suppress_printk; =20 +/* The sysrq infrastructure needs this even on !CONFIG_PRINTK. */ +bool __read_mostly ignore_per_console_loglevel; + #ifdef CONFIG_LOCKDEP static struct lockdep_map console_lock_dep_map =3D { .name =3D "console_lock" @@ -1298,9 +1301,21 @@ module_param(ignore_loglevel, bool, S_IRUGO | S_IWUS= R); MODULE_PARM_DESC(ignore_loglevel, "ignore loglevel setting (prints all kernel messages to the console)"); =20 +static int __init ignore_per_console_loglevel_setup(char *str) +{ + ignore_per_console_loglevel =3D true; + return 0; +} + +early_param("ignore_per_console_loglevel", ignore_per_console_loglevel_set= up); +module_param(ignore_per_console_loglevel, bool, 0644); +MODULE_PARM_DESC( + ignore_per_console_loglevel, + "ignore per-console loglevel setting (only respect global console logleve= l)"); + bool has_per_console_loglevel(const struct console *con) { - return con && (console_srcu_read_loglevel(con) > 0); + return !ignore_per_console_loglevel && con && (console_srcu_read_loglevel= (con) > 0); } =20 /** @@ -1340,7 +1355,7 @@ console_effective_loglevel_source(int con_level) if (ignore_loglevel) return LLS_IGNORE_LOGLEVEL; =20 - if (is_valid_per_console_loglevel(con_level)) + if (!ignore_per_console_loglevel && is_valid_per_console_loglevel(con_lev= el)) return LLS_LOCAL; =20 return LLS_GLOBAL; @@ -1863,6 +1878,7 @@ int do_syslog(int type, char __user *buf, int len, in= t source) struct printk_info info; bool clear =3D false; static int saved_console_loglevel =3D LOGLEVEL_DEFAULT; + static bool saved_ignore_per_console_loglevel; int error; =20 error =3D check_syslog_permissions(type, source); @@ -1904,9 +1920,12 @@ int do_syslog(int type, char __user *buf, int len, i= nt source) /* Disable logging to console */ case SYSLOG_ACTION_CONSOLE_OFF: mutex_lock(&syslog_lock); - if (saved_console_loglevel =3D=3D LOGLEVEL_DEFAULT) + if (saved_console_loglevel =3D=3D LOGLEVEL_DEFAULT) { saved_console_loglevel =3D console_loglevel; + saved_ignore_per_console_loglevel =3D ignore_per_console_loglevel; + } console_loglevel =3D minimum_console_loglevel; + ignore_per_console_loglevel =3D true; mutex_unlock(&syslog_lock); break; /* Enable logging to console */ @@ -1914,12 +1933,16 @@ int do_syslog(int type, char __user *buf, int len, = int source) mutex_lock(&syslog_lock); if (saved_console_loglevel !=3D LOGLEVEL_DEFAULT) { console_loglevel =3D saved_console_loglevel; + ignore_per_console_loglevel =3D saved_ignore_per_console_loglevel; saved_console_loglevel =3D LOGLEVEL_DEFAULT; } mutex_unlock(&syslog_lock); break; /* Set level of messages printed to console */ case SYSLOG_ACTION_CONSOLE_LEVEL: + if (!ignore_per_console_loglevel) + pr_warn_once( + "SYSLOG_ACTION_CONSOLE_LEVEL is ignored by consoles with an explicitly= set per-console loglevel, see Documentation/admin-guide/per-console-loglev= el.rst\n"); if (len < 1 || len > 8) return -EINVAL; if (len < minimum_console_loglevel) --=20 2.51.2 From nobody Tue Dec 2 02:31:07 2025 Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com [209.85.210.169]) (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 258D63A8D5D for ; Tue, 18 Nov 2025 19:07:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763492852; cv=none; b=ajqYojevzDfoKjysMsGcT4c1ziaVMfyrduf89ncjRqGIBa9zXaxsY2XegkDf3acZkJw2LO0XbddKY8xFLp9IoVHNrYZdTmd2G8/SPJAbkPfImv6S+grcUnaJjc6rQ7ya76PE4zXNGG2GJUl/8KMSPrSC5HCCgPoMXhIoQevvZUg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763492852; c=relaxed/simple; bh=HT0QxSDa7a8BHmQG/mGJtMU6TV8tU166Zjb+23/L2rA=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=hJVg69rV1Z16zQvg24zJgfDngCoQ/B4vYNYQ9n4TREGNQrpmK44KTIx0Io5LNAb1UsremVxiVO2K0gjM75qFB50av2WC/UjKgCM0j77orMP9JmQ3uXj2zxAcYOTIQdm06LxsxRCy/ZdnCnCzaWWSuexE0J6zlIKVCV1NO93ckL0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=chrisdown.name; spf=pass smtp.mailfrom=chrisdown.name; dkim=pass (1024-bit key) header.d=chrisdown.name header.i=@chrisdown.name header.b=pxATSeED; arc=none smtp.client-ip=209.85.210.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=chrisdown.name Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chrisdown.name Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chrisdown.name header.i=@chrisdown.name header.b="pxATSeED" Received: by mail-pf1-f169.google.com with SMTP id d2e1a72fcca58-7ba55660769so4011706b3a.1 for ; Tue, 18 Nov 2025 11:07:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chrisdown.name; s=google; t=1763492849; x=1764097649; darn=vger.kernel.org; h=user-agent: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=KSozgwJ7y+AXQ2vEHjuoQgquZuDni9Lb1m7WIFPR8GY=; b=pxATSeEDmxLdAPI4OhZ1M4eUciXoTvF7Pw20t5nL0v5212Q0TuNHsYjpQj50egy2HB KnN0ngi2S4wSCDMRJHi8cMymIShWctwKiRME5iv9qT8jIlbyTQt+dF3ttkdAHcJqF6zF jIyYpnp19hqn3l/Xgulevm547sm9eqod8F0cI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763492849; x=1764097649; h=user-agent: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=KSozgwJ7y+AXQ2vEHjuoQgquZuDni9Lb1m7WIFPR8GY=; b=t6S2GeBo8j1gzcJyplydyg2n+tzUY+HcmbK4wLckb5jgwHIormeOkGTRwv7Xg8DNdt YDo3Jj7HP50tIgdwX/5WO9ttXBnx9pr9nm67RgD0evL/QSCQuf0OoKoeWXlB9lnoNKIQ sJVtUri59qIgz/Z+wUlEtIRJkT03LlA++35i+MyAzuX6svG1/bDVQAkAdd+ETJb5ktTQ 7imJpoWB6cvCKpzkgM/T4HrarpXILtkPt71ddVDqHPGkShOyNXbayXUWxcQjV2BfwoXL mmxQ2CoxxC6iNUd58q9J3+Qj3yYfDhQbR2OZAJDxuX/533+gE8GUPpaKDZOAv/tlQi7b DjRQ== X-Gm-Message-State: AOJu0Yyp+DqyJzma7xEXyqeiFRiRbnbdhVz99JMfnDAN7BvO18yCh6+B bE9rXGmqj8r9Au2q066aNtCz8pQzTWt4qOKsL75sqQQAZLNfEmGhwOBK7ggYmTNeFSI= X-Gm-Gg: ASbGncsmcRBaIwzBG3qHDfq9jkPUbg5lb/P8x6xxk7xoceSfVI09fFRD0eUfbsCNy3b F9MtiNAjc2kwSN3n6Twgh++7QTZmsVHz+yZEUW/EnHOCjhMkjy3H+lk8Lf8Ry8yZ/Vk7UG+vddk vqz18EqfOKBe6vGUC4aO2NJLci/oh8EMb3VRtjUaJyqJ5/suQf4/Vmm/LlNUofJpRinTySTJopi tpy3IL+nZ00PDhWZJwUOM2LBmlwTA0HbAjFthz9AvdFmXjLf7tCPVoNmqFumT9pyiE7E3zhNkZ9 JjC4SO/CiB3Kz5GeuuTysAfwB7dqtUL05G2SfQQz4OgzBUOE3ut7IvAN8/8HyqXY6iqmxc1upo9 NxM5FSlCypKuhHBrTlJEzjyhZ9QjPa4MlnxilUB+ywss1KbSMxIOsfwWEYSdtDV7FB/R7rU24HN qGahwQ0r7xQLYzq/M/XVg= X-Google-Smtp-Source: AGHT+IEDS/Wv6FeLiLOblIhEKrEIohUpdRAcbphdwF92eUa/PzhXPL532kK1k4dFjYPN3NgyXgyDDQ== X-Received: by 2002:a05:6a00:4902:b0:7bb:272d:a4a9 with SMTP id d2e1a72fcca58-7bb272daffcmr11111658b3a.1.1763492849162; Tue, 18 Nov 2025 11:07:29 -0800 (PST) Received: from localhost ([116.86.198.140]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7b924aea0f8sm17405368b3a.5.2025.11.18.11.07.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Nov 2025 11:07:28 -0800 (PST) Date: Wed, 19 Nov 2025 03:07:27 +0800 From: Chris Down To: Petr Mladek Cc: linux-kernel@vger.kernel.org, Greg Kroah-Hartman , Sergey Senozhatsky , Steven Rostedt , John Ogness , Geert Uytterhoeven , Tony Lindgren , kernel-team@fb.com Subject: [PATCH v7 07/13] printk: console: Introduce sysfs interface for per-console loglevels Message-ID: <464d918b5497f6c7463b96b8241a65a575d932e0.1763492585.git.chris@chrisdown.name> References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/2.2.15 (2b349c5e) (2025-10-02) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" A sysfs interface under /sys/class/console/ is created that permits viewing and configuring per-console attributes. This is the main interface with which we expect users to interact with and configure per-console loglevels. Each console device now has its own directory (for example, /sys/class/console/ttyS0/) containing the following attributes: - effective_loglevel (ro): The effective loglevel for the console after considering all loglevel authorities (e.g., global loglevel, per-console loglevel). - effective_loglevel_source (ro): The source of the effective loglevel (e.g., local, global, ignore_loglevel). - loglevel (rw): The per-console loglevel. Writing a value between 0 (KERN_EMERG) and 8 (KERN_DEBUG + 1) sets the per-console loglevel. Writing -1 disables the per-console loglevel. In terms of technical implementation, we embed a device pointer in the console struct, and register each console using it so we can expose attributes in sysfs. We currently expose the following attributes: % ls -l /sys/class/console/ttyS0/ total 0 lrwxrwxrwx 1 root root 0 Oct 23 13:17 subsystem -> ../../../../class= /console/ -r--r--r-- 1 root root 4096 Oct 23 13:18 effective_loglevel -r--r--r-- 1 root root 4096 Oct 23 13:18 effective_loglevel_source -rw-r--r-- 1 root root 4096 Oct 23 13:18 loglevel -rw-r--r-- 1 root root 4096 Oct 23 13:17 uevent The lifecycle of this classdev looks like this on registration: register_console(con)/printk_late_init() console_register_device(con) device_initialize(con->classdev) # kref_init: refcount =3D 1 device_add(con->classdev) # get_device: refcount++ (to 2) At stable state, the refcount is two. Console unregistration looks like this: unregister_console_locked(con) struct device *dev =3D console->classdev; console->classdev =3D NULL; device_unregister(dev) device_del(dev) device_remove_class_symlinks(dev) sysfs_delete_link() kernfs_remove_by_name_ns() __kernfs_remove() kernfs_drain() kernfs_drain_open_files() # wait for close() kobject_del(&dev->kobj) # removes from sysfs, does NOT change ref= count put_device(dev) # kref_put: refcount-- (from 2 to 1) put_device(dev) # kref_put: refcount-- (from 1 to 0) kobject_release() kobject_cleanup() device_release() console_classdev_release(dev) kfree(dev) Signed-off-by: Chris Down --- Documentation/ABI/testing/sysfs-class-console | 58 +++++ .../admin-guide/per-console-loglevel.rst | 38 ++++ Documentation/core-api/printk-basics.rst | 35 +-- Documentation/networking/netconsole.rst | 13 ++ MAINTAINERS | 1 + include/linux/console.h | 4 + kernel/printk/Makefile | 2 +- kernel/printk/internal.h | 6 + kernel/printk/printk.c | 14 ++ kernel/printk/sysfs.c | 213 ++++++++++++++++++ 10 files changed, 366 insertions(+), 18 deletions(-) create mode 100644 Documentation/ABI/testing/sysfs-class-console create mode 100644 kernel/printk/sysfs.c diff --git a/Documentation/ABI/testing/sysfs-class-console b/Documentation/= ABI/testing/sysfs-class-console new file mode 100644 index 000000000000..8c0f0cf3f6c5 --- /dev/null +++ b/Documentation/ABI/testing/sysfs-class-console @@ -0,0 +1,58 @@ +What: /sys/class/console/ +Date: November 2025 +Contact: Chris Down +Description: Interface for viewing and setting per-console attributes, like + the per-console loglevel. For a high-level document describing + the motivations for this interface and related non-sysfs + controls, see + Documentation/admin-guide/per-console-loglevel.rst. + +What: /sys/class/console//effective_loglevel +Date: November 2025 +Contact: Chris Down +Permissions: 0444 (world readable) +Description: Read only. The currently effective loglevel for this console. + All messages emitted with a loglevel below the effective value + will be emitted to the console. + +What: /sys/class/console//effective_loglevel_source +Date: November 2025 +Contact: Chris Down +Permissions: 0444 (world readable) +Description: Read only. The currently effective loglevel source for this + console -- for example, whether it was set globally, or whether + it was set locally for this console. + + Possible values are: + =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + local The loglevel comes from the console's + per-console loglevel setting. + global The loglevel comes from the global + console_loglevel. + ignore_loglevel Both the per-console loglevel and global + loglevel are ignored as ignore_loglevel is + present on the kernel command line. + =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +What: /sys/class/console//loglevel +Date: November 2025 +Contact: Chris Down +Permissions: 0644 (root read/write, user read) +Description: Read write. The current per-console loglevel, which will take + effect if not overridden by other non-sysfs controls (see + Documentation/admin-guide/per-console-loglevel.rst). + + Valid values: + 1-8: LOGLEVEL_ALERT (1) to LOGLEVEL_DEBUG + 1 (8) + -1: Use global console_loglevel (default) + 0: Explicitly rejected (KERN_EMERG not allowed) + + Error codes: + EINVAL: Non-numeric input + ERANGE: Value out of valid range (< 1 or > 8, excluding -1) + ERANGE: Value is 0 (KERN_EMERG not allowed for per-console) + ERANGE: Value below system minimum_console_loglevel + + The special value -1 disables the per-console loglevel, making + the console use the global loglevel instead. + diff --git a/Documentation/admin-guide/per-console-loglevel.rst b/Documenta= tion/admin-guide/per-console-loglevel.rst index 1f8f1eabc75c..4908d5d8ed4f 100644 --- a/Documentation/admin-guide/per-console-loglevel.rst +++ b/Documentation/admin-guide/per-console-loglevel.rst @@ -69,3 +69,41 @@ The default value for ``kernel.console_loglevel`` comes = from ``CONFIG_CONSOLE_LOGLEVEL_DEFAULT``, or ``CONFIG_CONSOLE_LOGLEVEL_QUIET`` = if ``quiet`` is passed on the kernel command line. =20 +Console attributes +~~~~~~~~~~~~~~~~~~ + +Registered consoles are exposed at ``/sys/class/console``. For example, if= you +are using ``ttyS0``, the console backing it can be viewed at +``/sys/class/console/ttyS0/``. The following files are available: + +* ``effective_loglevel`` (r): The effective loglevel after considering all + loglevel authorities. For example, it shows the value of the console-spe= cific + loglevel when a console-specific loglevel is defined, and shows the glob= al + console loglevel value when the console-specific one is not defined. + +* ``effective_loglevel_source`` (r): The loglevel authority which resulted= in + the effective loglevel being set. The following values can be present: + + * ``local``: The console-specific loglevel is in effect. + + * ``global``: The global loglevel (``kernel.console_loglevel``) is in + effect. Set a console-specific loglevel to override it. + + * ``ignore_loglevel``: ``ignore_loglevel`` was specified on the kernel + command line or at ``/sys/module/printk/parameters/ignore_loglevel``. + Disable it to use level controls. + +* ``loglevel`` (rw): The local, console-specific loglevel for this console. + This will be in effect if no other global control overrides it. Look at + ``effective_loglevel`` and ``effective_loglevel_source`` to verify that. + +Deprecated +~~~~~~~~~~ + +* ``kernel.printk`` sysctl: this takes four values, setting + ``kernel.console_loglevel``, ``kernel.default_message_loglevel``, the mi= nimum + console loglevel, and a fourth unused value. The interface is generally + considered to quite confusing, doesn't perform checks on the values give= n, + and is unaware of per-console loglevel semantics. + +Chris Down , 18-November-2025 diff --git a/Documentation/core-api/printk-basics.rst b/Documentation/core-= api/printk-basics.rst index 2dde24ca7d9f..bfad359505bb 100644 --- a/Documentation/core-api/printk-basics.rst +++ b/Documentation/core-api/printk-basics.rst @@ -54,32 +54,33 @@ string, the log level is not a separate argument). The = available log levels are: =20 The log level specifies the importance of a message. The kernel decides wh= ether to show the message immediately (printing it to the current console) depen= ding -on its log level and the current *console_loglevel* (a kernel variable). I= f the -message priority is higher (lower log level value) than the *console_logle= vel* -the message will be printed to the console. +on its log level and the current global *console_loglevel* or local per-co= nsole +loglevel (kernel variables). If the message priority is higher (lower log = level +value) than the effective loglevel the message will be printed to the cons= ole. =20 If the log level is omitted, the message is printed with ``KERN_DEFAULT`` level. =20 -You can check the current *console_loglevel* with:: +You can check the current console's loglevel -- for example if you want to +check the loglevel for serial consoles: =20 - $ cat /proc/sys/kernel/printk - 4 4 1 7 + $ cat /sys/class/console/ttyS0/effective_loglevel + 6 + $ cat /sys/class/console/ttyS0/effective_loglevel_source + local =20 -The result shows the *current*, *default*, *minimum* and *boot-time-defaul= t* log -levels. +To change the default loglevel for all consoles, simply write the desired = level +to ``/proc/sys/kernel/console_loglevel``. For example:: =20 -To change the current console_loglevel simply write the desired level to -``/proc/sys/kernel/printk``. For example, to print all messages to the con= sole:: + # echo 5 > /proc/sys/kernel/console_loglevel =20 - # echo 8 > /proc/sys/kernel/printk +This sets the console_loglevel to print KERN_WARNING (4) or more severe +messages to console. Consoles with a per-console loglevel set will ignore = it +unless ``ignore_per_console_loglevel`` is set on the kernel command line o= r at +``/sys/module/printk/parameters/ignore_per_console_loglevel``. =20 -Another way, using ``dmesg``:: - - # dmesg -n 5 - -sets the console_loglevel to print KERN_WARNING (4) or more severe message= s to -console. See ``dmesg(1)`` for more information. +For more information on per-console loglevels, see +Documentation/admin-guide/per-console-loglevel.rst. =20 As an alternative to printk() you can use the ``pr_*()`` aliases for logging. This family of macros embed the log level in the macro names. For diff --git a/Documentation/networking/netconsole.rst b/Documentation/networ= king/netconsole.rst index 59cb9982afe6..5fabcf9367d1 100644 --- a/Documentation/networking/netconsole.rst +++ b/Documentation/networking/netconsole.rst @@ -78,6 +78,19 @@ Built-in netconsole starts immediately after the TCP sta= ck is initialized and attempts to bring up the supplied dev at the supplied address. =20 +You can also set a loglevel at runtime:: + + $ ls -l /sys/class/console/netcon0/ + total 0 + lrwxrwxrwx 1 root root 0 May 18 13:28 subsystem -> ../../../../class/= console/ + -r--r--r-- 1 root root 4096 May 18 13:28 effective_loglevel + -r--r--r-- 1 root root 4096 May 18 13:28 effective_loglevel_source + -r--r--r-- 1 root root 4096 May 18 13:28 enabled + -rw-r--r-- 1 root root 4096 May 18 13:28 loglevel + -rw-r--r-- 1 root root 4096 May 18 13:28 uevent + +See Documentation/admin-guide/per-console-loglevel.rst for more informatio= n. + The remote host has several options to receive the kernel messages, for example: =20 diff --git a/MAINTAINERS b/MAINTAINERS index 8018a4db2d9f..9a509a0bc65a 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -20505,6 +20505,7 @@ R: John Ogness R: Sergey Senozhatsky S: Maintained T: git git://git.kernel.org/pub/scm/linux/kernel/git/printk/linux.git +F: Documentation/ABI/testing/sysfs-class-console F: Documentation/admin-guide/per-console-loglevel.rst F: Documentation/core-api/printk-basics.rst F: include/linux/printk.h diff --git a/include/linux/console.h b/include/linux/console.h index c0749a48fc3f..4b2b87079cd8 100644 --- a/include/linux/console.h +++ b/include/linux/console.h @@ -16,6 +16,7 @@ =20 #include #include +#include #include #include #include @@ -323,6 +324,8 @@ struct nbcon_write_context { * @dropped: Number of unreported dropped ringbuffer records * @data: Driver private data * @node: hlist node for the console list + * @classdev: sysfs class device for this console, used to expose + * per-console controls in /sys/class/console// * * @nbcon_state: State for nbcon consoles * @nbcon_seq: Sequence number of the next record for nbcon to print @@ -352,6 +355,7 @@ struct console { unsigned long dropped; void *data; struct hlist_node node; + struct device *classdev; =20 /* nbcon console specific members */ =20 diff --git a/kernel/printk/Makefile b/kernel/printk/Makefile index f8004ac3983d..19e4919a13a7 100644 --- a/kernel/printk/Makefile +++ b/kernel/printk/Makefile @@ -1,6 +1,6 @@ # SPDX-License-Identifier: GPL-2.0-only obj-y =3D printk.o -obj-$(CONFIG_PRINTK) +=3D printk_safe.o nbcon.o +obj-$(CONFIG_PRINTK) +=3D sysfs.o printk_safe.o nbcon.o obj-$(CONFIG_A11Y_BRAILLE_CONSOLE) +=3D braille.o obj-$(CONFIG_PRINTK_INDEX) +=3D index.o =20 diff --git a/kernel/printk/internal.h b/kernel/printk/internal.h index 41e37b44778f..3b3a3c982412 100644 --- a/kernel/printk/internal.h +++ b/kernel/printk/internal.h @@ -48,6 +48,9 @@ int console_effective_loglevel(int con_level); =20 #ifdef CONFIG_PRINTK =20 +void console_register_device(struct console *new); +void console_setup_class(void); + #ifdef CONFIG_PRINTK_CALLER #define PRINTK_PREFIX_MAX 48 #else @@ -219,6 +222,9 @@ static inline void nbcon_kthreads_wake(void) { } static inline bool console_is_usable(struct console *con, short flags, bool use_atomic) { return false; } =20 +static inline void console_register_device(struct console *new) { } +static inline void console_setup_class(void) { } + #endif /* CONFIG_PRINTK */ =20 extern bool have_boot_console; diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 80204cbb7bc8..62114aa61999 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -4010,6 +4010,9 @@ static void try_enable_default_console(struct console= *newcon) if (newcon->index < 0) newcon->index =3D 0; =20 + newcon->level =3D LOGLEVEL_DEFAULT; + newcon->classdev =3D NULL; + if (console_call_setup(newcon, NULL) !=3D 0) return; =20 @@ -4264,6 +4267,7 @@ void register_console(struct console *newcon) if (use_device_lock) newcon->device_unlock(newcon, flags); =20 + console_register_device(newcon); console_sysfs_notify(); =20 /* @@ -4379,6 +4383,13 @@ static int unregister_console_locked(struct console = *console) if (console->flags & CON_NBCON) nbcon_free(console); =20 + if (console->classdev) { + struct device *dev =3D console->classdev; + console->classdev =3D NULL; + device_unregister(dev); + put_device(dev); + } + console_sysfs_notify(); =20 if (console->exit) @@ -4528,6 +4539,9 @@ static int __init printk_late_init(void) console_cpu_notify, NULL); WARN_ON(ret < 0); printk_sysctl_init(); + + console_setup_class(); + return 0; } late_initcall(printk_late_init); diff --git a/kernel/printk/sysfs.c b/kernel/printk/sysfs.c new file mode 100644 index 000000000000..5252e6e04908 --- /dev/null +++ b/kernel/printk/sysfs.c @@ -0,0 +1,213 @@ +// SPDX-License-Identifier: GPL-2.0 +#include +#include +#include +#include +#include +#include "internal.h" + +static const char * +console_effective_loglevel_source_str(const struct console *con) +{ + enum loglevel_source source; + const char *str; + int con_level; + int cookie; + + cookie =3D console_srcu_read_lock(); + con_level =3D console_srcu_read_loglevel(con); + console_srcu_read_unlock(cookie); + source =3D console_effective_loglevel_source(con_level); + + switch (source) { + case LLS_IGNORE_LOGLEVEL: + str =3D "ignore_loglevel"; + break; + case LLS_LOCAL: + str =3D "local"; + break; + case LLS_GLOBAL: + str =3D "global"; + break; + default: + str =3D "unknown"; + break; + } + + return str; +} + +static ssize_t effective_loglevel_source_show(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + struct console *con =3D dev_get_drvdata(dev); + const char *str; + + str =3D console_effective_loglevel_source_str(con); + return sysfs_emit(buf, "%s\n", str); +} + +static DEVICE_ATTR_RO(effective_loglevel_source); + +static ssize_t effective_loglevel_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct console *con =3D dev_get_drvdata(dev); + int con_level; + int cookie; + + cookie =3D console_srcu_read_lock(); + con_level =3D console_srcu_read_loglevel(con); + console_srcu_read_unlock(cookie); + return sysfs_emit(buf, "%d\n", console_effective_loglevel(con_level)); +} + +static DEVICE_ATTR_RO(effective_loglevel); + +static ssize_t loglevel_show(struct device *dev, struct device_attribute *= attr, + char *buf) +{ + struct console *con =3D dev_get_drvdata(dev); + int con_level; + int cookie; + + cookie =3D console_srcu_read_lock(); + con_level =3D console_srcu_read_loglevel(con); + console_srcu_read_unlock(cookie); + return sysfs_emit(buf, "%d\n", con_level); +} + +static ssize_t loglevel_store(struct device *dev, struct device_attribute = *attr, + const char *buf, size_t size) +{ + struct console *con =3D dev_get_drvdata(dev); + ssize_t ret; + int level; + int cookie; + + ret =3D kstrtoint(buf, 10, &level); + if (ret < 0) + return ret; + + /* -1 means "use global loglevel" */ + if (level =3D=3D -1) + goto out; + + /* + * Reject level 0 (KERN_EMERG) - per-console loglevel must be > 0. + * Emergency messages should go to all consoles, so they cannot be + * filtered per-console. + */ + if (level =3D=3D 0) + return -ERANGE; + + if (console_clamp_loglevel(level) !=3D level) + return -ERANGE; + + /* + * If the system has a minimum console loglevel set (via sysctl or + * kernel parameter), enforce it. This prevents setting per-console + * loglevels below the system minimum. + */ + if (minimum_console_loglevel > CONSOLE_LOGLEVEL_MIN && + level < minimum_console_loglevel) + return -ERANGE; + +out: + cookie =3D console_srcu_read_lock(); + WRITE_ONCE(con->level, level); + console_srcu_read_unlock(cookie); + + return size; +} + +static DEVICE_ATTR_RW(loglevel); + +static struct attribute *console_sysfs_attrs[] =3D { + &dev_attr_loglevel.attr, + &dev_attr_effective_loglevel_source.attr, + &dev_attr_effective_loglevel.attr, + NULL, +}; + +ATTRIBUTE_GROUPS(console_sysfs); + +static const struct class console_class =3D { + .name =3D "console", + .dev_groups =3D console_sysfs_groups, +}; +static bool console_class_registered; + +static void console_classdev_release(struct device *dev) +{ + kfree(dev); +} + +void console_register_device(struct console *con) +{ + /* + * We might be called from register_console() before the class is + * registered. If that happens, we'll take care of it in + * printk_late_init. + */ + if (!console_class_registered) + return; + + if (WARN_ON(con->classdev)) + return; + + con->classdev =3D kzalloc(sizeof(struct device), GFP_KERNEL); + if (!con->classdev) + return; + + device_initialize(con->classdev); + dev_set_name(con->classdev, "%s%d", con->name, con->index); + dev_set_drvdata(con->classdev, con); + con->classdev->release =3D console_classdev_release; + con->classdev->class =3D &console_class; + + /* + * This class device exists solely to expose attributes (like loglevel) + * and does not control physical power states. Power is managed by the + * underlying hardware device. Disable PM entirely to prevent the + * creation of confusing and unused power sysfs attributes. + */ + device_set_pm_not_required(con->classdev); + + if (device_add(con->classdev)) { + put_device(con->classdev); + con->classdev =3D NULL; + } +} + +void console_setup_class(void) +{ + struct console *con; + int cookie; + int err; + + /* + * printk exists for the lifetime of the kernel, it cannot be unloaded, + * so we should never end up back in here. + */ + if (WARN_ON(console_class_registered)) + return; + + err =3D class_register(&console_class); + if (err) + return; + + /* + * Take console_list_lock() before exposing the class globally. + * This ensures register_console() (which holds the lock) cannot + * see the class until it's fully initialized with dev_groups. + */ + console_list_lock(); + console_class_registered =3D true; + cookie =3D console_srcu_read_lock(); + for_each_console_srcu(con) + console_register_device(con); + console_srcu_read_unlock(cookie); + console_list_unlock(); +} --=20 2.51.2 From nobody Tue Dec 2 02:31:07 2025 Received: from mail-pf1-f179.google.com (mail-pf1-f179.google.com [209.85.210.179]) (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 B66322E1747 for ; Tue, 18 Nov 2025 19:07:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763492856; cv=none; b=YWPw6VDByTSM2Ysf7RAg8CU+/XG/yTQSZUNuQr1RU2+tCYAMZFvbE1ux2/84H2pf6NpJ2rcw9CXAMlzzNxbKtGF763m1si76ToNXz6DeBgPhbaDcTWjW6+adzGE5uoB4hpm360sdq3ydhxpc9+CjXSpH2KjzK5SKRBHOtvdm8+Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763492856; c=relaxed/simple; bh=zv1xmi1xOTFtCeM+OyGTFFLuTPMVGxxPDKrfjbolSn8=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=XkaYGykQkeEEjn3ANtFvxiNx2VNovs+yncT6co5T/catQ8jY0fDM8uye8uWob9xH2e27Dq/WOQ5H9n022HMxT3MhVgYrsaHlcwCZcM9eKiFzzGkCrw/+HLf34C7u5KpYkVdtxU8gaV2CYRFo66TqKAw6sx+yWfqgGXE3ApRDyWo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=chrisdown.name; spf=pass smtp.mailfrom=chrisdown.name; dkim=pass (1024-bit key) header.d=chrisdown.name header.i=@chrisdown.name header.b=lAsF3nJX; arc=none smtp.client-ip=209.85.210.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=chrisdown.name Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chrisdown.name Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chrisdown.name header.i=@chrisdown.name header.b="lAsF3nJX" Received: by mail-pf1-f179.google.com with SMTP id d2e1a72fcca58-7bf0ad0cb87so2799607b3a.2 for ; Tue, 18 Nov 2025 11:07:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chrisdown.name; s=google; t=1763492854; x=1764097654; darn=vger.kernel.org; h=user-agent: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=LGijqZX+hQqk0oTXy8PNUWIkVrEqhd8XSfK1D4tIzhs=; b=lAsF3nJX5IAXnWYlrDPBwnBwxbGBjxcvanv51Q6zr6tG5qCxjAbT5G7eTdr4Rg9Z80 O40Hvldtif2Re73VBOdMG7fZxpVo2OmbE4rRt1pJvkQ+O21imcdsh9box3ZFBoOT6cET jASpOT8kO8GzuHi/iEn9IkykM6bfh2wyFbO2w= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763492854; x=1764097654; h=user-agent: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=LGijqZX+hQqk0oTXy8PNUWIkVrEqhd8XSfK1D4tIzhs=; b=ZH9v97fu/oXqKZ57pjv45XarZfpHTCc7/18FaIbzl2a9Ggy/yxF7OtaDa4MiBGl87i f85H10RCsdJ/R4nI/q/4PHlBUeet/Fm81NN4u99H9l7UCTi/3O0MZeUAbfBUSQAl6ysn YK1OmDgFBBrWDdMbxwQHTfM2NH9P2NOASQ4rykw9+Uat9WGhvLn2ncD37ypSsruZUHzP DfJYg/cd0MyAzmhvkJI/f3JRDOZ5ydlYp1Cz8GnxGzoQz/3MU1ecMx9RQCN/QxxkGmKF dGr8moKeC33wTEd0BmGoxTIYm1IUvbesGSRfXmPdpaGBh5TadLxwTgTH+qgUkiddEWZW NMjg== X-Gm-Message-State: AOJu0YwiRMIX6nliIQ9WvHfsxIyEYAwbpJvtcZSH//5Cl+b6Iw9G9Gx8 LVSNRVFv/36wADGSrHgb2FCPqsK6Sp4JqjyQDDQs7x+FZF13zmz3DUnzpJYHEReDbEk= X-Gm-Gg: ASbGncuyPZYLOvGLOiP1aGtkYfcskOIrNPnHHWlnKS45SFlz/t7ecTTALctsV1vn8nB lDAkR530fXlruBnyJocf6v/6wrZlv/zRjoACOxu4IRo2RdsWcdcHiVKiYh1LPpY4d/nRF82OAM1 mfecXhuAJ0q7gPCla60aPyqscq9FhsIvaV9YO7GRV7Gvt5dLazXo/Rbu5IvWgJAudQvp5egGWO2 n6CeDywV/waJSg4D8DNAQSCztTB0Rap3DH2BHmFktAsq0x3MlE2JnPZIT2uRthfogWThXt09B/N 3bidPaTNEHls/AVbRGJVrQUP3/ZwK0Gj31ANQwma+J4kkIztYUczKTH8SXjD90J04ym1KV/mCHh rmz0Wt7uORu4IIfRxDtU9qz/izvZMoJC7Xy0jFyXj0BIBuho1S/vjA+FVijl8MC3KuVLjLkZjSZ i688pq4jI/ X-Google-Smtp-Source: AGHT+IGo80tGCBwctehbgu/DKW4CR9Cq+zOaHlhC9Gzy2SOezOgY2koi1dCCpbp3Mw406AOGTa2A8g== X-Received: by 2002:a05:6a21:9988:b0:35e:2a82:fdf4 with SMTP id adf61e73a8af0-35e2a830598mr14014854637.59.1763492854099; Tue, 18 Nov 2025 11:07:34 -0800 (PST) Received: from localhost ([116.86.198.140]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7bba051085esm12776488b3a.42.2025.11.18.11.07.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Nov 2025 11:07:33 -0800 (PST) Date: Wed, 19 Nov 2025 03:07:31 +0800 From: Chris Down To: Petr Mladek Cc: linux-kernel@vger.kernel.org, Greg Kroah-Hartman , Sergey Senozhatsky , Steven Rostedt , John Ogness , Geert Uytterhoeven , Tony Lindgren , kernel-team@fb.com Subject: [PATCH v7 08/13] printk: Constrain hardware-addressed console checks to name position Message-ID: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/2.2.15 (2b349c5e) (2025-10-02) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Commit 7640f1a44eba ("printk: Add match_devname_and_update_preferred_console()") adds support for DEVNAME:n:n style console=3D registration. It determines whether or not this is a hardware-addressed console by looking at whether the console=3D string has a colon in it. However, this interferes with loglevel:n and potentially other future named options, which also make use of the character. In order to avoid this, only search positions before options. Reviewed-by: Petr Mladek Reviewed-by: Tony Lindgren Signed-off-by: Chris Down --- kernel/printk/printk.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 62114aa61999..fb54101133d2 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -2733,6 +2733,7 @@ static int __init console_setup(char *str) char *devname =3D NULL; char *options; char *s; + char *first_delim; int idx; =20 /* @@ -2748,8 +2749,13 @@ static int __init console_setup(char *str) if (_braille_console_setup(&str, &brl_options)) return 1; =20 - /* For a DEVNAME:0.0 style console the character device is unknown early = */ - if (strchr(str, ':')) + /* + * For a DEVNAME:0.0 style console the character device is unknown + * early. We must restrict this to before any comma to avoid interfering + * with named options, like "loglevel". + */ + first_delim =3D strpbrk(str, ":,"); + if (first_delim && *first_delim =3D=3D ':') devname =3D buf; else ttyname =3D buf; --=20 2.51.2 From nobody Tue Dec 2 02:31:07 2025 Received: from mail-pf1-f179.google.com (mail-pf1-f179.google.com [209.85.210.179]) (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 2C8712DE6ED for ; Tue, 18 Nov 2025 19:07:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763492862; cv=none; b=gvASXf065lFYftbCYgL39tQmow4lF4jQO8f1uxq7YlIp0l3Ct82cG0K8xxJN1CKqT9wl9z6dNuJPysVB8FEQHl2N5EjMrBa2/BEF3O9Vi7loMrZ5efc9pn9PhKFI7x5zBjon2BQbkKjDRKhfYy5e+fuPf1f0AoPWx1F8LSlaydk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763492862; c=relaxed/simple; bh=zMmsDfXzBtA8QccjGa2qJ6o8bc+OkNzS64LTK4x9B4w=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=kLV145NcB3njLiB1HEAZcYB9BFil3sjgtrDLH4ngfLUMhjpg34tfJx6EbuAziAukzmbOV7Tiu/DoalsZH2pg4RIkvnN1XzENraXRSGwCOaeMnbV20o/L5Itw3KLkLRnVX4I7K9+oQuG0X2ACPmx2mB0swYS2+VaedPWPzMECyFw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=chrisdown.name; spf=pass smtp.mailfrom=chrisdown.name; dkim=pass (1024-bit key) header.d=chrisdown.name header.i=@chrisdown.name header.b=qyv5ZrXe; arc=none smtp.client-ip=209.85.210.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=chrisdown.name Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chrisdown.name Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chrisdown.name header.i=@chrisdown.name header.b="qyv5ZrXe" Received: by mail-pf1-f179.google.com with SMTP id d2e1a72fcca58-7bc248dc16aso3543265b3a.0 for ; Tue, 18 Nov 2025 11:07:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chrisdown.name; s=google; t=1763492859; x=1764097659; darn=vger.kernel.org; h=user-agent: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=zcW4jHl/TIT8YeAjrkHTb4XBZJtoJtM1QESiU4rYiNI=; b=qyv5ZrXeQyG+OdxULZ+nKuXzyEhmppWg0tkrXZAsjyd1zAbZ92yg4Thk0oh+b3Tb2r fsEXiNt0f/ExLgfvnZmGvo659Bn8pUXspTVmnJRFt4BbB7tllPCmj+nYgaazQSwxkOwc irr9QsB2S5+bfZV55Lkcd9+/gaD+uD69k1EPA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763492859; x=1764097659; h=user-agent: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=zcW4jHl/TIT8YeAjrkHTb4XBZJtoJtM1QESiU4rYiNI=; b=Kt/wfjcxoCbpVY1eGQ3/wSIxlkResYP4RxGODxK/SZPBxXHUm2n3kTH4fu0wsdD6Gw /maly/5of7gODeymSbQsJ6gj4CcNw1UC7YP8ncYbpC+ICcyTsZe9eFKwJv6SCOIHaCOe 6ixvxfnC0Hcdx944uHzbThiAuKObT0j4Ejvv11fZyj1Stvv1hahCyu1donm8wGfO8AFv C1sHMMo4FkRpje+k2VrFT3XszzZgbMAJTW3arfhgwgLFr+eKFEJCzUXYnzHZ0uz7L0fu UyyoOHgI3M/BE3Q03kvIrJuckiq5KkaqPLPqx/bGLFefiE9gJRjbxR6UVHuzWfF4BoXK xxpg== X-Gm-Message-State: AOJu0YygLvEcaWKQVbs8sPrEU7UfjP7gGTwNhjUzWyAyuXvsi/3Gx28v E5rbVD7fv11QQvZ/n2VArCye70QmKsD8vQtVDOglOKA4FSVn6UxQDReRuSM+xV4mm7I= X-Gm-Gg: ASbGnctZrH/5Tn5xznzMflYf0tqow6YaGcBEqV9XWwLz830Np7CxoLfcecohfrQG6wq rrQQ3JMDlqFGIUc/yFnMKbNfUifyiDWVy1K0Hnly6Wx3erVLTXi8YPOlNFtt673wKT2nHTDoccq Q6x6ihOpERa78mMYj0JbwLTo6/f7FmKIsiI0oX0QTMj1lhX8MYjUuMn7yPHwndPSC4rK3QXkTvX rcKuGt/nfiBWXIbhMisa/ppAUc7NUiJCD/584wvo3otZ4ih+IAWdr5yDck1fl34FF0vMNQbLJdN PKCslNX0+AXDMrqcZMCbDWCXJlcHC4rEAhy1TccI3mpOTaBRIqiLgDAFlaLZULvo/PuG2+IaDAx s7TFn9xjpy7AQ4gEcj8iwOuvez20NVgZFy3iei56bOyyHHzG4I94snlpy5d+5ESCGvObX0+Vz3C 9tREp4MUEl X-Google-Smtp-Source: AGHT+IGeBxzS9A/VPFSV0f6oOr56wNvWSyEmbbakeZ46lLzBW6N/6YKw1eBAMgubbrW6oR1cMdI/Ow== X-Received: by 2002:a05:6a20:734d:b0:35e:6c3:c8d0 with SMTP id adf61e73a8af0-35e06c3cb56mr14930972637.54.1763492859412; Tue, 18 Nov 2025 11:07:39 -0800 (PST) Received: from localhost ([116.86.198.140]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7b92772fa72sm17295597b3a.55.2025.11.18.11.07.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Nov 2025 11:07:38 -0800 (PST) Date: Wed, 19 Nov 2025 03:07:37 +0800 From: Chris Down To: Petr Mladek Cc: linux-kernel@vger.kernel.org, Greg Kroah-Hartman , Sergey Senozhatsky , Steven Rostedt , John Ogness , Geert Uytterhoeven , Tony Lindgren , kernel-team@fb.com Subject: [PATCH v7 09/13] printk: Support setting initial console loglevel via console= on cmdline Message-ID: <77aa59337507e067f3a4ad7e15375893612bcfa3.1763492585.git.chris@chrisdown.name> References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/2.2.15 (2b349c5e) (2025-10-02) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Extend the console=3D kernel command line parameter to support specifying per-console loglevels at boot time. This is achieved by introducing a new loglevel option that can be passed as a loglevel option within a console=3D stanza. For example, this is an example of how one might configure netconsole devices to print messages with a higher priority than loglevel 3 (KERN_ERR) at startup: console=3Dnetcon0,loglevel:3 Signed-off-by: Chris Down Reviewed-by: Petr Mladek Tested-by: Petr Mladek --- .../admin-guide/kernel-parameters.txt | 24 ++-- Documentation/admin-guide/serial-console.rst | 37 +++++- Documentation/networking/netconsole.rst | 6 +- kernel/printk/console_cmdline.h | 1 + kernel/printk/printk.c | 108 +++++++++++++++++- 5 files changed, 161 insertions(+), 15 deletions(-) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentatio= n/admin-guide/kernel-parameters.txt index 7b62a99489b8..dec9e29ba8d2 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -819,13 +819,18 @@ ttyS[,options] ttyUSB0[,options] Use the specified serial port. The options are of - the form "bbbbpnf", where "bbbb" is the baud rate, - "p" is parity ("n", "o", or "e"), "n" is number of - bits, and "f" is flow control ("r" for RTS or - omit it). Default is "9600n8". + the form "bbbbpnf,extra", where "bbbb" is the baud + rate, "p" is parity ("n", "o", or "e"), "n" is + number of bits, and "f" is flow control ("r" for RTS + or omit it). Default is "9600n8". =20 - See Documentation/admin-guide/serial-console.rst for more - information. See + At present the only extra option is "loglevel" to + set the per-console loglevel. For example: + + console=3DttyS0,9600n8,loglevel:3 + + See Documentation/admin-guide/serial-console.rst for + more information. See Documentation/networking/netconsole.rst for an alternative. =20 @@ -3411,8 +3416,11 @@ loglevel=3D [KNL,EARLY] All Kernel Messages with a loglevel smaller than the console loglevel will be printed to the console. It can - also be changed with klogd or other programs. The - loglevels are defined as follows: + also be changed with klogd or other programs. Note that + this can be overridden per-console, see + Documentation/admin-guide/per-console-loglevel.rst. + + The loglevels are defined as follows: =20 0 (KERN_EMERG) system is unusable 1 (KERN_ALERT) action must be taken immediately diff --git a/Documentation/admin-guide/serial-console.rst b/Documentation/a= dmin-guide/serial-console.rst index 1609e7479249..b8163e6eb95a 100644 --- a/Documentation/admin-guide/serial-console.rst +++ b/Documentation/admin-guide/serial-console.rst @@ -32,6 +32,33 @@ The format of this option is:: and F is flow control ('r' for RTS). Default is 9600n8. The maximum baudrate is 115200. =20 + One can also specify the per-console loglevel for this + console by providing a loglevel parameter, for example + "loglevel:4" to set this console's loglevel to 4. The + value provided can be from 1 (LOGLEVEL_ALERT) to 8 + (LOGLEVEL_DEBUG + 1), and messages below that will be + emitted onto the console as they become available. + +The available loglevels are defined thus: + ++---+--------------+-----------------------------------+ +| 0 | KERN_EMERG | system is unusable | ++---+--------------+-----------------------------------+ +| 1 | KERN_ALERT | action must be taken immediately | ++---+--------------+-----------------------------------+ +| 2 | KERN_CRIT | critical conditions | ++---+--------------+-----------------------------------+ +| 3 | KERN_ERR | error conditions | ++---+--------------+-----------------------------------+ +| 4 | KERN_WARNING | warning conditions | ++---+--------------+-----------------------------------+ +| 5 | KERN_NOTICE | normal but significant condition | ++---+--------------+-----------------------------------+ +| 6 | KERN_INFO | informational | ++---+--------------+-----------------------------------+ +| 7 | KERN_DEBUG | debug-level messages | ++---+--------------+-----------------------------------+ + You can specify multiple console=3D options on the kernel command line. =20 The behavior is well defined when each device type is mentioned only once. @@ -39,11 +66,14 @@ In this case, the output will appear on all requested c= onsoles. And the last device will be used when you open ``/dev/console``. So, for example:: =20 - console=3DttyS1,9600 console=3Dtty0 + console=3DttyS1,9600,loglevel:5 console=3Dtty0 =20 defines that opening ``/dev/console`` will get you the current foreground -virtual console, and kernel messages will appear on both the VGA -console and the 2nd serial port (ttyS1 or COM2) at 9600 baud. +virtual console, and kernel messages will appear on both the VGA console a= nd +the 2nd serial port (ttyS1 or COM2) at 9600 baud. The optional loglevel "5" +indicates that this console will emit messages more serious than +LOGLEVEL_NOTICE (that is, LOGLEVEL_WARNING and below, since more serious +messages have lower ordering). =20 The behavior is more complicated when the same device type is defined more times. In this case, there are the following two rules: @@ -145,3 +175,4 @@ Replace the sample values as needed. the integration of these patches into m68k, ppc and alpha. =20 Miquel van Smoorenburg , 11-Jun-2000 +Chris Down , 18-Nov-2025 diff --git a/Documentation/networking/netconsole.rst b/Documentation/networ= king/netconsole.rst index 5fabcf9367d1..5a7405986934 100644 --- a/Documentation/networking/netconsole.rst +++ b/Documentation/networking/netconsole.rst @@ -78,7 +78,11 @@ Built-in netconsole starts immediately after the TCP sta= ck is initialized and attempts to bring up the supplied dev at the supplied address. =20 -You can also set a loglevel at runtime:: +You can also set a loglevel at boot time on the kernel command line:: + + console=3Dnetcon0,loglevel:2 + +This can also be changed at runtime:: =20 $ ls -l /sys/class/console/netcon0/ total 0 diff --git a/kernel/printk/console_cmdline.h b/kernel/printk/console_cmdlin= e.h index 0ab573b6d4dc..cb3b99d31d80 100644 --- a/kernel/printk/console_cmdline.h +++ b/kernel/printk/console_cmdline.h @@ -7,6 +7,7 @@ struct console_cmdline char name[16]; /* Name of the driver */ int index; /* Minor dev. to use */ char devname[32]; /* DEVNAME:0.0 style device name */ + int level; /* Log level to use */ bool user_specified; /* Specified by command line vs. platform */ char *options; /* Options for the driver */ #ifdef CONFIG_A11Y_BRAILLE_CONSOLE diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index fb54101133d2..a6e1fa924294 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -2660,12 +2660,108 @@ static void set_user_specified(struct console_cmdl= ine *c, bool user_specified) console_set_on_cmdline =3D 1; } =20 +/** + * find_and_remove_console_option - Find and remove a named option from co= nsole options string + * @options: The console options string (will be modified in-place) + * @key: The option name to find (e.g., "loglevel") + * @val_buf: Buffer to store the option value (if present) + * @val_buf_size: Size of @val_buf + * + * This function searches for a named option in a comma-separated options = string + * (e.g., "9600n8,loglevel:3,other:value"). If found, it extracts the value + * (the part after ':') and removes the entire option from the string. + * + * The function modifies @options in-place by: + * 1. Temporarily null-terminating option names and values during parsing + * 2. Restoring separators if the option isn't found + * 3. Removing the found option by shifting the remaining string + * + * Return: true if the option was found and removed, false otherwise + */ +static bool find_and_remove_console_option(char *options, const char *key, + char *val_buf, size_t val_buf_size) +{ + bool found =3D false, first =3D true; + char *option, *next =3D options; + + while ((option =3D strsep(&next, ","))) { + char *value; + + value =3D strchr(option, ':'); + if (value) + *(value++) =3D '\0'; + + if (strcmp(option, key) =3D=3D 0) { + found =3D true; + if (value) { + if (strlen(value) >=3D val_buf_size) { + pr_warn("Can't copy console option value for %s:%s: not enough space = (%zu)\n", + option, value, val_buf_size); + found =3D false; + } else { + strscpy(val_buf, value, val_buf_size); + } + } else + *val_buf =3D '\0'; + } + + if (found) + break; + + if (next) + *(next - 1) =3D ','; + if (value) + *(value - 1) =3D ':'; + + first =3D false; + } + + if (found) { + if (next) + memmove(option, next, strlen(next) + 1); + else if (first) + *option =3D '\0'; + else + *--option =3D '\0'; + } + + return found; +} + +static int find_and_remove_loglevel_option(char *options) +{ + char val[16]; + int loglevel; + + if (!find_and_remove_console_option(options, "loglevel", val, + sizeof(val))) + return -ENOENT; + + if (kstrtoint(val, 10, &loglevel)) { + pr_warn("Invalid console loglevel, ignoring: %s\n", val); + return -EINVAL; + } + + /* Reject level 0 (KERN_EMERG) - per-console loglevel must be > 0 */ + if (loglevel =3D=3D 0) { + pr_warn("Per-console loglevel 0 (KERN_EMERG) is not allowed, ignoring\n"= ); + return -ERANGE; + } + + if (console_clamp_loglevel(loglevel) !=3D loglevel) { + pr_warn("Per-console loglevel out of range, ignoring: %d\n", loglevel); + return -ERANGE; + } + + return loglevel; +} + static int __add_preferred_console(const char *name, const short idx, const char *devname, char *options, char *brl_options, bool user_specified) { struct console_cmdline *c; - int i; + int i, ret; =20 if (!name && !devname) return -EINVAL; @@ -2702,6 +2798,13 @@ static int __add_preferred_console(const char *name,= const short idx, strscpy(c->name, name); if (devname) strscpy(c->devname, devname); + + ret =3D find_and_remove_loglevel_option(options); + if (ret >=3D 0) + c->level =3D ret; + else + c->level =3D -1; + c->options =3D options; set_user_specified(c, user_specified); braille_set_options(c, brl_options); @@ -3979,8 +4082,7 @@ static int try_enable_preferred_console(struct consol= e *newcon, if (newcon->index < 0) newcon->index =3D c->index; =20 - /* TODO: will be configurable in a later patch */ - newcon->level =3D LOGLEVEL_DEFAULT; + newcon->level =3D c->level; =20 if (_braille_register_console(newcon, c)) return 0; --=20 2.51.2 From nobody Tue Dec 2 02:31:07 2025 Received: from mail-pf1-f171.google.com (mail-pf1-f171.google.com [209.85.210.171]) (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 2550F2DE6ED for ; Tue, 18 Nov 2025 19:07:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763492872; cv=none; b=HokmoDBsVFRTW+1v3D8un0BZZunml6Bn+thN9vUPj2YmYn2k3yUIzB4WBglLAh8kXDsGNVxDkqVHLznEuVcqL1RxmzwYd1FgVseU+RS/iw68Ub8XuOtKRUJckGVaaE0XvcP/G1vSSTIsoymfxyf2DE9KGC6kgGm9oq+FBy7RsUY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763492872; c=relaxed/simple; bh=jp5TF+mMssM49N2V0hrjmfoqlHwyjkzqZ5qatUhGias=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=mwj6Z+EvLC4qCslaUf8PtBnvK7OABvYukS+s2PhLOMQLw4UMp+AA3BWvTAEvGa8ypmgPGypI9I5XagRvA9PHNtHBGbFs1pSyYJXHuz/mWRlez8CdA4xw/wgDzLYjXjm6nThdlqlSy1gyvQkwmxRZKHWSS+6LuYn+RoF9vDghsV4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=chrisdown.name; spf=pass smtp.mailfrom=chrisdown.name; dkim=pass (1024-bit key) header.d=chrisdown.name header.i=@chrisdown.name header.b=eePQN13C; arc=none smtp.client-ip=209.85.210.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=chrisdown.name Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chrisdown.name Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chrisdown.name header.i=@chrisdown.name header.b="eePQN13C" Received: by mail-pf1-f171.google.com with SMTP id d2e1a72fcca58-7b852bb31d9so6596206b3a.0 for ; Tue, 18 Nov 2025 11:07:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chrisdown.name; s=google; t=1763492869; x=1764097669; darn=vger.kernel.org; h=user-agent: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=OebVyWjLvth45w1zsGJ4pPsdGFSD9/D/2nuZsy8PNDs=; b=eePQN13CQqZKhDry6WXiQ30XCShpq2QbKv2tGD7CVlf/OKB6mXzSx2gBk1lIvmZr4t E72rJvjX/9zvfxOXFciAZYsj7i+FkUdS8SujIttb9r06lf+WAaRlZJwKwiDeTg+biw6R t/UXwsSHkrwGumq5MtzAus3R9/mTmM4eFx8B4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763492869; x=1764097669; h=user-agent: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=OebVyWjLvth45w1zsGJ4pPsdGFSD9/D/2nuZsy8PNDs=; b=PZw+65wH5W8OYOTdBrN+i7wNWQjr88ajpnyC5tW3nW/yz3h7jXc11Xe5S0x0TssWOe mx4eQIHxYwfHiCQRQROnN5YV9AcNHo+cMMAFQBPae5UCcBL8eGmsgnBfGanucziH5/bK krnbnQhLFUnzjgOYEPpjWOPtFizv33+v05y6/xspGWecrUJXnDshtZaKTuRuB0phpJRs 0YCeHM31V4c+g4XMTxw2Za/MjaD+6URVSaxZpKdMJ7jsI2WjLS02mptOw6Ly4l+rwf9K E4fadNH9NwhICVgR4WXWg4l2nTMYJUj2gUbSUG9shYfVPpePxaauJOSI6mJACXxSkfRu W1lQ== X-Gm-Message-State: AOJu0Yyirq7Of3wlD4rLBBUDSW5YHqFvqfRKQKkJaNlk+nv8RhYBbUPy /fIBVV6geqdIyut5JgnEepujqJ9HqGniC1Auv2xcbtjiuq8VAHgTEv4Zf0LlQa/vzBM= X-Gm-Gg: ASbGncvAlhd9F/UA8suuGqo6aiMd91AVNqaL3+1nMTIAUUsLrTKFZ/UApzQ0ZykvshW R/HpgNHh6e+8Udj/okf6S1NtfbdbdHjoba/8ICnPctuTOkSAdzq+bHU3y8Cl1AoK6na2bWBBt90 rptSV33290043BpSutRFPukwE58pUMnQEpSp31pR4iPziUrLG77SYw8Ikg4Qfmfw+2Cbbqr+UJf mRII0WcdyD3GGUOvUWrmPkQUAehxefDbSjAywnCSDUflG6ajB34AqoOV36OzsmoaxblfDpzAFp6 zHWPMEHErplskrAzGs8S+TOwAnyjdmlDqhyg/vBu5C2H3smK1mpR2IAmvFv3zxv3Z636K3yBFEf h65xhvlofjvmLWP/jOSRqMUAsgeUuIPAbJVENI8bWBnVO5/ZIkNqedONcqmav+CUAdp8953aG73 WkeMMceYbyNWarhxs1xkuVAkpLELqZmw== X-Google-Smtp-Source: AGHT+IH7jwOFUNrZfph0q4lJ6LbmxlBZ7N+lbrnGmia6R1n2lXif5uLlit7ShIsTGbhUQ6w403PZLw== X-Received: by 2002:a05:6a00:3d42:b0:7ab:fc99:d856 with SMTP id d2e1a72fcca58-7ba3b4aaf8emr20206582b3a.18.1763492869405; Tue, 18 Nov 2025 11:07:49 -0800 (PST) Received: from localhost ([116.86.198.140]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7b927150b13sm17153904b3a.46.2025.11.18.11.07.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Nov 2025 11:07:48 -0800 (PST) Date: Wed, 19 Nov 2025 03:07:46 +0800 From: Chris Down To: Petr Mladek Cc: linux-kernel@vger.kernel.org, Greg Kroah-Hartman , Sergey Senozhatsky , Steven Rostedt , John Ogness , Geert Uytterhoeven , Tony Lindgren , kernel-team@fb.com Subject: [PATCH v7 10/13] printk: Add sysctl interface to set global loglevels Message-ID: <95295969cda8464d95339b2a7ecaefe1d865f8d8.1763492585.git.chris@chrisdown.name> References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/2.2.15 (2b349c5e) (2025-10-02) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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: Petr Mladek Signed-off-by: Chris Down Reviewed-by: Petr Mladek Tested-by: Petr Mladek --- Documentation/admin-guide/sysctl/kernel.rst | 17 ++++++- include/linux/sysctl.h | 7 +++ kernel/printk/sysctl.c | 52 +++++++++++++++++++++ kernel/sysctl.c | 18 +++---- 4 files changed, 84 insertions(+), 10 deletions(-) diff --git a/Documentation/admin-guide/sysctl/kernel.rst b/Documentation/ad= min-guide/sysctl/kernel.rst index f3ee807b5d8b..043d5f663b7d 100644 --- a/Documentation/admin-guide/sysctl/kernel.rst +++ b/Documentation/admin-guide/sysctl/kernel.rst @@ -1079,6 +1079,20 @@ otherwise the 'doze' mode will be used. =20 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =20 +Some of these settings may be overridden per-console, see +Documentation/admin-guide/per-console-loglevel.rst. See ``man 2 syslog`` f= or +more information on the different loglevels. + +console_loglevel +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +Messages with a higher priority than this will be printed to consoles. + +default_message_loglevel +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +Messages without an explicit priority will be printed with this priority. + printk =3D=3D=3D=3D=3D=3D =20 @@ -1087,8 +1101,7 @@ The four values in printk denote: ``console_loglevel`= `, ``default_console_loglevel`` respectively. =20 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. =20 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D = =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D console_loglevel messages with a higher priority than diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h index 92e9146b1104..c2f72d172f64 100644 --- 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); =20 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, diff --git a/kernel/printk/sysctl.c b/kernel/printk/sysctl.c index da77f3f5c1fe..feec6cf939af 100644 --- a/kernel/printk/sysctl.c +++ b/kernel/printk/sysctl.c @@ -11,6 +11,9 @@ =20 static const int ten_thousand =3D 10000; =20 +static int min_msg_loglevel =3D LOGLEVEL_EMERG; +static int max_msg_loglevel =3D LOGLEVEL_DEBUG; + static int proc_dointvec_minmax_sysadmin(const struct ctl_table *table, in= t write, void *buffer, size_t *lenp, loff_t *ppos) { @@ -20,6 +23,39 @@ static int proc_dointvec_minmax_sysadmin(const struct ct= l_table *table, int writ return proc_dointvec_minmax(table, write, buffer, lenp, ppos); } =20 +static int do_proc_dointvec_console_loglevel(bool *negp, unsigned long *lv= alp, + int *valp, + int write, void *data) +{ + int level, ret; + + /* + * If writing, first do so via a temporary local int so we can + * bounds-check it before touching *valp. + */ + int *intp =3D write ? &level : valp; + + ret =3D do_proc_dointvec_conv(negp, lvalp, intp, write, data); + if (ret) + return ret; + + if (write) { + if (level !=3D console_clamp_loglevel(level)) + return -ERANGE; + WRITE_ONCE(*valp, 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); +} + static const struct ctl_table printk_sysctls[] =3D { { .procname =3D "printk", @@ -76,6 +112,22 @@ static const struct ctl_table printk_sysctls[] =3D { .extra1 =3D SYSCTL_ZERO, .extra2 =3D SYSCTL_TWO, }, + { + .procname =3D "console_loglevel", + .data =3D &console_loglevel, + .maxlen =3D sizeof(int), + .mode =3D 0644, + .proc_handler =3D proc_dointvec_console_loglevel, + }, + { + .procname =3D "default_message_loglevel", + .data =3D &default_message_loglevel, + .maxlen =3D sizeof(int), + .mode =3D 0644, + .proc_handler =3D proc_dointvec_minmax, + .extra1 =3D &min_msg_loglevel, + .extra2 =3D &max_msg_loglevel, + }, }; =20 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, cha= r c) } } =20 -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 l= ong *lvalp, } return 0; } +EXPORT_SYMBOL(do_proc_dointvec_conv); =20 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 s= truct ctl_table *table, return err; } =20 -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); =20 static int do_proc_douintvec_w(unsigned int *tbl_data, const struct ctl_table *table, --=20 2.51.2 From nobody Tue Dec 2 02:31:07 2025 Received: from mail-pj1-f44.google.com (mail-pj1-f44.google.com [209.85.216.44]) (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 334292E1F11 for ; Tue, 18 Nov 2025 19:08:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763492886; cv=none; b=YanOhKMDo0aEFlMVfwrVLB/aptPgn9QIT35RCw7GQfoM5qRHh2FCBMaSZrFsEvsdd25VB9MhkWETJFe2QhIsdhyU4oIzRMlg1YCqp1gU4UvZsO5OIirJUl/npPcQCSHyZXfncAgXNdXuFMtBmAMT/srx2sdmRsr6sfrpRCy6pOc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763492886; c=relaxed/simple; bh=OqB8QsrlmQi+iJkS57ZcXLS461wspDc6oQWqwOU4/oc=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=H/q4cymg2ZngzZBjyjdqZIZCo7dmGkEgr00X4fZlXKQlqlt87klxp7FX+hJQ/4nW2Rk4Z+h8E6d59M7H6uEiyQ9Ju85MlPOah1SYxhNG9O7idjYOmfqQHCz77R6hOVJ+tH0LfCviqSvBqDwGXzGe+5/Dod26vJ/bLLViSjHJhr8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=chrisdown.name; spf=pass smtp.mailfrom=chrisdown.name; dkim=pass (1024-bit key) header.d=chrisdown.name header.i=@chrisdown.name header.b=ZbaJuuAv; arc=none smtp.client-ip=209.85.216.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=chrisdown.name Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chrisdown.name Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chrisdown.name header.i=@chrisdown.name header.b="ZbaJuuAv" Received: by mail-pj1-f44.google.com with SMTP id 98e67ed59e1d1-34361025290so4493538a91.1 for ; Tue, 18 Nov 2025 11:08:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chrisdown.name; s=google; t=1763492884; x=1764097684; darn=vger.kernel.org; h=user-agent: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=rHOi0QL0/c3tomQ4yvX19ikD6nsO02TviKx8yiTQ0BU=; b=ZbaJuuAvJVvX9oWhMxs2BCqfXehstiUHxPjucO83ytnyyOp/ac+kxHTE/ZjTTxgAR0 HN7rvd3PEzd9wei3ckf0LaJgUahdjdjMF2ZtDGFVKtEXM5ko/3GUV4nVo/uGh5RJQ1Z6 kxzkak4kD9cMNyXkSNkl14HTr3xokrfjKVbGw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763492884; x=1764097684; h=user-agent: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=rHOi0QL0/c3tomQ4yvX19ikD6nsO02TviKx8yiTQ0BU=; b=DYhvC7WLOoSuKf1VDRsSnB8Vl18h5BI+1QP9uw9bIe3yxDarp4O7cMvZtGTcStNs2O +wXyZwbI/h0EHFmOukcKpuwNVmx5yGheD0CD8Nk8ih7bpO8Hmm3YGBf0B1W05Pk+hKDU tYEXHBdlqzq9X396sjCc4Hw+4qoPWYKeaoNS4+4LM7a74PKDwlbN6A84IhTf4Mz38Yk4 y/xY7WzbWzqhQsvbOtyz1RkWAW3wLRvZZOerQfDSTQCifDtkVJs4YZbREwC4QuH8ePH3 DDdGNfxI6afOJCkkRVDuM9li9l5FgkpXUYby8T37hVVpycW+R4YN2hPgVbtoM6E5LR4h P5Ow== X-Gm-Message-State: AOJu0YyF2OTrHZoojbdSbcoaNNoOD45iH5r+7PfM9hTxeOx+8wzAb6ZX oANUbxTq71IiCuU1eT+thS2uHMzNtIdp6PNfY50u/+7UVskHAnUcVWw4hXxzy5vHNwE= X-Gm-Gg: ASbGnctQisJxSebSIW0/1eVc0rUTeaXlrvHvogQ7Mfy4vXgtMhamC2efx4ZMzAUVSGE QQyYNCfP1za+T3pvhCp/ShsZpW+1M1Uao4so3ANYtBWuioLBBeKC6KPXNk2po0X9DOa228gkAVK ED5/gRIrRV9Azti42y7PqB+nqIqY28QnLbZAYzR+DQCP0VblsAUmoXche20/7glRvjBJWQ4CUZH loRGVoGik2AwY630mcFIyathJkEhzrKkFaTrRyhQACOMxvqkyVH5j7KxhuE2+gfy9tkS1tUlwZj PeFUDWFPr4uja5p+XkS/dUHE9+K3UVD0R+L4dUXyMKwI1OJF/UQsNFhDKVlhjDQRpR3WyZdy4rE +gRsYllC4xzTHxSlWoufmYykCfsQZMrNdWlOwAiVLng+ed8Mir8qoipWwlEjNVI7ix5PasndkJr /8YWVDRyU+aU8iUPqg9H0= X-Google-Smtp-Source: AGHT+IHlgKTjklFL/yEZEbXkSwoZKTktvWTvfIgIU4+NHDm+JiNHiqkXErOT9pWqI14OMkdpvX6rag== X-Received: by 2002:a17:90b:38ca:b0:340:c151:2d66 with SMTP id 98e67ed59e1d1-343fa638ef3mr16475298a91.30.1763492884378; Tue, 18 Nov 2025 11:08:04 -0800 (PST) Received: from localhost ([116.86.198.140]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-345bbc17312sm246110a91.0.2025.11.18.11.08.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Nov 2025 11:08:03 -0800 (PST) Date: Wed, 19 Nov 2025 03:08:01 +0800 From: Chris Down To: Petr Mladek Cc: linux-kernel@vger.kernel.org, Greg Kroah-Hartman , Sergey Senozhatsky , Steven Rostedt , John Ogness , Geert Uytterhoeven , Tony Lindgren , kernel-team@fb.com Subject: [PATCH v7 11/13] printk: docs: Add comprehensive guidance for per-console loglevels Message-ID: <60de5c9e249579d8d4e5a9423067157a462eb763.1763492585.git.chris@chrisdown.name> References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/2.2.15 (2b349c5e) (2025-10-02) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The per-console loglevel feature documentation could use some practical guidance. This commit adds: - Examples section covering runtime configuration, effective loglevel checking, and boot-time configuration - Common use case demonstrating high-performance netconsole with quiet serial console fallback - Performance impact section explaining how per-console loglevels reduce latency by filtering messages before slow console writes - Troubleshooting section addressing common issues like messages not appearing, loglevel constraints, and minimum console loglevel - Edge cases section documenting behavior with concurrent writes, console unregistration, and global loglevel changes The guidance interleaves advice about many parts of this patchset, so let's have it in a distinct commit. This documentation will help users understand how to effectively use and debug per-console loglevels. Signed-off-by: Chris Down --- .../admin-guide/per-console-loglevel.rst | 152 ++++++++++++++++++ 1 file changed, 152 insertions(+) diff --git a/Documentation/admin-guide/per-console-loglevel.rst b/Documenta= tion/admin-guide/per-console-loglevel.rst index 4908d5d8ed4f..69eede12e20f 100644 --- a/Documentation/admin-guide/per-console-loglevel.rst +++ b/Documentation/admin-guide/per-console-loglevel.rst @@ -97,6 +97,158 @@ are using ``ttyS0``, the console backing it can be view= ed at This will be in effect if no other global control overrides it. Look at ``effective_loglevel`` and ``effective_loglevel_source`` to verify that. =20 +Examples +-------- + +Setting per-console loglevel at runtime +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Set serial console to only show warnings and above (level 4):: + + echo 4 > /sys/class/console/ttyS0/loglevel + +Set netconsole to show info and above (level 6):: + + echo 6 > /sys/class/console/netcon0/loglevel + +Reset a console to use the global loglevel:: + + echo -1 > /sys/class/console/ttyS0/loglevel + +Checking effective loglevel +~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Check what loglevel is actually in effect for a console:: + + $ cat /sys/class/console/ttyS0/effective_loglevel + 4 + $ cat /sys/class/console/ttyS0/effective_loglevel_source + local + +If the source shows ``global``, the console is using the global loglevel. +If it shows ``local``, the console is using its per-console loglevel. +If it shows ``ignore_loglevel``, all loglevel controls are being ignored. + +Boot-time configuration +~~~~~~~~~~~~~~~~~~~~~~~~ + +Set different loglevels for different consoles at boot:: + + console=3DttyS0,115200n8,loglevel:3 console=3Dtty0,loglevel:5 + +This sets the serial console (ttyS0) to level 3 (KERN_ERR) and the VGA +console (tty0) to level 5 (KERN_NOTICE). + +For netconsole:: + + netconsole=3D@/,@192.168.1.1/ console=3Dnetcon0,loglevel:6 + +Common use case - high performance with serial fallback +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +A common configuration is to set netconsole to a verbose level for normal +debugging, while keeping the serial console quiet to avoid performance imp= act, +but still available for emergencies:: + + # Netconsole gets INFO and above (verbose) + echo 6 > /sys/class/console/netcon0/loglevel + + # Serial console gets only WARN and above (quiet, for emergencies) + echo 4 > /sys/class/console/ttyS0/loglevel + +This allows you to see informational messages on the fast netconsole witho= ut +the latency impact of writing them to the slow serial port. + +Performance Impact +------------------ + +When a console has a higher (less verbose) loglevel than the global level, +messages that would normally be sent to that console are filtered out befo= re +the console write callback is invoked. This eliminates the latency that wo= uld +be incurred by writing those messages to slow consoles (e.g., serial ports= ). + +For example, setting a serial console to WARN level (4) while keeping +netconsole at INFO level (6) prevents INFO and NOTICE messages from being +written to the slow serial port, reducing application stalls during verbose +logging periods. + +Serial console writes can take tens of milliseconds per message. During +periods of heavy logging (e.g., during network debugging or block I/O trac= ing), +this can cause significant application-level stalls. By setting a higher +per-console loglevel for the serial console, you can avoid these stalls wh= ile +still capturing all messages on faster consoles like netconsole. + +Troubleshooting +--------------- + +Messages not appearing on console despite setting loglevel +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +1. Check effective loglevel source:: + + cat /sys/class/console//effective_loglevel_source + + If it shows ``ignore_loglevel``, you have the ``printk.ignore_loglevel`` + kernel parameter set, which overrides all level controls. Remove it from + your kernel command line or set it to N in sysfs:: + + echo N > /sys/module/printk/parameters/ignore_loglevel + +2. Check if per-console loglevels are being ignored:: + + cat /sys/module/printk/parameters/ignore_per_console_loglevel + + If it shows ``Y``, per-console settings are disabled. Set it to N:: + + echo N > /sys/module/printk/parameters/ignore_per_console_loglevel + +3. Verify the message priority is high enough:: + + cat /sys/class/console//effective_loglevel + + Messages must have priority less than this value to appear. For example, + if effective_loglevel is 4, only messages with priority 0-3 (EMERG, ALE= RT, + CRIT, ERR) will be printed. If you want to see WARN messages (priority = 4), + you need to increase the effective_loglevel to at least 5. + +Cannot set loglevel to 0 +~~~~~~~~~~~~~~~~~~~~~~~~~ + +Per-console loglevels cannot be set to 0 (KERN_EMERG). This is by design, = as +level 0 is reserved for the most critical system messages that should alwa= ys +go to all consoles. To use the global loglevel, set the per-console loglev= el +to -1:: + + echo -1 > /sys/class/console//loglevel + +Setting below minimum_console_loglevel fails +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +If you get an error when trying to set a loglevel, check the system-wide +minimum:: + + cat /proc/sys/kernel/console_loglevel + +Per-console loglevels cannot be set below this minimum. This is a safety +feature to ensure critical messages are always visible. + +Edge cases +~~~~~~~~~~ + +**Setting all consoles to high loglevels**: If you set all consoles to +very high loglevels (e.g., 1 or 2), most messages won't appear anywhere. +This is valid but probably not what you want. Keep at least one console +at a reasonable level for monitoring. + +**Console unregistration while sysfs file is open**: If a console is +unregistered (e.g., module unloaded) while you have its sysfs files open, +the files will become stale. Close and reopen them, or they will eventually +return errors. + +**Global loglevel changes**: If you change the global console_loglevel +via sysctl, consoles set to -1 (use global) will immediately reflect the +new level. Consoles with explicit per-console levels are unaffected. + Deprecated ~~~~~~~~~~ =20 --=20 2.51.2 From nobody Tue Dec 2 02:31:07 2025 Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) (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 0A69535CB99 for ; Tue, 18 Nov 2025 19:08:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763492900; cv=none; b=PlOfZqD4us4lX6qHsjWtlNW949MsrCKBw2YzKfm+3BK6DKwKwPuV8yw0ITNwp3SExkpt/Y/E7jo4N/pYXXcpEzjVbOhyr0T2BjatRsRsvKn+aqg3Zs71PpYWHOf15fN1vkACNx0f8DihEsr6N2Cf0LsUnfJFPUsxJenpQLAr6T8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763492900; c=relaxed/simple; bh=eisP/xbphN7/7oRjxa7967qgHcZFsrBxk8CE9k49X8s=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=NvF1B6ib7xIG5e3uqI+HPNbOtBjIqr3SAqh4zluC4S4KNpARAYENCiEG6EfOJ1p6Oi4s94YSjp3UpUUnrAQ4I/mQzCHc4uqns0PaifKnqmjYXagpk1NmTsJ4WI3flEkx6MZ3Y6lq/r6O3T/zhuYPzp7TBHMYMieCnCZ1pT9CZd0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=chrisdown.name; spf=pass smtp.mailfrom=chrisdown.name; dkim=pass (1024-bit key) header.d=chrisdown.name header.i=@chrisdown.name header.b=VyzXr4Dy; arc=none smtp.client-ip=209.85.214.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=chrisdown.name Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chrisdown.name Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chrisdown.name header.i=@chrisdown.name header.b="VyzXr4Dy" Received: by mail-pl1-f180.google.com with SMTP id d9443c01a7336-29568d93e87so53347515ad.2 for ; Tue, 18 Nov 2025 11:08:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chrisdown.name; s=google; t=1763492898; x=1764097698; darn=vger.kernel.org; h=user-agent: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=07GsZTKRZUMw2kqRQJtb66HAz52UrWx2fVcU/BAMqSs=; b=VyzXr4DyIE8fQJ3Dt6VHM9+Zd1WLAPiHPs1rbef4DIzXxckvTDMqdPIqWy5W7UNKAp NIteK8Ih0VUBa6kJPK8UmxtlBk/SZRansG6lmeuvsqZSOVZvUaWKKuIyzA9+K5o0Wroh BfyM6PyKpV2Y+G9QyC1H3/z43OumQ/T3Fp57Y= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763492898; x=1764097698; h=user-agent: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=07GsZTKRZUMw2kqRQJtb66HAz52UrWx2fVcU/BAMqSs=; b=eps7MnJmffjvJmIiXKRLFcprTBuIVf1SoDyF7pGbzRDt05hPu9vNiNXq+oEUwaC0MG GheWgDjvdIy8/WUBCZCCteZ9HIpvBkzUqaotkJUtG2MLnzeHBbiY2yfTxykoTRf3pe3a SjExTozuv8x0fKj1EhvpJOgA7YjWzUtQ0qT++HhszR6s8DqMqRDYqaNhMqeGHd77f2PB O+s1PEy+PGhOVxeacN+97isN3p7z/KfBaiLBZeaxHcTKW6vLr8Bg6lgG74iAOSEjVrnA 7NkV0Ga5O/oiobhos322sav0DDbCyk2/pakOzf7c3eA22AfTpcOelcKdij8OWAHs1QiA 8F+Q== X-Gm-Message-State: AOJu0Yw1Xltf0ZSyTyjCsVhN4Iu52EvSakLB1z0mzo+3RjFH5MHcqVmf wZkpKiTYGXMtuY3KFCy/1TQ7JR1M/MHcSng46db2hBwDRhUBzswRIt2YZu9eSSvm3yY= X-Gm-Gg: ASbGncsywwH6o8o73Xnd8oyNmd9qs7vt3GbLHITssdfO08Gj8whC+jlgp/cD87kBSWC 40DjThqXm+fuSELdCvAuHfoOIZl52ja+yqXmrUllqHHz0vzKRaAmRFUi7L7ObR9UySRN9qb7QnB MOLMSpg23RXf2XPiJMT01yaiOYqCLmqw+8PSonLZtrpvragDwahn31rctki0CyYuf4kMmANv8l2 JH5kDk1njqo4z1m4iEdKGTl1NT4uqJFQeNECbSyJqgeRFPn7STXscVgNNrhQuQSr2RdnL5+xTb2 9JTcQqmsButUrege0i8fRwKdQHq8vfWWIyVTGw0RCUcYoKCc1N7gtuMlKhyjf4g2yz9FVXc9Rsn zeG4VRCp3hvzhFmOK9lXCqS+A5PNmmo9Xmuko5XL1bTLWqITD6XN39VR9u3/4sGoL2JNHIuKKPR fJTSiVV+pH X-Google-Smtp-Source: AGHT+IEFo+7eXnooMW0Z1Ea6JAkJqrG7YPrB0Mih4OlHMK0o3Bixh26L7C7G8ZJgl3dPENXU4psFeg== X-Received: by 2002:a17:903:252:b0:246:e1b6:f9b0 with SMTP id d9443c01a7336-2986a6cfd38mr213014835ad.18.1763492898215; Tue, 18 Nov 2025 11:08:18 -0800 (PST) Received: from localhost ([116.86.198.140]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2985ce19a20sm178233345ad.84.2025.11.18.11.08.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Nov 2025 11:08:17 -0800 (PST) Date: Wed, 19 Nov 2025 03:08:16 +0800 From: Chris Down To: Petr Mladek Cc: linux-kernel@vger.kernel.org, Greg Kroah-Hartman , Sergey Senozhatsky , Steven Rostedt , John Ogness , Geert Uytterhoeven , Tony Lindgren , kernel-team@fb.com Subject: [PATCH v7 12/13] printk: Deprecate the kernel.printk sysctl interface Message-ID: <42d7254ffdfa30fc0bd3f1aa7cac354891e95231.1763492585.git.chris@chrisdown.name> References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/2.2.15 (2b349c5e) (2025-10-02) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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. Reviewed-by: Petr Mladek Signed-off-by: Chris Down --- Documentation/admin-guide/sysctl/kernel.rst | 3 +++ kernel/printk/sysctl.c | 14 +++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/Documentation/admin-guide/sysctl/kernel.rst b/Documentation/ad= min-guide/sysctl/kernel.rst index 043d5f663b7d..5ac6db03c2fb 100644 --- a/Documentation/admin-guide/sysctl/kernel.rst +++ b/Documentation/admin-guide/sysctl/kernel.rst @@ -1096,6 +1096,9 @@ Messages without an explicit priority will be printed= with this priority. printk =3D=3D=3D=3D=3D=3D =20 +This sysctl is deprecated and will be removed in future. Please consider u= sing +``kernel.console_loglevel`` or ``kernel.default_message_loglevel`` instead. + The four values in printk denote: ``console_loglevel``, ``default_message_loglevel``, ``minimum_console_loglevel`` and ``default_console_loglevel`` respectively. diff --git a/kernel/printk/sysctl.c b/kernel/printk/sysctl.c index feec6cf939af..921e0f80ee8f 100644 --- a/kernel/printk/sysctl.c +++ b/kernel/printk/sysctl.c @@ -7,6 +7,7 @@ #include #include #include +#include #include "internal.h" =20 static const int ten_thousand =3D 10000; @@ -56,13 +57,24 @@ static int proc_dointvec_console_loglevel(const struct = ctl_table *table, do_proc_dointvec_console_loglevel, NULL); } =20 +static int proc_dointvec_printk_deprecated(const struct ctl_table *table, = int write, + void *buffer, size_t *lenp, loff_t *ppos) +{ + int res =3D proc_dointvec(table, write, buffer, lenp, ppos); + + if (write) + pr_warn_once("printk: The kernel.printk sysctl is deprecated. Consider u= sing kernel.console_loglevel or kernel.default_message_loglevel instead.\n"= ); + + return res; +} + static const struct ctl_table printk_sysctls[] =3D { { .procname =3D "printk", .data =3D &console_loglevel, .maxlen =3D 4*sizeof(int), .mode =3D 0644, - .proc_handler =3D proc_dointvec, + .proc_handler =3D proc_dointvec_printk_deprecated, }, { .procname =3D "printk_ratelimit", --=20 2.51.2 From nobody Tue Dec 2 02:31:07 2025 Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) (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 E9441366575 for ; Tue, 18 Nov 2025 19:08:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763492908; cv=none; b=jwK4HNBN69HojTXRaIwyvogYeR9iBEfKehuSu9VXYKr5+qqA/6E75vpnaooUMbWysTYkm54h0UJSlbsLkCX+RUrq5gTIFEDMjxH5BhtN73ED2TPo2ywhmpLufM6DOej22tx3IKpnpWDTETeeXSorfgQMlwQwhYmapAdqbNxWvAU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763492908; c=relaxed/simple; bh=c9vD0SvDt7Y9IDAUvCmtbGWC/AO0DBknWIdg3C7yNZY=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=rVzbpq+U0IxjCW1piXUdXIQfAWM7oV+sf8HvPk2N5juJ0CA70AgdzV3dYgfLBeL6NCD2kw95ywM9m7lTfVf0voEnUy2jUJiO03lb9onIGshCgiURepgyGuBOqTw2OHY4ZpdjVeYWff/o23c9UbZ5i84pYOyC2BG4zgQBk66Ii8A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=chrisdown.name; spf=pass smtp.mailfrom=chrisdown.name; dkim=pass (1024-bit key) header.d=chrisdown.name header.i=@chrisdown.name header.b=mVlKC8em; arc=none smtp.client-ip=209.85.214.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=chrisdown.name Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chrisdown.name Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chrisdown.name header.i=@chrisdown.name header.b="mVlKC8em" Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-29806bd47b5so37794745ad.3 for ; Tue, 18 Nov 2025 11:08:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chrisdown.name; s=google; t=1763492906; x=1764097706; darn=vger.kernel.org; h=user-agent: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=sRNnypcEFsiD57ue+ARqdr8/hiSyVS3dM000M+doBjA=; b=mVlKC8emFy79pfl0ESJB9y2EW+8FhTOKiyfUrthkW8F1x649rEObhWy8YBACzDe4eg BcLe6pe/gjLhXPrDcMP7YmuN8MOPibedJGsBgGhJyY2xTTalu4F+oozNyTfMrr3Q6NwZ SrwBX6Off4BrZJX0537Yhxn2cPSN8gGmei6J0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763492906; x=1764097706; h=user-agent: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=sRNnypcEFsiD57ue+ARqdr8/hiSyVS3dM000M+doBjA=; b=w0MO3Cu3m26lSX9XeGpPUZlA12HlYmIvmmmtkf+OHurACO0x5Uu86oExNpq9S0xD4q uAdE4rRDsrqe8a2zlhAgjea/e9jPU/wVwPCq0Ax6TxRaWrzVIOcO3Ze4kbvN9x8AWPGJ LSbHB46qTONgVajYAlzVwNTotq+ovTtu3DjaSBxKtlt5rAOsNDI8Tj/BubaqX/Q/JjfQ 7z7pG9Mfu2qg58dQDP+eBCIXfqtuXIdiYhPvnFMBwt/LcpmUqjDeeOB+otLZlXJD0u4g +PQY0ipao3L5PceMDjhWGAxHCSCQVTMiMRI1DjDdb8WY1HHnlmTgwlo3Ib9hpDqmme7W GX1w== X-Gm-Message-State: AOJu0YxOLF6VzHWIJGsrB7bJR3ucyPbJaYZstj+i51hAvzksc0nADAc+ rm2OuCAWAxk+HsCEUFJuCh56fqYyB9b9a6V1JZ7YuGg4wJaiKBAZANL9E0tWAYnmHzA= X-Gm-Gg: ASbGncsdJNhUYjibBPHTnqKcM3mdlHZrg5h8UaZcur5b4w1lmsGNjAGAy0+QRSUv8Wk X0ppnuL7NdyZ56aKgVTmUd7DlQ86rNy+nvQ25Eu68WwQpg8w5QZMtPYxyMhbQZsORy/63YgUICw TuZblk1QiErwnOgm+2iIKs7sSMu8GpQ1NBNTWsQK3deAk4dIi/Y8ZuWq0KhE0oIfbkKpO+D0VVx oKnSUov6h47Ta6avC4iRhji69113bbFl6zmCCF8VgcSTFkJL2niD7CVj3xG7/R9tMFOCrVyy96J R6I0Wfh02sfBhFgLB97QxpYKtI5CoLsInXfLwo6kvoGpBFnaRmrmSa6Ehsj3TfIobbzJLgqbOcw wi8iztLwJPgSZeIhLQV1jWBfswa3OYBWDIOufgj/dpj8C7EWubZr68OVpekDCQHohy3Se4jAxKy 9szenSVC8q X-Google-Smtp-Source: AGHT+IGBN+6PyP7dyDOUUS1Zs/ob8ywMSavQn9AOvqOE+fUv9Y31ruO+uVtGMn+7pjVWox0aCF2sEA== X-Received: by 2002:a17:903:230a:b0:295:94e1:91da with SMTP id d9443c01a7336-2986a73b093mr209729285ad.33.1763492906273; Tue, 18 Nov 2025 11:08:26 -0800 (PST) Received: from localhost ([116.86.198.140]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2985c2b0710sm181768085ad.66.2025.11.18.11.08.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Nov 2025 11:08:25 -0800 (PST) Date: Wed, 19 Nov 2025 03:08:23 +0800 From: Chris Down To: Petr Mladek Cc: linux-kernel@vger.kernel.org, Greg Kroah-Hartman , Sergey Senozhatsky , Steven Rostedt , John Ogness , Geert Uytterhoeven , Tony Lindgren , kernel-team@fb.com Subject: [PATCH v7 13/13] printk: Purge default_console_loglevel Message-ID: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/2.2.15 (2b349c5e) (2025-10-02) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" default_console_loglevel (then DEFAULT_LOGLEVEL) was created in Linux 0.99.13 (September 1993) to power what we now call SYSLOG_ACTION_CONSOLE_{ON,OFF}. It was originally hardcoded to 7. In Linux 2.3.12 (March 1997), Chris Horn made it configurable by sysctl through kernel.printk. Its demise came about in July 2009 in commit 1aaad49e856c ("printk: Restore previous console_loglevel when re-enabling logging"), which replaces default_console_loglevel with the previously used console_loglevel. However, the documentation was never updated, and we still kept on telling users that this sets the default value for console_loglevel, even though this hasn't been true for over 15 years. Purge both the documentation and all remaining references to default_console_loglevel. It will still be initialised in the sysctl array. Reviewed-by: Petr Mladek Signed-off-by: Chris Down --- Documentation/admin-guide/sysctl/kernel.rst | 5 ++--- include/linux/printk.h | 1 - kernel/printk/printk.c | 2 +- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/Documentation/admin-guide/sysctl/kernel.rst b/Documentation/ad= min-guide/sysctl/kernel.rst index 5ac6db03c2fb..37f2f417eaf7 100644 --- a/Documentation/admin-guide/sysctl/kernel.rst +++ b/Documentation/admin-guide/sysctl/kernel.rst @@ -1100,8 +1100,8 @@ This sysctl is deprecated and will be removed in futu= re. Please consider using ``kernel.console_loglevel`` or ``kernel.default_message_loglevel`` instead. =20 The four values in printk denote: ``console_loglevel``, -``default_message_loglevel``, ``minimum_console_loglevel`` and -``default_console_loglevel`` respectively. +``default_message_loglevel``, ``minimum_console_loglevel`` and an unused l= egacy +value respectively. =20 These values influence printk() behavior when printing or logging error messages. @@ -1113,7 +1113,6 @@ default_message_loglevel messages without an explicit= priority will be printed with this priority minimum_console_loglevel minimum (highest) value to which console_loglevel can be set -default_console_loglevel default value for console_loglevel =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D = =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =20 =20 diff --git a/include/linux/printk.h b/include/linux/printk.h index e36cae1805b2..432bef48e212 100644 --- a/include/linux/printk.h +++ b/include/linux/printk.h @@ -71,7 +71,6 @@ extern int console_printk[]; #define console_loglevel (console_printk[0]) #define default_message_loglevel (console_printk[1]) #define minimum_console_loglevel (console_printk[2]) -#define default_console_loglevel (console_printk[3]) =20 extern bool ignore_per_console_loglevel; =20 diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index a6e1fa924294..170fa8e14ea9 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -66,7 +66,7 @@ int console_printk[4] =3D { CONSOLE_LOGLEVEL_DEFAULT, /* console_loglevel */ MESSAGE_LOGLEVEL_DEFAULT, /* default_message_loglevel */ CONSOLE_LOGLEVEL_MIN, /* minimum_console_loglevel */ - CONSOLE_LOGLEVEL_DEFAULT, /* default_console_loglevel */ + /* legacy default console loglevel, unused */ }; EXPORT_SYMBOL_GPL(console_printk); =20 --=20 2.51.2