Skip to content

Commit ccb6c25

Browse files
Junxian Huangnmorey
authored andcommitted
libhns: Fix pad refcnt leaking in error flow of create qp/cq/srq
[ Upstream commit f877d6e ] Decrease pad refcnt by 1 in error flow of create qp/cq/srq. Fixes: 8c865c3 ("libhns: Add support for lock-free CQ") Fixes: 179f015 ("libhns: Add support for lock-free QP") Fixes: b38bae4 ("libhns: Add support for lock-free SRQ") Signed-off-by: Junxian Huang <[email protected]> Signed-off-by: Nicolas Morey <[email protected]>
1 parent a4db9be commit ccb6c25

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

providers/hns/hns_roce_u_verbs.c

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -429,12 +429,9 @@ static int verify_cq_create_attr(struct ibv_cq_init_attr_ex *attr,
429429
if (!check_comp_mask(attr->wc_flags, CREATE_CQ_SUPPORTED_WC_FLAGS))
430430
return EOPNOTSUPP;
431431

432-
if (attr->comp_mask & IBV_CQ_INIT_ATTR_MASK_PD) {
433-
if (!pad) {
434-
verbs_err(&context->ibv_ctx, "failed to check the pad of cq.\n");
435-
return EINVAL;
436-
}
437-
atomic_fetch_add(&pad->pd.refcount, 1);
432+
if (attr->comp_mask & IBV_CQ_INIT_ATTR_MASK_PD && !pad) {
433+
verbs_err(&context->ibv_ctx, "failed to check the pad of cq.\n");
434+
return EINVAL;
438435
}
439436

440437
attr->cqe = max_t(uint32_t, HNS_ROCE_MIN_CQE_NUM,
@@ -501,6 +498,7 @@ static int exec_cq_create_cmd(struct ibv_context *context,
501498
static struct ibv_cq_ex *create_cq(struct ibv_context *context,
502499
struct ibv_cq_init_attr_ex *attr)
503500
{
501+
struct hns_roce_pad *pad = to_hr_pad(attr->parent_domain);
504502
struct hns_roce_context *hr_ctx = to_hr_ctx(context);
505503
struct hns_roce_cq *cq;
506504
int ret;
@@ -515,8 +513,10 @@ static struct ibv_cq_ex *create_cq(struct ibv_context *context,
515513
goto err;
516514
}
517515

518-
if (attr->comp_mask & IBV_CQ_INIT_ATTR_MASK_PD)
516+
if (attr->comp_mask & IBV_CQ_INIT_ATTR_MASK_PD) {
519517
cq->parent_domain = attr->parent_domain;
518+
atomic_fetch_add(&pad->pd.refcount, 1);
519+
}
520520

521521
ret = hns_roce_cq_spinlock_init(cq, attr);
522522
if (ret)
@@ -550,6 +550,8 @@ static struct ibv_cq_ex *create_cq(struct ibv_context *context,
550550
err_buf:
551551
hns_roce_spinlock_destroy(&cq->hr_lock);
552552
err_lock:
553+
if (attr->comp_mask & IBV_CQ_INIT_ATTR_MASK_PD)
554+
atomic_fetch_sub(&pad->pd.refcount, 1);
553555
free(cq);
554556
err:
555557
if (ret < 0)
@@ -871,6 +873,8 @@ static struct ibv_srq *create_srq(struct ibv_context *context,
871873
hns_roce_spinlock_destroy(&srq->hr_lock);
872874

873875
err_free_srq:
876+
if (pad)
877+
atomic_fetch_sub(&pad->pd.refcount, 1);
874878
free(srq);
875879

876880
err:
@@ -1593,6 +1597,8 @@ static struct ibv_qp *create_qp(struct ibv_context *ibv_ctx,
15931597
err_buf:
15941598
hns_roce_qp_spinlock_destroy(qp);
15951599
err_spinlock:
1600+
if (pad)
1601+
atomic_fetch_sub(&pad->pd.refcount, 1);
15961602
free(qp);
15971603
err:
15981604
if (ret < 0)

0 commit comments

Comments
 (0)