linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: John Ogness <john.ogness@linutronix.de>
To: Leo Yan <leo.yan@arm.com>
Cc: Petr Mladek <pmladek@suse.com>,
	Sergey Senozhatsky <senozhatsky@chromium.org>,
	Steven Rostedt <rostedt@goodmis.org>,
	Breno Leitao <leitao@debian.org>,
	linux@armlinux.org.uk, paulmck@kernel.org,
	usamaarif642@gmail.com, linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, kernel-team@meta.com,
	rmikey@meta.com
Subject: Re: [PATCH] printk/nbcon: Restore IRQ in atomic flush after each emitted record
Date: Wed, 03 Dec 2025 13:33:38 +0106	[thread overview]
Message-ID: <87ikenyclh.fsf@jogness.linutronix.de> (raw)
In-Reply-To: <20251202162639.GD724103@e132581.arm.com>

On 2025-12-02, Leo Yan <leo.yan@arm.com> wrote:
>> I am not really happy about all the local_irq_restore() usage. Using
>> guard syntax would be nice here, but AFAICT there is no guard for
>> local_irq_save()/_restore().
>
> Sorry for suddenly jumping in.  Wouldn't guard(irqsave)() be helpful
> here?

Thanks, I was not aware of the irqsave variant. We would want the scoped
version. So something like this?

$ git diff -w
diff --git a/kernel/printk/nbcon.c b/kernel/printk/nbcon.c
index 3fa403f9831f..55beb64c4f4a 100644
--- a/kernel/printk/nbcon.c
+++ b/kernel/printk/nbcon.c
@@ -1557,6 +1557,14 @@ static int __nbcon_atomic_flush_pending_con(struct console *con, u64 stop_seq)
 	ctxt->allow_unsafe_takeover	= nbcon_allow_unsafe_takeover();
 
 	while (nbcon_seq_read(con) < stop_seq) {
+		/*
+		 * Atomic flushing does not use console driver synchronization
+		 * (i.e. it does not hold the port lock for uart consoles).
+		 * Therefore IRQs must be disabled to avoid being interrupted
+		 * and then calling into a driver that will deadlock trying
+		 * to acquire console ownership.
+		 */
+		scoped_guard(irqsave) {
 			if (!nbcon_context_try_acquire(ctxt, false))
 				return -EPERM;
 
@@ -1569,6 +1577,7 @@ static int __nbcon_atomic_flush_pending_con(struct console *con, u64 stop_seq)
 				return -EAGAIN;
 
 			nbcon_context_release(ctxt);
+		}
 
 		if (!ctxt->backlog) {
 			/* Are there reserved but not yet finalized records? */

John


  reply	other threads:[~2025-12-03 12:27 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20251202135832.156559-1-pmladek@suse.com>
2025-12-02 14:33 ` [PATCH] printk/nbcon: Restore IRQ in atomic flush after each emitted record John Ogness
2025-12-02 16:26   ` Leo Yan
2025-12-03 12:27     ` John Ogness [this message]
2025-12-04 10:20       ` 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=87ikenyclh.fsf@jogness.linutronix.de \
    --to=john.ogness@linutronix.de \
    --cc=kernel-team@meta.com \
    --cc=leitao@debian.org \
    --cc=leo.yan@arm.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=paulmck@kernel.org \
    --cc=pmladek@suse.com \
    --cc=rmikey@meta.com \
    --cc=rostedt@goodmis.org \
    --cc=senozhatsky@chromium.org \
    --cc=usamaarif642@gmail.com \
    /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;
as well as URLs for NNTP newsgroup(s).