* [PATCH rdma-next 2/2] RDMA/irdma: Scrub software flush completions on QP destroy
2026-11-26 18:53 [PATCH rdma-next 1/2] RDMA/irdma: Wait for all refs to drop when destroying RoCE QPs Jacob Moroni
@ 2026-11-26 18:53 ` Jacob Moroni
2026-11-26 19:04 ` [PATCH rdma-next 1/2] RDMA/irdma: Wait for all refs to drop when destroying RoCE QPs sashiko-bot
2026-11-26 19:04 ` sashiko-bot
2 siblings, 0 replies; 5+ messages in thread
From: Jacob Moroni @ 2026-11-26 18:53 UTC (permalink / raw)
To: tatyana.e.nikolova, jgg, leon; +Cc: linux-rdma, Owen Gentry, Jacob Moroni
From: Owen Gentry <owengentry@google.com>
When a kernel QP transitions to error state, irdma_flush_worker() can
append software-generated flush completions. During QP teardown,
irdma scrubs HW CQEs but leaves SW CQEs intact, causing subsequent
CQ polling to dereference the freed QP.
In addition, _irdma_destroy_qp() calls irdma_modify_qp_to_err() before
cancelling iwqp->dwork_flush with cancel_delayed_work_sync(), which
needlessly arms the flush work during teardown and leaves a window where
concurrent paths can re-schedule dwork_flush after CQEs are scrubbed and
before the QP is freed.
Disable and drain iwqp->dwork_flush via disable_delayed_work_sync()
before calling irdma_modify_qp_to_err(), and free matching SW CQEs from
iwcq->cmpl_generated in irdma_clean_cqes().
Fixes: 81091d7696ae ("RDMA/irdma: Add SW mechanism to generate completions on error")
Signed-off-by: Owen Gentry <owengentry@google.com>
Signed-off-by: Jacob Moroni <jmoroni@google.com>
---
drivers/infiniband/hw/irdma/verbs.c | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)
diff --git a/drivers/infiniband/hw/irdma/verbs.c b/drivers/infiniband/hw/irdma/verbs.c
index 29ccd19da032..04ebba436eea 100644
--- a/drivers/infiniband/hw/irdma/verbs.c
+++ b/drivers/infiniband/hw/irdma/verbs.c
@@ -514,10 +514,17 @@ static struct irdma_pbl *irdma_get_pbl(unsigned long va,
static void irdma_clean_cqes(struct irdma_qp *iwqp, struct irdma_cq *iwcq)
{
struct irdma_cq_uk *ukcq = &iwcq->sc_cq.cq_uk;
+ struct irdma_cmpl_gen *cmpl, *tmp;
unsigned long flags;
spin_lock_irqsave(&iwcq->lock, flags);
irdma_uk_clean_cq(&iwqp->sc_qp.qp_uk, ukcq);
+ list_for_each_entry_safe(cmpl, tmp, &iwcq->cmpl_generated, list) {
+ if (cmpl->cpi.qp_handle != &iwqp->sc_qp.qp_uk)
+ continue;
+ list_del(&cmpl->list);
+ kfree(cmpl);
+ }
spin_unlock_irqrestore(&iwcq->lock, flags);
}
@@ -577,12 +584,12 @@ static void _irdma_destroy_qp(struct ib_qp *ibqp)
iwqp->sc_qp.qp_uk.destroy_pending = true;
+ if (!iwqp->user_mode)
+ disable_delayed_work_sync(&iwqp->dwork_flush);
+
if (iwqp->iwarp_state >= IRDMA_QP_STATE_IDLE)
irdma_modify_qp_to_err(&iwqp->sc_qp);
- if (!iwqp->user_mode)
- cancel_delayed_work_sync(&iwqp->dwork_flush);
-
if (!iwqp->user_mode) {
if (iwqp->iwscq) {
irdma_clean_cqes(iwqp, iwqp->iwscq);
--
2.56.1.839.g22a8290db9-goog
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH rdma-next 1/2] RDMA/irdma: Wait for all refs to drop when destroying RoCE QPs
2026-11-26 18:53 [PATCH rdma-next 1/2] RDMA/irdma: Wait for all refs to drop when destroying RoCE QPs Jacob Moroni
2026-11-26 18:53 ` [PATCH rdma-next 2/2] RDMA/irdma: Scrub software flush completions on QP destroy Jacob Moroni
2026-11-26 19:04 ` [PATCH rdma-next 1/2] RDMA/irdma: Wait for all refs to drop when destroying RoCE QPs sashiko-bot
@ 2026-11-26 19:04 ` sashiko-bot
2026-11-26 19:14 ` Jacob Moroni
2 siblings, 1 reply; 5+ messages in thread
From: sashiko-bot @ 2026-11-26 19:04 UTC (permalink / raw)
To: Jacob Moroni; +Cc: linux-rdma
Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [High] RDMA/irdma: use-after-free from incomplete CQ scrub in
irdma_clean_cqes() [1]
--
commit ec08c5024cb50836ff76a6f7d89b61c4ac172b85
Author: Jacob Moroni <jmoroni@google.com>
RDMA/irdma: Wait for all refs to drop when destroying RoCE QPs
This commit restores waiting on iwqp->free_qp when destroying RoCE QPs
during a device reset so that transient references from the AEQ handler
or disconnect work finish before the QP is freed.
> diff --git a/drivers/infiniband/hw/irdma/verbs.c b/drivers/infiniband/hw/irdma/verbs.c
> index e07b6b40dd992..29ccd19da0321 100644
> --- a/drivers/infiniband/hw/irdma/verbs.c
> +++ b/drivers/infiniband/hw/irdma/verbs.c
> @@ -592,7 +592,7 @@ static void _irdma_destroy_qp(struct ib_qp *ibqp)
> }
>
> irdma_qp_rem_ref(&iwqp->ibqp);
> - if (!iwdev->rf->reset)
> + if (!iwdev->rf->reset || iwdev->roce_mode)
> wait_for_completion(&iwqp->free_qp);
> irdma_free_lsmm_rsrc(iwqp);
> irdma_cqp_qp_destroy_cmd(&iwdev->rf->sc_dev, &iwqp->sc_qp);
[Severity: High]
This problem wasn't introduced by this patch, but can _irdma_destroy_qp()
leave behind stale completions for the QP on iwcq->cmpl_generated and
iwcq->resize_list [1]?
Earlier in _irdma_destroy_qp(), transitioning a kernel QP to error can
queue software flush completions onto iwcq->cmpl_generated, and earlier
irdma_resize_cq() calls can leave unpolled CQ buffers on
iwcq->resize_list. However, irdma_clean_cqes() only scrubs the active CQ
ring:
drivers/infiniband/hw/irdma/verbs.c:irdma_clean_cqes() {
struct irdma_cq_uk *ukcq = &iwcq->sc_cq.cq_uk;
unsigned long flags;
spin_lock_irqsave(&iwcq->lock, flags);
irdma_uk_clean_cq(&iwqp->sc_qp.qp_uk, ukcq);
spin_unlock_irqrestore(&iwcq->lock, flags);
}
After _irdma_destroy_qp() frees the QP, a subsequent irdma_poll_cq() can
pull those remaining entries and dereference the dangling qp_handle in
irdma_uk_cq_poll_cmpl() and irdma_process_cqe(), causing a use-after-free
of struct irdma_qp.
[1] https://sashiko.dev/#/bug/linux-e3f313d2-d1fd-48a1-8be3-bb6bfb32a341
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261126185344.2784303-1-jmoroni@google.com?part=1
^ permalink raw reply [flat|nested] 5+ messages in thread