Re: [PATCH 2/2] serial: amba-pl011: keep console clock enabled for atomic writes

From: Petr Mladek

Date: Mon Jul 20 2026 - 07:53:07 EST


Adding ARM mailing list into Cc.

On Sun 2026-07-19 08:35:02, Karl Mehltretter wrote:
> pl011_console_write_atomic() runs from nbcon atomic context, where
> sleeping is not allowed. It calls clk_enable(), which takes the
> common-clk enable_lock. Under PREEMPT_RT that is a sleeping lock:
> clk_enable_lock() first tries spin_trylock_irqsave(), but on contention
> falls back to spin_lock_irqsave(), so an atomic-context printk on an RT
> kernel with a clk-backed pl011 can trip:
>
> BUG: sleeping function called from invalid context at spinlock_rt.c:48
> __might_resched from rt_spin_lock
> rt_spin_lock from clk_enable_lock
> clk_enable_lock from clk_enable
> clk_enable from pl011_console_write_atomic
> ... from vprintk_emit
>
> This was found and reproduced on 32-bit ARM with PREEMPT_RT. In
> addition, write_atomic() may be invoked from NMI context and is
> documented to avoid locking. Since clk_enable() acquires the
> common-clock enable_lock, removing it from the callback also avoids a
> potentially unsafe NMI lock acquisition.
>
> An nbcon atomic-capable console must be printable from any context, so
> the clock cannot be gated between writes. Enable the clock while the
> console is registered: use clk_prepare_enable() in
> pl011_console_setup(), release it via clk_disable_unprepare() in the
> console .exit() callback, and drop the per-write
> clk_enable()/clk_disable() pairs from write_atomic() and
> write_thread().
>
> Keeping UARTCLK enabled may increase idle power on platforms where it
> would otherwise be gated between console writes.

Just to be sure. Is this acceptable, please?

I have no idea what is the real life effect. It might be negligible.
Or maybe it does not effect production systems at all because
they do not have the serial console enabled.

I just wonder if it might considerably increase the battery usage
of some devices, e.g. watches or earbuds, just because of the possibility
to write emergency messages via the serial console.

Best Regards,
Petr