From: sashiko-bot@kernel.org
To: "Sai Sree Kartheek Adivi" <s-adivi@ti.com>
Cc: vkoul@kernel.org, robh@kernel.org, conor+dt@kernel.org,
devicetree@vger.kernel.org, Frank.Li@kernel.org,
dmaengine@vger.kernel.org
Subject: Re: [PATCH v8 16/19] dmaengine: ti: k3-udma-v2: New driver for K3 BCDMA_V2
Date: Mon, 10 Aug 2026 17:04:09 +0000 [thread overview]
Message-ID: <20260810170410.5278C1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260810151423.1948224-17-s-adivi@ti.com>
Thank you for your contribution! Sashiko AI review found 6 potential issue(s) to consider:
- [High] Unconstrained virtual channel ID (`uc->id`) is used as a hardware index for `bchan` allocation, leading to out-of-bounds array and bitmap accesses.
- [High] Missing `.remove` function in `bcdma_v2_driver` causes a use-after-free on module unload.
- [High] PM suspend forcefully frees active channel resources and descriptor pools, causing Use-After-Free on resume.
- [Medium] Lockless call to `complete_all()` races with `reinit_completion()` during channel teardown.
- [Low] `TI_K3_UDMA_V2` selects `TI_K3_RINGACC` without inheriting its dependencies, causing Kconfig unmet dependency warnings.
- [Low] The return values of consecutive `k3_ringacc_ring_cfg` calls are accumulated using a bitwise OR, which mangles negative error codes.
--
--- Patch [16]: [PATCH v8 16/19] dmaengine: ti: k3-udma-v2: New driver for K3 BCDMA_V2 ---
commit 61b786131a37c8bebad4a083b46e1ce421934a6f
Author: Sai Sree Kartheek Adivi <s-adivi@ti.com>
dmaengine: ti: k3-udma-v2: New driver for K3 BCDMA_V2
Add support for BCDMA_V2, which differs from existing BCDMA by not
requiring PSIL pairing, using static channel mapping, direct IRQs,
and having a unified channel space.
> diff --git a/drivers/dma/ti/Kconfig b/drivers/dma/ti/Kconfig
> --- a/drivers/dma/ti/Kconfig
> +++ b/drivers/dma/ti/Kconfig
> @@ -49,6 +49,18 @@ config TI_K3_UDMA
> Enable support for the TI UDMA (Unified DMA) controller. This
> DMA engine is used in AM65x and j721e.
>
> +config TI_K3_UDMA_V2
> + tristate "Texas Instruments K3 UDMA v2 support"
> + depends on ARCH_K3
> + select DMA_ENGINE
> + select DMA_VIRTUAL_CHANNELS
> + select TI_K3_UDMA_COMMON
> + select TI_K3_RINGACC
[Severity: Low]
Is it possible for this select statement to cause unmet dependency warnings?
TI_K3_RINGACC depends on TI_SCI_INTA_IRQCHIP, but select bypasses dependencies,
which could lead to build warnings if the IRQ chip driver is disabled.
> + select TI_K3_PSIL
> + help
> + Enable support for the TI UDMA (Unified DMA) v2 controller. This
> + DMA engine is used in AM62L.
> +
> config TI_K3_UDMA_COMMON
[ ... ]
> diff --git a/drivers/dma/ti/k3-udma-v2.c b/drivers/dma/ti/k3-udma-v2.c
> new file mode 100644
> --- /dev/null
> +++ b/drivers/dma/ti/k3-udma-v2.c
[ ... ]
> +static int udma_v2_stop(struct udma_chan *uc)
> +{
> + uc->state = UDMA_CHAN_IS_TERMINATING;
> + reinit_completion(&uc->teardown_completed);
[Severity: Medium]
Can a data race occur between the interrupt handler and this stop function?
In the interrupt handler, complete_all() is called without a lock. Concurrently,
a channel termination path holding the channel lock could call udma_v2_stop(),
which runs reinit_completion(). If reinit_completion() occurs right after
complete_all(), the completion gets cleared before waiting threads consume it,
potentially causing a timeout.
> +
> + if (uc->config.dir == DMA_DEV_TO_MEM) {
[ ... ]
> +static int bcdma_v2_get_bchan(struct udma_chan *uc)
> +{
> + struct udma_dev *ud = uc->ud;
> + enum udma_tp_level tpl;
> + int ret;
> +
> + if (uc->bchan) {
> + dev_dbg(ud->dev, "chan%d: already have bchan%d allocated\n",
> + uc->id, uc->bchan->id);
> + return 0;
> + }
> +
> + /*
> + * Use normal channels for peripherals, and highest TPL channel for
> + * mem2mem
> + */
> + if (uc->config.tr_trigger_type)
> + tpl = 0;
> + else
> + tpl = ud->bchan_tpl.levels - 1;
> +
> + /*
> + * UDMA V2 uses a static 1:1 mapping between the virtual channel index
> + * (uc->id) and the hardware bchan/tchan/rchan index -- unlike V1, which
> + * dynamically allocates from a shared pool. Passing uc->id directly to
> + * __udma_reserve_*() is intentional, not a bug.
> + */
> + uc->bchan = __udma_reserve_bchan(ud, tpl, uc->id);
[Severity: High]
Could this result in out-of-bounds accesses? The DMA filter function accepts
virtual channels for MEM_TO_MEM workflows without enforcing that uc->id is
within the valid bchan count limit (16). If previous allocations consume the
first 16 channels, a subsequent request would get an ID >= 16. Passing this
unconstrained ID directly to __udma_reserve_bchan would perform an
out-of-bounds set_bit() on the ud->bchan_map bitmap and read out of bounds.
> + if (IS_ERR(uc->bchan)) {
> + ret = PTR_ERR(uc->bchan);
> + uc->bchan = NULL;
> + return ret;
> + }
> + uc->chan = uc->bchan;
> + uc->tchan = uc->bchan;
> +
> + return 0;
> +}
> +
> +static int bcdma_v2_alloc_bchan_resources(struct udma_chan *uc)
> +{
> + struct k3_ring_cfg ring_cfg;
> + struct udma_dev *ud = uc->ud;
> + int ret;
> +
> + ret = bcdma_v2_get_bchan(uc);
> + if (ret)
> + return ret;
> +
> + ret = k3_ringacc_request_rings_pair(ud->ringacc, ud->match_data->chan_cnt + uc->id, -1,
[Severity: High]
Following the above logic, requesting a ring pair with this unconstrained
uc->id could also exceed the bounds of the num_rings array here.
> + &uc->bchan->t_ring,
> + &uc->bchan->tc_ring);
[ ... ]
> +static int udma_v2_alloc_tx_resources(struct udma_chan *uc)
> +{
> + struct k3_ring_cfg ring_cfg;
> + struct udma_dev *ud = uc->ud;
> + struct udma_tchan *tchan;
> + int ring_idx, ret;
[ ... ]
> + ret = k3_ringacc_ring_cfg(tchan->t_ring, &ring_cfg);
> + ret |= k3_ringacc_ring_cfg(tchan->tc_ring, &ring_cfg);
[Severity: Low]
Does accumulating return values with a bitwise OR mangle negative error codes?
If the first call fails with an error like -EINVAL, ORing the result of the
second call will produce a corrupted error code, destroying the original
POSIX error mapping.
> +
> + if (ret)
> + goto err_ringcfg;
[ ... ]
> +static int __maybe_unused udma_v2_pm_suspend(struct device *dev)
> +{
> + struct udma_dev *ud = dev_get_drvdata(dev);
> + struct dma_device *dma_dev = &ud->ddev;
> + struct dma_chan *chan;
> + struct udma_chan *uc;
> +
> + list_for_each_entry(chan, &dma_dev->channels, device_node) {
> + if (chan->client_count) {
> + uc = to_udma_chan(chan);
> + /* backup the channel configuration */
> + memcpy(&uc->backup_config, &uc->config,
> + sizeof(struct udma_chan_config));
> + dev_dbg(dev, "Suspending channel %s\n",
> + dma_chan_name(chan));
> + ud->ddev.device_free_chan_resources(chan);
[Severity: High]
Is it safe to free active channel resources and descriptor pools during
suspend? DMA clients generally only pause transfers during suspend and expect
their pre-allocated descriptors to remain valid.
> + }
> + }
> +
> + return 0;
> +}
> +
> +static int __maybe_unused udma_v2_pm_resume(struct device *dev)
> +{
> + struct udma_dev *ud = dev_get_drvdata(dev);
> + struct dma_device *dma_dev = &ud->ddev;
> + struct dma_chan *chan;
> + struct udma_chan *uc;
> + int ret;
> +
> + list_for_each_entry(chan, &dma_dev->channels, device_node) {
> + if (chan->client_count) {
> + uc = to_udma_chan(chan);
> + /* restore the channel configuration */
> + memcpy(&uc->config, &uc->backup_config,
> + sizeof(struct udma_chan_config));
> + dev_dbg(dev, "Resuming channel %s\n",
> + dma_chan_name(chan));
> + ret = ud->ddev.device_alloc_chan_resources(chan);
[Severity: High]
Reallocating a new pool on resume leaves clients holding dangling pointers to
the old destroyed pool, which could cause a use-after-free when they attempt
to submit or free their old descriptors.
> + if (ret)
> + return ret;
> + }
> + }
> +
> + return 0;
> +}
> +
> +static const struct dev_pm_ops udma_pm_ops = {
> + SET_LATE_SYSTEM_SLEEP_PM_OPS(udma_v2_pm_suspend, udma_v2_pm_resume)
> +};
> +
> +static struct platform_driver bcdma_v2_driver = {
> + .driver = {
> + .name = "ti-udma-v2",
> + .of_match_table = udma_of_match,
> + .suppress_bind_attrs = true,
> + .pm = &udma_pm_ops,
> + },
> + .probe = udma_v2_probe,
> +};
[Severity: High]
Should this platform driver include a remove callback? Without it, module
unload leaves the DMA engine core and OF subsystems with dangling pointers to
the freed ud->ddev structure, which could cause a use-after-free on subsequent
access when the module is removed.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260810151423.1948224-1-s-adivi@ti.com?part=16
next prev parent reply other threads:[~2026-08-10 17:04 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-10 15:13 [PATCH v8 00/19] dmaengine: ti: Add support for BCDMA v2 and PKTDMA v2 Sai Sree Kartheek Adivi
2026-08-10 15:13 ` [PATCH v8 01/19] dmaengine: ti: k3-udma: Fix sporadic crash on AM62x Sai Sree Kartheek Adivi
2026-08-10 15:36 ` sashiko-bot
2026-08-10 15:13 ` [PATCH v8 02/19] dmaengine: ti: k3-udma: move macros to header file Sai Sree Kartheek Adivi
2026-08-10 15:25 ` sashiko-bot
2026-08-10 15:13 ` [PATCH v8 03/19] dmaengine: ti: k3-udma: move structs and enums " Sai Sree Kartheek Adivi
2026-08-10 15:13 ` [PATCH v8 04/19] dmaengine: ti: k3-udma: move static inline helper functions " Sai Sree Kartheek Adivi
2026-08-10 15:13 ` [PATCH v8 05/19] dmaengine: ti: k3-udma: move descriptor management to k3-udma-common.c Sai Sree Kartheek Adivi
2026-08-10 15:56 ` sashiko-bot
2026-08-10 15:14 ` [PATCH v8 06/19] dmaengine: ti: k3-udma: move ring management functions " Sai Sree Kartheek Adivi
2026-08-10 15:52 ` sashiko-bot
2026-08-10 15:14 ` [PATCH v8 07/19] dmaengine: ti: k3-udma: Add variant-specific function pointers to udma_dev Sai Sree Kartheek Adivi
2026-08-10 16:06 ` sashiko-bot
2026-08-10 15:14 ` [PATCH v8 08/19] dmaengine: ti: k3-udma: move udma utility functions to k3-udma-common.c Sai Sree Kartheek Adivi
2026-08-10 16:09 ` sashiko-bot
2026-08-10 15:14 ` [PATCH v8 09/19] dmaengine: ti: k3-udma: move resource management " Sai Sree Kartheek Adivi
2026-08-10 16:26 ` sashiko-bot
2026-08-10 15:14 ` [PATCH v8 10/19] dmaengine: ti: k3-udma: refactor resource setup functions Sai Sree Kartheek Adivi
2026-08-10 15:14 ` [PATCH v8 11/19] dmaengine: ti: k3-udma: move inclusion of k3-udma-private.c to k3-udma-common.c Sai Sree Kartheek Adivi
2026-08-10 16:27 ` sashiko-bot
2026-08-10 15:14 ` [PATCH v8 12/19] drivers: soc: ti: k3-ringacc: handle absence of tisci Sai Sree Kartheek Adivi
2026-08-10 16:38 ` sashiko-bot
2026-08-10 15:14 ` [PATCH v8 13/19] dt-bindings: dma: ti: Add K3 BCDMA V2 Sai Sree Kartheek Adivi
2026-08-11 6:32 ` Krzysztof Kozlowski
2026-08-10 15:14 ` [PATCH v8 14/19] dt-bindings: dma: ti: Add K3 PKTDMA V2 Sai Sree Kartheek Adivi
2026-08-10 15:14 ` [PATCH v8 15/19] dmaengine: ti: k3-psil-am62l: Add AM62Lx PSIL and PDMA data Sai Sree Kartheek Adivi
2026-08-10 16:45 ` sashiko-bot
2026-08-10 15:14 ` [PATCH v8 16/19] dmaengine: ti: k3-udma-v2: New driver for K3 BCDMA_V2 Sai Sree Kartheek Adivi
2026-08-10 17:04 ` sashiko-bot [this message]
2026-08-10 15:14 ` [PATCH v8 17/19] dmaengine: ti: k3-udma-v2: Add support for PKTDMA V2 Sai Sree Kartheek Adivi
2026-08-10 17:09 ` sashiko-bot
2026-08-10 15:14 ` [PATCH v8 18/19] dmaengine: ti: k3-udma-v2: Update glue layer to support " Sai Sree Kartheek Adivi
2026-08-10 17:20 ` sashiko-bot
2026-08-10 15:14 ` [PATCH v8 19/19] dmaengine: ti: k3-udma: Validate resource ID and fix logging in reservation Sai Sree Kartheek Adivi
2026-08-10 17:35 ` 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=20260810170410.5278C1F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=Frank.Li@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=dmaengine@vger.kernel.org \
--cc=robh@kernel.org \
--cc=s-adivi@ti.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