RDMA/hns: Add mutex_destroy()
authorwenglianfa <wenglianfa@huawei.com>
Fri, 12 Apr 2024 09:16:14 +0000 (17:16 +0800)
committerLeon Romanovsky <leon@kernel.org>
Tue, 16 Apr 2024 12:06:47 +0000 (15:06 +0300)
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>
drivers/infiniband/hw/hns/hns_roce_cq.c
drivers/infiniband/hw/hns/hns_roce_hem.c
drivers/infiniband/hw/hns/hns_roce_hw_v2.c
drivers/infiniband/hw/hns/hns_roce_main.c
drivers/infiniband/hw/hns/hns_roce_qp.c
drivers/infiniband/hw/hns/hns_roce_srq.c

index 68e22f368d43a3968069db5a5289b029690cbb41..56dc3908da2f4ce80952841a0e70b43108664073 100644 (file)
@@ -536,4 +536,5 @@ void hns_roce_cleanup_cq_table(struct hns_roce_dev *hr_dev)
 
        for (i = 0; i < HNS_ROCE_CQ_BANK_NUM; i++)
                ida_destroy(&hr_dev->cq_table.bank[i].ida);
+       mutex_destroy(&hr_dev->cq_table.bank_mutex);
 }
index 1c2ec803e030338fd5b69a966edb821cd83d2f80..02baa853a76c9bc270adfb14b68184bacad5cad7 100644 (file)
@@ -877,6 +877,7 @@ void hns_roce_cleanup_hem_table(struct hns_roce_dev *hr_dev,
 
        if (hns_roce_check_whether_mhop(hr_dev, table->type)) {
                hns_roce_cleanup_mhop_hem_table(hr_dev, table);
+               mutex_destroy(&table->mutex);
                return;
        }
 
@@ -891,6 +892,7 @@ void hns_roce_cleanup_hem_table(struct hns_roce_dev *hr_dev,
                        hns_roce_free_hem(hr_dev, table->hem[i]);
                }
 
+       mutex_destroy(&table->mutex);
        kfree(table->hem);
 }
 
index 89d0f5b8be758cf2cc147663468a5530bf0bb7a8..5d526b5c4b818b4733ca62f84c70456a76e95778 100644 (file)
@@ -2667,6 +2667,8 @@ static void free_mr_exit(struct hns_roce_dev *hr_dev)
                kfree(free_mr->rsv_pd);
                free_mr->rsv_pd = NULL;
        }
+
+       mutex_destroy(&free_mr->mutex);
 }
 
 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)
        mutex_init(&free_mr->mutex);
 
        ret = free_mr_alloc_res(hr_dev);
-       if (ret)
+       if (ret) {
+               mutex_destroy(&free_mr->mutex);
                return ret;
+       }
 
        ret = free_mr_modify_qp(hr_dev);
        if (ret)
index d202258368ed99bb4d928bb8faa3f31f660e6c39..4cb0af73358708e016e5825100343f15995b1690 100644 (file)
@@ -429,6 +429,9 @@ static int hns_roce_alloc_ucontext(struct ib_ucontext *uctx,
        return 0;
 
 error_fail_copy_to_udata:
+       if (hr_dev->caps.flags & HNS_ROCE_CAP_FLAG_CQ_RECORD_DB ||
+           hr_dev->caps.flags & HNS_ROCE_CAP_FLAG_QP_RECORD_DB)
+               mutex_destroy(&context->page_mutex);
        hns_roce_dealloc_uar_entry(context);
 
 error_fail_uar_entry:
@@ -445,6 +448,10 @@ static void hns_roce_dealloc_ucontext(struct ib_ucontext *ibcontext)
        struct hns_roce_ucontext *context = to_hr_ucontext(ibcontext);
        struct hns_roce_dev *hr_dev = to_hr_dev(ibcontext->device);
 
+       if (hr_dev->caps.flags & HNS_ROCE_CAP_FLAG_CQ_RECORD_DB ||
+           hr_dev->caps.flags & HNS_ROCE_CAP_FLAG_QP_RECORD_DB)
+               mutex_destroy(&context->page_mutex);
+
        hns_roce_dealloc_uar_entry(context);
 
        ida_free(&hr_dev->uar_ida.ida, (int)context->uar.logic_idx);
@@ -933,6 +940,15 @@ err_unmap_dmpt:
        return ret;
 }
 
+static void hns_roce_teardown_hca(struct hns_roce_dev *hr_dev)
+{
+       hns_roce_cleanup_bitmap(hr_dev);
+
+       if (hr_dev->caps.flags & HNS_ROCE_CAP_FLAG_CQ_RECORD_DB ||
+           hr_dev->caps.flags & HNS_ROCE_CAP_FLAG_QP_RECORD_DB)
+               mutex_destroy(&hr_dev->pgdir_mutex);
+}
+
 /**
  * hns_roce_setup_hca - setup host channel adapter
  * @hr_dev: pointer to hns roce device
@@ -981,6 +997,10 @@ static int hns_roce_setup_hca(struct hns_roce_dev *hr_dev)
 
 err_uar_table_free:
        ida_destroy(&hr_dev->uar_ida.ida);
+       if (hr_dev->caps.flags & HNS_ROCE_CAP_FLAG_CQ_RECORD_DB ||
+           hr_dev->caps.flags & HNS_ROCE_CAP_FLAG_QP_RECORD_DB)
+               mutex_destroy(&hr_dev->pgdir_mutex);
+
        return ret;
 }
 
@@ -1126,7 +1146,7 @@ error_failed_register_device:
                hr_dev->hw->hw_exit(hr_dev);
 
 error_failed_engine_init:
-       hns_roce_cleanup_bitmap(hr_dev);
+       hns_roce_teardown_hca(hr_dev);
 
 error_failed_setup_hca:
        hns_roce_cleanup_hem(hr_dev);
@@ -1156,7 +1176,7 @@ void hns_roce_exit(struct hns_roce_dev *hr_dev)
 
        if (hr_dev->hw->hw_exit)
                hr_dev->hw->hw_exit(hr_dev);
-       hns_roce_cleanup_bitmap(hr_dev);
+       hns_roce_teardown_hca(hr_dev);
        hns_roce_cleanup_hem(hr_dev);
 
        if (hr_dev->cmd_mod)
index dc3cb26f434ec21ec5fd9dcd076c5d22349800e6..db34665d1dfbf4ce624d52479a61b48fd3db70cf 100644 (file)
@@ -1140,7 +1140,7 @@ static int hns_roce_create_qp_common(struct hns_roce_dev *hr_dev,
        ret = set_qp_param(hr_dev, hr_qp, init_attr, udata, &ucmd);
        if (ret) {
                ibdev_err(ibdev, "failed to set QP param, ret = %d.\n", ret);
-               return ret;
+               goto err_out;
        }
 
        if (!udata) {
@@ -1148,7 +1148,7 @@ static int hns_roce_create_qp_common(struct hns_roce_dev *hr_dev,
                if (ret) {
                        ibdev_err(ibdev, "failed to alloc wrid, ret = %d.\n",
                                  ret);
-                       return ret;
+                       goto err_out;
                }
        }
 
@@ -1219,6 +1219,8 @@ err_qpn:
        free_qp_buf(hr_dev, hr_qp);
 err_buf:
        free_kernel_wrid(hr_qp);
+err_out:
+       mutex_destroy(&hr_qp->mutex);
        return ret;
 }
 
@@ -1234,6 +1236,7 @@ void hns_roce_qp_destroy(struct hns_roce_dev *hr_dev, struct hns_roce_qp *hr_qp,
        free_qp_buf(hr_dev, hr_qp);
        free_kernel_wrid(hr_qp);
        free_qp_db(hr_dev, hr_qp, udata);
+       mutex_destroy(&hr_qp->mutex);
 }
 
 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)
 
        for (i = 0; i < HNS_ROCE_QP_BANK_NUM; i++)
                ida_destroy(&hr_dev->qp_table.bank[i].ida);
+       mutex_destroy(&hr_dev->qp_table.bank_mutex);
+       mutex_destroy(&hr_dev->qp_table.scc_mutex);
        kfree(hr_dev->qp_table.idx_table.spare_idx);
 }
index 7210e53a82f339cf24a40a8adbb00e6bc2feeb62..f1997abc97cac84503f0a3611a1c5bdc9cbffb7e 100644 (file)
@@ -518,6 +518,7 @@ err_srq_db:
 err_srq_buf:
        free_srq_buf(hr_dev, srq);
 err_out:
+       mutex_destroy(&srq->mutex);
        atomic64_inc(&hr_dev->dfx_cnt[HNS_ROCE_DFX_SRQ_CREATE_ERR_CNT]);
 
        return ret;
@@ -532,6 +533,7 @@ int hns_roce_destroy_srq(struct ib_srq *ibsrq, struct ib_udata *udata)
        free_srqn(hr_dev, srq);
        free_srq_db(hr_dev, srq, udata);
        free_srq_buf(hr_dev, srq);
+       mutex_destroy(&srq->mutex);
        return 0;
 }