From: sashiko-bot@kernel.org
To: "Tate Whiteberg" <whiteberg@arista.com>
Cc: linux-serial@vger.kernel.org
Subject: Re: [PATCH v3 2/2] serial: 8250_mid: wait for LSR tx empty before setting termios
Date: Mon, 31 Aug 2026 19:35:55 +0000 [thread overview]
Message-ID: <20260831193555.C61471F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260831165911.2029839-3-whiteberg@arista.com>
Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider:
- [High] Spin-waiting for up to 1 second with interrupts disabled causes severe scheduling latency and hard lockups.
- [High] The baud rate hardware state update is split across two critical sections, leaving a race window for corrupted transmissions.
- [High] Bypassing the `uart_port_lock` wrappers fails to acquire the nbcon console lock.
- [High] `scoped_guard(spinlock_irq)` unconditionally enables interrupts on exit, violating caller context guarantees.
- [Low] Missing `MODULE_IMPORT_NS("SERIAL_8250")` causes modpost errors for modular builds.
--
commit 7b0bf61b54075c1cffc2c3cc1ed56d43ba829821
Author: Tate Whiteberg <whiteberg@arista.com>
Subject: serial: 8250_mid: wait for LSR tx empty before setting termios
This commit modifies mid8250_set_termios() to lock the port and wait for the
transmitter to empty before updating baud rate registers. This is intended to
prevent transmission corruption when updates occur while data is still in
flight.
> diff --git a/drivers/tty/serial/8250/8250_mid.c b/drivers/tty/serial/8250/8250_mid.c
> index 82656645b8a64..c02ecb96e8b6f 100644
> --- a/drivers/tty/serial/8250/8250_mid.c
> +++ b/drivers/tty/serial/8250/8250_mid.c
[ ... ]
> @@ -231,11 +233,16 @@ static void mid8250_set_termios(struct uart_port *p, struct ktermios *termios,
> }
>
> rational_best_approximation(fuart, mid->board->freq, w, w, &mul, &div);
> - p->uartclk = fuart * 16 / ps; /* core uses ps = 16 always */
>
> - writel(ps, p->membase + INTEL_MID_UART_PS); /* set PS */
> - writel(mul, p->membase + INTEL_MID_UART_MUL); /* set MUL */
> - writel(div, p->membase + INTEL_MID_UART_DIV);
> + scoped_guard(spinlock_irq, &p->lock) {
[Severity: High]
Does using scoped_guard(spinlock_irq, ...) here unconditionally enable
interrupts on exit, violating caller context guarantees?
If set_termios is called from a context where interrupts are already disabled
(such as early console initialization or system resume), this will unmask
interrupts prematurely.
Also, does bypassing the uart_port_lock wrappers fail to acquire the nbcon
console lock? This could result in concurrent nbcon atomic console printers
mutating UART state simultaneously.
> + p->uartclk = fuart * 16 / ps; /* core uses ps = 16 always */
> +
> + serial8250_wait_for_xmitr(up, UART_LSR_BOTH_EMPTY);
[Severity: High]
Can this call cause a hard lockup?
Because scoped_guard(spinlock_irq, ...) is active, interrupts are strictly
disabled here. Looking at the called function:
void serial8250_wait_for_xmitr(struct uart_8250_port *up, int bits)
{
...
if (uart_console_hwflow_active(&up->port) && !up->canary) {
for (tmout = 1000000; tmout; tmout--) {
...
udelay(1);
...
This loop busy-waits for up to 1 second. When called under a spinlock with
interrupts disabled, this can block the CPU and trigger the NMI watchdog.
[Severity: Low]
Does this missing namespace import cause modpost errors for modular builds?
The patch uses the serial8250_wait_for_xmitr symbol which is exported in the
SERIAL_8250 namespace, but fails to import the namespace via
MODULE_IMPORT_NS("SERIAL_8250").
> +
> + writel(ps, p->membase + INTEL_MID_UART_PS); /* set PS */
> + writel(mul, p->membase + INTEL_MID_UART_MUL); /* set MUL */
> + writel(div, p->membase + INTEL_MID_UART_DIV);
> + }
>
> serial8250_do_set_termios(p, termios, old);
[Severity: High]
Is there a race condition introduced by splitting the hardware state update
across two critical sections?
The lock is released at the closing brace of the scoped_guard, and then
reacquired inside serial8250_do_set_termios():
void serial8250_do_set_termios(...)
{
...
scoped_guard(serial8250_rpm, up) {
guard(uart_port_lock_irqsave)(port);
...
This creates a window where a concurrent uart_write or TX interrupt handler
could acquire the lock between these two critical sections and transmit data
using a mismatched clock and divisor configuration.
> }
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260831165911.2029839-1-whiteberg@arista.com?part=2
next prev parent reply other threads:[~2026-08-31 19:35 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-31 16:59 [PATCH v3 0/2] serial: 8250_mid: fix race condition between output flush and termios update Tate Whiteberg
2026-08-31 16:59 ` [PATCH v3 1/2] serial: 8250: export and rename wait_for_xmitr() Tate Whiteberg
2026-08-31 19:23 ` sashiko-bot
2026-08-31 16:59 ` [PATCH v3 2/2] serial: 8250_mid: wait for LSR tx empty before setting termios Tate Whiteberg
2026-08-31 19:35 ` sashiko-bot [this message]
2026-09-01 9:04 ` Andy Shevchenko
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=20260831193555.C61471F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-serial@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=whiteberg@arista.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