From nobody Tue Feb 10 01:35:15 2026 Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) (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 9E33A3148C1 for ; Sat, 27 Dec 2025 12:16:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766837821; cv=none; b=C7siRF9Sz+lpE5b4KJC8MZS2b2H/MOVpvxhOOuN8ZXsHakXsIo7dN+tG3yVS/NvNYbq/Mhv8ch/bnoXjituloxhcv3cazYspdAKVU2DacYwmGcFD+UzdaMs2gtzmvSISYkHtVsXD4/qyI1XV5baHpr74+iECdOOWoJ9lgOPaevg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766837821; c=relaxed/simple; bh=v10odBRNUVRtYegW6AWVkSJvotaiGNuLgfoYzWWV1rM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=atVKBpDDH2K/6H+i1sPojtVriditUNZq8ZbdyJF89U8/VMWkUqOJojPFu16scj8fF3pi55g8+IWzXBk47IVtrRyOm5ZcEOwlI7DijtLiKw5u3nmjId+xAk+kiKRUMYFgDvM7Cc8SS+6+r6vWhEDXcvCqPO8gjPnmQQJL2SraVSM= 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=DMUmFiWz; arc=none smtp.client-ip=209.85.128.45 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="DMUmFiWz" Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-477ba2c1ca2so81584905e9.2 for ; Sat, 27 Dec 2025 04:16:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1766837817; x=1767442617; 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=TucCmhZOA7i1Z82TbHC9/BloO3wYJZCYcsSdo+RW81I=; b=DMUmFiWzHX0o702RXlNMcEQ2cD/DjpnfuoHHOJoTIcKKhZIo9omcFr3imdCVOqBaOg SVQNjLoTegksSaT63LNuwneYGO4tCgcISdG8wQaQIXAifa+se/Fr4PqdJB9sC8YAUalh RM+y7BagUND0Ml2nxuZKJCZMr7qGQfnzG/lF+/8zdVKg8Z9N8WcR+WA1fqxqqg1865bU V5sTglDxntuHDXoX9jjEUqtY88NA4CNaWtQhfgXEat2ltH88kk6O4dMte8GJ1N7CnFvy +1Qmm3vou72xsyYOlRjnLCNr6BnDjHHtZAcVTTn6jnmQYQpZtvTO9v3HC6v9KZgpSCA4 xOMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1766837817; x=1767442617; 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=TucCmhZOA7i1Z82TbHC9/BloO3wYJZCYcsSdo+RW81I=; b=QYmpqLLkp9iSxiWLuvw1y7veG61f+92fWw4+a42ru/QxOJ0OpqIp8uGfz5svMd1Gx+ yFHZ75IfdurL9Kd2lTZmd/IHLJmS0x1EOQFFWfR45DwdHlYaE/FCAXr9wkH9ZT5s+aTe 6XMfPQRBb2OGH/BJuVVmZMVpau5+VHoCb+CQIE4jdGKmOVRpj61Gfb1vvH/smUeh6ezX DRYsxnlAuYmJyP6mj2EIzQeaLMmRo0ZJIVgC9Cldk+/o49PJp2AbTSxakW6gb+ykYdQV y/IRpJTd7KQRhVoS/L/7Zq5ajD8oQTKBC/yqlYY5B8WujMV1+NPhP8ia0B5uaOaW9pNP 1DVQ== X-Forwarded-Encrypted: i=1; AJvYcCVZBM+e6DmK/Bpdp2arLbZde3hSqQq+AtE+n+bQ1ecNx+UJ2ZtsAvhnS1/p92nvOwv5KilWDMPni+4/xXM=@vger.kernel.org X-Gm-Message-State: AOJu0YyLCcuHa2E4LdibfkMx/dw6apYfRaZrtjt1DmdB8Lyhr/JUi2sL 8NwgO7XrPGQpqtadWnxVuvzKZL5p8+rWmPE5vdgvBxGBZRBGf0D7/yaHQeElnNbvXG4= X-Gm-Gg: AY/fxX5NVhbD8c5AXpOgFz6/hXGwUVjpZCnrI6PzrTUf26j3Tv+n5iHKOCNfHsBCJDU MVZGJ+kkXp26kq9GJRYrOzE9Ti/iBIX/4rANWrKuyWEgaa/QcBUj57xCTKFnRHGiOOy3E3eUoeA p4H159ZFFQg30C3TvzpYWw3JZGl8AUwPi3uzbE5yLgAuKhzfK0fk7295Qc7USu4/xxWYcrJTsPE GiAjuo3oZg7g/+frq4XhtNEp/pzc/89M8iklWhsVAaeTYq9bfs03116p/m0yEcRMF5Y79D5xlB1 1JDtM37QtQjbeSIExFu5lb9klDiJPO7LXRUWYLN351rDjv5+YdQ77cBRTiwFPuXptPOV5wdp7iK vCeFrVHMi2IEEehpr88d7x2kZ0XxmlWZOo+ELkGv9LoN5LIM3L5aS9EWv1uUBvIRrr7Y1FgydpC 00Jb16hYVW X-Google-Smtp-Source: AGHT+IF/Ogs7VBJ7Lrr7CGG7veshYzlT60dJ+vTxBr8CJY/jnjI8AOD4UQ6PSSMzci7/2/zJylqGqg== X-Received: by 2002:a05:600c:314f:b0:47d:4fbe:e6cc with SMTP id 5b1f17b1804b1-47d4fbee749mr22553095e9.13.1766837816753; Sat, 27 Dec 2025 04:16:56 -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.16.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 27 Dec 2025 04:16:56 -0800 (PST) From: Marcos Paulo de Souza Date: Sat, 27 Dec 2025 09:16:08 -0300 Subject: [PATCH 01/19] printk/nbcon: Use an enum to specify the required callback in console_is_usable() 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-1-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=7808; i=mpdesouza@suse.com; s=20231031; h=from:subject:message-id; bh=v10odBRNUVRtYegW6AWVkSJvotaiGNuLgfoYzWWV1rM=; b=pFG5z/R9mPhdW0GcbWwBqAYRxphqjaw37XiHB8zK2Svw6cgWPnnbt5ix8LVRTlDSXoMKx6YOe j641rf88XbSCyYZnTx7OjU6MTkBS6ecM7BDrludb53BNNBG+/Mhcz0A X-Developer-Key: i=mpdesouza@suse.com; a=ed25519; pk=/Ni/TsKkr69EOmdZXkp1Q/BlzDonbOBRsfPa18ySIwU= The current usage of console_is_usable() is clumsy. The parameter @use_atomic is boolean and thus not self-explanatory. The function is called twice in situations when there are no-strict requirements. Replace it with enum nbcon_write_cb which provides a more descriptive values for all 3 situations: atomic, thread or any. Note that console_is_usable() checks only NBCON_USE_ATOMIC because .write_thread() callback is mandatory. But the other two values still make sense because they describe the intention of the caller. Suggested-by: Petr Mladek Signed-off-by: Marcos Paulo de Souza Reviewed-by: John Ogness --- arch/um/kernel/kmsg_dump.c | 3 ++- include/linux/console.h | 20 +++++++++++++++++--- kernel/debug/kdb/kdb_io.c | 2 +- kernel/printk/nbcon.c | 8 ++++---- kernel/printk/printk.c | 16 ++++++++-------- 5 files changed, 32 insertions(+), 17 deletions(-) diff --git a/arch/um/kernel/kmsg_dump.c b/arch/um/kernel/kmsg_dump.c index fc0f543d1d8e..8ae38308b67c 100644 --- a/arch/um/kernel/kmsg_dump.c +++ b/arch/um/kernel/kmsg_dump.c @@ -31,7 +31,8 @@ static void kmsg_dumper_stdout(struct kmsg_dumper *dumper, * expected to output the crash information. */ if (strcmp(con->name, "ttynull") !=3D 0 && - console_is_usable(con, console_srcu_read_flags(con), true)) { + console_is_usable(con, console_srcu_read_flags(con), + NBCON_USE_ATOMIC)) { break; } } diff --git a/include/linux/console.h b/include/linux/console.h index fc9f5c5c1b04..35c03fc4ed51 100644 --- a/include/linux/console.h +++ b/include/linux/console.h @@ -202,6 +202,19 @@ enum cons_flags { CON_NBCON_ATOMIC_UNSAFE =3D BIT(9), }; =20 +/** + * enum nbcon_write_cb - Defines which nbcon write() callback must be used= based + * on the caller context. + * @NBCON_USE_ATOMIC: Use con->write_atomic(). + * @NBCON_USE_THREAD: Use con->write_thread(). + * @NBCON_USE_ANY: The caller does not have any strict requirements. + */ +enum nbcon_write_cb { + NBCON_USE_ATOMIC, + NBCON_USE_THREAD, + NBCON_USE_ANY, +}; + /** * struct nbcon_state - console state for nbcon consoles * @atom: Compound of the state fields for atomic operations @@ -622,7 +635,8 @@ extern void nbcon_kdb_release(struct nbcon_write_contex= t *wctxt); * which can also play a role in deciding if @con can be used to print * records. */ -static inline bool console_is_usable(struct console *con, short flags, boo= l use_atomic) +static inline bool console_is_usable(struct console *con, short flags, + enum nbcon_write_cb nwc) { if (!(flags & CON_ENABLED)) return false; @@ -631,7 +645,7 @@ static inline bool console_is_usable(struct console *co= n, short flags, bool use_ return false; =20 if (flags & CON_NBCON) { - if (use_atomic) { + if (nwc & NBCON_USE_ATOMIC) { /* The write_atomic() callback is optional. */ if (!con->write_atomic) return false; @@ -679,7 +693,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 use_atomic) { return false; } + enum nbcon_write_cb nwc) { return false; } #endif =20 extern int console_set_on_cmdline; diff --git a/kernel/debug/kdb/kdb_io.c b/kernel/debug/kdb/kdb_io.c index 61c1690058ed..6ffb962392a4 100644 --- a/kernel/debug/kdb/kdb_io.c +++ b/kernel/debug/kdb/kdb_io.c @@ -591,7 +591,7 @@ static void kdb_msg_write(const char *msg, int msg_len) for_each_console_srcu(c) { short flags =3D console_srcu_read_flags(c); =20 - if (!console_is_usable(c, flags, true)) + if (!console_is_usable(c, flags, NBCON_USE_ATOMIC)) continue; if (c =3D=3D dbg_io_ops->cons) continue; diff --git a/kernel/printk/nbcon.c b/kernel/printk/nbcon.c index be5a04367e60..13865ef85990 100644 --- a/kernel/printk/nbcon.c +++ b/kernel/printk/nbcon.c @@ -1184,7 +1184,7 @@ static bool nbcon_kthread_should_wakeup(struct consol= e *con, struct nbcon_contex cookie =3D console_srcu_read_lock(); =20 flags =3D console_srcu_read_flags(con); - if (console_is_usable(con, flags, false)) { + if (console_is_usable(con, flags, NBCON_USE_THREAD)) { /* Bring the sequence in @ctxt up to date */ ctxt->seq =3D nbcon_seq_read(con); =20 @@ -1251,7 +1251,7 @@ static int nbcon_kthread_func(void *__console) =20 con_flags =3D console_srcu_read_flags(con); =20 - if (console_is_usable(con, con_flags, false)) + if (console_is_usable(con, con_flags, NBCON_USE_THREAD)) backlog =3D nbcon_emit_one(&wctxt, false); =20 console_srcu_read_unlock(cookie); @@ -1650,7 +1650,7 @@ static void __nbcon_atomic_flush_pending(u64 stop_seq) if (!(flags & CON_NBCON)) continue; =20 - if (!console_is_usable(con, flags, true)) + if (!console_is_usable(con, flags, NBCON_USE_ATOMIC)) continue; =20 if (nbcon_seq_read(con) >=3D stop_seq) @@ -1904,7 +1904,7 @@ void nbcon_device_release(struct console *con) */ cookie =3D console_srcu_read_lock(); printk_get_console_flush_type(&ft); - if (console_is_usable(con, console_srcu_read_flags(con), true) && + if (console_is_usable(con, console_srcu_read_flags(con), NBCON_USE_ATOMIC= ) && !ft.nbcon_offload && prb_read_valid(prb, nbcon_seq_read(con), NULL)) { /* diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 7394f1b6033b..5f4b84f9562e 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -3203,7 +3203,9 @@ static bool console_flush_one_record(bool do_cond_res= ched, u64 *next_seq, bool * if ((flags & CON_NBCON) && (ft.nbcon_atomic || ft.nbcon_offload)) continue; =20 - if (!console_is_usable(con, flags, !do_cond_resched)) + if (!console_is_usable(con, flags, + do_cond_resched ? NBCON_USE_THREAD + : NBCON_USE_ATOMIC)) continue; any_usable =3D true; =20 @@ -3392,7 +3394,7 @@ void console_unblank(void) */ cookie =3D console_srcu_read_lock(); for_each_console_srcu(c) { - if (!console_is_usable(c, console_srcu_read_flags(c), true)) + if (!console_is_usable(c, console_srcu_read_flags(c), NBCON_USE_ATOMIC)) continue; =20 if (c->unblank) { @@ -3432,7 +3434,7 @@ void console_unblank(void) =20 cookie =3D console_srcu_read_lock(); for_each_console_srcu(c) { - if (!console_is_usable(c, console_srcu_read_flags(c), true)) + if (!console_is_usable(c, console_srcu_read_flags(c), NBCON_USE_ATOMIC)) continue; =20 if (c->unblank) @@ -3633,7 +3635,7 @@ static bool legacy_kthread_should_wakeup(void) if ((flags & CON_NBCON) && (ft.nbcon_atomic || ft.nbcon_offload)) continue; =20 - if (!console_is_usable(con, flags, false)) + if (!console_is_usable(con, flags, NBCON_USE_THREAD)) continue; =20 if (flags & CON_NBCON) { @@ -4204,7 +4206,7 @@ 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, true)) + else if (console_is_usable(console, console->flags, NBCON_USE_ATOMIC)) __pr_flush(console, 1000, true); =20 /* Disable it unconditionally */ @@ -4485,10 +4487,8 @@ static bool __pr_flush(struct console *con, int time= out_ms, bool reset_on_progre * that they make forward progress, so only increment * @diff for usable consoles. */ - if (!console_is_usable(c, flags, true) && - !console_is_usable(c, flags, false)) { + if (!console_is_usable(c, flags, NBCON_USE_ANY)) continue; - } =20 if (flags & CON_NBCON) { printk_seq =3D nbcon_seq_read(c); --=20 2.52.0