Skip to content

Commit 9a84848

Browse files
wenglianfarleon
authored andcommitted
RDMA/hns: Add mutex_destroy()
Add mutex_destroy(). Signed-off-by: wenglianfa <wenglianfa@huawei.com> Signed-off-by: Junxian Huang <huangjunxian6@hisilicon.com> Link: https://lore.kernel.org/r/20240412091616.370789-9-huangjunxian6@hisilicon.com Signed-off-by: Leon Romanovsky <leon@kernel.org>
1 parent ee04549 commit 9a84848

6 files changed

Lines changed: 39 additions & 5 deletions

File tree

drivers/infiniband/hw/hns/hns_roce_cq.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,4 +536,5 @@ void hns_roce_cleanup_cq_table(struct hns_roce_dev *hr_dev)
536536

537537
for (i = 0; i < HNS_ROCE_CQ_BANK_NUM; i++)
538538
ida_destroy(&hr_dev->cq_table.bank[i].ida);
539+
mutex_destroy(&hr_dev->cq_table.bank_mutex);
539540
}

drivers/infiniband/hw/hns/hns_roce_hem.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -877,6 +877,7 @@ void hns_roce_cleanup_hem_table(struct hns_roce_dev *hr_dev,
877877

878878
if (hns_roce_check_whether_mhop(hr_dev, table->type)) {
879879
hns_roce_cleanup_mhop_hem_table(hr_dev, table);
880+
mutex_destroy(&table->mutex);
880881
return;
881882
}
882883

@@ -891,6 +892,7 @@ void hns_roce_cleanup_hem_table(struct hns_roce_dev *hr_dev,
891892
hns_roce_free_hem(hr_dev, table->hem[i]);
892893
}
893894

895+
mutex_destroy(&table->mutex);
894896
kfree(table->hem);
895897
}
896898

drivers/infiniband/hw/hns/hns_roce_hw_v2.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2667,6 +2667,8 @@ static void free_mr_exit(struct hns_roce_dev *hr_dev)
26672667
kfree(free_mr->rsv_pd);
26682668
free_mr->rsv_pd = NULL;
26692669
}
2670+
2671+
mutex_destroy(&free_mr->mutex);
26702672
}
26712673

26722674
static int free_mr_alloc_res(struct hns_roce_dev *hr_dev)
@@ -2817,8 +2819,10 @@ static int free_mr_init(struct hns_roce_dev *hr_dev)
28172819
mutex_init(&free_mr->mutex);
28182820

28192821
ret = free_mr_alloc_res(hr_dev);
2820-
if (ret)
2822+
if (ret) {
2823+
mutex_destroy(&free_mr->mutex);
28212824
return ret;
2825+
}
28222826

28232827
ret = free_mr_modify_qp(hr_dev);
28242828
if (ret)

drivers/infiniband/hw/hns/hns_roce_main.c

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,9 @@ static int hns_roce_alloc_ucontext(struct ib_ucontext *uctx,
429429
return 0;
430430

431431
error_fail_copy_to_udata:
432+
if (hr_dev->caps.flags & HNS_ROCE_CAP_FLAG_CQ_RECORD_DB ||
433+
hr_dev->caps.flags & HNS_ROCE_CAP_FLAG_QP_RECORD_DB)
434+
mutex_destroy(&context->page_mutex);
432435
hns_roce_dealloc_uar_entry(context);
433436

434437
error_fail_uar_entry:
@@ -445,6 +448,10 @@ static void hns_roce_dealloc_ucontext(struct ib_ucontext *ibcontext)
445448
struct hns_roce_ucontext *context = to_hr_ucontext(ibcontext);
446449
struct hns_roce_dev *hr_dev = to_hr_dev(ibcontext->device);
447450

451+
if (hr_dev->caps.flags & HNS_ROCE_CAP_FLAG_CQ_RECORD_DB ||
452+
hr_dev->caps.flags & HNS_ROCE_CAP_FLAG_QP_RECORD_DB)
453+
mutex_destroy(&context->page_mutex);
454+
448455
hns_roce_dealloc_uar_entry(context);
449456

450457
ida_free(&hr_dev->uar_ida.ida, (int)context->uar.logic_idx);
@@ -933,6 +940,15 @@ static int hns_roce_init_hem(struct hns_roce_dev *hr_dev)
933940
return ret;
934941
}
935942

943+
static void hns_roce_teardown_hca(struct hns_roce_dev *hr_dev)
944+
{
945+
hns_roce_cleanup_bitmap(hr_dev);
946+
947+
if (hr_dev->caps.flags & HNS_ROCE_CAP_FLAG_CQ_RECORD_DB ||
948+
hr_dev->caps.flags & HNS_ROCE_CAP_FLAG_QP_RECORD_DB)
949+
mutex_destroy(&hr_dev->pgdir_mutex);
950+
}
951+
936952
/**
937953
* hns_roce_setup_hca - setup host channel adapter
938954
* @hr_dev: pointer to hns roce device
@@ -981,6 +997,10 @@ static int hns_roce_setup_hca(struct hns_roce_dev *hr_dev)
981997

982998
err_uar_table_free:
983999
ida_destroy(&hr_dev->uar_ida.ida);
1000+
if (hr_dev->caps.flags & HNS_ROCE_CAP_FLAG_CQ_RECORD_DB ||
1001+
hr_dev->caps.flags & HNS_ROCE_CAP_FLAG_QP_RECORD_DB)
1002+
mutex_destroy(&hr_dev->pgdir_mutex);
1003+
9841004
return ret;
9851005
}
9861006

@@ -1126,7 +1146,7 @@ int hns_roce_init(struct hns_roce_dev *hr_dev)
11261146
hr_dev->hw->hw_exit(hr_dev);
11271147

11281148
error_failed_engine_init:
1129-
hns_roce_cleanup_bitmap(hr_dev);
1149+
hns_roce_teardown_hca(hr_dev);
11301150

11311151
error_failed_setup_hca:
11321152
hns_roce_cleanup_hem(hr_dev);
@@ -1156,7 +1176,7 @@ void hns_roce_exit(struct hns_roce_dev *hr_dev)
11561176

11571177
if (hr_dev->hw->hw_exit)
11581178
hr_dev->hw->hw_exit(hr_dev);
1159-
hns_roce_cleanup_bitmap(hr_dev);
1179+
hns_roce_teardown_hca(hr_dev);
11601180
hns_roce_cleanup_hem(hr_dev);
11611181

11621182
if (hr_dev->cmd_mod)

drivers/infiniband/hw/hns/hns_roce_qp.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1140,15 +1140,15 @@ static int hns_roce_create_qp_common(struct hns_roce_dev *hr_dev,
11401140
ret = set_qp_param(hr_dev, hr_qp, init_attr, udata, &ucmd);
11411141
if (ret) {
11421142
ibdev_err(ibdev, "failed to set QP param, ret = %d.\n", ret);
1143-
return ret;
1143+
goto err_out;
11441144
}
11451145

11461146
if (!udata) {
11471147
ret = alloc_kernel_wrid(hr_dev, hr_qp);
11481148
if (ret) {
11491149
ibdev_err(ibdev, "failed to alloc wrid, ret = %d.\n",
11501150
ret);
1151-
return ret;
1151+
goto err_out;
11521152
}
11531153
}
11541154

@@ -1219,6 +1219,8 @@ static int hns_roce_create_qp_common(struct hns_roce_dev *hr_dev,
12191219
free_qp_buf(hr_dev, hr_qp);
12201220
err_buf:
12211221
free_kernel_wrid(hr_qp);
1222+
err_out:
1223+
mutex_destroy(&hr_qp->mutex);
12221224
return ret;
12231225
}
12241226

@@ -1234,6 +1236,7 @@ void hns_roce_qp_destroy(struct hns_roce_dev *hr_dev, struct hns_roce_qp *hr_qp,
12341236
free_qp_buf(hr_dev, hr_qp);
12351237
free_kernel_wrid(hr_qp);
12361238
free_qp_db(hr_dev, hr_qp, udata);
1239+
mutex_destroy(&hr_qp->mutex);
12371240
}
12381241

12391242
static int check_qp_type(struct hns_roce_dev *hr_dev, enum ib_qp_type type,
@@ -1573,5 +1576,7 @@ void hns_roce_cleanup_qp_table(struct hns_roce_dev *hr_dev)
15731576

15741577
for (i = 0; i < HNS_ROCE_QP_BANK_NUM; i++)
15751578
ida_destroy(&hr_dev->qp_table.bank[i].ida);
1579+
mutex_destroy(&hr_dev->qp_table.bank_mutex);
1580+
mutex_destroy(&hr_dev->qp_table.scc_mutex);
15761581
kfree(hr_dev->qp_table.idx_table.spare_idx);
15771582
}

drivers/infiniband/hw/hns/hns_roce_srq.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,7 @@ int hns_roce_create_srq(struct ib_srq *ib_srq,
518518
err_srq_buf:
519519
free_srq_buf(hr_dev, srq);
520520
err_out:
521+
mutex_destroy(&srq->mutex);
521522
atomic64_inc(&hr_dev->dfx_cnt[HNS_ROCE_DFX_SRQ_CREATE_ERR_CNT]);
522523

523524
return ret;
@@ -532,6 +533,7 @@ int hns_roce_destroy_srq(struct ib_srq *ibsrq, struct ib_udata *udata)
532533
free_srqn(hr_dev, srq);
533534
free_srq_db(hr_dev, srq, udata);
534535
free_srq_buf(hr_dev, srq);
536+
mutex_destroy(&srq->mutex);
535537
return 0;
536538
}
537539

0 commit comments

Comments
 (0)