[PATCH] printk/nbcon: Restore IRQ in atomic flush after each emitted record
John Ogness
john.ogness at linutronix.de
Tue Dec 2 06:33:54 PST 2025
On 2025-12-02, Petr Mladek <pmladek at suse.com> wrote:
> diff --git a/kernel/printk/nbcon.c b/kernel/printk/nbcon.c
> index 3fa403f9831f..6b8becb6ecd9 100644
> --- a/kernel/printk/nbcon.c
> +++ b/kernel/printk/nbcon.c
> @@ -1549,6 +1549,7 @@ static int __nbcon_atomic_flush_pending_con(struct console *con, u64 stop_seq)
> {
> struct nbcon_write_context wctxt = { };
> struct nbcon_context *ctxt = &ACCESS_PRIVATE(&wctxt, ctxt);
> + unsigned long flags;
> int err = 0;
>
> ctxt->console = con;
> @@ -1557,18 +1558,31 @@ 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) {
> - if (!nbcon_context_try_acquire(ctxt, false))
> + /*
> + * 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.
> + */
> + local_irq_save(flags);
> + if (!nbcon_context_try_acquire(ctxt, false)) {
> + local_irq_restore(flags);
> return -EPERM;
> + }
>
> /*
> * nbcon_emit_next_record() returns false when the console was
> * handed over or taken over. In both cases the context is no
> * longer valid.
> */
> - if (!nbcon_emit_next_record(&wctxt, true))
> + if (!nbcon_emit_next_record(&wctxt, true)) {
> + local_irq_restore(flags);
> return -EAGAIN;
> + }
>
> nbcon_context_release(ctxt);
> + local_irq_restore(flags);
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(). :-/ And I could not come up with any other
alternative that looked more elegant. So let's just keep it this way.
Reviewed-by: John Ogness <john.ogness at linutronix.de>
More information about the linux-arm-kernel
mailing list