[PATCH for-rc v2 8/8] RDMA/bnxt_re: Check is_in_used before trusting RCFW completion
From: Selvin Xavier <selvin.xavier@broadcom.com>
Date: 2026-09-09 08:31:41
Subsystem:
broadcom netxtreme-e roce driver, infiniband subsystem, the rest · Maintainers:
Selvin Xavier, Kalesh AP, Jason Gunthorpe, Leon Romanovsky, Linus Torvalds
Gate the crsqe->resp memcpy in bnxt_qplib_process_qp_event() on
is_in_used in addition to is_waiter_alive, since a late/duplicate
completion for an already-retired cookie could still write through a
stale resp pointer.
Also disarm the waiter and clear resp when a wait call bails out early
on ERR_DEVICE_DETACHED, and require is_in_used before re-triggering
__destroy_timedout_ah(), closing the same stale-cookie exposure
elsewhere in the completion path.
Fixes: 691eb7c6110f ("RDMA/bnxt_re: handle command completions after driver detect a timedout")
Signed-off-by: Selvin Xavier <selvin.xavier@broadcom.com>
---
drivers/infiniband/hw/bnxt_re/qplib_rcfw.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/drivers/infiniband/hw/bnxt_re/qplib_rcfw.c b/drivers/infiniband/hw/bnxt_re/qplib_rcfw.c
index 9ee0d500436c..0339e55bea88 100644
--- a/drivers/infiniband/hw/bnxt_re/qplib_rcfw.c
+++ b/drivers/infiniband/hw/bnxt_re/qplib_rcfw.c@@ -511,14 +511,16 @@ static int __bnxt_qplib_rcfw_send_message(struct bnxt_qplib_rcfw *rcfw, else rc = __poll_for_resp(rcfw, cookie); - if (rc) { + if (rc || test_bit(ERR_DEVICE_DETACHED, &rcfw->cmdq.flags)) { spin_lock_bh(&rcfw->cmdq.hwq.lock); crsqe = &rcfw->crsqe_tbl[cookie]; crsqe->is_waiter_alive = false; + crsqe->resp = NULL; if (rc == -ENODEV) set_bit(FIRMWARE_STALL_DETECTED, &rcfw->cmdq.flags); spin_unlock_bh(&rcfw->cmdq.hwq.lock); - return -ETIMEDOUT; + if (rc) + return -ETIMEDOUT; } if (evnt->status) {
@@ -627,6 +629,7 @@ static int bnxt_qplib_process_qp_event(struct bnxt_qplib_rcfw *rcfw, struct bnxt_qplib_qp *qp; u16 cookie, blocked = 0; bool is_waiter_alive; + bool is_in_used; struct pci_dev *pdev; u32 wait_cmds = 0; int rc = 0;
@@ -682,7 +685,7 @@ static int bnxt_qplib_process_qp_event(struct bnxt_qplib_rcfw *rcfw, if (crsqe->is_internal_cmd && !qp_event->status) atomic_dec(&rcfw->timeout_send); - if (crsqe->is_waiter_alive) { + if (crsqe->is_waiter_alive && crsqe->is_in_used) { if (crsqe->resp) { memcpy(crsqe->resp, qp_event, sizeof(*qp_event)); /* Insert write memory barrier to ensure that
@@ -697,6 +700,7 @@ static int bnxt_qplib_process_qp_event(struct bnxt_qplib_rcfw *rcfw, req_size = crsqe->req_size; is_waiter_alive = crsqe->is_waiter_alive; + is_in_used = crsqe->is_in_used; crsqe->req_size = 0; if (!is_waiter_alive)
@@ -718,7 +722,7 @@ static int bnxt_qplib_process_qp_event(struct bnxt_qplib_rcfw *rcfw, * resource leak and relatively not critical + unlikely * scenario. Current design is not to handle such case. */ - if (!is_waiter_alive && !qp_event->status && + if (is_in_used && !is_waiter_alive && !qp_event->status && qp_event->event == CREQ_QP_EVENT_EVENT_CREATE_AH) __destroy_timedout_ah(rcfw, (struct creq_create_ah_resp *)
--
2.39.3