From: John Ogness <john.ogness@linutronix.de>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Jiri Slaby <jirislaby@kernel.org>
Cc: "Andy Shevchenko" <andy.shevchenko@gmail.com>,
"Petr Mladek" <pmladek@suse.com>,
"Sebastian Andrzej Siewior" <bigeasy@linutronix.de>,
linux-kernel@vger.kernel.org,
"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>,
"Andy Shevchenko" <andriy.shevchenko@linux.intel.com>,
"Hugo Villeneuve" <hvilleneuve@dimonoff.com>,
"Stepan Ionichev" <sozdayvek@gmail.com>,
"Kees Cook" <kees@kernel.org>, "Xin Zhao" <jackzxcui1989@163.com>,
linux-serial@vger.kernel.org
Subject: Re: [PATCH tty v8 1/2] serial: 8250: Switch to nbcon console, take 2
Date: Wed, 22 Jul 2026 16:59:09 +0206 [thread overview]
Message-ID: <87v7a7cbze.fsf@jogness.linutronix.de> (raw)
In-Reply-To: <20260722110925.74387-2-john.ogness@linutronix.de>
On 2026-07-22, Sashiko wrote:
>> diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c
>> index 8c241ec7f4f29..7726cca00d364 100644
>> --- a/drivers/tty/serial/8250/8250_port.c
>> +++ b/drivers/tty/serial/8250/8250_port.c
>> @@ -3198,11 +3218,22 @@ void serial8250_set_defaults(struct uart_8250_port *up)
>> }
>> EXPORT_SYMBOL_GPL(serial8250_set_defaults);
>>
>> -void serial8250_fifo_wait_for_lsr_thre(struct uart_8250_port *up, unsigned int count)
>> +void serial8250_fifo_wait_for_lsr_thre(struct uart_8250_port *up,
>> + struct nbcon_write_context *wctxt,
>> + unsigned int count)
>> {
>> unsigned int i;
>>
>> for (i = 0; i < count; i++) {
>> + /*
>> + * Pass the ownership as quickly as possible to a higher
>> + * priority context. Otherwise, its attempt to take over
>> + * the ownership might timeout. The new owner will wait
>> + * for UART_LSR_THRE before reusing the fifo.
>> + */
>> + if (wctxt && !nbcon_can_proceed(wctxt))
>> + return;
>> +
>> if (wait_for_lsr(up, UART_LSR_THRE))
>> return;
>> }
>
> Does this leave the hardware state vulnerable to corruption during an
> emergency console takeover?
>
> The serial8250_fifo_wait_for_lsr_thre() function polls the UART_LSR
> register by calling wait_for_lsr() and modifies up->lsr_saved_flags
> non-atomically. Since reading UART_LSR clears hardware error flags
> (parity, framing, overrun, break), concurrent reads can cause one CPU
> to consume and lose the flags before the other can observe them.
>
> Because serial8250_fifo_wait_for_lsr_thre() is called outside the
> nbcon_enter_unsafe() block, the nbcon system might grant a safe
> takeover to an emergency message (e.g. sysrq, panic, or NMI printk)
> preempting this loop, as it assumes no hardware access is taking
> place. The emergency writer will then access the same hardware
> registers concurrently.
Sashiko is correct. I did not know that the serial_lsr_in() macro (used
by wait_for_lsr()) updates @lsr_saved_flags! I looked at the other
serial_lsr_in() call sites and they are all in nbcon unsafe sections.
The for-loop in serial8250_fifo_wait_for_lsr_thre() should look like
this:
for (i = 0; i < count; i++) {
/* ... */
if (wctxt && !nbcon_enter_unsafe(wctxt))
return;
if (wait_for_lsr(up, UART_LSR_THRE))
return;
if (wctxt)
nbcon_exit_unsafe(wctxt);
}
Note that Sashiko already reported [0] this in v7, but I did not look
deep enough at that comment, thinking Sashiko was misunderstanding nbcon
ownership. Instead it was me who was misunderstanding. :-/
John
[0] https://sashiko.dev/#/patchset/20260720135407.3925-1-john.ogness%40linutronix.de
next prev parent reply other threads:[~2026-07-22 14:53 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-22 11:09 [PATCH tty v8 0/2] Convert 8250 to NBCON, take 2 John Ogness
2026-07-22 11:09 ` [PATCH tty v8 1/2] serial: 8250: Switch to nbcon console, " John Ogness
2026-07-22 14:53 ` John Ogness [this message]
2026-07-23 11:04 ` Petr Mladek
2026-07-23 10:59 ` Petr Mladek
2026-07-22 11:09 ` [PATCH tty v8 2/2] Revert "serial: 8250: drop lockdep annotation from serial8250_clear_IER()" John Ogness
2026-07-23 11:05 ` 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=87v7a7cbze.fsf@jogness.linutronix.de \
--to=john.ogness@linutronix.de \
--cc=andriy.shevchenko@linux.intel.com \
--cc=andy.shevchenko@gmail.com \
--cc=bigeasy@linutronix.de \
--cc=gregkh@linuxfoundation.org \
--cc=hvilleneuve@dimonoff.com \
--cc=ilpo.jarvinen@linux.intel.com \
--cc=jackzxcui1989@163.com \
--cc=jirislaby@kernel.org \
--cc=kees@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-serial@vger.kernel.org \
--cc=pmladek@suse.com \
--cc=sozdayvek@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