From: John Ogness <john.ogness@linutronix.de>
To: Petr Mladek <pmladek@suse.com>
Cc: Sergey Senozhatsky <senozhatsky@chromium.org>,
Steven Rostedt <rostedt@goodmis.org>,
linux-kernel@vger.kernel.org
Subject: [PATCH printk v2] printk/nbcon: WARN on unsafe reentrance
Date: Fri, 31 Jul 2026 16:45:46 +0206 [thread overview]
Message-ID: <20260731144000.592883-1-john.ogness@linutronix.de> (raw)
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
next reply other threads:[~2026-07-31 14:40 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-31 14:39 John Ogness [this message]
2026-08-19 15:52 ` Petr Mladek
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260731144000.592883-1-john.ogness@linutronix.de \
--to=john.ogness@linutronix.de \
--cc=linux-kernel@vger.kernel.org \
--cc=pmladek@suse.com \
--cc=rostedt@goodmis.org \
--cc=senozhatsky@chromium.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®