From: Cheng Xu <chengyou@linux.alibaba.com>
To: Leon Romanovsky <leon@kernel.org>,
Kai Shen <kaishen@linux.alibaba.com>,
Jason Gunthorpe <jgg@ziepe.ca>,
Wei Yongjun <weiyongjun1@huawei.com>,
Yang Li <yang.lee@linux.alibaba.com>
Cc: linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH rdma-next] RDMA/erdma: complete object teardown when the destroy command fails
Date: Thu, 23 Jul 2026 16:08:28 +0800 [thread overview]
Message-ID: <4c1bbac8-b010-ce2d-3d96-25623cbdeec1@linux.alibaba.com> (raw)
In-Reply-To: <20260722-b4-qp-and-cq-memory-are-leaked-if-the-d-v1-1-97e223dc1c96@nvidia.com>
On 7/22/26 9:13 PM, Leon Romanovsky wrote:
> From: Leon Romanovsky <leonro@nvidia.com>
>
> erdma_destroy_qp(), erdma_destroy_cq(), erdma_dereg_mr(), and
> erdma_destroy_ah() returned early when erdma_post_cmd_wait() failed,
> leaking the queue buffers, MTTs, doorbells and the STAG, QPN, CQN and AHN
> identifiers. A command timeout clears ERDMA_CMDQ_STATE_OK_BIT and
> permanently disables the command queue, so no retry can succeed; the RDMA
> core keeps the object after a failed destructor and forced uverbs cleanup
> then nulls the pointers, making the resources unreachable.
>
> Warn on failure but release every software-owned resource and return
> success, since during terminal destruction the hardware command result is
> only diagnostic.
>
> Fixes: 155055771704 ("RDMA/erdma: Add verbs implementation")
> Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
> ---
> drivers/infiniband/hw/erdma/erdma_verbs.c | 21 +++++++++++++++++----
> 1 file changed, 17 insertions(+), 4 deletions(-)
>
Thanks Leon, this makes sense to me.
Acked-by: Cheng Xu <chengyou@linux.alibaba.com>
Thanks,
Cheng Xu
> diff --git a/drivers/infiniband/hw/erdma/erdma_verbs.c b/drivers/infiniband/hw/erdma/erdma_verbs.c
> index 71e3e8618a61..ab6abbab029e 100644
> --- a/drivers/infiniband/hw/erdma/erdma_verbs.c
> +++ b/drivers/infiniband/hw/erdma/erdma_verbs.c
> @@ -1302,8 +1302,15 @@ int erdma_dereg_mr(struct ib_mr *ibmr, struct ib_udata *udata)
>
> ret = erdma_post_cmd_wait(&dev->cmdq, &req, sizeof(req), NULL, NULL,
> true);
> + /*
> + * A timeout disables the command queue, so retry cannot succeed. Treat
> + * terminal command failures as diagnostic; propagating them can make
> + * forced uverbs cleanup discard the last software resource pointers.
> + */
> if (ret)
> - return ret;
> + ibdev_warn_ratelimited(&dev->ibdev,
> + "failed to deregister MR 0x%x: %d\n",
> + ibmr->lkey, ret);
>
> erdma_free_idx(&dev->res_cb[ERDMA_RES_TYPE_STAG_IDX], ibmr->lkey >> 8);
>
> @@ -1329,7 +1336,9 @@ int erdma_destroy_cq(struct ib_cq *ibcq, struct ib_udata *udata)
> err = erdma_post_cmd_wait(&dev->cmdq, &req, sizeof(req), NULL, NULL,
> true);
> if (err)
> - return err;
> + ibdev_warn_ratelimited(&dev->ibdev,
> + "failed to destroy CQ %u: %d\n",
> + cq->cqn, err);
>
> if (rdma_is_kernel_res(&cq->ibcq.res)) {
> dma_free_coherent(&dev->pdev->dev, cq->depth << CQE_SHIFT,
> @@ -1377,7 +1386,9 @@ int erdma_destroy_qp(struct ib_qp *ibqp, struct ib_udata *udata)
> err = erdma_post_cmd_wait(&dev->cmdq, &req, sizeof(req), NULL, NULL,
> true);
> if (err)
> - return err;
> + ibdev_warn_ratelimited(&dev->ibdev,
> + "failed to destroy QP %u: %d\n",
> + QP_ID(qp), err);
>
> erdma_qp_put(qp);
> wait_for_completion(&qp->safe_free);
> @@ -2279,7 +2290,9 @@ int erdma_destroy_ah(struct ib_ah *ibah, u32 flags)
> ret = erdma_post_cmd_wait(&dev->cmdq, &req, sizeof(req), NULL, NULL,
> flags & RDMA_DESTROY_AH_SLEEPABLE);
> if (ret)
> - return ret;
> + ibdev_warn_ratelimited(&dev->ibdev,
> + "failed to destroy AH %u: %d\n",
> + ah->ahn, ret);
>
> erdma_free_idx(&dev->res_cb[ERDMA_RES_TYPE_AH], ah->ahn);
>
>
> ---
> base-commit: 0e8e94c15091041ea8910cbfcade5a9c7cfe3f90
> change-id: 20260722-b4-qp-and-cq-memory-are-leaked-if-the-d-760a0f866319
>
> Best regards,
> --
> Leon Romanovsky <leonro@nvidia.com>
next prev parent reply other threads:[~2026-07-23 8:08 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-22 13:13 Leon Romanovsky
2026-07-23 8:08 ` Cheng Xu [this message]
2026-07-23 11:35 ` 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=4c1bbac8-b010-ce2d-3d96-25623cbdeec1@linux.alibaba.com \
--to=chengyou@linux.alibaba.com \
--cc=jgg@ziepe.ca \
--cc=kaishen@linux.alibaba.com \
--cc=leon@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rdma@vger.kernel.org \
--cc=weiyongjun1@huawei.com \
--cc=yang.lee@linux.alibaba.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
all inboxes | Powered by JetHome®