Re: [PATCH v4 1/1] braille: nbcon: Allow to use a serial console with NBCON API as Braille console
From: Petr Mladek
Date: Fri Oct 02 2026 - 04:51:00 EST
On Thu 2026-10-01 17:38:01, John Ogness wrote:
> On 2026-10-01, Petr Mladek <pmladek@xxxxxxxx> wrote:
> > The Braille console is not registered in console_list. Instead, it is
> > integrated with the virtual terminal (VT) and shows what is displayed
> > on the terminal. It writes the data using con->write*() callback
> > of the associated serial console driver.
> >
> > braille_write() is called from the VT code under console_lock().
> > The associated serial console driver can be converted to the NBCON API
> > though. The situation is similar to flushing nbcon consoles in the legacy
> > loop when some boot consoles are still registered, see
> > nbcon_legacy_emit_next_record().
> >
> > But there is a big difference though. braille_write() is not directly
> > called from the code paths flushing registered consoles. The VT code
> > expects that braille_write() succeeds. It does not replay the message
> > when it can't acquire the ownership. As a result, braille_write():
> >
> > + must try harder to get the ownership.
> >
> > + has to be synchronized only against non-printk serial console
> > which depend nbcon_device_try_acquire() using NBCON_PRIO_NORMAL.
> >
> > Let's look at it from another side and try to simulate the original
> > locking using the NBCON API:
> >
> > 1. Take con->device_lock(), aka the port->lock in the legacy serial
> > console driver.
> >
> > 2. Acquire nbcon context to provide some synchronization for a panic()
> > context. Use NBCON_PRIO_NORMAL because it contends only with
> > nbcon_device_try_acquire() users. Do it in a busy loop. It should
> > always succeed when con->device_lock() succeeded because all other
> > users do the same. The only exception is when the context get acquired
> > by a CPU handling panic.
> >
> > 3. In panic, disable interrupts and try to acquire the nbcon context.
> > Use NBCON_PRIO_PANIC. And try even an unsafe takeover because
> > otherwise the Braille console won't see the text shown during panic().
> > It is similar to the oops_in_progress/trylock handling in the legacy
> > serial console driver.
> >
> > Finally, avoid the newline prepending logic in the existing serial console
> > drivers when they are used as a Braille console. As explained above,
> > the Braille console shows the last modified line on the terminal (VT).
> > braille_write() is called when single characters are added. Most
> > messages are not ended by newline. Anyway, the VT code does not have
> > logic to reply partially printed messages.
> >
> > Fixes: 13189fa73afa ("printk: nbcon: Rely on kthreads for normal operation")
> > Signed-off-by: Petr Mladek <pmladek@xxxxxxxx>
>
> Minor comments follow, but no need to send a v5 for them. You could fix
> them up on your own.
>
> Reviewed-by: John Ogness <john.ogness@xxxxxxxxxxxxx>
Thanks a lot for the review.
I have updated the patch as you suggested and committed it into
printk/linux.git, branch for-7.3-hotfix, see
https://git.kernel.org/pub/scm/linux/kernel/git/printk/linux.git/commit/?id=c83e3d2912432107148cc5e288ddd153a84c0f43
It should be good enough for 7.3. And I wanted to get it into
linux-next ASAP.
There is still an open problem with the dependency on CONFIG_PRINTK
to fix the Sashiko complains. We might add it as a separate patch.
But we might also try to fix it properly by enabling nbcon.c code
even when CONFIG_PRINTK is disabled, ...
Best Regards,
Petr