Skip to contentSkip to conversation

RDMA/bnxt_re: Don't republish a QP whose destroy failed

PATCH New Yuho Choi 2 participants 2 messages Nov 24

Subsystems (2)
lore
Share & tools
lore

Yuho Choi

author
#0 lore raw

PATCH 1/1 RDMA/bnxt_re: Don't republish a QP whose destroy failed

bnxt_qplib_destroy_qp() removes the QP from rcfw->qp_tbl before sending DESTROY_QP and re-inserts it if bnxt_qplib_rcfw_send_message() fails.

No caller uses the QP after a failure, though:
- bnxt_re_destroy_qp() logs the error and returns 0 since commit d507d29bfde3 ("RDMA/bnxt_re: Don't fail destroy QP and cleanup debugfs earlier"), so the IB core frees the QP.
- bnxt_re_destroy_gsi_sqp() logs the error and frees gsi_sqp.
- bnxt_re_create_qp() frees the QP resources and returns the error so the IB core frees the QP.
- bnxt_re_create_shadow_gsi() abandons the shadow QP on failure.

Moreover, on the error paths of bnxt_qplib_create_qp() and bnxt_qplib_create_qp1(), bnxt_qplib_destroy_qp() is called before the QP is even inserted into rcfw->qp_tbl (and before sq_flush/rq_flush are initialized in bnxt_qplib_create_qp()), so the rollback publishes a half-initialized QP that is about to be freed.

Except for the abandoned shadow QP, the QP is freed right after, so rcfw->qp_tbl is left with a dangling pointer. On a later QP error notification, bnxt_qplib_process_qp_event() marks that QP in error and passes it to the async event handler.

Drop the rollback so the QP stays out of rcfw->qp_tbl when DESTROY_QP fails.

Fixes f218d67ef004 ("RDMA/bnxt_re: Allow posting when QPs are in error")
Fixes d507d29bfde3 ("RDMA/bnxt_re: Don't fail destroy QP and cleanup debugfs earlier")

---
Compile-tested only (x86_64 with INFINIBAND_BNXT_RE, W=1). I have no NetXtreme-E RoCE hardware, and DESTROY_QP only fails when the firmware times out or returns an error status, so I could not trigger it.

 drivers/infiniband/hw/bnxt_re/qplib_fp.c | 16 +++++-----------
 1 file changed, 5 insertions(+), 11 deletions(-)
drivers/infiniband/hw/bnxt_re/qplib_fp.c +5 -11
index 5301e4f21ade..a5660002d184 100644
@@ -1473,7 +1473,6 @@ int bnxt_qplib_destroy_qp(struct bnxt_qplib_res *res,
 	struct bnxt_qplib_cmdqmsg msg = {};
 	struct cmdq_destroy_qp req = {};
 	u32 tbl_indx;
-	int rc;
 
 	spin_lock_bh(&rcfw->tbl_lock);
 	tbl_indx = map_qp_id_to_tbl_indx(qp->id, rcfw);
@@ -1488,16 +1487,11 @@ int bnxt_qplib_destroy_qp(struct bnxt_qplib_res *res,
 	req.qp_cid = cpu_to_le32(qp->id);
 	bnxt_qplib_fill_cmdqmsg(&msg, &req, &resp, NULL, sizeof(req),
 				sizeof(resp), 0);
-	rc = bnxt_qplib_rcfw_send_message(rcfw, &msg);
-	if (rc) {
-		spin_lock_bh(&rcfw->tbl_lock);
-		rcfw->qp_tbl[tbl_indx].qp_id = qp->id;
-		rcfw->qp_tbl[tbl_indx].qp_handle = qp;
-		spin_unlock_bh(&rcfw->tbl_lock);
-		return rc;
-	}
-
-	return 0;
+	/*
+	 * Don't put the QP back into qp_tbl if the command fails: no caller
+	 * uses the QP after a failure, and most of them free it right away.
+	 */
+	return bnxt_qplib_rcfw_send_message(rcfw, &msg);
 }
 
 void bnxt_qplib_free_qp_res(struct bnxt_qplib_res *res,

base-commit: 8dac6df92a2e66e2098bbc69061964cfe7e8375b

Signature · 1 line
2.56.1
#1 lore raw
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/bnxt_re: data race in…

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/bnxt_re: data race in bnxt_qplib_create_qp1() [1] --

commit 1b21d21008b23e4ba7182837a1d5e17b617eab26
Author: Yuho Choi <[email protected]>

RDMA/bnxt_re: Don't republish a QP whose destroy failed

This commit drops the rcfw->qp_tbl rollback in bnxt_qplib_destroy_qp() so a QP is not reinserted into the table if the DESTROY_QP firmware command fails.

Quoted 22 lines
drivers/infiniband/hw/bnxt_re/qplib_fp.c +0 -7
index 5301e4f21ade0..a5660002d1840 100644
@@ -1473,7 +1473,6 @@ int bnxt_qplib_destroy_qp(struct bnxt_qplib_res *res,
 	struct bnxt_qplib_cmdqmsg msg = {};
 	struct cmdq_destroy_qp req = {};
 	u32 tbl_indx;
-	int rc;
 
 	spin_lock_bh(&rcfw->tbl_lock);
 	tbl_indx = map_qp_id_to_tbl_indx(qp->id, rcfw);
@@ -1488,16 +1487,11 @@ int bnxt_qplib_destroy_qp(struct bnxt_qplib_res *res,
 	req.qp_cid = cpu_to_le32(qp->id);
 	bnxt_qplib_fill_cmdqmsg(&msg, &req, &resp, NULL, sizeof(req),
 				sizeof(resp), 0);
-	rc = bnxt_qplib_rcfw_send_message(rcfw, &msg);
-	if (rc) {
-		spin_lock_bh(&rcfw->tbl_lock);
-		rcfw->qp_tbl[tbl_indx].qp_id = qp->id;
-		rcfw->qp_tbl[tbl_indx].qp_handle = qp;
-		spin_unlock_bh(&rcfw->tbl_lock);

drivers/infiniband/hw/bnxt_re/qplib_fp.c int bnxt_qplib_destroy_qp(struct bnxt_qplib_res *res, · line 1495

Quoted 10 lines
drivers/infiniband/hw/bnxt_re/qplib_fp.c +5 -4
-		return rc;
-	}
-
-	return 0;
+	/*
+	 * Don't put the QP back into qp_tbl if the command fails: no caller
+	 * uses the QP after a failure, and most of them free it right away.
+	 */
+	return bnxt_qplib_rcfw_send_message(rcfw, &msg);
 }

[Severity: High]
This problem wasn't introduced by this patch, but shouldn't bnxt_qplib_create_qp1() also hold rcfw->tbl_lock when populating rcfw->qp_tbl [1]?

drivers/infiniband/hw/bnxt_re/qplib_fp.c:bnxt_qplib_create_qp1() {
	...
	tbl_indx = map_qp_id_to_tbl_indx(qp->id, rcfw);
	rcfw->qp_tbl[tbl_indx].qp_id = qp->id;
	rcfw->qp_tbl[tbl_indx].qp_handle = (void *)qp;

	return 0;
	...
}

Once bnxt_qplib_rcfw_send_message() completes CREATE_QP1, firmware can emit events for the new QP while bnxt_qplib_create_qp1() is still running:

CPU0 CPU1 (CREQ tasklet)
bnxt_qplib_create_qp1()
bnxt_qplib_rcfw_send_message()

                                      bnxt_qplib_process_qp_event()
                                        spin_lock(&rcfw->tbl_lock)
  rcfw->qp_tbl[tbl_indx].qp_id = ...
  rcfw->qp_tbl[tbl_indx].qp_handle = ...
                                        reads rcfw->qp_tbl[tbl_indx]
                                          <-- data race
                                        spin_unlock(&rcfw->tbl_lock)

Without rcfw->tbl_lock, bnxt_qplib_process_qp_event() can observe a partially updated qp_tbl entry, missing a QP error notification or dereferencing an uninitialized qp_handle.

[1] https://sashiko.dev/#/bug/linux-c8dafdae-4eb3-4ddb-a2a2-5d1da6ca2da5

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1