From: sashiko-bot@kernel.org
To: "Logan Gunthorpe" <logang@deltatee.com>
Cc: vkoul@kernel.org, linux-pci@vger.kernel.org, Frank.Li@kernel.org,
dmaengine@vger.kernel.org
Subject: Re: [PATCH v5 02/12] dmaengine: switchtec-dma: fix resource leak in alloc_chan_resources
Date: Mon, 31 Aug 2026 21:38:48 +0000 [thread overview]
Message-ID: <20260831213849.645A51F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260831191403.207631-3-logang@deltatee.com>
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
Pre-existing issues:
- [High] switchtec_dma_remove() tears down hardware resources before unregistering the DMA device, exposing a race window where new clients can request channels on a dying device.
- [High] The driver holds a spinlock between dmaengine prep_desc and tx_submit, violating dmaengine semantics and risking deadlocks.
- [High] The driver performs massive allocations using GFP_NOWAIT in process context, which is highly likely to fail under memory pressure.
--
commit dac58125b9c3b4ce36e518a88347266e281e5a57
Author: Logan Gunthorpe <logang@deltatee.com>
dmaengine: switchtec-dma: fix resource leak in alloc_chan_resources
This commit fixes a resource leak in switchtec_dma_alloc_chan_resources()
where descriptor rings and coherent DMA memory were not freed on failure.
It adds an error-unwind path to properly disable the channel and free the
resources since the dmaengine core does not handle this automatically.
Link: https://lore.kernel.org/dmaengine/20260707165555.350951F000E9@smtp.kernel.org
> diff --git a/drivers/dma/switchtec_dma.c b/drivers/dma/switchtec_dma.c
> index a10818efba4e5..e55fe9ff7e2c5 100644
> --- a/drivers/dma/switchtec_dma.c
> +++ b/drivers/dma/switchtec_dma.c
[ ... ]
While reviewing this code, I noticed a few pre-existing issues in the driver
that might need attention:
drivers/dma/switchtec_dma.c:switchtec_dma_remove() {
...
> switchtec_dma_chans_release(pdev, swdma_dev);
>
> rcu_assign_pointer(swdma_dev->pdev, NULL);
> synchronize_rcu();
>
> pci_free_irq(pdev, swdma_dev->chan_status_irq, swdma_dev);
>
> pci_free_irq_vectors(pdev);
>
> dma_async_device_unregister(&swdma_dev->dma_dev);
[Severity: High]
This isn't a bug introduced by this patch, but does this teardown order expose
a race window where new clients can request channels on a dying device?
If a concurrent client requests a channel via dma_request_chan() during
switchtec_dma_remove(), the DMA core will route it to this device because it
has not yet been unregistered.
The client will then trigger switchtec_dma_alloc_chan_resources(), which
re-activates a channel whose IRQs and tasklets were already permanently
destroyed by switchtec_dma_chans_release().
Should dma_async_device_unregister() be called first to safely detach the
device from the subsystem before destroying local hardware resources?
drivers/dma/switchtec_dma.c:switchtec_dma_prep_desc() {
...
> spin_lock_bh(&swdma_chan->submit_lock);
>
> if (!swdma_chan->ring_active)
> goto err_unlock;
and in switchtec_dma_tx_submit():
> spin_unlock_bh(&swdma_chan->submit_lock);
>
> return cookie;
[Severity: High]
This is a pre-existing issue, but could holding submit_lock across dmaengine
API boundaries risk deadlocks?
If a client attempts to prepare multiple descriptors sequentially before
submitting them (batching prep operations), wouldn't the second call to
dmaengine_prep_dma_memcpy() attempt to acquire the exact same lock and
deadlock?
Furthermore, this leaves the caller's CPU permanently locked with softirqs
disabled if the client prepares a descriptor but aborts before submitting it.
The dmaengine API explicitly allows batching of prep operations.
drivers/dma/switchtec_dma.c:switchtec_dma_alloc_desc() {
...
> swdma_chan->hw_sq = dma_alloc_coherent(swdma_dev->dma_dev.dev, size,
> &swdma_chan->dma_addr_sq,
> GFP_NOWAIT);
...
> for (i = 0; i < SWITCHTEC_DMA_RING_SIZE; i++) {
> desc = kzalloc_obj(*desc, GFP_NOWAIT);
> if (!desc) {
> rc = -ENOMEM;
> goto free_and_exit;
> }
[Severity: High]
This isn't a bug introduced by this patch, but could these allocations use
GFP_KERNEL instead?
Because switchtec_dma_alloc_chan_resources() is called in process context and
is allowed to sleep, using GFP_NOWAIT here performs massive allocations
without direct reclaim.
The driver attempts to allocate 1MB of coherent DMA memory and performs 32,768
consecutive atomic allocations, which seems highly likely to fail on
fragmented or loaded systems under memory pressure.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260831191403.207631-1-logang@deltatee.com?part=2
next prev parent reply other threads:[~2026-08-31 21:38 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-31 19:13 [PATCH v5 00/12] dmaengine: miscellaneous fixes for ioat, switchtec_dma and plx_dma Logan Gunthorpe
2026-08-31 19:13 ` [PATCH v5 01/12] dmaengine: switchtec-dma: fix double-free in switchtec_dma_free_desc() Logan Gunthorpe
2026-08-31 21:28 ` sashiko-bot
2026-08-31 19:13 ` [PATCH v5 02/12] dmaengine: switchtec-dma: fix resource leak in alloc_chan_resources Logan Gunthorpe
2026-08-31 21:38 ` sashiko-bot [this message]
2026-08-31 19:13 ` [PATCH v5 03/12] dmaengine: switchtec-dma: always clear DMA base registers on chan_stop() Logan Gunthorpe
2026-08-31 21:51 ` sashiko-bot
2026-08-31 22:43 ` Logan Gunthorpe
2026-08-31 19:13 ` [PATCH v5 04/12] dmaengine: switchtec-dma: halt channel on alloc_chan_resources error Logan Gunthorpe
2026-08-31 22:04 ` sashiko-bot
2026-08-31 19:13 ` [PATCH v5 05/12] dmaengine: switchtec-dma: fix channel leak on registration failure Logan Gunthorpe
2026-08-31 22:18 ` sashiko-bot
2026-08-31 19:13 ` [PATCH v5 06/12] dmaengine: switchtec-dma: make switchtec_dma_chans_release() void Logan Gunthorpe
2026-08-31 22:24 ` sashiko-bot
2026-08-31 19:13 ` [PATCH v5 07/12] dmaengine: switchtec-dma: fix chan_status_irq cleanup on create() error Logan Gunthorpe
2026-08-31 22:35 ` sashiko-bot
2026-08-31 19:13 ` [PATCH v5 08/12] dmaengine: switchtec-dma: disable channels before freeing on registration failure Logan Gunthorpe
2026-08-31 22:50 ` sashiko-bot
2026-08-31 19:13 ` [PATCH v5 09/12] dmaengine: switchtec-dma: fix use-after-free of swdma_dev in remove() Logan Gunthorpe
2026-08-31 23:04 ` sashiko-bot
2026-08-31 19:14 ` [PATCH v5 10/12] dmaengine: ioat: disable relaxed ordering before registering the device Logan Gunthorpe
2026-08-31 23:13 ` sashiko-bot
2026-08-31 19:14 ` [PATCH v5 11/12] dmaengine: ioat: use sysfs_emit() in per-channel sysfs show() Logan Gunthorpe
2026-08-31 23:19 ` sashiko-bot
2026-08-31 19:14 ` [PATCH v5 12/12] dmaengine: plx_dma: fix NULL pointer deref in plx_dma_isr() Logan Gunthorpe
2026-08-31 23:30 ` sashiko-bot
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=20260831213849.645A51F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=Frank.Li@kernel.org \
--cc=dmaengine@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=logang@deltatee.com \
--cc=sashiko-reviews@lists.linux.dev \
--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