Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

RDMA/core: Create and destroy rdma_counter using rdma_zalloc_drv_obj()

Change rdma_counter allocation to use rdma_zalloc_drv_obj() instead of,
explicitly allocating at core, in order to be contained inside driver
specific structures.

Adjust all drivers that use it to have their containing structure, and
add driver specific initialization operation.

This change is needed to allow upcoming patches to implement
optional-counters binding whereas inside each driver specific counter
struct his bound optional-counters will be maintained.

Signed-off-by: Patrisious Haddad <phaddad@nvidia.com>
Reviewed-by: Mark Bloch <mbloch@nvidia.com>
Link: https://patch.msgid.link/a5a484f421fc2e5595158e61a354fba43272b02d.1741875070.git.leon@kernel.org
Signed-off-by: Leon Romanovsky <leon@kernel.org>

authored by

Patrisious Haddad and committed by
Leon Romanovsky
7e53b31a d375db42

+30 -1
+3 -1
drivers/infiniband/core/counters.c
··· 149 149 if (!dev->ops.counter_dealloc || !dev->ops.counter_alloc_stats) 150 150 return NULL; 151 151 152 - counter = kzalloc(sizeof(*counter), GFP_KERNEL); 152 + counter = rdma_zalloc_drv_obj(dev, rdma_counter); 153 153 if (!counter) 154 154 return NULL; 155 155 156 156 counter->device = dev; 157 157 counter->port = port; 158 + 159 + dev->ops.counter_init(counter); 158 160 159 161 rdma_restrack_new(&counter->res, RDMA_RESTRACK_COUNTER); 160 162 counter->stats = dev->ops.counter_alloc_stats(counter);
+2
drivers/infiniband/core/device.c
··· 2683 2683 SET_DEVICE_OP(dev_ops, counter_alloc_stats); 2684 2684 SET_DEVICE_OP(dev_ops, counter_bind_qp); 2685 2685 SET_DEVICE_OP(dev_ops, counter_dealloc); 2686 + SET_DEVICE_OP(dev_ops, counter_init); 2686 2687 SET_DEVICE_OP(dev_ops, counter_unbind_qp); 2687 2688 SET_DEVICE_OP(dev_ops, counter_update_stats); 2688 2689 SET_DEVICE_OP(dev_ops, create_ah); ··· 2798 2797 SET_OBJ_SIZE(dev_ops, ib_srq); 2799 2798 SET_OBJ_SIZE(dev_ops, ib_ucontext); 2800 2799 SET_OBJ_SIZE(dev_ops, ib_xrcd); 2800 + SET_OBJ_SIZE(dev_ops, rdma_counter); 2801 2801 } 2802 2802 EXPORT_SYMBOL(ib_set_device_ops); 2803 2803
+8
drivers/infiniband/hw/mlx5/counters.c
··· 1105 1105 return 0; 1106 1106 } 1107 1107 1108 + static void mlx5_ib_counter_init(struct rdma_counter *counter) {} 1109 + 1108 1110 static const struct ib_device_ops hw_stats_ops = { 1109 1111 .alloc_hw_port_stats = mlx5_ib_alloc_hw_port_stats, 1110 1112 .get_hw_stats = mlx5_ib_get_hw_stats, ··· 1117 1115 .counter_update_stats = mlx5_ib_counter_update_stats, 1118 1116 .modify_hw_stat = IS_ENABLED(CONFIG_INFINIBAND_USER_ACCESS) ? 1119 1117 mlx5_ib_modify_stat : NULL, 1118 + .counter_init = mlx5_ib_counter_init, 1119 + 1120 + INIT_RDMA_OBJ_SIZE(rdma_counter, mlx5_rdma_counter, rdma_counter), 1120 1121 }; 1121 1122 1122 1123 static const struct ib_device_ops hw_switchdev_vport_op = { ··· 1134 1129 .counter_dealloc = mlx5_ib_counter_dealloc, 1135 1130 .counter_alloc_stats = mlx5_ib_counter_alloc_stats, 1136 1131 .counter_update_stats = mlx5_ib_counter_update_stats, 1132 + .counter_init = mlx5_ib_counter_init, 1133 + 1134 + INIT_RDMA_OBJ_SIZE(rdma_counter, mlx5_rdma_counter, rdma_counter), 1137 1135 }; 1138 1136 1139 1137 static const struct ib_device_ops counters_ops = {
+11
drivers/infiniband/hw/mlx5/counters.h
··· 8 8 9 9 #include "mlx5_ib.h" 10 10 11 + 12 + struct mlx5_rdma_counter { 13 + struct rdma_counter rdma_counter; 14 + }; 15 + 16 + static inline struct mlx5_rdma_counter * 17 + to_mcounter(struct rdma_counter *counter) 18 + { 19 + return container_of(counter, struct mlx5_rdma_counter, rdma_counter); 20 + } 21 + 11 22 int mlx5_ib_counters_init(struct mlx5_ib_dev *dev); 12 23 void mlx5_ib_counters_cleanup(struct mlx5_ib_dev *dev); 13 24 void mlx5_ib_counters_clear_description(struct ib_counters *counters);
+6
include/rdma/ib_verbs.h
··· 2666 2666 int (*counter_update_stats)(struct rdma_counter *counter); 2667 2667 2668 2668 /** 2669 + * counter_init - Initialize the driver specific rdma counter struct. 2670 + */ 2671 + void (*counter_init)(struct rdma_counter *counter); 2672 + 2673 + /** 2669 2674 * Allows rdma drivers to add their own restrack attributes 2670 2675 * dumped via 'rdma stat' iproute2 command. 2671 2676 */ ··· 2721 2716 DECLARE_RDMA_OBJ_SIZE(ib_srq); 2722 2717 DECLARE_RDMA_OBJ_SIZE(ib_ucontext); 2723 2718 DECLARE_RDMA_OBJ_SIZE(ib_xrcd); 2719 + DECLARE_RDMA_OBJ_SIZE(rdma_counter); 2724 2720 }; 2725 2721 2726 2722 struct ib_core_device {