From: sashiko-bot@kernel.org
To: "Vinicius Costa Gomes" <vinicius.gomes@intel.com>
Cc: dmaengine@vger.kernel.org, vkoul@kernel.org, Frank.Li@kernel.org
Subject: Re: [PATCH v2 8/8] dmaengine: idxd: Don't flush the descriptors on terminate_all()
Date: Thu, 26 Nov 2026 00:19:55 +0000 [thread overview]
Message-ID: <sashiko-outbox-234461@kernel.org> (raw)
In-Reply-To: <20261125-wt-idxd-fixes-v2-8-25a4691dfb9e@intel.com>
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] dmaengine: idxd: use-after-free of idxd_chan on quiesced WQ in
synchronize()
- [Medium] dmaengine: idxd: terminated descriptors resubmitted on
invalid int handle
--
commit fcece576ebf908c4c4a2589f3aea6943e129e474
Author: Vinicius Costa Gomes <vinicius.gomes@intel.com>
dmaengine: idxd: Don't flush the descriptors on terminate_all()
This commit marks the DMA channel as terminated in idxd_dma_terminate_all()
to suppress completion callbacks and defers draining and flushing pending
descriptors to idxd_dma_synchronize().
> diff --git a/drivers/dma/idxd/dma.c b/drivers/dma/idxd/dma.c
> index 9937b671f6376..f8ce06274ef46 100644
> --- a/drivers/dma/idxd/dma.c
> +++ b/drivers/dma/idxd/dma.c
[ ... ]
> @@ -47,7 +50,8 @@ void idxd_dma_complete_txd(struct idxd_desc *desc,
> if (complete && tx->cookie) {
> dma_cookie_complete(tx);
> dma_descriptor_unmap(tx);
> - dmaengine_desc_get_callback_invoke(tx, &res);
> + if (!READ_ONCE(to_idxd_dma_chan(tx->chan)->terminated))
> + dmaengine_desc_get_callback_invoke(tx, &res);
> tx->callback = NULL;
> tx->callback_result = NULL;
> }
[Severity: Medium]
Can a terminated descriptor that completes with DSA_COMP_INT_HANDLE_INVAL
still be resubmitted instead of aborted?
Earlier in idxd_dma_complete_txd(), a descriptor with status
DSA_COMP_INT_HANDLE_INVAL is queued onto idxd->wq via
idxd_queue_int_handle_resubmit() and returns before reaching the
terminated check above:
drivers/dma/idxd/dma.c:idxd_dma_complete_txd() {
if (desc->completion->status == DSA_COMP_SUCCESS) {
res.result = DMA_TRANS_NOERROR;
} else if (desc->completion->status) {
if (idxd->request_int_handles && comp_type != IDXD_COMPLETE_ABORT &&
desc->completion->status == DSA_COMP_INT_HANDLE_INVAL &&
idxd_queue_int_handle_resubmit(desc))
return;
...
}
Because idxd_flush_pending_descs() passes IDXD_COMPLETE_NORMAL whenever
desc->completion->status is non-zero, both idxd_wq_thread() and
idxd_flush_pending_descs() queue the terminated descriptor for
asynchronous resubmission on idxd->wq without unmapping or freeing it.
idxd_dma_synchronize() then clears idxd_chan->terminated and returns while
idxd_int_handle_resubmit_work can still resubmit the descriptor to the
device.
> @@ -196,18 +200,43 @@ static void idxd_dma_release(struct dma_device *device)
>
> static int idxd_dma_terminate_all(struct dma_chan *c)
> {
> - struct idxd_wq *wq = to_idxd_wq(c);
> -
> - idxd_wq_flush_descs(wq);
> + /* The device still runs them, synchronize() waits for it */
> + WRITE_ONCE(to_idxd_dma_chan(c)->terminated, true);
>
> return 0;
> }
>
> static void idxd_dma_synchronize(struct dma_chan *c)
> {
> - struct idxd_wq *wq = to_idxd_wq(c);
> + struct idxd_dma_chan *idxd_chan = to_idxd_dma_chan(c);
> + struct idxd_wq *wq = idxd_chan->wq;
>
> idxd_wq_drain(wq);
> + if (!READ_ONCE(idxd_chan->terminated))
> + return;
> +
> + /*
> + * Not wq_lock: dma_release_channel() calls this under dma_list_mutex,
> + * which the WQ removal takes under wq_lock. The removal waits for
> + * wq_active instead.
> + */
> + if (!percpu_ref_tryget_live(&wq->wq_active)) {
> + wait_for_completion(&wq->wq_resurrect);
> + /* The WQ is quiesced, disabling it flushes them */
> + if (!percpu_ref_tryget_live(&wq->wq_active))
> + return;
> + }
[Severity: High]
Does returning early when wq->wq_active is dead cause a use-after-free on
wq->idxd_chan when idxd_drv_disable_wq() later flushes the pending
descriptors?
In idxd_dmaengine_drv_remove(), idxd_unregister_dma_channel() frees
wq->idxd_chan before idxd_drv_disable_wq() stops the IRQ and flushes the
remaining descriptors:
CPU0 CPU1
idxd_dmaengine_drv_remove() dma_release_channel()
mutex_lock(&wq->wq_lock) mutex_lock(&dma_list_mutex)
__idxd_wq_quiesce(wq) idxd_dma_synchronize()
percpu_ref_kill(&wq->wq_active) percpu_ref_tryget_live() -> false
... wait_for_completion()
complete(&wq->wq_resurrect) percpu_ref_tryget_live() -> false
idxd_unregister_dma_channel(wq) return
... mutex_unlock(&dma_list_mutex)
kfree(wq->idxd_chan)
idxd_drv_disable_wq(wq)
idxd_flush_pending_descs(&wq->ie)
idxd_dma_complete_txd()
dma_cookie_complete(tx)
to_idxd_dma_chan(tx->chan)->terminated <-- use-after-free
Each flushed descriptor's tx->chan still points into the freed
wq->idxd_chan, so idxd_dma_complete_txd() writes
tx->chan->completed_cookie and reads
to_idxd_dma_chan(tx->chan)->terminated on freed memory (and idxd_wq_thread()
can do the same before idxd_wq_free_irq() runs). idxd_dma_synchronize()
also returns to the caller while the IRQ thread and DMA mappings are still
active.
In addition, paths such as idxd_int_handle_revoke(), idxd_misc_thread() and
idxd_halt() quiesce wq->wq_active without disabling the workqueue, leaving
pending descriptors unmapped and leaked if idxd_dma_synchronize() returns
early here.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261125-wt-idxd-fixes-v2-0-25a4691dfb9e@intel.com?part=8
prev parent reply other threads:[~2026-11-26 0:20 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-25 23:48 [PATCH v2 0/8] dmaengine: idxd: More error handling fixes Vinicius Costa Gomes
2026-11-25 23:48 ` [PATCH v2 1/8] dmaengine: idxd: Do not call destroy_workqueue() with null idxd->wq Vinicius Costa Gomes
2026-11-25 23:49 ` [PATCH v2 2/8] dmaengine: idxd: Fix potential double free on probe error path Vinicius Costa Gomes
2026-11-25 23:49 ` [PATCH v2 3/8] dmaengine: idxd: fix duplicate memory frees on initialization " Vinicius Costa Gomes
2026-11-25 23:49 ` [PATCH v2 4/8] dmaengine: idxd: Fix the device registration error paths Vinicius Costa Gomes
2026-11-25 23:49 ` [PATCH v2 5/8] dmaengine: idxd: Fix error handling in idxd_cdev_open() Vinicius Costa Gomes
2026-11-25 23:49 ` [PATCH v2 6/8] dmaengine: idxd: Initialize the WQ XArray before the WQ can be released Vinicius Costa Gomes
2026-11-25 23:49 ` [PATCH v2 7/8] dmaengine: idxd: Do not release interrupt handles on terminate_all() Vinicius Costa Gomes
2026-11-25 23:49 ` [PATCH v2 8/8] dmaengine: idxd: Don't flush the descriptors " Vinicius Costa Gomes
2026-11-26 0:19 ` 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-234461@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=Frank.Li@kernel.org \
--cc=dmaengine@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=vinicius.gomes@intel.com \
--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