From: tianci xie <xiex16070@gmail.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Jiri Slaby <jirislaby@kernel.org>
Cc: Krzysztof Kozlowski <krzk@kernel.org>,
Peter Griffin <peter.griffin@linaro.org>,
Alim Akhtar <alim.akhtar@samsung.com>,
Marek Szyprowski <m.szyprowski@samsung.com>,
Samarth Narang <samarth.colleges@gmail.com>,
linux-serial@vger.kernel.org, linux-samsung-soc@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, tianci xie <xiex16070@gmail.com>
Subject: [PATCH 0/1] tty: serial: samsung: fix TX fifo underflow on flush race
Date: Sat, 31 Oct 2026 23:26:55 +0800 [thread overview]
Message-ID: <20261031152656.1422-1-xiex16070@gmail.com> (raw)
In-Reply-To: <2026103122-repurpose-cost-2da7@gregkh>
On Sat, Oct 31, 2026 at 09:54:55AM +0100, Greg Kroah-Hartman wrote:
> Always just send us patches, after testing them, you never need to ask
> if you should do so.
Understood. Here is the samsung_tty part of the report; the other four
drivers are separate and I have not touched them.
The analysis holds up against mainline. Neither s3c64xx_serial_ops nor
apple_s5l_serial_ops has a ->flush_buffer() callback, and
s3c24xx_serial_tx_dma_complete() samples tx_bytes_requested before it
takes the port lock. A completion that raced with uart_flush_buffer()
therefore advances the freshly reset kfifo by the byte count of the
discarded transfer, and since kfifo_skip_count() does not clamp, ->out
passes ->in and kfifo_len() wraps.
One detail worth adding to the report. In 29bef7990845, where TX DMA was
introduced, the callback advanced the buffer with
xmit->tail = (xmit->tail + count) & (UART_XMIT_SIZE - 1);
so an over-advance was masked away and could not wrap. The wrap only
became possible once the driver moved to the kfifo helpers, which drop
the mask. That is probably why this never showed up on the older code.
The patch follows the 8250 fix in 9e512eaaf8f4, with one addition. The
8250 changelog says that clearing the outstanding byte count under the
port lock is sufficient "since the port lock is held when the kfifo is
reset in uart_flush_buffer() and in __dma_tx_complete()". That holds for
8250 because __dma_tx_complete() reads tx_size inside the lock. Here the
count is read before the lock, so clearing alone would not help; the
patch also moves the sample under the lock. The same gap applies to
serial-tegra as reported.
Testing so far:
- BUILD_RESULT: builds cleanly with gcc 12.3 on x86_64 (COMPILE_TEST,
CONFIG_SERIAL_SAMSUNG=m, W=1) and with aarch64-linux-gcc 13.3.0 on
arm64 (arm64 defconfig, which enables ARCH_EXYNOS, ARCH_APPLE and
SERIAL_SAMSUNG_CONSOLE); no warnings from the new code.
- BOOT_OR_RUNTIME_RESULT: not booted; I have no Exynos or Apple board.
Runtime behaviour is covered by the exhaustive interleaving model.
- the patch applies to mainline at 83f32c773255 with git am;
- a model of the two actors, with the kfifo semantics taken from
include/linux/kfifo.h, exhausts every interleaving under the port
lock: the unpatched callback wraps kfifo_len() in all four flush
scenarios, the patched one in none, and both agree when no flush
happens.
I do not have a Linux machine of my own. The x86_64 build above was run
on a rented Linux server, and the arm64 build was cross-compiled there
with a no-libc aarch64 toolchain; that is as far as I can take testing
without hardware. There is no Exynos or Apple board available to me, so
the model is what stands in for a runtime reproduction. If you would
rather have the flush modelled as a KUnit test in the tree, say so and I
will send that instead.
Thanks,
tianci xie
tianci xie (1):
tty: serial: samsung: fix TX fifo underflow on flush race
drivers/tty/serial/samsung_tty.c | 40 +++++++++++++++++++++++++++++++-
1 file changed, 39 insertions(+), 1 deletion(-)
next prev parent reply other threads:[~2026-10-31 15:27 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-31 0:47 [BUG] serial: TX kfifo underflow when TCOFLUSH races with TX DMA (samsung, sprd, msm, pch_uart, tegra) Samarth Narang
2026-10-31 8:54 ` Greg Kroah-Hartman
2026-10-31 15:26 ` tianci xie [this message]
2026-10-31 15:26 ` [PATCH] tty: serial: samsung: fix TX fifo underflow on flush race tianci xie
2026-10-31 12:39 ` [PATCH 0/5] serial: fix TX kfifo underflow on flush in five drivers Samarth Narang
2026-10-31 12:39 ` [PATCH 1/5] tty: serial: samsung: fix TX kfifo underflow on flush Samarth Narang
2026-10-31 12:39 ` [PATCH 2/5] serial: tegra: don't advance the TX kfifo for a flushed transfer Samarth Narang
2026-10-31 12:39 ` [PATCH 3/5] serial: sprd: fix TX kfifo underflow on flush Samarth Narang
2026-10-31 12:39 ` [PATCH 4/5] tty: serial: msm: " Samarth Narang
2026-10-31 12:39 ` [PATCH 5/5] serial: pch_uart: " Samarth Narang
2026-10-31 12:59 ` [PATCH 0/5] serial: fix TX kfifo underflow on flush in five drivers Greg Kroah-Hartman
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=20261031152656.1422-1-xiex16070@gmail.com \
--to=xiex16070@gmail.com \
--cc=alim.akhtar@samsung.com \
--cc=gregkh@linuxfoundation.org \
--cc=jirislaby@kernel.org \
--cc=krzk@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-samsung-soc@vger.kernel.org \
--cc=linux-serial@vger.kernel.org \
--cc=m.szyprowski@samsung.com \
--cc=peter.griffin@linaro.org \
--cc=samarth.colleges@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