From: Frank Li <Frank.li@oss.nxp.com>
To: Shivank Garg <shivankg@amd.com>
Cc: Vinod Koul <vkoul@kernel.org>, Frank Li <Frank.Li@kernel.org>,
Logan Gunthorpe <logang@deltatee.com>,
Andrew Morton <akpm@linux-foundation.org>,
stable@vger.kernel.org, dmaengine@vger.kernel.org,
linux-kernel@vger.kernel.org, Sashiko <sashiko-bot@kernel.org>
Subject: Re: [PATCH v3 3/3] dmaengine: wait for RCU readers before releasing dma_device
Date: Mon, 17 Aug 2026 09:29:40 -0500 [thread overview]
Message-ID: <aoMa1GTFd-R0Ep6J@SMW015318> (raw)
In-Reply-To: <20260816-dmaengine-kref-fix-v3-3-7e76187145df@amd.com>
On Sun, Aug 16, 2026 at 03:49:27PM +0000, Shivank Garg wrote:
> [You don't often get email from shivankg@amd.com. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]
>
> dma_issue_pending_all() walks the dma_device_list with
> list_for_each_entry_rcu() under rcu_read_lock(). dma_device_release()
> unlinks the device with list_del_rcu() and then calls
> device->device_release() (which in many drivers, such as plx_dma.c,
> directly calls kfree()).
>
> Because there is no grace period between unlinking the device and
> freeing it, concurrent RCU readers in dma_issue_pending_all() can
> access the device after it has been freed.
>
> The lockless walk originally relied on clients holding a dmaengine
> reference to pin the provider module, and therefore the device, for as
> long as they might traverse the list. Commit 8ad342a86359 ("dmaengine:
> Add reference counting to dma_device struct") decoupled the dma_device
> lifetime from the module reference, so the device can now be released
> while a reader is still walking the list.
>
> Add synchronize_rcu() before the device is freed, so RCU readers are
> guaranteed to have finished. Keep it unconditional: providers that do
> not implement device_release() free the device themselves once
> dma_async_device_unregister() returns, so they need the same grace
> period.
>
> Fixes: 2ba05622b8b1 ("dmaengine: provide a common 'issue_pending_all' implementation")
> Suggested-by: Sashiko <sashiko-bot@kernel.org>
> Link: https://sashiko.dev/#/patchset/20260526-dmaengine-kref-fix-v2-0-3df60afac01d@amd.com
> Signed-off-by: Shivank Garg <shivankg@amd.com>
> ---
Reviewed-by: Frank Li <Frank.Li@nxp.com>
> drivers/dma/dmaengine.c | 6 ++++++
> 1 file changed, 6 insertions(+)
>
> diff --git a/drivers/dma/dmaengine.c b/drivers/dma/dmaengine.c
> index bf491eb10596..29b128aa0bea 100644
> --- a/drivers/dma/dmaengine.c
> +++ b/drivers/dma/dmaengine.c
> @@ -429,6 +429,12 @@ static void dma_device_release(struct kref *ref)
> list_del_rcu(&device->global_node);
> dma_channel_rebalance();
>
> + /*
> + * Wait for RCU readers (e.g. dma_issue_pending_all()) that may still
> + * be traversing dma_device_list before the device is freed.
> + */
> + synchronize_rcu();
> +
> if (device->device_release)
> device->device_release(device);
> }
>
> --
> 2.43.0
>
prev parent reply other threads:[~2026-08-17 14:29 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-16 15:49 [PATCH v3 0/3] dmaengine: fix kref underflow and UAF in dma_chan_put() Shivank Garg
2026-08-16 15:49 ` [PATCH v3 1/3] dmaengine: Fix device kref underflow " Shivank Garg
2026-08-16 16:02 ` sashiko-bot
2026-08-16 18:14 ` Garg, Shivank
2026-08-17 14:17 ` Frank Li
2026-08-16 15:49 ` [PATCH v3 2/3] dmaengine: fix use-after-free in dma_chan_put() and dma_release_channel() Shivank Garg
2026-08-16 16:07 ` sashiko-bot
2026-08-16 18:05 ` Garg, Shivank
2026-08-17 14:26 ` Frank Li
2026-08-17 14:24 ` Frank Li
2026-08-16 15:49 ` [PATCH v3 3/3] dmaengine: wait for RCU readers before releasing dma_device Shivank Garg
2026-08-16 16:10 ` sashiko-bot
2026-08-17 14:29 ` 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=aoMa1GTFd-R0Ep6J@SMW015318 \
--to=frank.li@oss.nxp.com \
--cc=Frank.Li@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=dmaengine@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=logang@deltatee.com \
--cc=sashiko-bot@kernel.org \
--cc=shivankg@amd.com \
--cc=stable@vger.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