]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commit
serial: 8250: Fix race condition in RTS-after-send handling
authorUwe Kleine-König <u.kleine-koenig@pengutronix.de>
Tue, 15 Feb 2022 16:02:36 +0000 (17:02 +0100)
committerStefan Bader <stefan.bader@canonical.com>
Fri, 20 May 2022 12:39:23 +0000 (14:39 +0200)
commitb4a735ca546ba000713a0cab791bdb144a7bec0e
tree646a588e54465a9c45613a5dcdd3c8fcb94e7750
parentf58e0bcadbdb4c6288fca53e1d82445a34d31242
serial: 8250: Fix race condition in RTS-after-send handling

BugLink: https://bugs.launchpad.net/bugs/1969110
[ Upstream commit dedab69fd650ea74710b2e626e63fd35584ef773 ]

Set em485->active_timer = NULL isn't always enough to take out the stop
timer. While there is a check that it acts in the right state (i.e.
waiting for RTS-after-send to pass after sending some chars) but the
following might happen:

 - CPU1: some chars send, shifter becomes empty, stop tx timer armed
 - CPU0: more chars send before RTS-after-send expired
 - CPU0: shifter empty irq, port lock taken
 - CPU1: tx timer triggers, waits for port lock
 - CPU0: em485->active_timer = &em485->stop_tx_timer, hrtimer_start(),
   releases lock()
 - CPU1: get lock, see em485->active_timer == &em485->stop_tx_timer,
   tear down RTS too early

This fix bases on research done by Steffen Trumtrar.

Fixes: b86f86e8e7c5 ("serial: 8250: fix potential deadlock in rs485-mode")
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Link: https://lore.kernel.org/r/20220215160236.344236-1-u.kleine-koenig@pengutronix.de
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
(cherry picked from commit 3e843460fb4252368bef6c9c8897a40a1268d5a0)
Signed-off-by: Paolo Pisati <paolo.pisati@canonical.com>
drivers/tty/serial/8250/8250_port.c