]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
serial: 8250: Fix serial8250_tx_empty() race with DMA Tx
authorIlpo Järvinen <ilpo.jarvinen@linux.intel.com>
Fri, 17 Mar 2023 11:33:18 +0000 (13:33 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 11 May 2023 14:10:50 +0000 (23:10 +0900)
commit601e1a9fefcd2f316cbfe77421cc79c7b56b5cdd
treeb152e59b608dea7e25917fcf56f93217f8a5c78c
parent9f354556fee41b6ea1bc920af68671e62a1f90b0
serial: 8250: Fix serial8250_tx_empty() race with DMA Tx

commit 146a37e05d620cef4ad430e5d1c9c077fe6fa76f upstream.

There's a potential race before THRE/TEMT deasserts when DMA Tx is
starting up (or the next batch of continuous Tx is being submitted).
This can lead to misdetecting Tx empty condition.

It is entirely normal for THRE/TEMT to be set for some time after the
DMA Tx had been setup in serial8250_tx_dma(). As Tx side is definitely
not empty at that point, it seems incorrect for serial8250_tx_empty()
claim Tx is empty.

Fix the race by also checking in serial8250_tx_empty() whether there's
DMA Tx active.

Note: This fix only addresses in-kernel race mainly to make using
TCSADRAIN/FLUSH robust. Userspace can still cause other races but they
seem userspace concurrency control problems.

Fixes: 9ee4b83e51f74 ("serial: 8250: Add support for dmaengine")
Cc: stable@vger.kernel.org
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Link: https://lore.kernel.org/r/20230317113318.31327-3-ilpo.jarvinen@linux.intel.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/tty/serial/8250/8250.h
drivers/tty/serial/8250/8250_port.c