mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Frank Li <Frank.li@oss.nxp.com>
To: Daniel Byrne <daniel1.byrne@intel.com>
Cc: Vinod Koul <vkoul@kernel.org>,
	dmaengine@vger.kernel.org,
	Vinicius Costa Gomes <vinicius.gomes@intel.com>,
	Dave Jiang <dave.jiang@intel.com>, Frank Li <Frank.Li@kernel.org>,
	Dan Williams <djbw@kernel.org>, Ruoyu Wang <ruoyuw560@gmail.com>,
	Zhejun Huang <zhejun_huang@linux.alibaba.com>,
	Changyul Lee <lcy8047@gmail.com>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 4/4] dmaengine: rebalance a dynamically registered channel under dma_list_mutex
Date: Mon, 30 Nov 2026 16:09:22 -0600	[thread overview]
Message-ID: <aw30EuN0a9N04z3b@SMW015318> (raw)
In-Reply-To: <20261130195203.1901143-5-daniel1.byrne@intel.com>

On Mon, Nov 30, 2026 at 11:52:03AM -0800, Daniel Byrne wrote:
> dma_async_device_channel_register() and
> dma_async_device_channel_unregister() call dma_channel_rebalance()
> without dma_list_mutex, which the function requires. It clears every
> slot of the channel table and repopulates it from a walk of the device
> list, so a concurrent locked rebalance from dmaengine_get() or a device
> registration interleaves with it. Public channels lose their table
> entries until the next one, and a device release can delete the entry
> the unlocked walk is on. The device's channel count is bumped without
> the mutex on the same path and dropped under it on the other.
>
> Take the mutex around the two rebalances and the count. Neither caller
> holds it, and the helpers underneath take and drop it themselves.
>
> Fixes: e81274cd6b52 ("dmaengine: add support to dynamic register/unregister of channels")
> Signed-off-by: Daniel Byrne <daniel1.byrne@intel.com>
> ---

Reviewed-by: Frank Li <Frank.Li@nxp.com>

> New in v2.
>
>  drivers/dma/dmaengine.c | 6 ++++++
>  1 file changed, 6 insertions(+)
>
> diff --git a/drivers/dma/dmaengine.c b/drivers/dma/dmaengine.c
> index 85a98aae6a97..49ecbdaf6dbb 100644
> --- a/drivers/dma/dmaengine.c
> +++ b/drivers/dma/dmaengine.c
> @@ -1137,7 +1137,9 @@ static int __dma_async_device_channel_register(struct dma_device *device,
>  		goto err_free_local;
>  	}
>  	chan->client_count = 0;
> +	mutex_lock(&dma_list_mutex);
>  	device->chancnt++;
> +	mutex_unlock(&dma_list_mutex);
>
>  	return 0;
>
> @@ -1159,7 +1161,9 @@ int dma_async_device_channel_register(struct dma_device *device,
>  	if (rc < 0)
>  		return rc;
>
> +	mutex_lock(&dma_list_mutex);
>  	dma_channel_rebalance();
> +	mutex_unlock(&dma_list_mutex);
>  	return 0;
>  }
>  EXPORT_SYMBOL_GPL(dma_async_device_channel_register);
> @@ -1227,7 +1231,9 @@ void dma_async_device_channel_unregister(struct dma_device *device,
>  					 struct dma_chan *chan)
>  {
>  	__dma_async_device_channel_unregister(device, chan);
> +	mutex_lock(&dma_list_mutex);
>  	dma_channel_rebalance();
> +	mutex_unlock(&dma_list_mutex);
>  }
>  EXPORT_SYMBOL_GPL(dma_async_device_channel_unregister);
>
> --
> 2.43.0
>

      reply	other threads:[~2026-11-30 22:09 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-30 19:51 [PATCH v2 0/4] dmaengine: fixes for channels registered and removed at run time Daniel Byrne
2026-11-30 19:52 ` [PATCH v2 1/4] dmaengine: put a channel device whose registration failed Daniel Byrne
2026-11-30 21:13   ` Frank Li
2026-11-30 19:52 ` [PATCH v2 2/4] dmaengine: idxd: list a new channel only once it is complete Daniel Byrne
2026-11-30 21:30   ` Frank Li
2026-11-30 19:52 ` [PATCH v2 3/4] dmaengine: idxd: unlink a channel under dma_list_mutex before removing it Daniel Byrne
2026-11-30 21:32   ` Frank Li
2026-11-30 19:52 ` [PATCH v2 4/4] dmaengine: rebalance a dynamically registered channel under dma_list_mutex Daniel Byrne
2026-11-30 22:09   ` 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=aw30EuN0a9N04z3b@SMW015318 \
    --to=frank.li@oss.nxp.com \
    --cc=Frank.Li@kernel.org \
    --cc=daniel1.byrne@intel.com \
    --cc=dave.jiang@intel.com \
    --cc=djbw@kernel.org \
    --cc=dmaengine@vger.kernel.org \
    --cc=lcy8047@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ruoyuw560@gmail.com \
    --cc=vinicius.gomes@intel.com \
    --cc=vkoul@kernel.org \
    --cc=zhejun_huang@linux.alibaba.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

all inboxes | Powered by JetHome®