From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796379836; b=W324DT+IEGVNY+T4/zCVQxaBjGgGNE3VEKNPwAPFQLwbgR3YIdDb2Tn/tehUO1/jsxON 0Fx7yzzT/cu86sugnUtGCnCdBM//k97I6pHgxChV2cVh9EUKmu+yKbvZz2gJdy8e4wcGb FRUSFAx6UXmnXQb8PKNmtSnDa/XZQE0dWjMDPQ+J9WofFRSh6qViLvcshRQkeGkK7IIjn vfR9eIbi94YSW+3HAiwhP71MMM0B5zL0PR2zGmDOgi/7zyP3xGV+uJRH8Fx+t1loNq/my enQz+mjDloFImJNygX24j68yDIKt6Xp5CYQNPwcmDz8LxhM/c/8EtwjvrTDg9EOZLkQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796379836; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=WbvleIY1aa+ytwGT4R5vea1h7qa5gEYSZEgg7cJR4gU=; b=aAu1IBk8XoudSeROGULre2nRwxrVqzeJyFRQVM6n/B+svE0Mn7QqundQIDSfmDOmF1PN 4Gj4h5WkI+iJTRYhQJ5weRdMr64ZMhLL6PsqZL/rax8h1GowncNowqVvCmO42yC42y5z5 WB/ynljFgAT8De1RHPzpguD4CpQ68ftM7sw6D6q27fmRUEtgECPb6Xmxs7ntbupg3LqRA mmW9EGN+MJQx1LxF4aftG+GLFFBWHXHwWZPwSviwbp/cK8taCWsmF9/jFqHx3FHYWeRiX o43sr2dFjnv+ryAmeloU5m5FztjaLSS3wwRV/AQYy50D0gZ8myEyCTC/QGzNjYqy08g== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=e8yyzJPg; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DF169606A322 for ; Fri, 4 Dec 2026 10:23:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=e8yyzJPg Received: by smtp.kernel.org (Postfix) with ESMTPSA id 99D9F1F000CE; Fri, 4 Dec 2026 10:23:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796379836; bh=WbvleIY1aa+ytwGT4R5vea1h7qa5gEYSZEgg7cJR4gU=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=e8yyzJPgox7hv1uv7ml/2unbHDpaBs01e+31+rv9dGVNsmoXRwAtJQBX7+jawN8tl Ipp7gmY7yoBz68eewPdrnIU8NeoGJGCb+yR8oC+MnkKOZOvMM8GZe81lJ/a+LzVclc I14Hnm1tOW3RW3RUcuMA2jjQx0t1JhQ6GDnzyJngNbu6Fe0Q0u+54ixD+PUq/WZpcW l+028xX1yPJ6Z+ywWd/pxkbfT3eOcMRQa2oEoZ6UUZShOh+w20ZFxnxwlCZX57BlOn 8RmyX/Rq7eF+JiePZpVekMgAV7iDZ6RQwTuMX+hD8XEWnmAM+VtBYvgw0NjgiuQpBi Khl8i7rLUZfuA== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v2] serial: 8250: release the transmit PM reference on shutdown Reply-To: sashiko-reviews@lists.linux.dev To: "James Hilliard" Cc: linux-serial@vger.kernel.org In-Reply-To: <20261204-submit-serial-8250-tx-pm-shutdown-v1-v2-1-f32936284ef7@gmail.com> References: <20261204-submit-serial-8250-tx-pm-shutdown-v1-v2-1-f32936284ef7@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 10:23:56 +0000 X-Mailing-List: linux-serial@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list 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 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/825= 0/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); > } > =20 > 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/825= 0/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_po= rt *p) > pm_runtime_get_sync(p->port.dev); > } > =20 > -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; > =20 > @@ -684,6 +684,7 @@ static void serial8250_rpm_put_tx(struct uart_8250_po= rt *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); > =20 > + /* TX interrupts can no longer release the transmit reference. */ > + serial8250_rpm_put_tx(up); > serial8250_rpm_put(up); > =20 > 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. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261204-submit-ser= ial-8250-tx-pm-shutdown-v1-v2-1-f32936284ef7@gmail.com?part=3D1