From: sashiko-bot@kernel.org
To: "Frank Li" <Frank.Li@nxp.com>
Cc: linux-pci@vger.kernel.org
Subject: Re: [PATCH v4 2/9] dmaengine: Add safe API to combine configuration and preparation
Date: Wed, 06 May 2026 22:02:55 +0000 [thread overview]
Message-ID: <20260506220256.02992C2BCB0@smtp.kernel.org> (raw)
In-Reply-To: <20260506-dma_prep_config-v4-2-85b3d22babff@nxp.com>
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] Deadlock risk due to using `spin_lock()` instead of `spin_lock_irqsave()`.
- [High] Calling `dmaengine_slave_config()` while holding a spinlock causes 'sleeping while atomic' kernel panics.
- [Medium] Meaningful code and commit message mismatch regarding lock type, and truncated comment.
--
commit 4872a557291e0d82176d77b1a17c5e410863322e
Author: Frank Li <Frank.Li@nxp.com>
dmaengine: Add safe API to combine configuration and preparation
This commit introduces dmaengine_prep_config_single_safe() and
dmaengine_prep_config_sg_safe() to provide a safe way to combine slave
configuration and transfer preparation. Drivers can implement a new
device_prep_config_sg() callback or the code falls back to executing both
steps under a per-channel lock.
> Drivers may implement the new device_prep_config_sg() callback to perform
> both steps atomically. If the callback is not provided, the helpers fall
> back to calling dmaengine_slave_config() followed by
> dmaengine_prep_slave_sg() under per-channel mutex protection.
This isn't a bug, but the commit message mentions per-channel mutex
protection, while the implementation actually uses a spinlock. Could the
commit message be updated to match the code?
> --- a/include/linux/dmaengine.h
> +++ b/include/linux/dmaengine.h
> @@ -341,6 +343,12 @@ struct dma_chan {
> dma_cookie_t cookie;
> dma_cookie_t completed_cookie;
>
> + /*
> + * protect between config and prepare transfer because *_prep() may be
> + * called from complete callback, which is in GFP_NOSLEEP context.
> + */
> + spinlock_t lock; /* protect between config and prepare transfer since */
This isn't a bug, but the inline comment for the lock appears to be truncated
mid-sentence after the word since.
[ ... ]
> +static inline struct dma_async_tx_descriptor *
> +dmaengine_prep_config_sg_safe(struct dma_chan *chan, struct scatterlist *sgl,
> + unsigned int sg_len,
> + enum dma_transfer_direction dir,
> + unsigned long flags,
> + struct dma_slave_config *config)
> +{
> + struct dma_async_tx_descriptor *tx;
> +
> + if (!chan || !chan->device)
> + return NULL;
> +
> + if (!chan->device->device_prep_config_sg)
> + spin_lock(&chan->lock);
Since this API can be called from process context, and completion callbacks
might attempt to re-queue transfers from hardware interrupt context, could
using spin_lock() here cause a deadlock regression if the CPU is interrupted
while holding chan->lock?
Would it be safer to use spin_lock_irqsave() here instead? If so, we might
need a new variable to save the interrupt state to avoid shadowing the
existing flags function argument.
> +
> + tx = dmaengine_prep_config_sg(chan, sgl, sg_len, dir, flags, config);
Does calling dmaengine_prep_config_sg() while holding a spinlock introduce a
regression where scheduling while atomic panics can occur?
Looking at dmaengine_prep_config_sg(), it calls dmaengine_slave_config(),
which invokes the driver's device_config() callback. Many DMA drivers
expect device_config() to be called in process context and perform sleeping
operations like acquiring mutexes, making sleeping memory allocations, or
calling pm_runtime_get_sync().
> +
> + if (!chan->device->device_prep_config_sg)
> + spin_unlock(&chan->lock);
> +
> + return tx;
> +}
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260506-dma_prep_config-v4-0-85b3d22babff@nxp.com?part=2
next prev parent reply other threads:[~2026-05-06 22:02 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-06 20:44 [PATCH v4 0/9] dmaengine: Add new API to combine configuration and descriptor preparation Frank Li
2026-05-06 20:44 ` [PATCH v4 1/9] dmaengine: Add API to combine configuration and preparation (sg and single) Frank Li
2026-05-06 21:39 ` sashiko-bot
2026-05-06 20:44 ` [PATCH v4 2/9] dmaengine: Add safe API to combine configuration and preparation Frank Li
2026-05-06 22:02 ` sashiko-bot [this message]
2026-05-06 20:44 ` [PATCH v4 3/9] PCI: endpoint: pci-epf-test: Use dmaenigne_prep_config_single() to simplify code Frank Li
2026-05-06 20:44 ` [PATCH v4 4/9] dmaengine: dw-edma: Use new .device_prep_config_sg() callback Frank Li
2026-05-06 22:17 ` sashiko-bot
2026-05-06 20:44 ` [PATCH v4 5/9] dmaengine: dw-edma: Pass dma_slave_config to dw_edma_device_transfer() Frank Li
2026-05-06 22:36 ` sashiko-bot
2026-05-06 20:44 ` [PATCH v4 6/9] nvmet: pci-epf: Remove unnecessary dmaengine_terminate_sync() on each DMA transfer Frank Li
2026-05-06 20:44 ` [PATCH v4 7/9] nvmet: pci-epf: Use dmaengine_prep_config_single_safe() API Frank Li
2026-05-06 23:05 ` sashiko-bot
2026-05-06 20:44 ` [PATCH v4 8/9] PCI: epf-mhi: Use dmaengine_prep_config_single() to simplify code Frank Li
2026-05-06 23:26 ` sashiko-bot
2026-05-06 20:44 ` [PATCH v4 9/9] crypto: atmel: Use dmaengine_prep_config_single() API Frank Li
2026-05-06 23:31 ` 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=20260506220256.02992C2BCB0@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=Frank.Li@nxp.com \
--cc=linux-pci@vger.kernel.org \
--cc=sashiko@lists.linux.dev \
/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