Skip to content

Commit 926fda6

Browse files
Junxian Huangnmorey
authored andcommitted
libhns: Fix freeing pad without checking refcnt
[ Upstream commit 234d135 ] Currently pad refcnt will be added when creating qp/cq/srq, but it is not checked when freeing pad. Add a check to prevent freeing pad when it is still used by any qp/cq/srq. Fixes: ae35032 ("libhns: Add support for thread domain and parent domain") Signed-off-by: Junxian Huang <[email protected]> Signed-off-by: Nicolas Morey <[email protected]>
1 parent ccb6c25 commit 926fda6

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

providers/hns/hns_roce_u_verbs.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -208,14 +208,18 @@ struct ibv_pd *hns_roce_u_alloc_pad(struct ibv_context *context,
208208
return &pad->pd.ibv_pd;
209209
}
210210

211-
static void hns_roce_free_pad(struct hns_roce_pad *pad)
211+
static int hns_roce_free_pad(struct hns_roce_pad *pad)
212212
{
213+
if (atomic_load(&pad->pd.refcount) > 1)
214+
return EBUSY;
215+
213216
atomic_fetch_sub(&pad->pd.protection_domain->refcount, 1);
214217

215218
if (pad->td)
216219
atomic_fetch_sub(&pad->td->refcount, 1);
217220

218221
free(pad);
222+
return 0;
219223
}
220224

221225
static int hns_roce_free_pd(struct hns_roce_pd *pd)
@@ -238,10 +242,8 @@ int hns_roce_u_dealloc_pd(struct ibv_pd *ibv_pd)
238242
struct hns_roce_pad *pad = to_hr_pad(ibv_pd);
239243
struct hns_roce_pd *pd = to_hr_pd(ibv_pd);
240244

241-
if (pad) {
242-
hns_roce_free_pad(pad);
243-
return 0;
244-
}
245+
if (pad)
246+
return hns_roce_free_pad(pad);
245247

246248
return hns_roce_free_pd(pd);
247249
}

0 commit comments

Comments
 (0)