All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/3] serial: max310x: teardown ordering and CTS locking fixes
@ 2026-11-20  7:33 Tapio Reijonen
  2026-11-20  7:33 ` [PATCH 1/3] serial: max310x: fix use-after-free on remove Tapio Reijonen
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Tapio Reijonen @ 2026-11-20  7:33 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Jiri Slaby, Alexander Shiyan, Andy Shevchenko
  Cc: linux-serial, linux-kernel, Hugo Villeneuve, stable,
	Tapio Reijonen

Three fixes for problems that predate the RS485 software-delay series
and were raised during its review: port removal cancelled the per-port
work before the IRQ was freed and the port unregistered, a failed probe
left queued work behind and could mark another chip's port line as
free, and the CTS change was reported to serial core without the port
lock.

Tested on two MAX14830, four UARTs each on SPI, on an ARMv7 single-core
board, on tty-next from the 7.4 merge window with the board support on
top, all ports in RS-485 mode and one switched to RS-232 where a test
needs it. For the teardown tests the kernel ran with PROVE_LOCKING,
DEBUG_OBJECTS, DEBUG_ATOMIC_SLEEP, DEBUG_KMEMLEAK and init_on_free, a
500 ms delay was added to the work items so that a late one is still
running when the port memory is freed, and the probe failures were
injected through test-only module parameters.

The first fix was reproduced that way: unbinding the chip with a port
open made md_work, queued by the hangup, run on the freed port and
oops; with the fix the unbind waits for it, also while the other chip
carries traffic. For the second, a failed IRQ request after all four
ports were registered waits for the rs_work items queued by the RS-485
configuration before probe returns, and a port registration failure on
the second chip leaves the first chip's port 0 in place; a rebind
brings every port back under its original number. The third was checked
with the chip's internal loopback feeding RTS to CTS under
PROVE_LOCKING.

The series then ran through a scripted campaign on the same board:
unbinding a chip under open ports with blocked readers, TIOCMIWAIT
waiters and a draining close pending (80 cycles), with sixteen
processes opening and closing its ports nonstop (100 cycles), and with
verified loopback traffic on the other chip (four one-hour runs and a
two-hour soak, 1250 cycles, no kmemleak report, Slab growth under
1 MB); the probe failure injections with openers racing the node names;
lockdep stayed enabled throughout and no warning, hung task or stuck
process was recorded. Two bugs outside this series surfaced in that
campaign and are fixed separately, this series does not depend on
either: serial core's port removal waited for the port's references
with the port mutex held, against which tcdrain() on the hung-up port
deadlocks, and the driver's TX work advanced the transmit fifo without
the port lock, racing uart_flush_buffer().

The teardown tests were repeated on v7.4-rc3 with the same debug
options, on one chip: 100 unbind and bind cycles with sixteen processes
opening and closing the ports, 100 with a blocked reader, TIOCMIWAIT
waiters and a draining close pending on every port, and 300 s of flush
under transmit on all four ports, again with no lockdep, debug-objects
or kmemleak report. The probe failure injections were repeated there
with two chips, with either chip as the failing one.

Patches 1 and 2 are marked for stable. On stable trees without the
software RTS delay code the backport of patch 1 drops the rts_work and
tx_delay_tmr lines. The IRQ change in patch 1 also covers the
single-port parts, where the handler reads the port status on every
event of the line; on the multi-port parts GlobalIRQ already hides a
port with its interrupts disabled. Patch 3 is not marked: the driver
enables the chip's auto-CTS whenever CRTSCTS is set, so serial core's
software flow control path can only be taken for a CTS edge that
arrives while set_termios() is changing the flow control mode, and
serial core recomputes the stopped state when that call returns. In
practice the symptom is limited to the lockdep report.

Not addressed here: on the multi-port parts the chip-level IRQ thread
does not return while a port receives faster than the thread reads it
out, and the close of another port or an unbind then waits in
synchronize_irq() until the traffic pauses. Where that starts depends
on how long a register access to the chip takes; on the test board,
on SPI, it is a continuous stream of about 19200 baud on one port.
That predates this series and is not changed by it.

Two further items noted during the same review were left out as
improvements rather than fixes: tx_empty() reporting the transmitter
empty one character early, and the refill size and x_char ordering in
the TX path.

The patches were written and reviewed with help from an LLM assistant
(Claude), used for code reading, review of the drafts, the stress
harness and the reproducer setup; the analysis, the changes and the
testing on hardware are mine.

---
Tapio Reijonen (3):
      serial: max310x: fix use-after-free on remove
      serial: max310x: unwind only the registered ports when probe fails
      serial: max310x: hold the port lock around the CTS change

 drivers/tty/serial/max310x.c | 62 +++++++++++++++++++++++++++++++-------------
 1 file changed, 44 insertions(+), 18 deletions(-)
---
base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
change-id: 20261028-max310x-teardown-fixes-e13949736e53

Best regards,
-- 
Tapio Reijonen <tapio.reijonen@vaisala.com>


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-11-20  7:45 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-20  7:33 [PATCH 0/3] serial: max310x: teardown ordering and CTS locking fixes Tapio Reijonen
2026-11-20  7:33 ` [PATCH 1/3] serial: max310x: fix use-after-free on remove Tapio Reijonen
2026-11-20  7:45   ` sashiko-bot
2026-11-20  7:33 ` [PATCH 2/3] serial: max310x: unwind only the registered ports when probe fails Tapio Reijonen
2026-11-20  7:39   ` sashiko-bot
2026-11-20  7:33 ` [PATCH 3/3] serial: max310x: hold the port lock around the CTS change Tapio Reijonen
2026-11-20  7:41   ` sashiko-bot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.