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

IB/mlx5: Support flow counters offset for bulk counters

Add support for flow steering counters action with a non-base counter
ID (offset) for bulk counters.

When creating a flow counter object, save the bulk value. This value is
used when a flow action with a non-base counter ID is requested - to
validate that the required offset is in the range of the allocated bulk.

Link: https://lore.kernel.org/r/20191103140723.77411-1-leon@kernel.org
Signed-off-by: Yevgeny Kliteynik <kliteyn@mellanox.com>
Signed-off-by: Leon Romanovsky <leonro@mellanox.com>
Reviewed-by: Mark Bloch <markb@mellanox.com>
Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>

authored by

Yevgeny Kliteynik and committed by
Jason Gunthorpe
208d70f5 e26e7b88

+43 -4
+14 -1
drivers/infiniband/hw/mlx5/devx.c
··· 100 100 struct mlx5_ib_devx_mr devx_mr; 101 101 struct mlx5_core_dct core_dct; 102 102 struct mlx5_core_cq core_cq; 103 + u32 flow_counter_bulk_size; 103 104 }; 104 105 struct list_head event_sub; /* holds devx_event_subscription entries */ 105 106 }; ··· 193 192 } 194 193 } 195 194 196 - bool mlx5_ib_devx_is_flow_counter(void *obj, u32 *counter_id) 195 + bool mlx5_ib_devx_is_flow_counter(void *obj, u32 offset, u32 *counter_id) 197 196 { 198 197 struct devx_obj *devx_obj = obj; 199 198 u16 opcode = MLX5_GET(general_obj_in_cmd_hdr, devx_obj->dinbox, opcode); 200 199 201 200 if (opcode == MLX5_CMD_OP_DEALLOC_FLOW_COUNTER) { 201 + 202 + if (offset && offset >= devx_obj->flow_counter_bulk_size) 203 + return false; 204 + 202 205 *counter_id = MLX5_GET(dealloc_flow_counter_in, 203 206 devx_obj->dinbox, 204 207 flow_counter_id); 208 + *counter_id += offset; 205 209 return true; 206 210 } 207 211 ··· 1468 1462 1469 1463 if (err) 1470 1464 goto obj_free; 1465 + 1466 + if (opcode == MLX5_CMD_OP_ALLOC_FLOW_COUNTER) { 1467 + u8 bulk = MLX5_GET(alloc_flow_counter_in, 1468 + cmd_in, 1469 + flow_counter_bulk); 1470 + obj->flow_counter_bulk_size = 128UL * bulk; 1471 + } 1471 1472 1472 1473 uobj->object = obj; 1473 1474 INIT_LIST_HEAD(&obj->event_sub);
+27 -2
drivers/infiniband/hw/mlx5/flow.c
··· 85 85 struct mlx5_ib_dev *dev = mlx5_udata_to_mdev(&attrs->driver_udata); 86 86 int len, ret, i; 87 87 u32 counter_id = 0; 88 + u32 *offset_attr; 89 + u32 offset = 0; 88 90 89 91 if (!capable(CAP_NET_RAW)) 90 92 return -EPERM; ··· 153 151 if (len) { 154 152 devx_obj = arr_flow_actions[0]->object; 155 153 156 - if (!mlx5_ib_devx_is_flow_counter(devx_obj, &counter_id)) 154 + if (uverbs_attr_is_valid(attrs, 155 + MLX5_IB_ATTR_CREATE_FLOW_ARR_COUNTERS_DEVX_OFFSET)) { 156 + 157 + int num_offsets = uverbs_attr_ptr_get_array_size( 158 + attrs, 159 + MLX5_IB_ATTR_CREATE_FLOW_ARR_COUNTERS_DEVX_OFFSET, 160 + sizeof(u32)); 161 + 162 + if (num_offsets != 1) 163 + return -EINVAL; 164 + 165 + offset_attr = uverbs_attr_get_alloced_ptr( 166 + attrs, 167 + MLX5_IB_ATTR_CREATE_FLOW_ARR_COUNTERS_DEVX_OFFSET); 168 + offset = *offset_attr; 169 + } 170 + 171 + if (!mlx5_ib_devx_is_flow_counter(devx_obj, offset, 172 + &counter_id)) 157 173 return -EINVAL; 174 + 158 175 flow_act.action |= MLX5_FLOW_CONTEXT_ACTION_COUNT; 159 176 } 160 177 ··· 619 598 UVERBS_ATTR_IDRS_ARR(MLX5_IB_ATTR_CREATE_FLOW_ARR_COUNTERS_DEVX, 620 599 MLX5_IB_OBJECT_DEVX_OBJ, 621 600 UVERBS_ACCESS_READ, 1, 1, 622 - UA_OPTIONAL)); 601 + UA_OPTIONAL), 602 + UVERBS_ATTR_PTR_IN(MLX5_IB_ATTR_CREATE_FLOW_ARR_COUNTERS_DEVX_OFFSET, 603 + UVERBS_ATTR_MIN_SIZE(sizeof(u32)), 604 + UA_OPTIONAL, 605 + UA_ALLOC_AND_COPY)); 623 606 624 607 DECLARE_UVERBS_NAMED_METHOD_DESTROY( 625 608 MLX5_IB_METHOD_DESTROY_FLOW,
+1 -1
drivers/infiniband/hw/mlx5/mlx5_ib.h
··· 1366 1366 struct mlx5_flow_act *flow_act, u32 counter_id, 1367 1367 void *cmd_in, int inlen, int dest_id, int dest_type); 1368 1368 bool mlx5_ib_devx_is_flow_dest(void *obj, int *dest_id, int *dest_type); 1369 - bool mlx5_ib_devx_is_flow_counter(void *obj, u32 *counter_id); 1369 + bool mlx5_ib_devx_is_flow_counter(void *obj, u32 offset, u32 *counter_id); 1370 1370 int mlx5_ib_get_flow_trees(const struct uverbs_object_tree_def **root); 1371 1371 void mlx5_ib_destroy_flow_action_raw(struct mlx5_ib_flow_action *maction); 1372 1372 #else
+1
include/uapi/rdma/mlx5_user_ioctl_cmds.h
··· 198 198 MLX5_IB_ATTR_CREATE_FLOW_ARR_FLOW_ACTIONS, 199 199 MLX5_IB_ATTR_CREATE_FLOW_TAG, 200 200 MLX5_IB_ATTR_CREATE_FLOW_ARR_COUNTERS_DEVX, 201 + MLX5_IB_ATTR_CREATE_FLOW_ARR_COUNTERS_DEVX_OFFSET, 201 202 }; 202 203 203 204 enum mlx5_ib_destoy_flow_attrs {