From nobody Mon Dec 1 22:03:16 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 215F03054F8 for ; Thu, 27 Nov 2025 19:44:04 +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=1764272646; cv=none; b=dJdmkceC/i8ok4aKiOPgsZDCfQee0Vq69Uk7Gr4iFEgOREtuq+WPru6f6D22gISLE/Vfz2pYe6BZjlDZB3ofUdxgXOYcEhkBpo+0PRuvrBivBHIQVoM1S1f4mjiLer+6mZhkATjp9PIkITyS2HJU2/MAiWtAafbjak3F9NMrPko= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764272646; c=relaxed/simple; bh=Tbt/2GM/9Lpi3G5ony3iNB9RaVP7Xu/mA1/WHb4z9bY=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=iZawEsuo8UiegcA8IRSac23diC5XxczKcZEjxrxmhjfjhTqeuujt2ecN7icPf56uRSCEJvSE1lWDcdBWzRhyNTmwOYK91YRBjYAZbmPq+AT9MWoTlho8CKxeHRLr9x6mFiPhImLlwJSO0MOkTxV/gHGCCcgxE1IKejtQ/8/hYQs= 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=FLLvIDeM; 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="FLLvIDeM" Received: by mail-pf1-f169.google.com with SMTP id d2e1a72fcca58-7b9c17dd591so1016307b3a.3 for ; Thu, 27 Nov 2025 11:44:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chrisdown.name; s=google; t=1764272644; x=1764877444; 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=G9BxejY3r2Nq73eTJdLWWmIYdAOYxH5XU1Ghi4l0AcQ=; b=FLLvIDeM0jAuD1baSSxog5UTbayfOd0GhPP8hxuqnlGU1k1aw2jl1SKOujnfjjt9pQ KeNuVNIh2cItaqytjSO/W5Y3GgzEAQoujIljsCxU8MB8WpNoR0zV/z/DjBbnWiYC4x5D wfsBr3ommVJWdAkAhEBvd6zpHpfdfNuiyAD6g= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764272644; x=1764877444; 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=G9BxejY3r2Nq73eTJdLWWmIYdAOYxH5XU1Ghi4l0AcQ=; b=jFs+r9P0l9qw3Dr48QQz73IsKBXwqpUVd7MSZhJBf6DE2Z9M0e9INLEqACfuuc2gqY 9DhMnvg6vcdXu26zvgl29/AcNavLtUZQD6dB8jmdq1bI0m+KsSMvSAyg4cvfTUv71GA2 exYzygHqjJVEEzM3wyrhfyafcavfOum2gQ5rDeAKMYyp66AX3234MVr1ZimVzeFTN9lY xl/3zgecVcGC1uuWB5lGaaLNh7eB5/NVLSRlBek7u72dJmpQzQw49aO8hlQObsuHajiI E4gHQqsDgHjRnQpp0/Zr+NG03jpErRMJFEFaw2yacFyuHs+ey1Mn1QrXPMMecFQwKuNo nAfQ== X-Gm-Message-State: AOJu0YxEvTg/U0e5l3mibSspL5QHGbEYgVDz+8MfY6tG8bJqjgK+89s5 qXUxsdrSO6L+S0pO+KyKB2L+0QnNR8mAnMqOytG3EVD5R0juJN5efhzIy+zWcJDsyke3/RsZWYs 9WQV/7KjSnQ== X-Gm-Gg: ASbGncuTiByMtJPRr0BJ+yojmfz3B+5/6aFmtLd7dK2RADvnPpJM5NGnUTOjjXJL3Z5 45UOzDxCA39aP4mQTp1gLI95Vmczkf2aSsSLI/VQLQ3gten4hrjvJLwHBLqCbFti4jBbOdqejNM zY7OpmgOyIlLImzNyfmHOQ8Y9AdAWSteEO0o48W3+pxe0nxibS/HFOTYFu+HbeltBVXAzpT2rvA wJNWRrWmrJvgdfIi7QajQvCvGXWL+WsoBanjKOnbFdOS3KoMKgJMuEE/ArVQlAZFffxljfsRZEh wGrFGVwxrsiPJhggcyqGoHuVZIyAjJ3+6o3t7QbV2Ox6caUNzXRqywbty14inqN2lXhOsSXTf0r bO1Mqxi2LMZG2zF95xj3bswOb9h1+mcJHam4BB79gej60a6Uc1JrrbiNFnf4Ug8p+LltO9t66If I4uN0A3/Z5 X-Google-Smtp-Source: AGHT+IGXKOrIOfsU0UTajll/tPKA/SXPHPNWXnlRgIIfUsN4/tNsPtrFhmG21LgikGl7D0KM+1qj4A== X-Received: by 2002:a05:6a20:6a0d:b0:35e:5bcd:8310 with SMTP id adf61e73a8af0-3637dea5f95mr12471208637.32.1764272644246; Thu, 27 Nov 2025 11:44:04 -0800 (PST) Received: from localhost ([116.86.198.140]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-be4fbb0094dsm2677247a12.10.2025.11.27.11.44.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Nov 2025 11:44:03 -0800 (PST) Date: Fri, 28 Nov 2025 03:44: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 v8 13/21] printk: Toggle ignore_per_console_loglevel via syslog Message-ID: <299a3c124f4e0ece36f2a04db2d4d2143e66ebca.1764272407.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() system call provides SYSLOG_ACTION_CONSOLE_OFF and SYSLOG_ACTION_CONSOLE_ON to disable and re-enable console logging. These actions save and restore the global console_loglevel. With per-console loglevels, simply setting console_loglevel to minimum_console_loglevel during CONSOLE_OFF is insufficient - consoles with explicit per-console loglevels would continue printing based on their local settings. Augment these actions to also save and restore the state of ignore_per_console_loglevel. When console logging is disabled via syslog(), ignore_per_console_loglevel is set to true so that the minimum_console_loglevel applies to all consoles. When logging is re-enabled, the previous ignore_per_console_loglevel state is restored. A forced flag tracks whether this code path actually set ignore_per_console_loglevel. This prevents blindly restoring stale state if other contexts (sysrq, module parameter writes) legitimately modified the flag in parallel. SYSLOG_ACTION_CONSOLE_LEVEL now emits a one-time warning when per-console loglevels are active, informing administrators that their level change only affects consoles using the global loglevel. The level change also properly restores ignore_per_console_loglevel state if it was forced by a previous CONSOLE_OFF. These changes allow userspace tools like dmesg to properly control console output even in the presence of per-console loglevels. Reviewed-by: Petr Mladek Signed-off-by: Chris Down --- kernel/printk/printk.c | 53 +++++++++++++++++++++++++++++++++++------- 1 file changed, 45 insertions(+), 8 deletions(-) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index e5b6a926135e..1d28887e7218 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -1869,6 +1869,8 @@ 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; + static bool saved_ignore_per_console_loglevel_forced; int error; =20 error =3D check_syslog_permissions(type, source); @@ -1910,9 +1912,23 @@ 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; + saved_ignore_per_console_loglevel_forced =3D false; + } console_loglevel =3D minimum_console_loglevel; + if (!ignore_per_console_loglevel) { + /* + * Only remember the saved value if this path actually + * forced the override. Other contexts (sysrq, module + * parameter writes, etc.) can legitimately toggle the + * flag in parallel, so blindly restoring it later would + * resurrect stale state. + */ + ignore_per_console_loglevel =3D true; + saved_ignore_per_console_loglevel_forced =3D true; + } mutex_unlock(&syslog_lock); break; /* Enable logging to console */ @@ -1920,20 +1936,41 @@ 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; + if (saved_ignore_per_console_loglevel_forced) + ignore_per_console_loglevel =3D saved_ignore_per_console_loglevel; saved_console_loglevel =3D LOGLEVEL_DEFAULT; + saved_ignore_per_console_loglevel_forced =3D false; } mutex_unlock(&syslog_lock); break; /* Set level of messages printed to console */ - case SYSLOG_ACTION_CONSOLE_LEVEL: - if (len < 1 || len > 8) + case SYSLOG_ACTION_CONSOLE_LEVEL: { + int new_level =3D len; + + 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 (new_level < 1 || new_level > 8) return -EINVAL; - if (len < minimum_console_loglevel) - len =3D minimum_console_loglevel; - console_loglevel =3D len; - /* Implicitly re-enable logging to console */ - saved_console_loglevel =3D LOGLEVEL_DEFAULT; + if (new_level < minimum_console_loglevel) + new_level =3D minimum_console_loglevel; + + mutex_lock(&syslog_lock); + console_loglevel =3D new_level; + /* + * If SYSLOG_ACTION_CONSOLE_OFF forced ignore_per_console_loglevel, + * restore the previous setting so per-console loglevels continue + * to work after administrators re-enable logging via syslog(). + */ + if (saved_console_loglevel !=3D LOGLEVEL_DEFAULT) { + if (saved_ignore_per_console_loglevel_forced) + ignore_per_console_loglevel =3D saved_ignore_per_console_loglevel; + saved_console_loglevel =3D LOGLEVEL_DEFAULT; + saved_ignore_per_console_loglevel_forced =3D false; + } + mutex_unlock(&syslog_lock); break; + } /* Number of chars in the log buffer */ case SYSLOG_ACTION_SIZE_UNREAD: mutex_lock(&syslog_lock); --=20 2.51.2