From nobody Tue Feb 10 05:44:54 2026 Received: from mail-wm1-f65.google.com (mail-wm1-f65.google.com [209.85.128.65]) (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 163C63128B4 for ; Sat, 27 Dec 2025 12:17:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.65 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766837849; cv=none; b=lRQnJrp2wZM3XJj87aAiH/xGCL+AXtyouLPc7LgKGyecTpLeSbCsszPpltKTa8DdEGJ0nn9Al5JsTPttK+q5rGWMsAKGhrRf+L3y9cixsf/sq31IjgQ0lHE3fQj6+g561sQwFYuRmjE3DIde1chn+85y075FoDjUDXxOf8oJjzA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766837849; c=relaxed/simple; bh=lE/1DIYMabiYcINvDQN+J482ZjUVJCV7RenaBaf63GU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=A08EymTwb7EDTDAI7Me8a6pMh3tTzxzr1rTYycIBwzJslx5fe681nni5OotJN/u3MrTICgV3Q9Fr8Y57ULnBzDQiVXawDXwXHObjTV+y2pE5tpH7XFv9MGl+c9r8KYc+xWtg62c7cYisDcFB/556Fo+ro9fToiAE3R60AYR/7PY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=DNG2+0ms; arc=none smtp.client-ip=209.85.128.65 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="DNG2+0ms" Received: by mail-wm1-f65.google.com with SMTP id 5b1f17b1804b1-47a8195e515so48973025e9.0 for ; Sat, 27 Dec 2025 04:17:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1766837844; x=1767442644; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=l5BRw7RvrfQfP/K6gt0hDAa/lWwGnQ3AR1h1gaT2J0c=; b=DNG2+0ms3Qjd5sDKLCpntZHF64m5WwiJRC+/amjqj2XoJPWkwy58NrCjLx9o5IMgZn 7NvIbTeaUqNJDtUYX/3C/pIjAi7GLMHXTnWapAj4SkVLhBHNVkp3jExYT0nxlEUmR4pq uEg2IEREnqQSHUiiDXYTqjk0l1OKzbOX7/JLEco5mubWjZlAwwbKZasYkN/js8Yhve3t uikpb7rDyzQEVGt2B+U0Fts23cMD1V9x5vzcjeJR1utq6maJCW2730EKWhme4RweI3fG IMsaDtuNBCo8+gvDZjwmm2tMPbvRQbmoZAC/mXiRiU2joBZEK0h9WSfY1B5m1UVHoM+3 hJEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1766837844; x=1767442644; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=l5BRw7RvrfQfP/K6gt0hDAa/lWwGnQ3AR1h1gaT2J0c=; b=VSkGHIRMJIW5UjQJqcJnuv/fws8tTi3lKywQiHd+RlYCLR+eWqR7vEDXFRq1XU96bU tvqz2j5j33jP40aapv+Yh0UqlBU3knsMOBrhkkVluMstYvVe10bT3ce/aVFJlo8u+ORG nGvqEx3Sk3RlAOlFoDaYD096ai80lf6XA+W4eegrvA2m6+BeZWs44lNnI0tZgpbLPkol azIMDqJLj7mTLFQHW4YVc5CLsZoHI9eg9cdUVjnWYo91SlYpWC2oWRUobWzsk4B2eanj bWwm1ktNvNuLySowUHQy0J0lKv+ypxqRy69sSDcvTXXeTki0oomCDt70Zf93zvmtZBYw OCzg== X-Forwarded-Encrypted: i=1; AJvYcCVEBDFinG/Y7iVD7MEYcphGGeSmJEOci3xLQyyOoXiZhvvamU/NV2KAAWww5/YzdZKmjYvjD6FYIHNInd0=@vger.kernel.org X-Gm-Message-State: AOJu0YwCVkym5IByftDnQY4SnXilHFvsM70M8zYRQWxt+aa20gq+9LOm KNIKdjCngKEm1tdFmx1OX/qi45GYMmuKZ7Nng63zbm5IoVjG/Ro1PI3P0a+yuzI9joU= X-Gm-Gg: AY/fxX5SldvIPAiqXrUdljgRAQn/7LFwDNnapGjn1bNTJmLqtn89gVmF1grOutq54xx mY4ngXAIXT4oLGfc0DamoVaBIm+ZSx9vw2V2pd0wk7ykosP8tJptdnN7ixg/SzQqp4Lis60rD50 Rt5EpVsA61SSAgjP7ddrQTCTysHEJw4+yVpQpi46+wiWP6DzIcVTxblTtyZHcuZtX9D6iWLGFTc Wj94rSfqa6jhMFrrd72L9BoGUD4BmYTves6eKjAiM2bOlxsp0SVYsygihu2MqCEVkg1tWjk4hjn EGecj4mNm3TJ/prhNjg+xvqnHUoJ7BTMijKxvVtOlaLUcbGhojxS107IZHGjnoJSm+YvXZzyEHD T63xYHGl7tRMzKI+SunsdJhIb3zKR96KfYG6+8LjSZ1Nqk2slXOv9yn5PrR6dfEp9VmasoLjn4c +L3WAlozK2 X-Google-Smtp-Source: AGHT+IFB/Fm/BbhF4rdbmVdiGzUqk88gX/08HvStcaIXA3100u27BggsIM2y0GxgIqiLG/N+dnbC3Q== X-Received: by 2002:a05:600c:4f52:b0:477:a978:3a7b with SMTP id 5b1f17b1804b1-47d1958a5d5mr344953125e9.22.1766837844304; Sat, 27 Dec 2025 04:17:24 -0800 (PST) Received: from [127.0.0.1] ([2804:5078:811:d400:58f2:fc97:371f:2]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-121724cfdd0sm97940127c88.4.2025.12.27.04.17.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 27 Dec 2025 04:17:23 -0800 (PST) From: Marcos Paulo de Souza Date: Sat, 27 Dec 2025 09:16:11 -0300 Subject: [PATCH 04/19] printk: Reintroduce consoles_suspended global state Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20251227-printk-cleanup-part3-v1-4-21a291bcf197@suse.com> References: <20251227-printk-cleanup-part3-v1-0-21a291bcf197@suse.com> In-Reply-To: <20251227-printk-cleanup-part3-v1-0-21a291bcf197@suse.com> To: Richard Weinberger , Anton Ivanov , Johannes Berg , Greg Kroah-Hartman , Jason Wessel , Daniel Thompson , Douglas Anderson , Petr Mladek , Steven Rostedt , John Ogness , Sergey Senozhatsky , Jiri Slaby , Breno Leitao , Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Geert Uytterhoeven , Kees Cook , Tony Luck , "Guilherme G. Piccoli" , Madhavan Srinivasan , Michael Ellerman , Nicholas Piggin , Christophe Leroy , Andreas Larsson , Alexander Shishkin , Maxime Coquelin , Alexandre Torgue , Jacky Huang , Shan-Chun Hung , Laurentiu Tudor Cc: linux-um@lists.infradead.org, linux-kernel@vger.kernel.org, kgdb-bugreport@lists.sourceforge.net, linux-serial@vger.kernel.org, netdev@vger.kernel.org, linux-m68k@lists.linux-m68k.org, linux-hardening@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, sparclinux@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, linux-fsdevel@vger.kernel.org, Marcos Paulo de Souza X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=ed25519-sha256; t=1766837798; l=7960; i=mpdesouza@suse.com; s=20231031; h=from:subject:message-id; bh=lE/1DIYMabiYcINvDQN+J482ZjUVJCV7RenaBaf63GU=; b=0Nm1rVm8usUyQfc8Y8VdqZ5lSxqrxogghCnWlBop68h2x3eX8wvULmkNK1yqxgDQDAsr7NT2A 16smAUrBtylBcdO0yBiCQkV9TDNRTRX47nnARx+C0eR1hFzoRnJz2MU X-Developer-Key: i=mpdesouza@suse.com; a=ed25519; pk=/Ni/TsKkr69EOmdZXkp1Q/BlzDonbOBRsfPa18ySIwU= This change partially reverts commit 9e70a5e109a4 ("printk: Add per-console suspended state"). The intent of the original commit was to move the management of the console suspended state to the consoles themselves to be able to use SRCU instead of console lock. But having a global state is still useful when checking if the global suspend was triggered by power management. This way, instead of setting the state of each individual console, the code would only set/read from the global state. Along with this change, two more fixes are necessary: change console_{suspend,resume} to set/clear CON_SUSPEND instead of setting CON_ENABLED and change show_cons_active to call __console_is_usable to check console usefulness. Link: https://lore.kernel.org/lkml/844j4lepak.fsf@jogness.linutronix.de/ Signed-off-by: Petr Mladek [mpdesouza@suse.com: Adapted code related to console_is_usable] Signed-off-by: Marcos Paulo de Souza --- drivers/tty/tty_io.c | 6 +++--- include/linux/console.h | 53 +++++++++++++++++++++++++++++++++++++++++++++= ++-- kernel/printk/printk.c | 23 +++++++++++---------- 3 files changed, 67 insertions(+), 15 deletions(-) diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c index e2d92cf70eb7..7d2bded75b75 100644 --- a/drivers/tty/tty_io.c +++ b/drivers/tty/tty_io.c @@ -3552,9 +3552,9 @@ static ssize_t show_cons_active(struct device *dev, for_each_console(c) { if (!c->device) continue; - if (!(c->flags & CON_NBCON) && !c->write) - continue; - if ((c->flags & CON_ENABLED) =3D=3D 0) + if (!__console_is_usable(c, c->flags, + consoles_suspended, + NBCON_USE_ANY)) continue; cs[i++] =3D c; if (i >=3D ARRAY_SIZE(cs)) diff --git a/include/linux/console.h b/include/linux/console.h index 648cf10e3f93..caf9b0951129 100644 --- a/include/linux/console.h +++ b/include/linux/console.h @@ -509,6 +509,7 @@ extern void console_list_lock(void) __acquires(console_= mutex); extern void console_list_unlock(void) __releases(console_mutex); =20 extern struct hlist_head console_list; +extern bool consoles_suspended; =20 /** * console_srcu_read_flags - Locklessly read flags of a possibly registered @@ -561,6 +562,47 @@ static inline void console_srcu_write_flags(struct con= sole *con, short flags) WRITE_ONCE(con->flags, flags); } =20 +/** + * consoles_suspended_srcu_read - Locklessly read the global flag for + * suspending all consoles. + * + * The global "consoles_suspended" flag is synchronized using console_list= _lock + * and console_srcu_read_lock. It is the same approach as CON_SUSPENDED fl= ag. + * See console_srcu_read_flags() for more details. + * + * Context: Any context. + * Return: The current value of the global "consoles_suspended" flag. + */ +static inline bool consoles_suspended_srcu_read(void) +{ + WARN_ON_ONCE(!console_srcu_read_lock_is_held()); + + /* + * The READ_ONCE() matches the WRITE_ONCE() when "consoles_suspended" + * is modified with consoles_suspended_srcu_write(). + */ + return data_race(READ_ONCE(consoles_suspended)); +} + +/** + * consoles_suspended_srcu_write - Write the global flag for suspending + * all consoles. + * @suspend: new value to write + * + * The write must be done under the console_list_lock. The caller is respo= nsible + * for calling synchronize_srcu() to make sure that all callers checking t= he + * usablility of registered consoles see the new state. + * + * Context: Any context. + */ +static inline void consoles_suspended_srcu_write(bool suspend) +{ + lockdep_assert_console_list_lock_held(); + + /* This matches the READ_ONCE() in consoles_suspended_srcu_read(). */ + WRITE_ONCE(consoles_suspended, suspend); +} + /** * console_srcu_is_nbcon - Locklessly check whether the console is nbcon * @con: struct console pointer of console to check @@ -658,8 +700,12 @@ extern void nbcon_kdb_release(struct nbcon_write_conte= xt *wctxt); =20 /* Variant of console_is_usable() when the console_list_lock is held. */ static inline bool __console_is_usable(struct console *con, short flags, - enum nbcon_write_cb nwc) + bool all_suspended, + enum nbcon_write_cb nwc) { + if (all_suspended) + return false; + if (!(flags & CON_ENABLED)) return false; =20 @@ -711,7 +757,9 @@ static inline bool __console_is_usable(struct console *= con, short flags, static inline bool console_is_usable(struct console *con, enum nbcon_write_cb nwc) { - return __console_is_usable(con, console_srcu_read_flags(con), nwc); + return __console_is_usable(con, console_srcu_read_flags(con), + consoles_suspended_srcu_read(), + nwc); } =20 #else @@ -727,6 +775,7 @@ static inline bool nbcon_kdb_try_acquire(struct console= *con, struct nbcon_write_context *wctxt) { return false; } static inline void nbcon_kdb_release(struct nbcon_write_context *wctxt) { } static inline bool __console_is_usable(struct console *con, short flags, + bool all_suspended, enum nbcon_write_cb nwc) { return false; } static inline bool console_is_usable(struct console *con, enum nbcon_write_cb nwc) { return false; } diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index b03ffc23c27c..173c14e08afe 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -104,6 +104,13 @@ DEFINE_STATIC_SRCU(console_srcu); */ int __read_mostly suppress_printk; =20 +/* + * Global flag for calling down all consoles during suspend. + * There is also a per-console flag which is used when the related + * device HW gets disabled, see CON_SUSPEND. + */ +bool consoles_suspended; + #ifdef CONFIG_LOCKDEP static struct lockdep_map console_lock_dep_map =3D { .name =3D "console_lock" @@ -2731,8 +2738,6 @@ MODULE_PARM_DESC(console_no_auto_verbose, "Disable co= nsole loglevel raise to hig */ void console_suspend_all(void) { - struct console *con; - if (console_suspend_enabled) pr_info("Suspending console(s) (use no_console_suspend to debug)\n"); =20 @@ -2749,8 +2754,7 @@ void console_suspend_all(void) return; =20 console_list_lock(); - for_each_console(con) - console_srcu_write_flags(con, con->flags | CON_SUSPENDED); + consoles_suspended_srcu_write(true); console_list_unlock(); =20 /* @@ -2765,7 +2769,6 @@ void console_suspend_all(void) void console_resume_all(void) { struct console_flush_type ft; - struct console *con; =20 /* * Allow queueing irq_work. After restoring console state, deferred @@ -2776,8 +2779,7 @@ void console_resume_all(void) =20 if (console_suspend_enabled) { console_list_lock(); - for_each_console(con) - console_srcu_write_flags(con, con->flags & ~CON_SUSPENDED); + consoles_suspended_srcu_write(false); console_list_unlock(); =20 /* @@ -3557,7 +3559,7 @@ void console_suspend(struct console *console) { __pr_flush(console, 1000, true); console_list_lock(); - console_srcu_write_flags(console, console->flags & ~CON_ENABLED); + console_srcu_write_flags(console, console->flags | CON_SUSPENDED); console_list_unlock(); =20 /* @@ -3576,7 +3578,7 @@ void console_resume(struct console *console) bool is_nbcon; =20 console_list_lock(); - console_srcu_write_flags(console, console->flags | CON_ENABLED); + console_srcu_write_flags(console, console->flags & ~CON_SUSPENDED); is_nbcon =3D console->flags & CON_NBCON; console_list_unlock(); =20 @@ -4200,7 +4202,8 @@ static int unregister_console_locked(struct console *= console) =20 if (!console_is_registered_locked(console)) res =3D -ENODEV; - else if (__console_is_usable(console, console->flags, NBCON_USE_ATOMIC)) + else if (__console_is_usable(console, console->flags, + consoles_suspended, NBCON_USE_ATOMIC)) __pr_flush(console, 1000, true); =20 /* Disable it unconditionally */ --=20 2.52.0