From: Vignesh R <vigneshr@ti.com>
To: "linux-serial@vger.kernel.org" <linux-serial@vger.kernel.org>
Cc: Peter Hurley <peter@hurleysoftware.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
"linux-omap@vger.kernel.org" <linux-omap@vger.kernel.org>,
Andy Shevchenko <andy.shevchenko@gmail.com>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: 8250: Possible race between console message vs DMA?
Date: Fri, 7 Apr 2017 16:38:54 +0530 [thread overview]
Message-ID: <7c75614c-71cb-0a4e-222c-713f65a89f23@ti.com> (raw)
Hi All,
I seem to be hitting a race condition using 8250_dma (and 8250_omap
specific dma) support:
Kernel writes log messages to console via
serial8250_console_write()->serial8250_console_putchar() which directly
accesses UART_TX register with port->lock acquired.
Now, if the same UART instance is being used by systemd/userspace,
characters are written to UART_TX register by serial8250_tx_chars(). The
concurrent access by serial8250_console_write() and
serial8250_tx_chars() is serialized by the use of port->lock spinlock
and hence there is no issue with` non DMA case.
But when using DMA with 8250 UART, I see that port->lock is held before
scheduling of DMA TX transfer and released as soon as the transfer is
submitted. The lock is not held until the transfer actually completes
See,
uart_start()
->serial8250_start_tx()->
__start_tx()
->up->dma->tx_dma(up)
Or
__dma_tx_complete() in 8250_dma.c that acquires and releases port->lock
once TX DMA transfer is submitted in serial8250_tx_dma()
So, when the port->lock is released, it is quite possible that DMA is
still transferring data to UART TX FIFO and UART FIFO might be almost full.
I see that when DMA is writing to UART TX FIFO,
serial8250_console_write() may also write kernel log messages to UART TX
FIFO(as port->lock is now free to be acquired), which is leading to
overflow and lose of data. serial8250_console_write() checks for
UART_LSR_THRE to check if Transmit hold register is empty but that may
not be enough as DMA might put data before CPU write.
It seems that both DMA and CPU might simultaneously put data to UART
FIFO and lead to potential loss of data.
Is the expectation that UART instance used to print kernel log messages
is not intended to use DMA? Or am I missing something?
Any help appreciated!
--
Regards
Vignesh
next reply other threads:[~2017-04-07 11:08 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-04-07 11:08 Vignesh R [this message]
2017-04-09 11:07 ` 8250: Possible race between console message vs DMA? Andy Shevchenko
2017-04-10 8:16 ` Vignesh R
2017-04-18 6:16 ` Andy Shevchenko
2017-04-18 6:19 ` Vignesh R
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=7c75614c-71cb-0a4e-222c-713f65a89f23@ti.com \
--to=vigneshr@ti.com \
--cc=andy.shevchenko@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-omap@vger.kernel.org \
--cc=linux-serial@vger.kernel.org \
--cc=peter@hurleysoftware.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