From: Zhu Yanjun <yanjun.zhu@linux.dev>
To: Selvin Xavier <selvin.xavier@broadcom.com>,
leon@kernel.org, jgg@ziepe.ca
Cc: linux-rdma@vger.kernel.org, andrew.gospodarek@broadcom.com,
kalesh-anakkur.purayil@broadcom.com
Subject: Re: [PATCH 4/4] RDMA/bnxt_re: synchronize the qp-handle table array
Date: Fri, 13 Sep 2024 12:30:20 +0800 [thread overview]
Message-ID: <cb3ec05b-9c6d-47f1-a4e5-562a30f6f855@linux.dev> (raw)
In-Reply-To: <1726079379-19272-5-git-send-email-selvin.xavier@broadcom.com>
在 2024/9/12 2:29, Selvin Xavier 写道:
> 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: f218d67ef004 ("RDMA/bnxt_re: Allow posting when QPs are in error")
> Fixes: 84cf229f4001 ("RDMA/bnxt_re: Fix the qp table indexing")
> Signed-off-by: Kalesh AP <kalesh-anakkur.purayil@broadcom.com>
> Signed-off-by: Selvin Xavier <selvin.xavier@broadcom.com>
> ---
> drivers/infiniband/hw/bnxt_re/qplib_fp.c | 5 +++++
> drivers/infiniband/hw/bnxt_re/qplib_rcfw.c | 12 ++++++++----
> drivers/infiniband/hw/bnxt_re/qplib_rcfw.h | 2 ++
> 3 files changed, 15 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/infiniband/hw/bnxt_re/qplib_fp.c b/drivers/infiniband/hw/bnxt_re/qplib_fp.c
> index 42e98e5..5d36216 100644
> --- a/drivers/infiniband/hw/bnxt_re/qplib_fp.c
> +++ b/drivers/infiniband/hw/bnxt_re/qplib_fp.c
> @@ -1524,12 +1524,15 @@ int bnxt_qplib_destroy_qp(struct bnxt_qplib_res *res,
> struct creq_destroy_qp_resp resp = {};
> struct bnxt_qplib_cmdqmsg msg = {};
> struct cmdq_destroy_qp req = {};
> + unsigned long flags;
> u32 tbl_indx;
> int rc;
>
> + spin_lock_irqsave(&rcfw->tbl_lock, flags);
Because the race occurs between tasklets, spin_lock_bh is enough to this?
Zhu Yanjun
> tbl_indx = map_qp_id_to_tbl_indx(qp->id, rcfw);
> rcfw->qp_tbl[tbl_indx].qp_id = BNXT_QPLIB_QP_ID_INVALID;
> rcfw->qp_tbl[tbl_indx].qp_handle = NULL;
> + spin_unlock_irqrestore(&rcfw->tbl_lock, flags);
>
> bnxt_qplib_rcfw_cmd_prep((struct cmdq_base *)&req,
> CMDQ_BASE_OPCODE_DESTROY_QP,
> @@ -1540,8 +1543,10 @@ int bnxt_qplib_destroy_qp(struct bnxt_qplib_res *res,
> sizeof(resp), 0);
> rc = bnxt_qplib_rcfw_send_message(rcfw, &msg);
> if (rc) {
> + spin_lock_irqsave(&rcfw->tbl_lock, flags);
> rcfw->qp_tbl[tbl_indx].qp_id = qp->id;
> rcfw->qp_tbl[tbl_indx].qp_handle = qp;
> + spin_unlock_irqrestore(&rcfw->tbl_lock, flags);
> return rc;
> }
>
> diff --git a/drivers/infiniband/hw/bnxt_re/qplib_rcfw.c b/drivers/infiniband/hw/bnxt_re/qplib_rcfw.c
> index 3ffaef0c..993c356 100644
> --- a/drivers/infiniband/hw/bnxt_re/qplib_rcfw.c
> +++ b/drivers/infiniband/hw/bnxt_re/qplib_rcfw.c
> @@ -637,17 +637,21 @@ static int bnxt_qplib_process_qp_event(struct bnxt_qplib_rcfw *rcfw,
> case CREQ_QP_EVENT_EVENT_QP_ERROR_NOTIFICATION:
> err_event = (struct creq_qp_error_notification *)qp_event;
> qp_id = le32_to_cpu(err_event->xid);
> + spin_lock(&rcfw->tbl_lock);
> tbl_indx = map_qp_id_to_tbl_indx(qp_id, rcfw);
> qp = rcfw->qp_tbl[tbl_indx].qp_handle;
> + if (!qp) {
> + spin_unlock(&rcfw->tbl_lock);
> + break;
> + }
> + bnxt_qplib_mark_qp_error(qp);
> + rc = rcfw->creq.aeq_handler(rcfw, qp_event, qp);
> + spin_unlock(&rcfw->tbl_lock);
> dev_dbg(&pdev->dev, "Received QP error notification\n");
> dev_dbg(&pdev->dev,
> "qpid 0x%x, req_err=0x%x, resp_err=0x%x\n",
> qp_id, err_event->req_err_state_reason,
> err_event->res_err_state_reason);
> - if (!qp)
> - break;
> - bnxt_qplib_mark_qp_error(qp);
> - rc = rcfw->creq.aeq_handler(rcfw, qp_event, qp);
> break;
> default:
> /*
> diff --git a/drivers/infiniband/hw/bnxt_re/qplib_rcfw.h b/drivers/infiniband/hw/bnxt_re/qplib_rcfw.h
> index 45996e6..07779ae 100644
> --- a/drivers/infiniband/hw/bnxt_re/qplib_rcfw.h
> +++ b/drivers/infiniband/hw/bnxt_re/qplib_rcfw.h
> @@ -224,6 +224,8 @@ struct bnxt_qplib_rcfw {
> struct bnxt_qplib_crsqe *crsqe_tbl;
> int qp_tbl_size;
> struct bnxt_qplib_qp_node *qp_tbl;
> + /* To synchronize the qp-handle hash table */
> + spinlock_t tbl_lock;
> u64 oos_prev;
> u32 init_oos_stats;
> u32 cmdq_depth;
next prev parent reply other threads:[~2024-09-13 4:30 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-11 18:29 [PATCH 0/4] RDMA/bnxt_re: Bug fixes for 6.12 kernel Selvin Xavier
2024-09-11 18:29 ` [PATCH 1/4] RDMA/bnxt_re: Fix a possible memory leak Selvin Xavier
2024-09-11 18:29 ` [PATCH 2/4] RDMA/bnxt_re: Fix incorrect AVID type in WQE structure Selvin Xavier
2024-09-11 18:29 ` [PATCH 3/4] RDMA/bnxt_re: Add a check for memory allocation Selvin Xavier
2024-09-11 18:29 ` [PATCH 4/4] RDMA/bnxt_re: synchronize the qp-handle table array Selvin Xavier
2024-09-13 4:26 ` Zhu Yanjun
2024-09-13 4:30 ` Zhu Yanjun [this message]
2024-09-13 7:59 ` Selvin Xavier
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=cb3ec05b-9c6d-47f1-a4e5-562a30f6f855@linux.dev \
--to=yanjun.zhu@linux.dev \
--cc=andrew.gospodarek@broadcom.com \
--cc=jgg@ziepe.ca \
--cc=kalesh-anakkur.purayil@broadcom.com \
--cc=leon@kernel.org \
--cc=linux-rdma@vger.kernel.org \
--cc=selvin.xavier@broadcom.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox