Skip to content

Commit

Permalink
efa: Change resource deallocation order in QP and CQ
Browse files Browse the repository at this point in the history
[ Upstream commit 884716f ]

When trying to destroy QP or CQ, we first release rdma-core resources
for the relevant object (mapping for address ranges, refcounts, locks
etc.) and only then request the driver to destroy the object. If the
driver or the device fails, the object isn't fully destroyed so the user
can try to destroy the object again which will lead to trying to release
already released rdma-core resources for the object.
Change deallocation order to first call kernel and driver code and if
succeeded release rdma-core resources.

Signed-off-by: Yonatan Nachum <ynachum@amazon.com>
Signed-off-by: Nicolas Morey <nmorey@suse.com>
  • Loading branch information
YonatanNachum authored and nmorey committed Jan 9, 2025
1 parent fcd821a commit e157913
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions providers/efa/verbs.c
Original file line number Diff line number Diff line change
Expand Up @@ -959,18 +959,18 @@ int efa_destroy_cq(struct ibv_cq *ibvcq)
struct efa_cq *cq = to_efa_cq(ibvcq);
int err;

munmap(cq->db, to_efa_dev(cq->verbs_cq.cq.context->device)->pg_sz);
munmap(cq->buf, cq->buf_size);

pthread_spin_destroy(&cq->lock);

err = ibv_cmd_destroy_cq(ibvcq);
if (err) {
verbs_err(verbs_get_ctx(ibvcq->context),
"Failed to destroy CQ[%u]\n", cq->cqn);
return err;
}

munmap(cq->db, to_efa_dev(cq->verbs_cq.cq.context->device)->pg_sz);
munmap(cq->buf, cq->buf_size);

pthread_spin_destroy(&cq->lock);

free(cq);

return 0;
Expand Down Expand Up @@ -1585,6 +1585,13 @@ int efa_destroy_qp(struct ibv_qp *ibvqp)
struct efa_qp *qp = to_efa_qp(ibvqp);
int err;

err = ibv_cmd_destroy_qp(ibvqp);
if (err) {
verbs_err(&ctx->ibvctx, "Failed to destroy QP[%u]\n",
ibvqp->qp_num);
return err;
}

pthread_spin_lock(&ctx->qp_table_lock);
efa_lock_cqs(ibvqp);

Expand All @@ -1599,13 +1606,6 @@ int efa_destroy_qp(struct ibv_qp *ibvqp)
efa_sq_terminate(qp);
efa_rq_terminate(qp);

err = ibv_cmd_destroy_qp(ibvqp);
if (err) {
verbs_err(&ctx->ibvctx, "Failed to destroy QP[%u]\n",
ibvqp->qp_num);
return err;
}

free(qp);
return 0;
}
Expand Down

0 comments on commit e157913

Please sign in to comment.