All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jacob Moroni <jmoroni@google.com>
To: tatyana.e.nikolova@intel.com, jgg@ziepe.ca, leon@kernel.org
Cc: linux-rdma@vger.kernel.org, Owen Gentry <owengentry@google.com>,
	 Jacob Moroni <jmoroni@google.com>
Subject: [PATCH rdma-next 2/2] RDMA/irdma: Scrub software flush completions on QP destroy
Date: Thu, 26 Nov 2026 18:53:44 +0000	[thread overview]
Message-ID: <20261126185344.2784303-2-jmoroni@google.com> (raw)
In-Reply-To: <20261126185344.2784303-1-jmoroni@google.com>

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


  reply	other threads:[~2026-11-26 18:53 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2026-11-26 19:04 ` sashiko-bot
2026-11-26 19:04 ` sashiko-bot
2026-11-26 19:14   ` Jacob Moroni
2026-11-29 12:03 ` Leon Romanovsky

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=20261126185344.2784303-2-jmoroni@google.com \
    --to=jmoroni@google.com \
    --cc=jgg@ziepe.ca \
    --cc=leon@kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=owengentry@google.com \
    --cc=tatyana.e.nikolova@intel.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.