From: sashiko-bot@kernel.org
To: "James Hilliard" <james.hilliard1@gmail.com>
Cc: linux-serial@vger.kernel.org
Subject: Re: [PATCH v2] serial: 8250: release the transmit PM reference on shutdown
Date: Fri, 04 Dec 2026 10:23:56 +0000 [thread overview]
Message-ID: <sashiko-outbox-249593@kernel.org> (raw)
In-Reply-To: <20261204-submit-serial-8250-tx-pm-shutdown-v1-v2-1-f32936284ef7@gmail.com>
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [High] serial: 8250: shutdown drops TX PM ref before cancelling em485
start_tx_timer
- [High] serial: 8250: shutdown drops TX PM ref without cancelling em485
start_tx_timer
- [Medium] serial: 8250: unlocked serial8250_rpm_put_tx() races with TX
PM get
--
commit 4f158a86b3f5586570a06a8414aa89964b94419b
Author: James Hilliard <james.hilliard1@gmail.com>
serial: 8250: release the transmit PM reference on shutdown
This commit exports serial8250_rpm_put_tx() and calls it during both
omap_8250_shutdown() and serial8250_do_shutdown() to drop any held transmit
runtime PM reference when a port is shut down.
> diff --git a/drivers/tty/serial/8250/8250_omap.c b/drivers/tty/serial/8250/8250_omap.c
> index ed0b8f1253327..bdef7c4b6b202 100644
> --- a/drivers/tty/serial/8250/8250_omap.c
> +++ b/drivers/tty/serial/8250/8250_omap.c
> @@ -795,6 +795,7 @@ static void omap_8250_shutdown(struct uart_port *port)
> if (up->lcr & UART_LCR_SBC)
> serial_out(up, UART_LCR, up->lcr & ~UART_LCR_SBC);
> serial_out(up, UART_FCR, UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT);
> + serial8250_rpm_put_tx(up);
> }
>
> static void omap_8250_throttle(struct uart_port *port)
[Severity: High]
Can calling serial8250_rpm_put_tx() here let the UART runtime-suspend while
em485->start_tx_timer is still armed?
When omap8250_rs485_config() falls back to software RS-485 emulation with
delay_rts_before_send > 0, serial8250_start_tx() takes rpm_tx_active and
defers __start_tx() to em485->start_tx_timer. Neither uart_port_shutdown()
nor omap_8250_shutdown() cancels em485->start_tx_timer, which previously
stayed safe only because rpm_tx_active kept the UART active.
If the port closes or hangs up during that delay window, dropping both
runtime PM references lets omap8250_runtime_suspend() gate clocks before the
timer fires. serial8250_em485_handle_start_tx() does not take a runtime PM
reference of its own and calls __start_tx(), writing UART_IER on a
runtime-suspended UART, which can cause a synchronous external bus abort or
hang on OMAP/K3 SoCs. Cancelling pending em485 timers and clearing
em485->active_timer before dropping the runtime PM references would prevent
this.
> diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c
> index 36b2b0a2c05cd..d8a5ca46d9a9b 100644
> --- a/drivers/tty/serial/8250/8250_port.c
> +++ b/drivers/tty/serial/8250/8250_port.c
> @@ -672,7 +672,7 @@ static void serial8250_rpm_get_tx(struct uart_8250_port *p)
> pm_runtime_get_sync(p->port.dev);
> }
>
> -static void serial8250_rpm_put_tx(struct uart_8250_port *p)
> +void serial8250_rpm_put_tx(struct uart_8250_port *p)
> {
> unsigned char rpm_active;
>
> @@ -684,6 +684,7 @@ static void serial8250_rpm_put_tx(struct uart_8250_port *p)
> return;
> pm_runtime_put_autosuspend(p->port.dev);
> }
> +EXPORT_SYMBOL_GPL(serial8250_rpm_put_tx);
[Severity: Medium]
Does calling serial8250_rpm_put_tx() without port->lock race with
serial8250_rpm_get_tx() and underflow the runtime PM usage count?
Previously all callers of serial8250_rpm_get_tx() and
serial8250_rpm_put_tx() held port->lock, serializing the xchg() on
rpm_tx_active with the paired pm_runtime_*() call. On an OMAP UART with a
DT cts-gpios line and CRTSCTS software flow control, mctrl_gpio_irq_handle()
remains enabled across shutdown and can still invoke
uart_handle_cts_change() -> serial8250_start_tx() ->
serial8250_rpm_get_tx() under port->lock:
CPU0 CPU1
omap_8250_shutdown()
guard(serial8250_rpm)
pm_runtime_get_sync() (0->1)
mctrl_gpio_irq_handle()
lock(&port->lock)
... -> serial8250_rpm_get_tx()
xchg(&rpm_tx_active, 1)
serial8250_rpm_put_tx()
xchg(&rpm_tx_active, 0) -> 1
pm_runtime_put_autosuspend()
(usage_count 1->0)
guard exit: serial8250_rpm_put()
pm_runtime_put_autosuspend()
<-- usage_count underflow!
pm_runtime_get_sync() (0->1)
<-- permanent PM ref leak
When rpm_drop_usage_count() detects the underflow it warns and resets
usage_count back to 0, so CPU1's pm_runtime_get_sync() leaves usage_count
stuck at 1 while rpm_tx_active is already 0, permanently leaking a runtime
PM reference. Taking port->lock around serial8250_rpm_put_tx() (and
asserting lockdep_assert_held_once(&p->port.lock)) would restore mutual
exclusion with serial8250_rpm_get_tx().
[ ... ]
> @@ -2486,6 +2487,8 @@ void serial8250_do_shutdown(struct uart_port *port)
> */
> synchronize_irq(port->irq);
>
> + /* TX interrupts can no longer release the transmit reference. */
> + serial8250_rpm_put_tx(up);
> serial8250_rpm_put(up);
>
> up->ops->release_irq(up);
[Severity: High]
Should serial8250_do_shutdown() cancel pending em485 timers before dropping
the transmit runtime PM reference here as well?
When serial8250_start_tx() defers transmission to em485->start_tx_timer,
nothing has been written to the FIFO or DMA yet, so serial8250_tx_empty()
returns TIOCSER_TEMT and a normal close() proceeds straight into
serial8250_do_shutdown() without waiting for the timer. Dropping both
rpm_tx_active and the shutdown PM reference while em485->start_tx_timer is
still pending allows the UART to runtime-suspend before
serial8250_em485_handle_start_tx() runs and calls __start_tx(), writing
UART_IER on a runtime-suspended port (and potentially entering DMA TX paths
since up->dma is not cleared here). Cancelling em485->start_tx_timer and
em485->stop_tx_timer before serial8250_rpm_put_tx(up) would close this
window.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204-submit-serial-8250-tx-pm-shutdown-v1-v2-1-f32936284ef7@gmail.com?part=1
prev parent reply other threads:[~2026-12-04 10:23 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-04 9:57 [PATCH v2] serial: 8250: release the transmit PM reference on shutdown James Hilliard
2026-12-04 10:23 ` sashiko-bot [this message]
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=sashiko-outbox-249593@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=james.hilliard1@gmail.com \
--cc=linux-serial@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/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