]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
RDMA/core: Create and destroy counters in the ib_core
authorLeon Romanovsky <leonro@mellanox.com>
Tue, 30 Jun 2020 10:18:52 +0000 (13:18 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 17 Jul 2025 16:24:59 +0000 (18:24 +0200)
[ Upstream commit 3b023e1b680a56e84c22d43486875a5aa4c78afe ]

Move allocation and destruction of counters under ib_core responsibility

Link: https://lore.kernel.org/r/20200630101855.368895-2-leon@kernel.org
Signed-off-by: Leon Romanovsky <leonro@mellanox.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
Stable-dep-of: acd245b1e33f ("RDMA/mlx5: Fix CC counters query for MPV")
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/infiniband/core/device.c
drivers/infiniband/core/uverbs_std_types_counters.c
drivers/infiniband/hw/mlx5/main.c
include/rdma/ib_verbs.h

index c46d68e6ccd0e6d75342c831891fa29ee1314092..cf3c0d6928ac2e211385063c56ef9d0dee6134e7 100644 (file)
@@ -2683,6 +2683,7 @@ void ib_set_device_ops(struct ib_device *dev, const struct ib_device_ops *ops)
        SET_DEVICE_OP(dev_ops, unmap_fmr);
 
        SET_OBJ_SIZE(dev_ops, ib_ah);
+       SET_OBJ_SIZE(dev_ops, ib_counters);
        SET_OBJ_SIZE(dev_ops, ib_cq);
        SET_OBJ_SIZE(dev_ops, ib_pd);
        SET_OBJ_SIZE(dev_ops, ib_srq);
index 35e41c5ca1bb119e68659f2d7cf851cab1703e3a..95b66ce4943b43dfb5b9717c1cdd1d0d21f509d4 100644 (file)
@@ -46,7 +46,9 @@ static int uverbs_free_counters(struct ib_uobject *uobject,
        if (ret)
                return ret;
 
-       return counters->device->ops.destroy_counters(counters);
+       counters->device->ops.destroy_counters(counters);
+       kfree(counters);
+       return 0;
 }
 
 static int UVERBS_HANDLER(UVERBS_METHOD_COUNTERS_CREATE)(
@@ -66,20 +68,19 @@ static int UVERBS_HANDLER(UVERBS_METHOD_COUNTERS_CREATE)(
        if (!ib_dev->ops.create_counters)
                return -EOPNOTSUPP;
 
-       counters = ib_dev->ops.create_counters(ib_dev, attrs);
-       if (IS_ERR(counters)) {
-               ret = PTR_ERR(counters);
-               goto err_create_counters;
-       }
+       counters = rdma_zalloc_drv_obj(ib_dev, ib_counters);
+       if (!counters)
+               return -ENOMEM;
 
        counters->device = ib_dev;
        counters->uobject = uobj;
        uobj->object = counters;
        atomic_set(&counters->usecnt, 0);
 
-       return 0;
+       ret = ib_dev->ops.create_counters(counters, attrs);
+       if (ret)
+               kfree(counters);
 
-err_create_counters:
        return ret;
 }
 
index fb5a1b4abcbceacffe500071fdecaabe11b49a45..d30c37688bdac2b5a9fcd3b92f71d1955a3ca399 100644 (file)
@@ -6113,7 +6113,7 @@ err_bound:
        return ret;
 }
 
-static int mlx5_ib_destroy_counters(struct ib_counters *counters)
+static void mlx5_ib_destroy_counters(struct ib_counters *counters)
 {
        struct mlx5_ib_mcounters *mcounters = to_mcounters(counters);
 
@@ -6121,24 +6121,15 @@ static int mlx5_ib_destroy_counters(struct ib_counters *counters)
        if (mcounters->hw_cntrs_hndl)
                mlx5_fc_destroy(to_mdev(counters->device)->mdev,
                                mcounters->hw_cntrs_hndl);
-
-       kfree(mcounters);
-
-       return 0;
 }
 
-static struct ib_counters *mlx5_ib_create_counters(struct ib_device *device,
-                                                  struct uverbs_attr_bundle *attrs)
+static int mlx5_ib_create_counters(struct ib_counters *counters,
+                                  struct uverbs_attr_bundle *attrs)
 {
-       struct mlx5_ib_mcounters *mcounters;
-
-       mcounters = kzalloc(sizeof(*mcounters), GFP_KERNEL);
-       if (!mcounters)
-               return ERR_PTR(-ENOMEM);
+       struct mlx5_ib_mcounters *mcounters = to_mcounters(counters);
 
        mutex_init(&mcounters->mcntrs_mutex);
-
-       return &mcounters->ibcntrs;
+       return 0;
 }
 
 static void mlx5_ib_stage_init_cleanup(struct mlx5_ib_dev *dev)
@@ -6296,6 +6287,7 @@ static const struct ib_device_ops mlx5_ib_dev_ops = {
        .resize_cq = mlx5_ib_resize_cq,
 
        INIT_RDMA_OBJ_SIZE(ib_ah, mlx5_ib_ah, ibah),
+       INIT_RDMA_OBJ_SIZE(ib_counters, mlx5_ib_mcounters, ibcntrs),
        INIT_RDMA_OBJ_SIZE(ib_cq, mlx5_ib_cq, ibcq),
        INIT_RDMA_OBJ_SIZE(ib_pd, mlx5_ib_pd, ibpd),
        INIT_RDMA_OBJ_SIZE(ib_srq, mlx5_ib_srq, ibsrq),
index 30d50528d710ebf8243de9e2e18a7d1b0a2e7b6d..7e5df8218689e18a1a8ff119260f08eb086af482 100644 (file)
@@ -2468,9 +2468,9 @@ struct ib_device_ops {
        struct ib_mr *(*reg_dm_mr)(struct ib_pd *pd, struct ib_dm *dm,
                                   struct ib_dm_mr_attr *attr,
                                   struct uverbs_attr_bundle *attrs);
-       struct ib_counters *(*create_counters)(
-               struct ib_device *device, struct uverbs_attr_bundle *attrs);
-       int (*destroy_counters)(struct ib_counters *counters);
+       int (*create_counters)(struct ib_counters *counters,
+                              struct uverbs_attr_bundle *attrs);
+       void (*destroy_counters)(struct ib_counters *counters);
        int (*read_counters)(struct ib_counters *counters,
                             struct ib_counters_read_attr *counters_read_attr,
                             struct uverbs_attr_bundle *attrs);
@@ -2563,6 +2563,7 @@ struct ib_device_ops {
        int (*counter_update_stats)(struct rdma_counter *counter);
 
        DECLARE_RDMA_OBJ_SIZE(ib_ah);
+       DECLARE_RDMA_OBJ_SIZE(ib_counters);
        DECLARE_RDMA_OBJ_SIZE(ib_cq);
        DECLARE_RDMA_OBJ_SIZE(ib_pd);
        DECLARE_RDMA_OBJ_SIZE(ib_srq);