From: sashiko-bot@kernel.org
To: Frank.Li@oss.nxp.com,
"open list:DMA GENERIC OFFLOAD ENGINE SUBSYSTEM"
<dmaengine@vger.kernel.org>,
"open list:NTB DRIVER CORE" <ntb@lists.linux.dev>
Cc: imx@lists.linux.dev, vkoul@kernel.org, Frank.Li@kernel.org
Subject: Re: [PATCH v4 1/2] dmaengine: change dmaengine_get_unmap_data() first arg to dma_chan
Date: Thu, 15 Oct 2026 16:01:43 +0000 [thread overview]
Message-ID: <sashiko-outbox-173122@kernel.org> (raw)
In-Reply-To: <20261015155118.3063149-1-Frank.Li@oss.nxp.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] dmaengine: Mismatched DMA device used for mapping and unmapping
- [High] dmaengine: NULL pointer dereference in dmaengine_get_dma_device() during mv_xor probe
--
commit 811fe2fcd19af9f3eb46610a12e2d1dc77b628e0
Author: Frank Li <Frank.Li@nxp.com>
dmaengine: change dmaengine_get_unmap_data() first arg to dma_chan
This commit modifies dmaengine_get_unmap_data() to accept a dma_chan
instead of a device pointer, automatically resolving the correct DMA device
for the channel. It updates various callers in the crypto, NTB, and DMA
test subsystems to match this new signature.
Link: https://lore.kernel.org/dmaengine/20260923-dmaengine_prep_dma_pq-v2-0-32ed65b8a9b4@nxp.com/
Link: https://lore.kernel.org/imx/b40fa0d7-fbd0-4ee8-b99c-781d08c18838@intel.com/T/#t
> diff --git a/crypto/async_tx/async_memcpy.c b/crypto/async_tx/async_memcpy.c
> --- a/crypto/async_tx/async_memcpy.c
> +++ b/crypto/async_tx/async_memcpy.c
> @@ -39,8 +39,8 @@
> struct dma_async_tx_descriptor *tx = NULL;
> struct dmaengine_unmap_data *unmap = NULL;
>
> - if (device)
> - unmap = dmaengine_get_unmap_data(device->dev, 2, GFP_NOWAIT);
> + if (chan)
> + unmap = dmaengine_get_unmap_data(chan, 2, GFP_NOWAIT);
[Severity: High]
Will this create a DMA API mapping mismatch for systems with per-channel IOMMUs?
The updated dmaengine_get_unmap_data() now sets unmap->dev using
dmaengine_get_dma_device(chan). If the channel supports a per-channel IOMMU,
this correctly resolves to the channel's specific device.
However, the memory mapping calls later in async_memcpy() still use the parent
device:
unmap->addr[0] = dma_map_page(device->dev, src, src_offset, len,
DMA_TO_DEVICE);
When the operation finishes, dmaengine_unmap() will attempt to unmap the
memory from unmap->dev (the child IOMMU device), while it was mapped to
device->dev (the parent device). This asymmetry can cause stranded IOMMU
mappings and invalid unmap page faults.
A similar mismatch appears in drivers/ntb/ntb_transport.c in
ntb_async_rx_submit(), which maps using device->dev instead of resolving
through the channel.
[ ... ]
> diff --git a/drivers/dma/mv_xor.c b/drivers/dma/mv_xor.c
> --- a/drivers/dma/mv_xor.c
> +++ b/drivers/dma/mv_xor.c
> @@ -789,7 +789,7 @@
> goto out;
> }
>
> - unmap = dmaengine_get_unmap_data(dma_chan->device->dev, 2, GFP_KERNEL);
> + unmap = dmaengine_get_unmap_data(dma_chan, 2, GFP_KERNEL);
[Severity: High]
Does this introduce a NULL pointer dereference during device probe?
In the mv_xor driver, mv_chan_memcpy_self_test() is called during driver
initialization via mv_xor_channel_add(). This happens before the channel
is fully registered with the DMA core.
At this point, the channel's sysfs device pointer chan->dev is not yet
allocated. When this patch changes the call to pass dma_chan instead of
dma_chan->device->dev, the implementation of dmaengine_get_unmap_data() will
call dmaengine_get_dma_device(chan).
Looking at include/linux/dmaengine.h:
static inline struct device *dmaengine_get_dma_device(struct dma_chan *chan)
{
if (chan->dev->chan_dma_dev)
return &chan->dev->device;
return chan->device->dev;
}
This unconditionally dereferences chan->dev, which is NULL during the
self-test, preventing the mv_xor driver from loading.
> if (!unmap) {
> err = -ENOMEM;
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261015155118.3063149-1-Frank.Li@oss.nxp.com?part=1
prev parent reply other threads:[~2026-10-15 16:01 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-15 15:51 [PATCH v4 1/2] dmaengine: change dmaengine_get_unmap_data() first arg to dma_chan Frank.Li
2026-10-15 15:51 ` [PATCH v4 2/2] dmaengine: replace dma_maxqp() with dmaengine_maxpq() taking struct dma_chan * Frank.Li
2026-10-15 15:57 ` sashiko-bot
2026-10-15 16:01 ` 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=sashiko-outbox-173122@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=Frank.Li@kernel.org \
--cc=Frank.Li@oss.nxp.com \
--cc=dmaengine@vger.kernel.org \
--cc=imx@lists.linux.dev \
--cc=ntb@lists.linux.dev \
--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