Skip to content

serial: 8250_dw: Fix clk-notifier/port suspend deadlock

Serge Semin linux-arm-kernel linux-serial lkml 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest3 patches 3 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/3serial: 8250: Discard RTS/DTS setting from clock update methoddrivers/tty/serial/8250/8250_port.c+0 -10 replies
2/3serial: 8250: Skip uninitialized TTY port baud rate updatedrivers/tty/serial/8250/8250_port.c+4 -00 replies
3/3serial: 8250_dw: Fix clk-notifier/port suspend deadlockdrivers/tty/serial/8250/8250_dw.c+19 -351 reply

Reviews trailers per patch

None of the 3 patches has a Reviewed-by or Acked-by.

PatchHans de GoedeJonathan Liu
SeriesT-b
1/3
2/3
3/3T-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v1 thread

Cover letter [PATCH 0/3] serial: 8250_dw: Fix clk-notifier/port suspend deadlock

Hans has discovered that there is a potential deadlock between the ref clock change notifier and the port suspension procedures {see the link at the bottom of the letter}. Indeed the deadlock is possible if the port suspension is initiated during the ref clock rate change:

    CPU0 (suspend CPU/UART)   CPU1 (update clock)
             ----                    ----
    lock(&port->mutex);
                              lock((work_completion)(&data->clk_work));
                              lock(&port->mutex);
    lock((work_completion)(&data->clk_work));

    *** DEADLOCK ***

So the CPU performing the UART port shutdown procedure will wait until the ref clock change notifier is finished (worker is flushed), while the later will wait for a port mutex being released.

A possible solution to bypass the deadlock is to move the worker flush out of the critical section protected by the TTY port mutex. For instance we can register and de-register the clock change notifier in the port probe and remove methods instead of having them called from the port startup/shutdown callbacks. But in order to do that we need to make sure that the serial8250_update_uartclk() method is safe to be used while the port is shutted down. Alas the current implementation doesn't provide that safety. The solution described above is introduced in the framework of this patchset. See individual patches for details.

Hans, could you test the patchset out on your Cherry Trail (x86)-based devices? After that we can merge it in into the kernels 5.8 and 5.9 if there is no objections against the fix.

Note, in order to have the fix working for the older kernel all of patches need to be backported.

Fixes cc816969d7b5 ("serial: 8250_dw: Fix common clocks usage race condition")
Fixes 868f3ee6e452 ("serial: 8250: Add 8250 port clock update method")
Cc Alexey Malahov <[email protected]>
Cc Pavel Parkhomenko <[email protected]>
Cc Andy Shevchenko <[email protected]>
Cc Maxime Ripard <[email protected]>
Cc Will Deacon <[email protected]>
Cc Russell King <[email protected]>

Serge Semin (3):
serial: 8250: Discard RTS/DTS setting from clock update method
serial: 8250: Skip uninitialized TTY port baud rate update
serial: 8250_dw: Fix clk-notifier/port suspend deadlock

 drivers/tty/serial/8250/8250_dw.c   | 54 ++++++++++-------------------
 drivers/tty/serial/8250/8250_port.c |  5 ++-
 2 files changed, 23 insertions(+), 36 deletions(-)
Signature · 1 line
2.27.0