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, stable@vger.kernel.org
Subject: Re: [PATCH v2 2/4] dmaengine: idxd: list a new channel only once it is complete
Date: Mon, 30 Nov 2026 15:30:12 -0600 [thread overview]
Message-ID: <aw3q5MfjV60Y6WHg@SMW015318> (raw)
In-Reply-To: <20261130195203.1901143-3-daniel1.byrne@intel.com>
On Mon, Nov 30, 2026 at 11:52:01AM -0800, Daniel Byrne wrote:
> idxd_register_dma_channel() links a new channel into the dma_device's
> channel list before it registers the channel, and sets the channel's
> work queue only after that. The dma_device is registered when the device
> is enabled, before any of its work queues, and a channel request walks
> the channel list of every registered device under dma_list_mutex and may
> hand out any listed channel without a client. A request that runs while
> a work queue is being enabled can therefore take the half-built channel,
> and the allocation callback dereferences its NULL work queue with
> dma_list_mutex held. After that every channel request and release hangs.
> The link runs without that mutex as well, so it races the walkers.
>
> When the registration fails, the channel is unlinked again before it is
> freed, since "dmaengine: idxd: Remove channel from list on registration
> failure" [1]. Until then it is on the list like any other, where a
> request can take the channel that is about to be freed, and the unlink
> runs without the mutex as the link does.
>
> Add dma_async_device_channel_add(), which registers a channel and only
> then links it into its device's list, under dma_list_mutex, and use it.
> The driver sets the channel's work queue and initializes its descriptors
> before the call, so a request finds the channel complete or not at all,
> and a channel that failed to register is never listed. An enable whose
> registration fails still fails, and has nothing to unlink, so drop the
> list_del() that [1] added on the error path.
>
> This is a new helper rather than a change to
> dma_async_device_channel_register(), whose contract requires the caller
> to have linked the channel into the device's list already. virt-dma's
> vchan_init() does that for stm32-dma3, the only other caller. That
> driver has the same window between the link and the registration and is
> left for a follow-up.
>
> The helper serves DMA_PRIVATE devices such as idxd's only. The channel
> list of a public device is also walked under RCU alone, and its channels
> hold references for the dmaengine_get() users, which the helper does not
> take. The unbind still unlinks the channel without the mutex, which
> needs a core helper that unlinks under it.
>
> The hang is reachable since the dma_device registration moved to the
> device enable in v5.13, so this is for stable too.
>
> Fixes: 8f47d1a5e545 ("dmaengine: idxd: connect idxd to dmaengine subsystem")
> Fixes: 397862855619 ("dmaengine: idxd: fix dma device lifetime")
> Cc: stable@vger.kernel.org # 5.13+
> Signed-off-by: Daniel Byrne <daniel1.byrne@intel.com>
> Link: https://lore.kernel.org/r/20260709062303.4167624-1-ruoyuw560@gmail.com [1]
> ---
> v2: dma_async_device_channel_add() is declared in
> drivers/dma/dmaengine.h, next to dma_async_device_channel_register() on
> the new base, instead of include/linux/dmaengine.h; the helper itself is
> unchanged. idxd_register_dma_channel() drops the list_del() that
> "dmaengine: idxd: Remove channel from list on registration failure"
> added to its error path, since a channel that failed to register is
> never listed. The message describes the failed registration as it is
> after that patch, with a Link to it, and no longer describes the -EEXIST
> id reuse; of the unbind's unlink without the mutex it now says that this
> needs a core helper, where v1 pointed at a later rework of the unbind.
>
> drivers/dma/dmaengine.c | 41 +++++++++++++++++++++++++++++++++++++++++
> drivers/dma/dmaengine.h | 2 ++
Use sperate patch to add APIs
> drivers/dma/idxd/dma.c | 13 +++++++++----
> 3 files changed, 52 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/dma/dmaengine.c b/drivers/dma/dmaengine.c
> index b1cb466f376f..1d8d2949a810 100644
> --- a/drivers/dma/dmaengine.c
> +++ b/drivers/dma/dmaengine.c
> @@ -1164,6 +1164,47 @@ int dma_async_device_channel_register(struct dma_device *device,
> }
> EXPORT_SYMBOL_GPL(dma_async_device_channel_register);
>
> +/**
> + * dma_async_device_channel_add - register a channel and make it available
> + * @device: the dmaengine device, DMA_PRIVATE and registered already
> + * @chan: the channel, not on @device's channel list
> + * @name: the channel's name, or NULL for the default one
> + *
> + * Channel requests walk the channel list of every registered device under
> + * dma_list_mutex and may hand out any listed channel that has no client.
> + * A channel added to a registered device is therefore linked to the list
> + * only once it is registered, and under that mutex, so that a request
> + * never finds it half initialized. The driver's own state behind the
> + * channel must be complete before the call. A channel that fails to
> + * register is not linked.
> + *
> + * Only a DMA_PRIVATE device may add channels this way. The channel list
> + * of a public device is also walked under RCU alone, and its channels
> + * hold references for the dmaengine_get() users, which this function
> + * does not take.
> + *
> + * Return: 0 on success or a negative errno.
> + */
> +int dma_async_device_channel_add(struct dma_device *device,
> + struct dma_chan *chan, const char *name)
> +{
New API should use prefix dmaengine_
Frank
next prev parent reply other threads:[~2026-11-30 21:30 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 [this message]
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
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=aw3q5MfjV60Y6WHg@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=stable@vger.kernel.org \
--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®