From: sashiko-bot@kernel.org
To: "Logan Gunthorpe" <logang@deltatee.com>
Cc: Frank.Li@kernel.org, vkoul@kernel.org, dmaengine@vger.kernel.org,
linux-pci@vger.kernel.org
Subject: Re: [PATCH v4 12/12] dmaengine: plx_dma: fix NULL pointer deref in plx_dma_isr()
Date: Tue, 28 Jul 2026 17:50:15 +0000 [thread overview]
Message-ID: <20260728175016.703BC1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260728171523.112244-13-logang@deltatee.com>
Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider:
Pre-existing issues:
- [High] Lock is held across DMA API boundaries (`prep` to `submit`), preventing descriptor batching and causing deadlocks.
- [High] Recursive deadlock when invoking client callbacks from `plx_dma_process_desc`.
- [High] Softirq preemption deadlock in `plx_dma_process_desc` due to missing `spin_lock_bh`.
- [High] 1-Second busy-wait loop inside an RCU read-side critical section.
- [Medium] Memory leak of `desc_ring` array and descriptors in `plx_dma_alloc_chan_resources` error path.
--
--- Patch [12]: [PATCH v4 12/12] dmaengine: plx_dma: fix NULL pointer deref in plx_dma_isr() ---
commit 255ac134d3a6a355b0f9fd6a9df9b4e6a75d09d7
Author: Logan Gunthorpe <logang@deltatee.com>
Subject: dmaengine: plx_dma: fix NULL pointer deref in plx_dma_isr()
plx_dma_create() registered the interrupt handler with request_irq()
before initializing plxdev->bar. If the device raised an interrupt in
that window, plx_dma_isr() would dereference the still-NULL bar.
This patch moves the bar assignment ahead of request_irq() so everything the
handler can touch is initialized before it can run.
Link: https://lore.kernel.org/all/20260610112121.676561-1-jjy600901@snu.ac.kr
> diff --git a/drivers/dma/plx_dma.c b/drivers/dma/plx_dma.c
> index 84941a918b01f..409898e92c320 100644
> --- a/drivers/dma/plx_dma.c
> +++ b/drivers/dma/plx_dma.c
[ ... ]
> @@ -504,17 +504,17 @@ static int plx_dma_create(struct pci_dev *pdev)
> if (!plxdev)
> return -ENOMEM;
>
> - rc = request_irq(pci_irq_vector(pdev, 0), plx_dma_isr, 0,
> - KBUILD_MODNAME, plxdev);
> - if (rc)
> - goto free_plx;
> -
> spin_lock_init(&plxdev->ring_lock);
> tasklet_setup(&plxdev->desc_task, plx_dma_desc_task);
>
> RCU_INIT_POINTER(plxdev->pdev, pdev);
> plxdev->bar = pcim_iomap_table(pdev)[0];
>
> + rc = request_irq(pci_irq_vector(pdev, 0), plx_dma_isr, 0,
> + KBUILD_MODNAME, plxdev);
> + if (rc)
> + goto free_plx;
> +
> dma = &plxdev->dma_dev;
[ ... ]
While reviewing this patch, I noticed a few pre-existing issues in the same
file that might be worth addressing:
In drivers/dma/plx_dma.c:plx_dma_prep_memcpy():
> spin_lock_bh(&plxdev->ring_lock);
> ...
> return &plxdesc->txd;
In drivers/dma/plx_dma.c:plx_dma_tx_submit():
> spin_unlock_bh(&plxdev->ring_lock);
>
> return cookie;
[Severity: High]
This is a pre-existing issue, but does holding ring_lock across DMA API
boundaries prevent descriptor batching?
If a client prepares two consecutive transfers before submitting them, wouldn't
the second plx_dma_prep_memcpy() call recursively attempt to acquire the
non-recursive ring_lock held by the first call, causing an immediate deadlock?
In drivers/dma/plx_dma.c:plx_dma_process_desc():
> spin_lock(&plxdev->ring_lock);
>
> while (plxdev->tail != plxdev->head) {
> ...
> dmaengine_desc_get_callback_invoke(&desc->txd, &res);
> ...
> }
>
> spin_unlock(&plxdev->ring_lock);
[Severity: High]
This is a pre-existing issue, but is it safe to invoke client callbacks while
holding ring_lock?
If a completion callback attempts to prepare a new transfer via
dmaengine_prep_dma_memcpy(), it will invoke plx_dma_prep_memcpy() which
attempts to acquire spin_lock_bh(&plxdev->ring_lock).
Would this cause an immediate recursive deadlock?
In drivers/dma/plx_dma.c:plx_dma_process_desc():
> spin_lock(&plxdev->ring_lock);
[Severity: High]
This is a pre-existing issue, but could acquiring ring_lock without disabling
softirqs lead to a preemption deadlock?
If plx_dma_process_desc() is called from process context via
plx_dma_tx_status(), a hardware interrupt could preempt the thread while the
lock is held and schedule the tasklet.
Would the softirq tasklet then spin forever in plx_dma_desc_task() trying
to acquire ring_lock?
In drivers/dma/plx_dma.c:plx_dma_stop():
> rcu_read_lock();
> if (!rcu_dereference(plxdev->pdev)) {
> rcu_read_unlock();
> return;
> }
>
> __plx_dma_stop(plxdev);
>
> rcu_read_unlock();
In drivers/dma/plx_dma.c:__plx_dma_stop():
> unsigned long timeout = jiffies + msecs_to_jiffies(1000);
> ...
> while (!time_after(jiffies, timeout)) {
> val = readl(plxdev->bar + PLX_REG_CTRL);
> if (val & PLX_REG_CTRL_GRACEFUL_PAUSE_DONE)
> break;
>
> cpu_relax();
> }
[Severity: High]
This is a pre-existing issue, but does __plx_dma_stop() spin for up to a second
inside an RCU read-side critical section?
Since plx_dma_stop() takes rcu_read_lock() and calls __plx_dma_stop(), waiting
for up to 1000 milliseconds using cpu_relax() could cause massive scheduling
latency spikes.
Could this explicitly block RCU grace periods and preemptions on
non-PREEMPT_RCU systems, potentially triggering RCU stall panics?
In drivers/dma/plx_dma.c:plx_dma_alloc_chan_resources():
> rc = plx_dma_alloc_desc(plxdev);
> if (rc)
> goto out_free_hw_ring;
>
> rcu_read_lock();
> if (!rcu_dereference(plxdev->pdev)) {
> rcu_read_unlock();
> rc = -ENODEV;
> goto out_free_hw_ring;
> }
> ...
> out_free_hw_ring:
> dma_free_coherent(plxdev->dma_dev.dev, ring_sz, plxdev->hw_ring,
> plxdev->hw_ring_dma);
> return rc;
[Severity: Medium]
This is a pre-existing issue, but does this error path leak the desc_ring array
and its associated descriptors?
If the check for rcu_dereference(plxdev->pdev) fails, it jumps to
out_free_hw_ring.
Since this only frees the DMA coherent memory hw_ring, are the allocated
descriptors completely leaked?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260728171523.112244-1-logang@deltatee.com?part=12
prev parent reply other threads:[~2026-07-28 17:50 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-28 17:15 [PATCH v4 00/12] dmaengine: miscellaneous fixes for ioat, switchtec_dma and plx_dma Logan Gunthorpe
2026-07-28 17:15 ` [PATCH v4 01/12] dmaengine: switchtec-dma: fix double-free in switchtec_dma_free_desc() Logan Gunthorpe
2026-07-28 17:34 ` sashiko-bot
2026-07-28 17:15 ` [PATCH v4 02/12] dmaengine: switchtec-dma: fix resource leak in alloc_chan_resources Logan Gunthorpe
2026-07-28 17:40 ` sashiko-bot
2026-07-28 17:15 ` [PATCH v4 03/12] dmaengine: switchtec-dma: always clear DMA base registers on chan_stop() Logan Gunthorpe
2026-07-28 17:34 ` sashiko-bot
2026-07-28 17:15 ` [PATCH v4 04/12] dmaengine: switchtec-dma: halt channel on alloc_chan_resources error Logan Gunthorpe
2026-07-28 17:35 ` sashiko-bot
2026-07-28 17:15 ` [PATCH v4 05/12] dmaengine: switchtec-dma: fix channel leak on registration failure Logan Gunthorpe
2026-07-28 17:38 ` sashiko-bot
2026-07-28 17:15 ` [PATCH v4 06/12] dmaengine: switchtec-dma: make switchtec_dma_chans_release() void Logan Gunthorpe
2026-07-28 17:44 ` sashiko-bot
2026-07-28 17:15 ` [PATCH v4 07/12] dmaengine: switchtec-dma: fix chan_status_irq cleanup on create() error Logan Gunthorpe
2026-07-28 17:39 ` sashiko-bot
2026-07-28 17:15 ` [PATCH v4 08/12] dmaengine: switchtec-dma: disable channels before freeing on registration failure Logan Gunthorpe
2026-07-28 17:39 ` sashiko-bot
2026-07-28 17:15 ` [PATCH v4 09/12] dmaengine: switchtec-dma: fix use-after-free of swdma_dev in remove() Logan Gunthorpe
2026-07-28 17:48 ` sashiko-bot
2026-07-28 17:15 ` [PATCH v4 10/12] dmaengine: ioat: disable relaxed ordering before registering the device Logan Gunthorpe
2026-07-28 17:53 ` sashiko-bot
2026-07-28 17:15 ` [PATCH v4 11/12] dmaengine: ioat: use sysfs_emit() in per-channel sysfs show() Logan Gunthorpe
2026-07-28 17:48 ` sashiko-bot
2026-07-28 17:15 ` [PATCH v4 12/12] dmaengine: plx_dma: fix NULL pointer deref in plx_dma_isr() Logan Gunthorpe
2026-07-28 17:50 ` sashiko-bot [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=20260728175016.703BC1F000E9@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.