Skip to content

Commit 3e358ea

Browse files
mark-blochrleon
authored andcommitted
RDMA/mlx5: Fix flow counter query via DEVX
Commit cited in "fixes" tag added bulk support for flow counters but it didn't account that's also possible to query a counter using a non-base id if the counter was allocated as bulk. When a user performs a query, validate the flow counter id given in the mailbox is inside the valid range taking bulk value into account. Fixes: 208d70f ("IB/mlx5: Support flow counters offset for bulk counters") Signed-off-by: Mark Bloch <mbloch@nvidia.com> Reviewed-by: Maor Gottlieb <maorg@nvidia.com> Link: https://lore.kernel.org/r/79d7fbe291690128e44672418934256254d93115.1681377114.git.leon@kernel.org Signed-off-by: Leon Romanovsky <leon@kernel.org>
1 parent f605f26 commit 3e358ea

2 files changed

Lines changed: 28 additions & 6 deletions

File tree

drivers/infiniband/hw/mlx5/devx.c

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,21 @@ static bool devx_is_valid_obj_id(struct uverbs_attr_bundle *attrs,
666666
obj_id;
667667

668668
case MLX5_IB_OBJECT_DEVX_OBJ:
669-
return ((struct devx_obj *)uobj->object)->obj_id == obj_id;
669+
{
670+
u16 opcode = MLX5_GET(general_obj_in_cmd_hdr, in, opcode);
671+
struct devx_obj *devx_uobj = uobj->object;
672+
673+
if (opcode == MLX5_CMD_OP_QUERY_FLOW_COUNTER &&
674+
devx_uobj->flow_counter_bulk_size) {
675+
u64 end;
676+
677+
end = devx_uobj->obj_id +
678+
devx_uobj->flow_counter_bulk_size;
679+
return devx_uobj->obj_id <= obj_id && end > obj_id;
680+
}
681+
682+
return devx_uobj->obj_id == obj_id;
683+
}
670684

671685
default:
672686
return false;
@@ -1517,10 +1531,17 @@ static int UVERBS_HANDLER(MLX5_IB_METHOD_DEVX_OBJ_CREATE)(
15171531
goto obj_free;
15181532

15191533
if (opcode == MLX5_CMD_OP_ALLOC_FLOW_COUNTER) {
1520-
u8 bulk = MLX5_GET(alloc_flow_counter_in,
1521-
cmd_in,
1522-
flow_counter_bulk);
1523-
obj->flow_counter_bulk_size = 128UL * bulk;
1534+
u32 bulk = MLX5_GET(alloc_flow_counter_in,
1535+
cmd_in,
1536+
flow_counter_bulk_log_size);
1537+
1538+
if (bulk)
1539+
bulk = 1 << bulk;
1540+
else
1541+
bulk = 128UL * MLX5_GET(alloc_flow_counter_in,
1542+
cmd_in,
1543+
flow_counter_bulk);
1544+
obj->flow_counter_bulk_size = bulk;
15241545
}
15251546

15261547
uobj->object = obj;

include/linux/mlx5/mlx5_ifc.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9283,7 +9283,8 @@ struct mlx5_ifc_alloc_flow_counter_in_bits {
92839283
u8 reserved_at_20[0x10];
92849284
u8 op_mod[0x10];
92859285

9286-
u8 reserved_at_40[0x38];
9286+
u8 reserved_at_40[0x33];
9287+
u8 flow_counter_bulk_log_size[0x5];
92879288
u8 flow_counter_bulk[0x8];
92889289
};
92899290

0 commit comments

Comments
 (0)