mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Frank Li <Frank.li@oss.nxp.com>
To: zhejun_huang@linux.alibaba.com
Cc: Vinod Koul <vkoul@kernel.org>, Frank Li <Frank.Li@kernel.org>,
	dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org,
	stable@vger.kernel.org
Subject: Re: [PATCH] dmaengine: Free channel ID after device_unregister()
Date: Tue, 10 Nov 2026 08:51:17 -0600	[thread overview]
Message-ID: <avMvZbxgeAgWEZUP@SMW015318> (raw)
In-Reply-To: <20261110101607.13784-1-zhejun_huang@linux.alibaba.com>

On Tue, Nov 10, 2026 at 06:16:07PM +0800, zhejun_huang@linux.alibaba.com wrote:
>
> From: Zhejun Huang <zhejun_huang@linux.alibaba.com>
>
> __dma_async_device_channel_unregister() frees the channel ID before calling
> device_unregister(). Between ida_free() and device_del() a concurrent
> __dma_async_device_channel_register() on the same device can reallocate the
> ID and try to register a device with the same name while the old one is
> still present, failing with -EEXIST.
>
> This is reachable in practice: idxd calls these functions from its
> per-workqueue probe and remove callbacks, which are only serialized by a
> per-wq mutex. Enabling one wq while another is being removed therefore
> runs them concurrently on the same dma_device.
>
> Move ida_free() after device_unregister() so that device_del() removes the
> name before the ID becomes reusable.
>
> Fixes: 0821009445a8 ("dmaengine: fix channel index enumeration")
> Cc: <stable@vger.kernel.org> # 5.7+
> Signed-off-by: Zhejun Huang <zhejun_huang@linux.alibaba.com>

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

> ---
>  drivers/dma/dmaengine.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/dma/dmaengine.c b/drivers/dma/dmaengine.c
> index 34be53487a21..2642abf105d7 100644
> --- a/drivers/dma/dmaengine.c
> +++ b/drivers/dma/dmaengine.c
> @@ -1171,8 +1171,8 @@ static void __dma_async_device_channel_unregister(struct dma_device *device,
>         device->chancnt--;
>         chan->chan_dev->chan = NULL;
>         mutex_unlock(&dma_list_mutex);
> -       ida_free(&device->chan_ida, chan->chan_id);
>         device_unregister(dmaengine_chan_dev(chan));
> +       ida_free(&device->chan_ida, chan->chan_id);
>         free_percpu(chan->local);
>  }
>
>
> base-commit: d48723711bae9b8cdc56719c448ba42fef28cbee
> --
> 2.50.1 (Apple Git-155)
>

      reply	other threads:[~2026-11-10 14:51 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-10 10:16 zhejun_huang
2026-11-10 14:51 ` 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=avMvZbxgeAgWEZUP@SMW015318 \
    --to=frank.li@oss.nxp.com \
    --cc=Frank.Li@kernel.org \
    --cc=dmaengine@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --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®