* [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
` (2 subsequent siblings)
3 siblings, 0 replies; 6+ 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] 6+ 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 ` sashiko-bot
2026-11-26 19:04 ` sashiko-bot
2026-11-29 12:03 ` Leon Romanovsky
3 siblings, 0 replies; 6+ messages in thread
From: sashiko-bot @ 2026-11-26 19:04 UTC (permalink / raw)
To: Jacob Moroni; +Cc: linux-rdma
Sashiko has finished reviewing this 2-patch series:
- Patch 2: no issues found.
- Patch 1 ("RDMA/irdma: Wait for all refs to drop when destroyin..."): 1
related pre-existing bug noted
A detailed review has been sent as a separate reply to patch 1.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261126185344.2784303-1-jmoroni@google.com
^ permalink raw reply [flat|nested] 6+ 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
2026-11-29 12:03 ` Leon Romanovsky
3 siblings, 1 reply; 6+ 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] 6+ messages in thread* Re: [PATCH rdma-next 1/2] RDMA/irdma: Wait for all refs to drop when destroying RoCE QPs
2026-11-26 19:04 ` sashiko-bot
@ 2026-11-26 19:14 ` Jacob Moroni
0 siblings, 0 replies; 6+ messages in thread
From: Jacob Moroni @ 2026-11-26 19:14 UTC (permalink / raw)
To: sashiko-reviews; +Cc: linux-rdma
The cmpl_generated part is what patch 2/2 of this series fixes. It disables
the flush work before the QP is moved to error and then scrubs the QP's
entries from cmpl_generated.
The resize_list part is not reachable. Entries are only added there when
irdma_resize_cq() is called without udata, i.e. for a kernel CQ, and there
is no caller for that since commit 6c45efd8f9bb ("RDMA/core: Remove unused
ib_resize_cq() implementation").
In fact, a lot of "resize CQ" related logic can be removed from IRDMA now
that it's not a supported kernel verb. I'll add it to my TODOs.
Thanks,
Jake
^ permalink raw reply [flat|nested] 6+ 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
` (2 preceding siblings ...)
2026-11-26 19:04 ` sashiko-bot
@ 2026-11-29 12:03 ` Leon Romanovsky
3 siblings, 0 replies; 6+ messages in thread
From: Leon Romanovsky @ 2026-11-29 12:03 UTC (permalink / raw)
To: tatyana.e.nikolova, jgg, Jacob Moroni; +Cc: linux-rdma
On Thu, 26 Nov 2026 18:53:43 +0000, Jacob Moroni wrote:
> Commit 6f52370970ac ("RDMA/irdma: Fix deadlock during netdev reset
> with active connections") made QP destruction skip the refcount wait
> if the device is being reset in order to fix a deadlock that could
> occur for iWARP mode QPs due to refs still being held by the CM.
>
> RoCE mode QPs are not subject to that issue and should still wait
> for all of the references to be dropped. Otherwise, the QP could
> be freed while the AEQ handler or disconnect work still holds a
> reference, leading to a UAF. In RoCE mode, any remaining references
> held by the AEQ handler/disconnect work are always transient so
> the wait is bounded.
>
> [...]
Applied, thanks!
[1/2] RDMA/irdma: Wait for all refs to drop when destroying RoCE QPs
https://git.kernel.org/rdma/rdma/c/f33738f9319fd0
[2/2] RDMA/irdma: Scrub software flush completions on QP destroy
https://git.kernel.org/rdma/rdma/c/78d9dd829f1250
Best regards,
--
Leon Romanovsky <leon@kernel.org>
^ permalink raw reply [flat|nested] 6+ messages in thread