mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH printk v2] printk/nbcon: WARN on unsafe reentrance
@ 2026-07-31 14:39 John Ogness
  2026-08-19 15:52 ` Petr Mladek
  0 siblings, 1 reply; 2+ messages in thread
From: John Ogness @ 2026-07-31 14:39 UTC (permalink / raw)
  To: Petr Mladek; +Cc: Sergey Senozhatsky, Steven Rostedt, linux-kernel

Since the nbcon unsafe enter/exit functions are simply toggling a
state boolean, a buggy nbcon driver might enter an unsafe section
when the context is already in an unsafe section and it would go
unnoticed, even though doing so is a bug. Unsafe sections are not
reentrant!

Add a WARN_ON_ONCE() to nbcon_enter_unsafe() if the context is
already in an unsafe section.

Signed-off-by: John Ogness <john.ogness@linutronix.de>
Link: https://lore.kernel.org/lkml/87o6fwms02.fsf@jogness.linutronix.de
---
 Changes since v1:

 - Move the WARN to after the can_proceed() check. Otherwise
   cur.unsafe could be referring to a different owning context.

 kernel/printk/nbcon.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/kernel/printk/nbcon.c b/kernel/printk/nbcon.c
index 4b03b019cd5ee..e88ddd742d5a0 100644
--- a/kernel/printk/nbcon.c
+++ b/kernel/printk/nbcon.c
@@ -848,6 +848,9 @@ static bool __nbcon_context_update_unsafe(struct nbcon_context *ctxt, bool unsaf
 		if (!nbcon_context_can_proceed(ctxt, &cur))
 			return false;
 
+		/* Unsafe sections are not reentrant. */
+		WARN_ON_ONCE(unsafe && cur.unsafe);
+
 		new.atom = cur.atom;
 		new.unsafe = unsafe;
 	} while (!nbcon_state_try_cmpxchg(con, &cur, &new));

base-commit: 703a9d76a45dd97b19b2432fc1ba4beb4d67a94f
-- 
2.47.3


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-08-19 15:52 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-07-31 14:39 [PATCH printk v2] printk/nbcon: WARN on unsafe reentrance John Ogness
2026-08-19 15:52 ` Petr Mladek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®