Re: [PATCH v2 3/4] dmaengine: idxd: unlink a channel under dma_list_mutex before removing it

From: Frank Li

Date: Mon Nov 30 2026 - 16:32:43 EST


On Mon, Nov 30, 2026 at 11:52:02AM -0800, Daniel Byrne wrote:
> The unbind of a work queue unlinks its channel from the dma_device's
> channel list after the core has unregistered the channel, and without
> dma_list_mutex. A channel request walks that list under the mutex and
> may hand out any listed channel without a client, so it can still take a
> channel whose sysfs device is gone and whose idxd_chan the unbind is
> about to free, and the unlocked list_del() races the locked link of
> another queue's channel. The quiesce that precedes the unregistration
> kills the queue's submissions, not the channel's presence on the list.
>
> Add dma_async_device_channel_remove(), the counterpart of
> dma_async_device_channel_add(). It unlinks the channel under the mutex
> first and unregisters it afterwards, which the core can do and the
> driver cannot, since the mutex is private to it. Use it in the unbind.
> After the locked unlink no walker under the mutex finds the channel.
>
> A client that took the channel between the quiesce and the unlink still
> holds idxd_chan across the kfree(). This is a broader lifetime problem
> of a channel unbound under its clients, and is left for the change that
> reworks the unbind for channels that clients still hold.
>
> Fixes: 397862855619 ("dmaengine: idxd: fix dma device lifetime")
> Cc: stable@xxxxxxxxxxxxxxx # 5.13+
> Signed-off-by: Daniel Byrne <daniel1.byrne@xxxxxxxxx>
> ---
> New in v2.
>
> drivers/dma/dmaengine.c | 26 ++++++++++++++++++++++++++
> drivers/dma/dmaengine.h | 2 ++

combine dma_async_device_channel_remove() and _add() to one prepare patch.

Frank

> drivers/dma/idxd/dma.c | 3 +--
> 3 files changed, 29 insertions(+), 2 deletions(-)