From: Michael Walle <michael@walle.cc>
To: Leonard Crestez <leonard.crestez@nxp.com>
Cc: Andy Duan <fugang.duan@nxp.com>,
linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org,
Jiri Slaby <jslaby@suse.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
shawnguo@kernel.org, dl-linux-imx <linux-imx@nxp.com>
Subject: Re: [RFC PATCH 3/3] tty: serial: fsl_lpuart: fix possible console deadlock
Date: Wed, 25 Mar 2020 13:44:00 +0100 [thread overview]
Message-ID: <201514c22f86f3599385d4ddbeb71f1a@walle.cc> (raw)
In-Reply-To: <VI1PR04MB6941AD02204DF50B8D24D23AEECE0@VI1PR04MB6941.eurprd04.prod.outlook.com>
Am 2020-03-25 13:21, schrieb Leonard Crestez:
> On 2020-03-24 8:48 PM, Michael Walle wrote:
>> If the kernel console output is on this console any
>> dev_{err,warn,info}() may result in a deadlock if the sport->port.lock
>> spinlock is already held. This is because the _console_write() try to
>> aquire this lock, too. Remove any error messages where the spinlock is
>> taken or print after the lock is released.
>>
>> Reported-by: Leonard Crestez <leonard.crestez@nxp.com>
>> Signed-off-by: Michael Walle <michael@walle.cc>
>
> It seems that this was an issue even before commit 159381df1442 ("tty:
> serial: fsl_lpuart: fix DMA operation when using IOMMU") but these
> error
> prints never triggered.
Yeah, it just triggers because there is now a print by default (if DMA
is
not available) thus this RFC doesn't contain the Fixes: tag.
> Would it be possible to move all the dma alloc/config/prep outside the
> serial port lock? As it stands this still calls into dmaengine coode
> and
> that might decide to print as well.
TBH I don't want to refactor the whole driver. All I wanted to do was to
add LS1028A support to this driver which already resulted in a 7 patches
series with various other bugfixes. Could NXP take this over? I could
certainly do rewiews/testing on my board, though.
> Really I don't think the lock needs to protect more than bits like
> TDMAE/RDMAE.
>
> BTW: You should add more people in CC for reviews, for example
> linux-imx@nxp.com is checked by a lot of people.
It would be good to have N: lpuart (or fsl_lpuart?) in the
corresponding entry in MAINTAINERS, so it will automatically added.
I'll try to remember for the next patches though.
-michael
>
>> ---
>> drivers/tty/serial/fsl_lpuart.c | 35
>> +++++++--------------------------
>> 1 file changed, 7 insertions(+), 28 deletions(-)
>>
>> diff --git a/drivers/tty/serial/fsl_lpuart.c
>> b/drivers/tty/serial/fsl_lpuart.c
>> index bbba298b68a4..0910308b38b1 100644
>> --- a/drivers/tty/serial/fsl_lpuart.c
>> +++ b/drivers/tty/serial/fsl_lpuart.c
>> @@ -420,7 +420,6 @@ static void lpuart_dma_tx(struct lpuart_port
>> *sport)
>> {
>> struct circ_buf *xmit = &sport->port.state->xmit;
>> struct scatterlist *sgl = sport->tx_sgl;
>> - struct device *dev = sport->port.dev;
>> struct dma_chan *chan = sport->dma_tx_chan;
>> int ret;
>>
>> @@ -442,10 +441,8 @@ static void lpuart_dma_tx(struct lpuart_port
>> *sport)
>>
>> ret = dma_map_sg(chan->device->dev, sgl, sport->dma_tx_nents,
>> DMA_TO_DEVICE);
>> - if (!ret) {
>> - dev_err(dev, "DMA mapping error for TX.\n");
>> + if (!ret)
>> return;
>> - }
>>
>> sport->dma_tx_desc = dmaengine_prep_slave_sg(chan, sgl,
>> ret, DMA_MEM_TO_DEV,
>> @@ -453,7 +450,6 @@ static void lpuart_dma_tx(struct lpuart_port
>> *sport)
>> if (!sport->dma_tx_desc) {
>> dma_unmap_sg(chan->device->dev, sgl, sport->dma_tx_nents,
>> DMA_TO_DEVICE);
>> - dev_err(dev, "Cannot prepare TX slave DMA!\n");
>> return;
>> }
>>
>> @@ -520,21 +516,12 @@ static int lpuart_dma_tx_request(struct
>> uart_port *port)
>> struct lpuart_port *sport = container_of(port,
>> struct lpuart_port, port);
>> struct dma_slave_config dma_tx_sconfig = {};
>> - int ret;
>>
>> dma_tx_sconfig.dst_addr = lpuart_dma_datareg_addr(sport);
>> dma_tx_sconfig.dst_addr_width = DMA_SLAVE_BUSWIDTH_1_BYTE;
>> dma_tx_sconfig.dst_maxburst = 1;
>> dma_tx_sconfig.direction = DMA_MEM_TO_DEV;
>> - ret = dmaengine_slave_config(sport->dma_tx_chan, &dma_tx_sconfig);
>> -
>> - if (ret) {
>> - dev_err(sport->port.dev,
>> - "DMA slave config failed, err = %d\n", ret);
>> - return ret;
>> - }
>> -
>> - return 0;
>> + return dmaengine_slave_config(sport->dma_tx_chan, &dma_tx_sconfig);
>> }
>>
>> static bool lpuart_is_32(struct lpuart_port *sport)
>> @@ -1074,8 +1061,8 @@ static void lpuart_copy_rx_to_tty(struct
>> lpuart_port *sport)
>>
>> dmastat = dmaengine_tx_status(chan, sport->dma_rx_cookie, &state);
>> if (dmastat == DMA_ERROR) {
>> - dev_err(sport->port.dev, "Rx DMA transfer failed!\n");
>> spin_unlock_irqrestore(&sport->port.lock, flags);
>> + dev_err(sport->port.dev, "Rx DMA transfer failed!\n");
>> return;
>> }
>>
>> @@ -1179,23 +1166,17 @@ static inline int lpuart_start_rx_dma(struct
>> lpuart_port *sport)
>> sg_init_one(&sport->rx_sgl, ring->buf, sport->rx_dma_rng_buf_len);
>> nent = dma_map_sg(chan->device->dev, &sport->rx_sgl, 1,
>> DMA_FROM_DEVICE);
>> -
>> - if (!nent) {
>> - dev_err(sport->port.dev, "DMA Rx mapping error\n");
>> + if (!nent)
>> return -EINVAL;
>> - }
>>
>> dma_rx_sconfig.src_addr = lpuart_dma_datareg_addr(sport);
>> dma_rx_sconfig.src_addr_width = DMA_SLAVE_BUSWIDTH_1_BYTE;
>> dma_rx_sconfig.src_maxburst = 1;
>> dma_rx_sconfig.direction = DMA_DEV_TO_MEM;
>> - ret = dmaengine_slave_config(chan, &dma_rx_sconfig);
>>
>> - if (ret < 0) {
>> - dev_err(sport->port.dev,
>> - "DMA Rx slave config failed, err = %d\n", ret);
>> + ret = dmaengine_slave_config(chan, &dma_rx_sconfig);
>> + if (ret < 0)
>> return ret;
>> - }
>>
>> sport->dma_rx_desc = dmaengine_prep_dma_cyclic(chan,
>> sg_dma_address(&sport->rx_sgl),
>> @@ -1203,10 +1184,8 @@ static inline int lpuart_start_rx_dma(struct
>> lpuart_port *sport)
>> sport->rx_sgl.length / 2,
>> DMA_DEV_TO_MEM,
>> DMA_PREP_INTERRUPT);
>> - if (!sport->dma_rx_desc) {
>> - dev_err(sport->port.dev, "Cannot prepare cyclic DMA\n");
>> + if (!sport->dma_rx_desc)
>> return -EFAULT;
>> - }
>>
>> sport->dma_rx_desc->callback = lpuart_dma_rx_complete;
>> sport->dma_rx_desc->callback_param = sport;
>>
next prev parent reply other threads:[~2020-03-25 12:44 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-06 21:44 [PATCH v4 0/4] tty: serial: fsl_lpuart: various fixes and LS1028A support Michael Walle
2020-03-06 21:44 ` [PATCH v4 1/4] tty: serial: fsl_lpuart: fix DMA operation when using IOMMU Michael Walle
2020-03-24 15:27 ` Leonard Crestez
2020-03-24 16:12 ` Andy Duan
2020-03-24 16:17 ` Michael Walle
2020-03-24 16:28 ` [EXT] " Andy Duan
2020-03-24 16:35 ` Michael Walle
2020-03-25 4:08 ` Andy Duan
2020-03-25 8:30 ` Michael Walle
2020-03-24 16:22 ` Michael Walle
2020-03-24 18:47 ` [PATCH 1/3] tty: serial: fsl_lpuart: move dev_info_once() Michael Walle
2020-03-24 18:47 ` [PATCH 2/3] tty: serial: fsl_lpuart: fix return value checking Michael Walle
2020-03-24 18:47 ` [RFC PATCH 3/3] tty: serial: fsl_lpuart: fix possible console deadlock Michael Walle
2020-03-25 12:21 ` Leonard Crestez
2020-03-25 12:44 ` Michael Walle [this message]
2020-03-25 9:15 ` [PATCH 1/3] tty: serial: fsl_lpuart: move dev_info_once() Michael Walle
2020-03-06 21:44 ` [PATCH v4 2/4] tty: serial: fsl_lpuart: fix DMA mapping Michael Walle
2020-03-06 21:44 ` [PATCH v4 3/4] tty: serial: fsl_lpuart: add LS1028A support Michael Walle
2020-03-06 21:44 ` [PATCH v4 4/4] tty: serial: fsl_lpuart: add LS1028A earlycon support Michael Walle
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=201514c22f86f3599385d4ddbeb71f1a@walle.cc \
--to=michael@walle.cc \
--cc=fugang.duan@nxp.com \
--cc=gregkh@linuxfoundation.org \
--cc=jslaby@suse.com \
--cc=leonard.crestez@nxp.com \
--cc=linux-imx@nxp.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-serial@vger.kernel.org \
--cc=shawnguo@kernel.org \
/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
all inboxes | Powered by JetHome®