Skip to content

Commit 1606abb

Browse files
Jan Sebastian Göttegregkh
authored andcommitted
serial: qcom-geni: fix TX DMA buffer flush
[ Upstream commit e3c0483 ] When transmit flushing a qcom-geni UART during an ongoing TX DMA, the UART gets stuck infinitely repeating corrupted TX DMA frames. The DMA-mode uart_ops does not provide a flush_buffer callback, so an in-flight transfer can complete after serial core has reset the transmit kfifo, underflowing its length and resubmitting page-sized transfers indefinitely. Add one that stops the transfer and clears tx_remaining and tx_queued. The stop path was also broken: it unmapped the buffer while the serial engine could still read it, and never reset the TX DMA state machine. Cancel the main sequencer command first, then reset the state machine and wait for it before unmapping. Drop the early return so a pending mapping is also cleaned up when the main command is inactive. The bug can be triggered from userspace with a large write immediately followed by TCOFLUSH. A following tcdrain will hang forever. The bug was reproduced and this fix was validated on Arduino Uno Q (QRB2210) using /dev/ttyHS1. Assisted-by: Claude:claude-5-opus Codex:gpt-5 Signed-off-by: Jan Sebastian Götte <linux@jaseg.de> Fixes: 2aaa43c ("tty: serial: qcom-geni-serial: add support for serial engine DMA") Cc: stable <stable@kernel.org> Reviewed-by: Praveen Talari <praveen.talari@oss.qualcomm.com> Link: https://patch.msgid.link/20260729174105.21838-2-git@jaseg.de Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> [ Inlined `__qcom_geni_serial_cancel_tx_cmd()` as the existing open-coded cancel/abort block and dropped the `flush_buffer`→`flush_buffer_fifo` rename and `tx_queued` reset, which don't exist in this tree. ] Signed-off-by: Sasha Levin <sashal@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 80c6054 commit 1606abb

1 file changed

Lines changed: 33 additions & 18 deletions

File tree

drivers/tty/serial/qcom_geni_serial.c

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ static const struct uart_ops qcom_geni_uart_pops;
144144
static struct uart_driver qcom_geni_console_driver;
145145
static struct uart_driver qcom_geni_uart_driver;
146146

147+
static void qcom_geni_serial_stop_tx_dma(struct uart_port *uport);
147148
static int qcom_geni_serial_port_setup(struct uart_port *uport);
148149

149150
static inline struct qcom_geni_serial_port *to_dev_port(struct uart_port *uport)
@@ -597,35 +598,48 @@ static unsigned int qcom_geni_serial_tx_empty(struct uart_port *uport)
597598
return !readl(uport->membase + SE_GENI_TX_FIFO_STATUS);
598599
}
599600

601+
static void qcom_geni_serial_flush_buffer_dma(struct uart_port *uport)
602+
{
603+
struct qcom_geni_serial_port *port = to_dev_port(uport);
604+
605+
qcom_geni_serial_stop_tx_dma(uport);
606+
port->tx_remaining = 0;
607+
}
608+
600609
static void qcom_geni_serial_stop_tx_dma(struct uart_port *uport)
601610
{
602611
struct qcom_geni_serial_port *port = to_dev_port(uport);
603612
bool done;
604613

605-
if (!qcom_geni_serial_main_active(uport))
606-
return;
614+
if (qcom_geni_serial_main_active(uport)) {
615+
geni_se_cancel_m_cmd(&port->se);
616+
617+
done = qcom_geni_serial_poll_bit(uport, SE_GENI_M_IRQ_STATUS,
618+
M_CMD_CANCEL_EN, true);
619+
if (!done) {
620+
geni_se_abort_m_cmd(&port->se);
621+
done = qcom_geni_serial_poll_bit(uport, SE_GENI_M_IRQ_STATUS,
622+
M_CMD_ABORT_EN, true);
623+
if (!done)
624+
dev_err_ratelimited(uport->dev, "M_CMD_ABORT_EN not set");
625+
writel(M_CMD_ABORT_EN, uport->membase + SE_GENI_M_IRQ_CLEAR);
626+
}
627+
628+
writel(M_CMD_CANCEL_EN, uport->membase + SE_GENI_M_IRQ_CLEAR);
629+
}
607630

608631
if (port->tx_dma_addr) {
632+
writel(1, uport->membase + SE_DMA_TX_FSM_RST);
633+
if (!qcom_geni_serial_poll_bit(uport, SE_DMA_TX_IRQ_STAT,
634+
TX_RESET_DONE, true))
635+
dev_err_ratelimited(uport->dev, "TX DMA reset failed");
636+
writel(TX_RESET_DONE | TX_DMA_DONE,
637+
uport->membase + SE_DMA_TX_IRQ_CLR);
638+
609639
geni_se_tx_dma_unprep(&port->se, port->tx_dma_addr,
610640
port->tx_remaining);
611641
port->tx_dma_addr = 0;
612-
port->tx_remaining = 0;
613-
}
614-
615-
geni_se_cancel_m_cmd(&port->se);
616-
617-
done = qcom_geni_serial_poll_bit(uport, SE_GENI_M_IRQ_STATUS,
618-
M_CMD_CANCEL_EN, true);
619-
if (!done) {
620-
geni_se_abort_m_cmd(&port->se);
621-
done = qcom_geni_serial_poll_bit(uport, SE_GENI_M_IRQ_STATUS,
622-
M_CMD_ABORT_EN, true);
623-
if (!done)
624-
dev_err_ratelimited(uport->dev, "M_CMD_ABORT_EN not set");
625-
writel(M_CMD_ABORT_EN, uport->membase + SE_GENI_M_IRQ_CLEAR);
626642
}
627-
628-
writel(M_CMD_CANCEL_EN, uport->membase + SE_GENI_M_IRQ_CLEAR);
629643
}
630644

631645
static void qcom_geni_serial_start_tx_dma(struct uart_port *uport)
@@ -1600,6 +1614,7 @@ static const struct uart_ops qcom_geni_uart_pops = {
16001614
.request_port = qcom_geni_serial_request_port,
16011615
.config_port = qcom_geni_serial_config_port,
16021616
.shutdown = qcom_geni_serial_shutdown,
1617+
.flush_buffer = qcom_geni_serial_flush_buffer_dma,
16031618
.type = qcom_geni_serial_get_type,
16041619
.set_mctrl = qcom_geni_serial_set_mctrl,
16051620
.get_mctrl = qcom_geni_serial_get_mctrl,

0 commit comments

Comments
 (0)