braille: nbcon: Fix Braille console for NBCON API
Subsystems (6)
Petr Mladek
maintainerv4 cover braille: nbcon: Fix Braille console for NBCON API
Hi,
this is v4 patch which tries to fix Braille console driver to work with serial console drivers ported to NBCON API.
I did a quick turnaround because it would be nice to get it into 7.3. Many people attend Plumbers conference the following week...
Changes against v3:
+ Removed unnecessary "locked" variable. [John]
+ Allow to use console driver even without write_atomic, except for panic mode [John]
+ Added parenthesis around (con->flags & CON_BRL) [John]
+ Exported nbcon_write_context_is_braille() [Sashiko]
+ Fixed many typos and wording [John]
Changes against v2:
+ Use con->device_lock() for non-panic case. Try even an unsafe acquire in panic(). This simulates the legacy locking using NBCON API.
+ Return when the nbcon context can't be acquired in panic(). The NBCON API is not ready to ignore the lock. Well, it should never happen in practice because the unsafe acquire...
+ Avoid the newline prepend logic in all serial consoles ported to NBCON API which have it. Add two APIs for checking whether either "con" or "wctxt" is in Braille mode.
+ Update commit message and comments in the code.
Changes against v1:
+ Merged into one patch. It is hard to explain nbcon_braille*() API without the user.
+ Reworked the locking, see the commit message for more details.
+ Fixed the check of CON_NBCON_ATOMIC_UNSAFE [Sashiko]
IMPORTANT: The solution is not safe in PREEMPT_RT. But it is better
then nothing. We could either solve it in v3. Or we could fix it later.
[v1] https://lore.kernel.org/r/[email protected]
[v2] https://lore.kernel.org/r/[email protected]
[v3] https://lore.kernel.org/r/[email protected]
Petr Mladek (1):
braille: nbcon: Allow to use a serial console with NBCON API as
Braille console
.../accessibility/braille/braille_console.c | 60 +++++++++++++- drivers/tty/serial/8250/8250_port.c | 5 +- drivers/tty/serial/amba-pl011.c | 2 +- drivers/tty/serial/imx.c | 2 +- drivers/tty/serial/sifive.c | 2 +- include/linux/console.h | 15 ++++ kernel/printk/nbcon.c | 79 +++++++++++++++++++ 7 files changed, 159 insertions(+), 6 deletions(-)
Signature · 1 line
2.55.0
Petr Mladek
maintainerPATCH v4 1/1 braille: nbcon: Allow to use a serial console with NBCON API as Braille console
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.
--- .../accessibility/braille/braille_console.c | 60 +++++++++++++- drivers/tty/serial/8250/8250_port.c | 5 +- drivers/tty/serial/amba-pl011.c | 2 +- drivers/tty/serial/imx.c | 2 +- drivers/tty/serial/sifive.c | 2 +- include/linux/console.h | 15 ++++ kernel/printk/nbcon.c | 79 +++++++++++++++++++ 7 files changed, 159 insertions(+), 6 deletions(-)
drivers/accessibility/braille/braille_console.c +58 -2
@@ -62,14 +62,50 @@ static void braille_write(u16 *buf) {static u16 lastwrite[WIDTH ];unsigned char data[1 +1 +2 *WIDTH +2 +1 ], csum =0 , *c; +struct nbcon_write_context wctxt = { }; +unsigned long flags;u16 out;int i;if (!braille_co)return ; +/* +* Braille console is not registered in console_list. Instead, it +* is integrated with VT and shows what appears on the graphical +* console under console_lock(). From this POV it is a legacy +* console. But it calls serial console driver which might be +* converted to the NBCON API. It is similar to +* nbcon_legacy_emit_next_record() except that we should try +* harder to get the lock. Otherwise, the Braille device won't show +* everything what is displayed on the terminal. +* +* In short, simulate the original locking using NBCON API. +*/ +if (braille_co->flags &CON_NBCON ) { +if (panic_on_this_cpu ()) { +/* +* This should be good enough in practice. Most/all +* serial console drivers have the atomic callback. +*/ +if (!braille_co->write_atomic) +return ; + +local_irq_save (flags); +/* NBCON API strictly requires the ownership. */ +if (!nbcon_braille_try_acquire (braille_co, &wctxt)) { +local_irq_restore (flags); +return ; + } + }else { + braille_co->device_lock (braille_co, &flags); +while (!nbcon_braille_try_acquire (braille_co, &wctxt)) +cpu_relax (); + } + } +if (!memcmp (lastwrite, buf,WIDTH *sizeof (*buf))) -return ; + goto unlock_nbcon;memcpy (lastwrite, buf,WIDTH *sizeof (*buf));#define SOH 1
@@ -102,7 +138,24 @@ static void braille_write(u16 *buf) *c++ = csum; *c++ =ETX ; - braille_co->write (braille_co, data, c - data); +if (braille_co->flags &CON_NBCON ) { +nbcon_write_context_set_buf (&wctxt, (char *)data, c - data); +if (panic_on_this_cpu ()) + braille_co->write_atomic (braille_co, &wctxt); +else + braille_co->write_thread (braille_co, &wctxt); + }else { + braille_co->write (braille_co, data, c - data); + } + +unlock_nbcon: +if (braille_co->flags &CON_NBCON ) { +nbcon_braille_release (&wctxt); +if (panic_on_this_cpu ()) +local_irq_restore (flags); +else + braille_co->device_unlock (braille_co, flags); + } }/* Follow the VC cursor*/
@@ -353,13 +406,16 @@ int braille_register_console(struct console *console, int index,if (!console_options)/* Only support VisioBraille for now */ console_options ="57600o8" ; +if (braille_co)return -ENODEV ; +if (console->setup) { ret = console->setup (console, console_options);if (ret !=0 )return ret; } + console->flags |=CON_ENABLED ; console->index = index; braille_co = console;
drivers/tty/serial/8250/8250_port.c +4 -1
@@ -3417,8 +3417,11 @@ static void __serial8250_console_write(struct uart_8250_port *up,* If the console printer did not fully output the previous line, it * must have been handed or taken over. Insert a newline in order to * maintain clean output. +* +* Braille consoles are an exception. The serial port is not used +* for printk(). The driver is supposed to write exactly what it gets. */ -if (!up->console_line_ended) { +if (unlikely (!up->console_line_ended && !nbcon_write_context_is_braille (wctxt))) {if (use_fifo)__serial8250_console_fifo_write (up, wctxt,"\n" ,1 );else
drivers/tty/serial/amba-pl011.c +1 -1
@@ -2656,7 +2656,7 @@ pl011_console_write_atomic(struct console *co, struct nbcon_write_context *wctxt uap, REG_CR); } -if (!uap->console_line_ended) +if (unlikely (!uap->console_line_ended && !nbcon_is_braille (co)))uart_console_write (&uap->port,"\n" ,1 , pl011_console_putchar);uart_console_write (&uap->port, wctxt->outbuf, wctxt->len, pl011_console_putchar);
drivers/tty/serial/imx.c +1 -1
@@ -2136,7 +2136,7 @@ static void imx_uart_console_write_atomic(struct console *co,imx_uart_writel (sport, ucr1,UCR1 );imx_uart_writel (sport, old_ucr.ucr2 |UCR2_TXEN ,UCR2 ); -if (!sport->last_putchar_was_newline) +if (unlikely (!sport->last_putchar_was_newline && !nbcon_is_braille (co)))uart_console_write (port,"\n" ,1 , imx_uart_console_putchar);uart_console_write (port, wctxt->outbuf, wctxt->len, imx_uart_console_putchar);
drivers/tty/serial/sifive.c +1 -1
@@ -821,7 +821,7 @@ static void sifive_serial_console_write_atomic(struct console *co, ier =__ssp_readl (ssp,SIFIVE_SERIAL_IE_OFFS );__ssp_writel (0 ,SIFIVE_SERIAL_IE_OFFS , ssp); -if (!ssp->console_line_ended) +if (unlikely (!ssp->console_line_ended && !nbcon_is_braille (co)))uart_console_write (port,"\n" ,1 , sifive_serial_console_putchar);uart_console_write (port, wctxt->outbuf, wctxt->len, sifive_serial_console_putchar);
include/linux/console.h +15 -0
@@ -615,6 +615,15 @@ extern bool nbcon_allow_unsafe_takeover(void);extern bool nbcon_kdb_try_acquire (struct console *con,struct nbcon_write_context *wctxt);extern void nbcon_kdb_release (struct nbcon_write_context *wctxt); +extern bool nbcon_write_context_is_braille (struct nbcon_write_context *wctxt); +extern bool nbcon_braille_try_acquire (struct console *con, +struct nbcon_write_context *wctxt); +extern void nbcon_braille_release (struct nbcon_write_context *wctxt); + +static inline bool nbcon_is_braille (struct console *con) +{ +return con && (con->flags &CON_BRL ); +}/* * Check if the given console is currently capable and allowed to print
@@ -678,8 +687,14 @@ static inline void nbcon_reacquire_nobuf(struct nbcon_write_context *wctxt) { }static inline bool nbcon_kdb_try_acquire (struct console *con,struct nbcon_write_context *wctxt) {return false; }static inline void nbcon_kdb_release (struct nbcon_write_context *wctxt) { } +static inline +bool nbcon_write_context_is_braille (struct nbcon_write_context *wctxt) {return false; }static inline bool console_is_usable (struct console *con,short flags,bool use_atomic) {return false; } +static inline bool nbcon_braille_try_acquire (struct console *con, +struct nbcon_write_context *wctxt) {return false; } +static inline void nbcon_braille_release (struct nbcon_write_context *wctxt) { } +static inline bool nbcon_is_braille (struct console *con) {return false; }#endif extern int console_set_on_cmdline;
kernel/printk/nbcon.c +79 -0
88 lines not on this page · raw message
Signature · 1 line
2.55.0
[email protected]
AI reviewRe: [PATCH v4 1/1] braille: nbcon: Allow to use a serial console with NBCON API as Braille console
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] console: deadlock in braille_write() from atomic/IRQ context - [High] console: infinite loop in…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] console: deadlock in braille_write() from atomic/IRQ context
- [High] console: infinite loop in braille_write() when CONFIG_PRINTK is disabled --
commit 0bb1344e643dce4e38416fdf04095c16fe6023c8
Author: Petr Mladek <[email protected]>
braille: nbcon: Allow to use a serial console with NBCON API as Braille console
This patch integrates the Braille console with the NBCON API by allowing braille_write() to attempt acquiring NBCON ownership before writing. It simulates the original locking using nbcon_braille_try_acquire() and routes output through write_atomic() or write_thread() callbacks.
Quoted 3 lines
drivers/accessibility/braille/braille_console.c +0
-0
[ ... ]
Quoted 1 line
drivers/accessibility/braille/braille_console.c +0
-0@@ -62,14 +62,50 @@ static void braille_write(u16 *buf)
[ ... ]
Quoted 11 lines
drivers/accessibility/braille/braille_console.c +11
-0+if (braille_co->flags &CON_NBCON ) { +if (panic_on_this_cpu ()) { +/* +* This should be good enough in practice. Most/all +* serial console drivers have the atomic callback. +*/ +if (!braille_co->write_atomic) +return ; + +local_irq_save (flags); +/* NBCON API strictly requires the ownership. */
drivers/accessibility/braille/braille_console.c static void braille_write(u16 *buf) · line 105
Quoted 10 lines
drivers/accessibility/braille/braille_console.c +10
-0+if (!nbcon_braille_try_acquire (braille_co, &wctxt)) { +local_irq_restore (flags); +return ; + } + }else { + braille_co->device_lock (braille_co, &flags); +while (!nbcon_braille_try_acquire (braille_co, &wctxt)) +cpu_relax (); + } + }
[Severity: High]
Could this lead to a deadlock? braille_write() can be invoked by VT notifiers from atomic or IRQ contexts (e.g., from keyboard interrupts or console_flush_all()). By calling device_lock() and spinning on NBCON ownership with a cpu_relax() loop, if the interrupted context already holds the lock (like an active nbcon flush), nbcon_braille_try_acquire() will permanently return false, causing an infinite busy-loop.
[ ... ]
Quoted 1 line
drivers/accessibility/braille/braille_console.c +0
-0@@ -102,7 +138,24 @@ static void braille_write(u16 *buf)
[ ... ]
drivers/accessibility/braille/braille_console.c static void braille_write(u16 *buf) · line 146
Quoted 7 lines
drivers/accessibility/braille/braille_console.c +6
-1- braille_co->write (braille_co, data, c - data); +if (braille_co->flags &CON_NBCON ) { +nbcon_write_context_set_buf (&wctxt, (char *)data, c - data); +if (panic_on_this_cpu ()) + braille_co->write_atomic (braille_co, &wctxt); +else + braille_co->write_thread (braille_co, &wctxt);
[Severity: High]
Does this violate the write_thread API constraints? The include/linux/console.h documentation specifies that write_thread must strictly execute in a task context. Since braille_write() can be called from an atomic or IRQ context, invoking the kthread-specific callback here could be unsafe.
Quoted 3 lines
drivers/accessibility/braille/braille_console.c +3
-0+ }else { + braille_co->write (braille_co, data, c - data); + }
[ ... ]
Quoted 3 lines
include/linux/console.h +0
-0
[ ... ]
include/linux/console.h static inline void nbcon_reacquire_nobuf(struct nbcon_write_context *wctxt) { } · line 695
Quoted 10 lines
include/linux/console.h +4
-0@@ -678,8 +687,14 @@ static inline void nbcon_reacquire_nobuf(struct nbcon_write_context *wctxt) { }static inline bool nbcon_kdb_try_acquire (struct console *con,struct nbcon_write_context *wctxt) {return false; }static inline void nbcon_kdb_release (struct nbcon_write_context *wctxt) { } +static inline +bool nbcon_write_context_is_braille (struct nbcon_write_context *wctxt) {return false; }static inline bool console_is_usable (struct console *con,short flags,bool use_atomic) {return false; } +static inline bool nbcon_braille_try_acquire (struct console *con, +struct nbcon_write_context *wctxt) {return false; }
[Severity: High]
Could this cause a hard lockup if CONFIG_A11Y_BRAILLE_CONSOLE is enabled but CONFIG_PRINTK is disabled?
Since this fallback stub unconditionally returns false, the while (!nbcon_braille_try_acquire(...)) cpu_relax(); loop in braille_write() will never terminate when triggered by terminal output.
Quoted 3 lines
include/linux/console.h +2
-0+static inline void nbcon_braille_release (struct nbcon_write_context *wctxt) { } +static inline bool nbcon_is_braille (struct console *con) {return false; }#endif
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Petr Mladek
maintainerRe: [PATCH v4 1/1] braille: nbcon: Allow to use a serial console with NBCON API as Braille console
Quoted 43 lines · On Thu 2026-10-01 14:24:07, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] console: deadlock inbraille_write()from atomic/IRQ context
- [High] console: infinite loop inbraille_write()whenCONFIG_PRINTKis disabled --commit
0bb1344e643dce4e38416fdf04095c16fe6023c8
Author: Petr Mladek <[email protected]>braille: nbcon: Allow to use a serial console with NBCON API as Braille console
This patch integrates the Braille console with the NBCON API by allowing
braille_write()to attempt acquiring NBCON ownership before writing. It simulates the original locking usingnbcon_braille_try_acquire()and routes output throughwrite_atomic()orwrite_thread()callbacks.Quoted 3 lines
drivers/accessibility/braille/braille_console.c +0
-0[ ... ]
Quoted 1 line
drivers/accessibility/braille/braille_console.c +0
-0@@ -62,14 +62,50 @@ static void braille_write(u16 *buf)[ ... ]
Quoted 11 lines
drivers/accessibility/braille/braille_console.c +11
-0+if (braille_co->flags &CON_NBCON ) { +if (panic_on_this_cpu ()) { +/* +* This should be good enough in practice. Most/all +* serial console drivers have the atomic callback. +*/ +if (!braille_co->write_atomic) +return ; + +local_irq_save (flags); +/* NBCON API strictly requires the ownership. */ drivers/accessibility/braille/braille_console.c
Quoted 10 lines
drivers/accessibility/braille/braille_console.c +10
-0+if (!nbcon_braille_try_acquire (braille_co, &wctxt)) { +local_irq_restore (flags); +return ; + } + }else { + braille_co->device_lock (braille_co, &flags); +while (!nbcon_braille_try_acquire (braille_co, &wctxt)) +cpu_relax (); + } + }
Quoted 7 lines
[Severity: High]
Could this lead to a deadlock?braille_write()can be invoked by VT notifiers from atomic or IRQ contexts (e.g., from keyboard interrupts orconsole_flush_all()). By callingdevice_lock()and spinning on NBCON ownership with acpu_relax()loop, if the interrupted context already holds the lock (like an active nbcon flush),nbcon_braille_try_acquire()will permanently return false, causing an infinite busy-loop.
The short answer is that we should be on the safe side because it used to work with the legacy uart 8250 console driver which took port->lock as well.
It should work when the code under port->lock:
+ is called with disabled interrupts.
+ do not call VT code (the is no reason to do so).
+ use only printk_deferred() (or better no printk() at all.
All the conditions should be fulfilled. Otherwise, it would cause deadlocks even when the serial console driver is used for printk() in the non-Braille mode.
Quoted 17 lines
[ ... ]
Quoted 1 line
drivers/accessibility/braille/braille_console.c +0
-0@@ -102,7 +138,24 @@ static void braille_write(u16 *buf)[ ... ]
drivers/accessibility/braille/braille_console.c
Quoted 7 lines
drivers/accessibility/braille/braille_console.c +6
-1- braille_co->write (braille_co, data, c - data); +if (braille_co->flags &CON_NBCON ) { +nbcon_write_context_set_buf (&wctxt, (char *)data, c - data); +if (panic_on_this_cpu ()) + braille_co->write_atomic (braille_co, &wctxt); +else + braille_co->write_thread (braille_co, &wctxt);[Severity: High]
Does this violate thewrite_threadAPI constraints? Theinclude/linux/console.hdocumentation specifies thatwrite_threadmust strictly execute in a task context. Sincebraille_write()can be called from an atomic or IRQ context, invoking the kthread-specific callback here could be unsafe.
It should be OK for all the currently converted serial console drivers which are candidates for the Braille console. We might need to revisit this in the future.
Quoted 23 lines
Quoted 3 lines
drivers/accessibility/braille/braille_console.c +3
-0+ }else { + braille_co->write (braille_co, data, c - data); + }[ ... ]
Quoted 3 lines
include/linux/console.h +0
-0[ ... ]
include/linux/console.h static inline void nbcon_reacquire_nobuf(struct nbcon_write_context *wctxt) { } · line 695
Quoted 10 lines
include/linux/console.h +4
-0@@ -678,8 +687,14 @@ static inline void nbcon_reacquire_nobuf(struct nbcon_write_context *wctxt) { }static inline bool nbcon_kdb_try_acquire (struct console *con,struct nbcon_write_context *wctxt) {return false; }static inline void nbcon_kdb_release (struct nbcon_write_context *wctxt) { } +static inline +bool nbcon_write_context_is_braille (struct nbcon_write_context *wctxt) {return false; }static inline bool console_is_usable (struct console *con,short flags,bool use_atomic) {return false; } +static inline bool nbcon_braille_try_acquire (struct console *con, +struct nbcon_write_context *wctxt) {return false; }[Severity: High]
Could this cause a hard lockup ifCONFIG_A11Y_BRAILLE_CONSOLEis enabled butCONFIG_PRINTKis disabled?
Quoted 3 lines
Since this fallback stub unconditionally returns false, the while (!nbcon_braille_try_acquire(...))
cpu_relax(); loop inbraille_write()will never terminate when triggered by terminal output.
Good point!
But there is a bigger problem. kernel/printk/nbcon.c is compiled only when CONFIG_PRINTK is enabled. We expected that con->write*() callbacks will be called only when there are printk() messages.
The Braille console is a new use-case. It uses con->write() callbacks even for non-printk messages.
A proper solution would be to allow building nbcon.c even when CONFIG_PRINTK is disbled. But we would need to review the entire design.
A short term workaround is to make Braille console dependent on CONFIG_PRINTK. It might be good enough in practice. I mean this:
drivers/accessibility/Kconfig +1 -0
@@ -20,6 +20,7 @@ if ACCESSIBILITY config A11Y_BRAILLE_CONSOLE bool "Console on braille device" depends on VT + depends on PRINTK depends on SERIAL_CORE_CONSOLE help Enables console output on a braille device connected to a 8250
Best Regards,
Petr
Re: [PATCH v4 1/1] braille: nbcon: Allow to use a serial console with NBCON API as Braille console
In reply to Petr MladekQuoted 47 lines · Petr Mladek
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 underconsole_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, seenbcon_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 thatbraille_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()usingNBCON_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 theport->lockin the legacy serial console driver.2. Acquire nbcon context to provide some synchronization for a
panic()context. UseNBCON_PRIO_NORMALbecause it contends only withnbcon_device_try_acquire()users. Do it in a busy loop. It should always succeed whencon->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 duringpanic(). 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.
Quoted 2 lines
Fixes 13189fa73afa ("printk: nbcon: Rely on kthreads for normal operation")Signed-off-by Petr Mladek <[email protected]>
Minor comments follow, but no need to send a v5 for them. You could fix them up on your own.
Quoted 11 lines
drivers/accessibility/braille/braille_console.c +1
-0@@ -353,13 +406,16 @@ int braille_register_console(struct console *console, int index,if (!console_options)/* Only support VisioBraille for now */ console_options ="57600o8" ; +if (braille_co)return -ENODEV ;
drivers/accessibility/braille/braille_console.c int braille_register_console(struct console *console, int index, · line 421
Quoted 10 lines
drivers/accessibility/braille/braille_console.c +2
-0+if (console->setup) { ret = console->setup (console, console_options);if (ret !=0 )return ret; } + console->flags |=CON_ENABLED ; console->index = index; braille_co = console;
This hunk is pure whitespace cleanup. It is a leftover from when you actually made changes here. I am OK if you keep it, but I would drop this hunk.
Quoted 6 lines
kernel/printk/nbcon.c +0
-0@@ -2002,3 +2003,81 @@ void nbcon_kdb_release(struct nbcon_write_context *wctxt)*/
kernel/printk/nbcon.c void nbcon_kdb_release(struct nbcon_write_context *wctxt) · line 2013
Quoted 10 lines
kernel/printk/nbcon.c +8
-0__nbcon_atomic_flush_pending_con (ctxt->console,prb_next_reserve_seq (prb)); } + +/** +* nbcon_is_braille - Checks whether the nbcon write context is using Braille console +* +* @wctxt: checked nbcon write context +* +* Return: True when the write context is associated with a Braille console. +* Othrewise, return false.
One more: Otherwise
I ran a spellcheck on the whole patch this time, so we should be good after this.
Thanks for doing the heavy lifting on this so quickly.
John
Petr Mladek
maintainerRe: [PATCH v4 1/1] braille: nbcon: Allow to use a serial console with NBCON API as Braille console
Quoted 48 lines · John Ogness
Quoted 47 lines · Petr Mladek
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 underconsole_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, seenbcon_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 thatbraille_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()usingNBCON_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 theport->lockin the legacy serial console driver.2. Acquire nbcon context to provide some synchronization for a
panic()context. UseNBCON_PRIO_NORMALbecause it contends only withnbcon_device_try_acquire()users. Do it in a busy loop. It should always succeed whencon->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 duringpanic(). 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.
Quoted 7 lines
Quoted 2 lines
Fixes 13189fa73afa ("printk: nbcon: Rely on kthreads for normal operation")Signed-off-by Petr Mladek <[email protected]>Minor comments follow, but no need to send a v5 for them. You could fix them up on your own.
Reviewed-by John Ogness <[email protected]>
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
John Ogness
maintainerRe: [PATCH v4 1/1] braille: nbcon: Allow to use a serial console with NBCON API as Braille console
Quoted 7 lines · Petr Mladek
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_PRINTKto fix the Sashiko complains. We might add it as a separate patch. But we might also try to fix it properly by enablingnbcon.ccode even whenCONFIG_PRINTKis disabled, ...
It would probably be enough just to set the !CONFIG_PRINTK case to:
static inline bool nbcon_braille_try_acquire(struct console *con,
struct nbcon_write_context *wctxt) { return true; }Since there is no PRINTK, there will be no consoles to synchronize against.
Or in drivers/accessibility/braille/braille_console.c you could change all the
panic_on_this_cpu()
checks to
IS_ENABLED(CONFIG_PRINTK) && panic_on_this_cpu()
John