mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Frank Li <Frank.li@oss.nxp.com>
To: James Hilliard <james.hilliard1@gmail.com>
Cc: "Viresh Kumar" <vireshk@kernel.org>,
	"Andy Shevchenko" <andriy.shevchenko@linux.intel.com>,
	"Vinod Koul" <vkoul@kernel.org>, "Frank Li" <Frank.Li@kernel.org>,
	"Dan Williams" <djbw@kernel.org>,
	"Serge Semin" <fancer.lancer@gmail.com>,
	"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	"Jiri Slaby" <jirislaby@kernel.org>,
	"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>,
	dmaengine@vger.kernel.org, linux-serial@vger.kernel.org,
	linux-kernel@vger.kernel.org, Sashiko <sashiko-bot@kernel.org>,
	"Lars-Peter Clausen" <lars@metafoo.de>,
	stable@vger.kernel.org
Subject: Re: [PATCH v6 10/10] dmaengine: dw: Prevent tx-status calling DMA-desc callback
Date: Fri, 13 Nov 2026 14:30:26 -0500	[thread overview]
Message-ID: <avdlUjK85rU08VHB@lizhi-Precision-Tower-5810> (raw)
In-Reply-To: <20261103-submit-dw-dma-synchronize-v1-v6-10-2ee0c348224d@gmail.com>

On Tue, Nov 03, 2026 at 03:26:12PM -0700, James Hilliard wrote:
> From: Serge Semin <fancer.lancer@gmail.com>
>
> The DMA transfer status getter can invoke a completion callback from
> dwc_scan_descriptors(). An 8250 RX timeout queries that status while
> holding the UART port lock, and its DMA callback takes the same lock:
>
>   serial8250_handle_irq()
>     uart_port_lock_irqsave(port)
>     serial8250_rx_dma_flush()
>       dmaengine_tx_status()
>         dwc_scan_descriptors()
>           dwc_descriptor_free()
>             dma_rx_complete()
>               uart_port_lock_irqsave(port)
>
> Queue completed descriptors on a channel completion list under the channel
> lock. Let the controller tasklet detach that list and invoke callbacks
> outside the lock. Termination discards notifications still on the shared
> list; the tasklet owns descriptors it has already detached, and the
> synchronization hook waits for that run.
>
> Keep handling raw completion events from tx_status(). Clients such as
> catpt poll transfers without DMA_PREP_INTERRUPT and can mask the controller
> interrupt externally. Polling must still advance software-emulated LLP
> blocks and complete cookies without waiting for tasklet execution. Hold
> the channel lock across event handling and status calculation, then
> schedule the tasklet for deferred notifications.
>
> On channel release, discard queued notifications after draining the
> tasklet, before clearing the controller's in-use state.
>
> Fixes: 3bfb1d20b547 ("dmaengine: Driver for the Synopsys DesignWare DMA controller")
> Cc: stable@vger.kernel.org
> Signed-off-by: Serge Semin <fancer.lancer@gmail.com>
> [james: defer notifications while preserving polled completion and cleanup]
> Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
> ---
...
> @@ -988,19 +994,26 @@ dwc_tx_status(struct dma_chan *chan,
>  	      struct dma_tx_state *txstate)
>  {
>  	struct dw_dma_chan	*dwc = to_dw_dma_chan(chan);
> +	struct dw_dma		*dw = to_dw_dma(chan->device);
>  	enum dma_status		ret;
> +	unsigned long		flags;
>
> +	spin_lock_irqsave(&dwc->lock, flags);

use clean up guard to avoid below goto

Frank

>  	ret = dma_cookie_status(chan, cookie, txstate);
>  	if (ret == DMA_COMPLETE)
> -		return ret;
> +		goto unlock;
>
> -	dwc_scan_descriptors(to_dw_dma(chan->device), dwc);
> +	/* Poll completion even when the client has masked the controller IRQ. */
> +	dwc_handle_channel(dw, dwc);
> +	if (!list_empty(&dwc->completed))
> +		tasklet_schedule(&dw->tasklet);
>
>  	ret = dma_cookie_status(chan, cookie, txstate);
> -	if (ret == DMA_COMPLETE)
> -		return ret;
> +	if (ret != DMA_COMPLETE)
> +		dma_set_residue(txstate, dwc_get_residue_and_status(dwc, cookie, &ret));
>
> -	dma_set_residue(txstate, dwc_get_residue_and_status(dwc, cookie, &ret));
> +unlock:
> +	spin_unlock_irqrestore(&dwc->lock, flags);
>  	return ret;
>  }
>
> @@ -1079,6 +1092,7 @@ static void dwc_free_chan_resources(struct dma_chan *chan)
>  	struct dw_dma		*dw = to_dw_dma(chan->device);
>  	unsigned long		flags;
>
> +	/* Polled completion can leave descriptors waiting for the tasklet. */
>  	tasklet_disable(&dw->tasklet);
>
>  	dev_dbg(dmaengine_chan_dev(chan), "%s: descs allocated=%u\n", __func__,
> @@ -1089,6 +1103,8 @@ static void dwc_free_chan_resources(struct dma_chan *chan)
>  	BUG_ON(!list_empty(&dwc->queue));
>  	BUG_ON(dma_readl(to_dw_dma(chan->device), CH_EN) & dwc->mask);
>
> +	dwc_free_completed(dwc, false);
> +
>  	spin_lock_irqsave(&dwc->lock, flags);
>
>  	/* Clear custom channel configuration */
> @@ -1238,6 +1254,7 @@ int do_dma_probe(struct dw_dma_chip *chip)
>
>  		INIT_LIST_HEAD(&dwc->active_list);
>  		INIT_LIST_HEAD(&dwc->queue);
> +		INIT_LIST_HEAD(&dwc->completed);
>
>  		channel_clear_bit(dw, CH_EN, dwc->mask);
>
> diff --git a/drivers/dma/dw/regs.h b/drivers/dma/dw/regs.h
> index 5969d9cc8d7a..c41f18281efe 100644
> --- a/drivers/dma/dw/regs.h
> +++ b/drivers/dma/dw/regs.h
> @@ -279,6 +279,7 @@ struct dw_dma_chan {
>  	unsigned long		flags;
>  	struct list_head	active_list;
>  	struct list_head	queue;
> +	struct list_head	completed;
>
>  	unsigned int		descs_allocated;
>
>
> --
> 2.53.0
>

      reply	other threads:[~2026-11-13 19:30 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-03 22:26 [PATCH v6 00/10] dmaengine: dw: serialize completion and termination James Hilliard
2026-11-03 22:26 ` [PATCH v6 01/10] dmaengine: dw: Fix XFER bit set, but channel not idle error James Hilliard
2026-11-03 22:26 ` [PATCH v6 02/10] dmaengine: dw: serialize error recovery with channel termination James Hilliard
2026-11-03 22:26 ` [PATCH v6 03/10] dmaengine: dw: complete cookies before releasing the channel lock James Hilliard
2026-11-03 22:26 ` [PATCH v6 04/10] dmaengine: dw: extract hardware-LLP residue calculation James Hilliard
2026-11-04 20:07   ` Frank Li
2026-11-13 19:20   ` Frank Li
2026-11-03 22:26 ` [PATCH v6 05/10] dmaengine: dw: calculate residue in the status getter James Hilliard
2026-11-04 20:21   ` Frank Li
2026-11-03 22:26 ` [PATCH v6 06/10] dmaengine: dw: simplify transfer-complete handling James Hilliard
2026-11-04 20:27   ` Frank Li
2026-11-03 22:26 ` [PATCH v6 07/10] dmaengine: dw: report residue for queued transfers James Hilliard
2026-11-13 19:21   ` Frank Li
2026-11-03 22:26 ` [PATCH v6 08/10] dmaengine: dw: drain the tasklet before releasing channel resources James Hilliard
2026-11-03 22:26 ` [PATCH v6 09/10] dmaengine: dw: synchronize completion callbacks James Hilliard
2026-11-03 22:26 ` [PATCH v6 10/10] dmaengine: dw: Prevent tx-status calling DMA-desc callback James Hilliard
2026-11-13 19:30   ` Frank Li [this message]

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=avdlUjK85rU08VHB@lizhi-Precision-Tower-5810 \
    --to=frank.li@oss.nxp.com \
    --cc=Frank.Li@kernel.org \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=djbw@kernel.org \
    --cc=dmaengine@vger.kernel.org \
    --cc=fancer.lancer@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=ilpo.jarvinen@linux.intel.com \
    --cc=james.hilliard1@gmail.com \
    --cc=jirislaby@kernel.org \
    --cc=lars@metafoo.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=sashiko-bot@kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=vireshk@kernel.org \
    --cc=vkoul@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®