]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
net/mlx5: Initialize bulk for single flow counters
authorMoshe Shemesh <moshe@nvidia.com>
Mon, 12 Jan 2026 09:40:25 +0000 (11:40 +0200)
committerPaolo Abeni <pabeni@redhat.com>
Thu, 15 Jan 2026 11:10:27 +0000 (12:10 +0100)
Ensure that flow counters allocated with mlx5_fc_single_alloc() have
bulk correctly initialized so they can safely be used in HWS rules.

Signed-off-by: Moshe Shemesh <moshe@nvidia.com>
Reviewed-by: Mark Bloch <mbloch@nvidia.com>
Reviewed-by: Yevgeny Kliteynik <kliteyn@nvidia.com>
Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
Link: https://patch.msgid.link/1768210825-1598472-4-git-send-email-tariqt@nvidia.com
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
drivers/net/ethernet/mellanox/mlx5/core/fs_core.h
drivers/net/ethernet/mellanox/mlx5/core/fs_counters.c

index 1c65914252604d3fc91afa44b0a15568558487af..dbaf33b537f711ba9549b655b29e68ec46763a8d 100644 (file)
@@ -308,7 +308,8 @@ struct mlx5_flow_root_namespace {
 };
 
 enum mlx5_fc_type {
-       MLX5_FC_TYPE_ACQUIRED = 0,
+       MLX5_FC_TYPE_POOL_ACQUIRED = 0,
+       MLX5_FC_TYPE_SINGLE,
        MLX5_FC_TYPE_LOCAL,
 };
 
index 14539a20a60f9f67f2a3b07b6d1558e5bb410e7b..fe7caa910219d1f8a7be27ea92deee563de17c31 100644 (file)
@@ -153,6 +153,7 @@ static void mlx5_fc_stats_query_all_counters(struct mlx5_core_dev *dev)
 static void mlx5_fc_free(struct mlx5_core_dev *dev, struct mlx5_fc *counter)
 {
        mlx5_cmd_fc_free(dev, counter->id);
+       kfree(counter->bulk);
        kfree(counter);
 }
 
@@ -163,7 +164,7 @@ static void mlx5_fc_release(struct mlx5_core_dev *dev, struct mlx5_fc *counter)
        if (WARN_ON(counter->type == MLX5_FC_TYPE_LOCAL))
                return;
 
-       if (counter->bulk)
+       if (counter->type == MLX5_FC_TYPE_POOL_ACQUIRED)
                mlx5_fc_pool_release_counter(&fc_stats->fc_pool, counter);
        else
                mlx5_fc_free(dev, counter);
@@ -220,8 +221,16 @@ static void mlx5_fc_stats_work(struct work_struct *work)
        mlx5_fc_stats_query_all_counters(dev);
 }
 
+static void mlx5_fc_bulk_init(struct mlx5_fc_bulk *fc_bulk, u32 base_id)
+{
+       fc_bulk->base_id = base_id;
+       refcount_set(&fc_bulk->hws_data.hws_action_refcount, 0);
+       mutex_init(&fc_bulk->hws_data.lock);
+}
+
 static struct mlx5_fc *mlx5_fc_single_alloc(struct mlx5_core_dev *dev)
 {
+       struct mlx5_fc_bulk *fc_bulk;
        struct mlx5_fc *counter;
        int err;
 
@@ -229,13 +238,26 @@ static struct mlx5_fc *mlx5_fc_single_alloc(struct mlx5_core_dev *dev)
        if (!counter)
                return ERR_PTR(-ENOMEM);
 
-       err = mlx5_cmd_fc_alloc(dev, &counter->id);
-       if (err) {
-               kfree(counter);
-               return ERR_PTR(err);
+       fc_bulk = kzalloc(sizeof(*fc_bulk), GFP_KERNEL);
+       if (!fc_bulk) {
+               err = -ENOMEM;
+               goto free_counter;
        }
+       err = mlx5_cmd_fc_alloc(dev, &counter->id);
+       if (err)
+               goto free_bulk;
 
+       counter->type = MLX5_FC_TYPE_SINGLE;
+       mlx5_fs_bulk_init(&fc_bulk->fs_bulk, 1);
+       mlx5_fc_bulk_init(fc_bulk, counter->id);
+       counter->bulk = fc_bulk;
        return counter;
+
+free_bulk:
+       kfree(fc_bulk);
+free_counter:
+       kfree(counter);
+       return ERR_PTR(err);
 }
 
 static struct mlx5_fc *mlx5_fc_acquire(struct mlx5_core_dev *dev, bool aging)
@@ -421,13 +443,6 @@ static void mlx5_fc_init(struct mlx5_fc *counter, struct mlx5_fc_bulk *bulk,
        counter->id = id;
 }
 
-static void mlx5_fc_bulk_init(struct mlx5_fc_bulk *fc_bulk, u32 base_id)
-{
-       fc_bulk->base_id = base_id;
-       refcount_set(&fc_bulk->hws_data.hws_action_refcount, 0);
-       mutex_init(&fc_bulk->hws_data.lock);
-}
-
 u32 mlx5_fc_get_base_id(struct mlx5_fc *counter)
 {
        return counter->bulk->base_id;