Skip to content

Commit 76d3ddf

Browse files
selvintxavierjgunthorpe
authored andcommitted
RDMA/bnxt_re: synchronize the qp-handle table array
There is a race between the CREQ tasklet and destroy qp when accessing the qp-handle table. There is a chance of reading a valid qp-handle in the CREQ tasklet handler while the QP is already moving ahead with the destruction. Fixing this race by implementing a table-lock to synchronize the access. Fixes: f218d67 ("RDMA/bnxt_re: Allow posting when QPs are in error") Fixes: 84cf229 ("RDMA/bnxt_re: Fix the qp table indexing") Link: https://patch.msgid.link/r/[email protected] Signed-off-by: Kalesh AP <[email protected]> Signed-off-by: Selvin Xavier <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]>
1 parent d71f4ac commit 76d3ddf

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

drivers/infiniband/hw/bnxt_re/qplib_fp.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1532,9 +1532,11 @@ int bnxt_qplib_destroy_qp(struct bnxt_qplib_res *res,
15321532
u32 tbl_indx;
15331533
int rc;
15341534

1535+
spin_lock_bh(&rcfw->tbl_lock);
15351536
tbl_indx = map_qp_id_to_tbl_indx(qp->id, rcfw);
15361537
rcfw->qp_tbl[tbl_indx].qp_id = BNXT_QPLIB_QP_ID_INVALID;
15371538
rcfw->qp_tbl[tbl_indx].qp_handle = NULL;
1539+
spin_unlock_bh(&rcfw->tbl_lock);
15381540

15391541
bnxt_qplib_rcfw_cmd_prep((struct cmdq_base *)&req,
15401542
CMDQ_BASE_OPCODE_DESTROY_QP,
@@ -1545,8 +1547,10 @@ int bnxt_qplib_destroy_qp(struct bnxt_qplib_res *res,
15451547
sizeof(resp), 0);
15461548
rc = bnxt_qplib_rcfw_send_message(rcfw, &msg);
15471549
if (rc) {
1550+
spin_lock_bh(&rcfw->tbl_lock);
15481551
rcfw->qp_tbl[tbl_indx].qp_id = qp->id;
15491552
rcfw->qp_tbl[tbl_indx].qp_handle = qp;
1553+
spin_unlock_bh(&rcfw->tbl_lock);
15501554
return rc;
15511555
}
15521556

drivers/infiniband/hw/bnxt_re/qplib_rcfw.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -634,17 +634,21 @@ static int bnxt_qplib_process_qp_event(struct bnxt_qplib_rcfw *rcfw,
634634
case CREQ_QP_EVENT_EVENT_QP_ERROR_NOTIFICATION:
635635
err_event = (struct creq_qp_error_notification *)qp_event;
636636
qp_id = le32_to_cpu(err_event->xid);
637+
spin_lock(&rcfw->tbl_lock);
637638
tbl_indx = map_qp_id_to_tbl_indx(qp_id, rcfw);
638639
qp = rcfw->qp_tbl[tbl_indx].qp_handle;
640+
if (!qp) {
641+
spin_unlock(&rcfw->tbl_lock);
642+
break;
643+
}
644+
bnxt_qplib_mark_qp_error(qp);
645+
rc = rcfw->creq.aeq_handler(rcfw, qp_event, qp);
646+
spin_unlock(&rcfw->tbl_lock);
639647
dev_dbg(&pdev->dev, "Received QP error notification\n");
640648
dev_dbg(&pdev->dev,
641649
"qpid 0x%x, req_err=0x%x, resp_err=0x%x\n",
642650
qp_id, err_event->req_err_state_reason,
643651
err_event->res_err_state_reason);
644-
if (!qp)
645-
break;
646-
bnxt_qplib_mark_qp_error(qp);
647-
rc = rcfw->creq.aeq_handler(rcfw, qp_event, qp);
648652
break;
649653
default:
650654
/*
@@ -973,6 +977,7 @@ int bnxt_qplib_alloc_rcfw_channel(struct bnxt_qplib_res *res,
973977
GFP_KERNEL);
974978
if (!rcfw->qp_tbl)
975979
goto fail;
980+
spin_lock_init(&rcfw->tbl_lock);
976981

977982
rcfw->max_timeout = res->cctx->hwrm_cmd_max_timeout;
978983

drivers/infiniband/hw/bnxt_re/qplib_rcfw.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,8 @@ struct bnxt_qplib_rcfw {
224224
struct bnxt_qplib_crsqe *crsqe_tbl;
225225
int qp_tbl_size;
226226
struct bnxt_qplib_qp_node *qp_tbl;
227+
/* To synchronize the qp-handle hash table */
228+
spinlock_t tbl_lock;
227229
u64 oos_prev;
228230
u32 init_oos_stats;
229231
u32 cmdq_depth;

0 commit comments

Comments
 (0)