* [PATCH net-next 1/3] net/mlx5: fs, factor out flow counter bulk init
2026-01-12 9:40 [PATCH net-next 0/3] net/mlx5: HWS single flow counter support Tariq Toukan
@ 2026-01-12 9:40 ` Tariq Toukan
2026-01-12 9:40 ` [PATCH net-next 2/3] net/mlx5: fs, split " Tariq Toukan
` (3 subsequent siblings)
4 siblings, 0 replies; 7+ messages in thread
From: Tariq Toukan @ 2026-01-12 9:40 UTC (permalink / raw)
To: Eric Dumazet, Jakub Kicinski, Paolo Abeni, Andrew Lunn,
David S. Miller
Cc: Saeed Mahameed, Leon Romanovsky, Tariq Toukan, Mark Bloch, netdev,
linux-rdma, linux-kernel, Gal Pressman, Moshe Shemesh,
Yevgeny Kliteynik
From: Mark Bloch <mbloch@nvidia.com>
Add mlx5_fc_bulk_init() to handle bulk initialization of flow counters.
This change does not alter any logic, but refactors the code to remove
duplicate initialization logic by centralizing it in a single function.
Signed-off-by: Mark Bloch <mbloch@nvidia.com>
Signed-off-by: Moshe Shemesh <moshe@nvidia.com>
Reviewed-by: Yevgeny Kliteynik <kliteyn@nvidia.com>
Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
---
.../ethernet/mellanox/mlx5/core/fs_counters.c | 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/fs_counters.c b/drivers/net/ethernet/mellanox/mlx5/core/fs_counters.c
index 83001eda3884..e14570a3d492 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/fs_counters.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/fs_counters.c
@@ -421,6 +421,13 @@ 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;
@@ -447,12 +454,11 @@ static struct mlx5_fs_bulk *mlx5_fc_bulk_create(struct mlx5_core_dev *dev,
if (mlx5_cmd_fc_bulk_alloc(dev, alloc_bitmask, &base_id))
goto fs_bulk_cleanup;
- fc_bulk->base_id = base_id;
+
+ mlx5_fc_bulk_init(fc_bulk, base_id);
for (i = 0; i < bulk_len; i++)
mlx5_fc_init(&fc_bulk->fcs[i], fc_bulk, base_id + i);
- refcount_set(&fc_bulk->hws_data.hws_action_refcount, 0);
- mutex_init(&fc_bulk->hws_data.lock);
return &fc_bulk->fs_bulk;
fs_bulk_cleanup:
@@ -560,10 +566,8 @@ mlx5_fc_local_create(u32 counter_id, u32 offset, u32 bulk_size)
counter->type = MLX5_FC_TYPE_LOCAL;
counter->id = counter_id;
- fc_bulk->base_id = counter_id - offset;
fc_bulk->fs_bulk.bulk_len = bulk_size;
- refcount_set(&fc_bulk->hws_data.hws_action_refcount, 0);
- mutex_init(&fc_bulk->hws_data.lock);
+ mlx5_fc_bulk_init(fc_bulk, counter_id - offset);
counter->bulk = fc_bulk;
refcount_set(&counter->fc_local_refcount, 1);
return counter;
--
2.31.1
^ permalink raw reply related [flat|nested] 7+ messages in thread* [PATCH net-next 2/3] net/mlx5: fs, split bulk init
2026-01-12 9:40 [PATCH net-next 0/3] net/mlx5: HWS single flow counter support Tariq Toukan
2026-01-12 9:40 ` [PATCH net-next 1/3] net/mlx5: fs, factor out flow counter bulk init Tariq Toukan
@ 2026-01-12 9:40 ` Tariq Toukan
2026-01-12 9:40 ` [PATCH net-next 3/3] net/mlx5: Initialize bulk for single flow counters Tariq Toukan
` (2 subsequent siblings)
4 siblings, 0 replies; 7+ messages in thread
From: Tariq Toukan @ 2026-01-12 9:40 UTC (permalink / raw)
To: Eric Dumazet, Jakub Kicinski, Paolo Abeni, Andrew Lunn,
David S. Miller
Cc: Saeed Mahameed, Leon Romanovsky, Tariq Toukan, Mark Bloch, netdev,
linux-rdma, linux-kernel, Gal Pressman, Moshe Shemesh,
Yevgeny Kliteynik
From: Mark Bloch <mbloch@nvidia.com>
Refactor mlx5_fs_bulk_init() by moving bitmap allocation logic into a
new helper function mlx5_fs_bulk_bitmap_alloc(). This change does not
alter any logic.
Signed-off-by: Mark Bloch <mbloch@nvidia.com>
Signed-off-by: Moshe Shemesh <moshe@nvidia.com>
Reviewed-by: Yevgeny Kliteynik <kliteyn@nvidia.com>
Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
---
.../ethernet/mellanox/mlx5/core/fs_counters.c | 6 ++++--
.../net/ethernet/mellanox/mlx5/core/fs_pool.c | 16 ++++++++++------
.../net/ethernet/mellanox/mlx5/core/fs_pool.h | 5 +++--
.../mlx5/core/steering/hws/fs_hws_pools.c | 8 ++++++--
4 files changed, 23 insertions(+), 12 deletions(-)
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/fs_counters.c b/drivers/net/ethernet/mellanox/mlx5/core/fs_counters.c
index e14570a3d492..14539a20a60f 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/fs_counters.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/fs_counters.c
@@ -449,7 +449,9 @@ static struct mlx5_fs_bulk *mlx5_fc_bulk_create(struct mlx5_core_dev *dev,
if (!fc_bulk)
return NULL;
- if (mlx5_fs_bulk_init(dev, &fc_bulk->fs_bulk, bulk_len))
+ mlx5_fs_bulk_init(&fc_bulk->fs_bulk, bulk_len);
+
+ if (mlx5_fs_bulk_bitmap_alloc(dev, &fc_bulk->fs_bulk))
goto fc_bulk_free;
if (mlx5_cmd_fc_bulk_alloc(dev, alloc_bitmask, &base_id))
@@ -566,7 +568,7 @@ mlx5_fc_local_create(u32 counter_id, u32 offset, u32 bulk_size)
counter->type = MLX5_FC_TYPE_LOCAL;
counter->id = counter_id;
- fc_bulk->fs_bulk.bulk_len = bulk_size;
+ mlx5_fs_bulk_init(&fc_bulk->fs_bulk, bulk_size);
mlx5_fc_bulk_init(fc_bulk, counter_id - offset);
counter->bulk = fc_bulk;
refcount_set(&counter->fc_local_refcount, 1);
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/fs_pool.c b/drivers/net/ethernet/mellanox/mlx5/core/fs_pool.c
index f6c226664602..faa519254316 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/fs_pool.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/fs_pool.c
@@ -4,23 +4,27 @@
#include <mlx5_core.h>
#include "fs_pool.h"
-int mlx5_fs_bulk_init(struct mlx5_core_dev *dev, struct mlx5_fs_bulk *fs_bulk,
- int bulk_len)
+int mlx5_fs_bulk_bitmap_alloc(struct mlx5_core_dev *dev,
+ struct mlx5_fs_bulk *fs_bulk)
{
int i;
- fs_bulk->bitmask = kvcalloc(BITS_TO_LONGS(bulk_len), sizeof(unsigned long),
- GFP_KERNEL);
+ fs_bulk->bitmask = kvcalloc(BITS_TO_LONGS(fs_bulk->bulk_len),
+ sizeof(unsigned long), GFP_KERNEL);
if (!fs_bulk->bitmask)
return -ENOMEM;
- fs_bulk->bulk_len = bulk_len;
- for (i = 0; i < bulk_len; i++)
+ for (i = 0; i < fs_bulk->bulk_len; i++)
set_bit(i, fs_bulk->bitmask);
return 0;
}
+void mlx5_fs_bulk_init(struct mlx5_fs_bulk *fs_bulk, int bulk_len)
+{
+ fs_bulk->bulk_len = bulk_len;
+}
+
void mlx5_fs_bulk_cleanup(struct mlx5_fs_bulk *fs_bulk)
{
kvfree(fs_bulk->bitmask);
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/fs_pool.h b/drivers/net/ethernet/mellanox/mlx5/core/fs_pool.h
index f04ec3107498..4deb66479d16 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/fs_pool.h
+++ b/drivers/net/ethernet/mellanox/mlx5/core/fs_pool.h
@@ -39,8 +39,9 @@ struct mlx5_fs_pool {
int threshold;
};
-int mlx5_fs_bulk_init(struct mlx5_core_dev *dev, struct mlx5_fs_bulk *fs_bulk,
- int bulk_len);
+void mlx5_fs_bulk_init(struct mlx5_fs_bulk *fs_bulk, int bulk_len);
+int mlx5_fs_bulk_bitmap_alloc(struct mlx5_core_dev *dev,
+ struct mlx5_fs_bulk *fs_bulk);
void mlx5_fs_bulk_cleanup(struct mlx5_fs_bulk *fs_bulk);
int mlx5_fs_bulk_get_free_amount(struct mlx5_fs_bulk *bulk);
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/fs_hws_pools.c b/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/fs_hws_pools.c
index 839d71bd4216..5bc8e97ecf1c 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/fs_hws_pools.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/fs_hws_pools.c
@@ -121,7 +121,9 @@ mlx5_fs_hws_pr_bulk_create(struct mlx5_core_dev *dev, void *pool_ctx)
if (!pr_bulk)
return NULL;
- if (mlx5_fs_bulk_init(dev, &pr_bulk->fs_bulk, bulk_len))
+ mlx5_fs_bulk_init(&pr_bulk->fs_bulk, bulk_len);
+
+ if (mlx5_fs_bulk_bitmap_alloc(dev, &pr_bulk->fs_bulk))
goto free_pr_bulk;
for (i = 0; i < bulk_len; i++) {
@@ -275,7 +277,9 @@ mlx5_fs_hws_mh_bulk_create(struct mlx5_core_dev *dev, void *pool_ctx)
if (!mh_bulk)
return NULL;
- if (mlx5_fs_bulk_init(dev, &mh_bulk->fs_bulk, bulk_len))
+ mlx5_fs_bulk_init(&mh_bulk->fs_bulk, bulk_len);
+
+ if (mlx5_fs_bulk_bitmap_alloc(dev, &mh_bulk->fs_bulk))
goto free_mh_bulk;
for (int i = 0; i < bulk_len; i++) {
--
2.31.1
^ permalink raw reply related [flat|nested] 7+ messages in thread* [PATCH net-next 3/3] net/mlx5: Initialize bulk for single flow counters
2026-01-12 9:40 [PATCH net-next 0/3] net/mlx5: HWS single flow counter support Tariq Toukan
2026-01-12 9:40 ` [PATCH net-next 1/3] net/mlx5: fs, factor out flow counter bulk init Tariq Toukan
2026-01-12 9:40 ` [PATCH net-next 2/3] net/mlx5: fs, split " Tariq Toukan
@ 2026-01-12 9:40 ` Tariq Toukan
2026-01-15 11:10 ` Paolo Abeni
2026-01-14 8:19 ` [PATCH net-next 0/3] net/mlx5: HWS single flow counter support Simon Horman
2026-01-15 11:20 ` patchwork-bot+netdevbpf
4 siblings, 1 reply; 7+ messages in thread
From: Tariq Toukan @ 2026-01-12 9:40 UTC (permalink / raw)
To: Eric Dumazet, Jakub Kicinski, Paolo Abeni, Andrew Lunn,
David S. Miller
Cc: Saeed Mahameed, Leon Romanovsky, Tariq Toukan, Mark Bloch, netdev,
linux-rdma, linux-kernel, Gal Pressman, Moshe Shemesh,
Yevgeny Kliteynik
From: Moshe Shemesh <moshe@nvidia.com>
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>
---
.../net/ethernet/mellanox/mlx5/core/fs_core.h | 3 +-
.../ethernet/mellanox/mlx5/core/fs_counters.c | 39 +++++++++++++------
2 files changed, 29 insertions(+), 13 deletions(-)
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/fs_core.h b/drivers/net/ethernet/mellanox/mlx5/core/fs_core.h
index 1c6591425260..dbaf33b537f7 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/fs_core.h
+++ b/drivers/net/ethernet/mellanox/mlx5/core/fs_core.h
@@ -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,
};
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/fs_counters.c b/drivers/net/ethernet/mellanox/mlx5/core/fs_counters.c
index 14539a20a60f..fe7caa910219 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/fs_counters.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/fs_counters.c
@@ -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;
--
2.31.1
^ permalink raw reply related [flat|nested] 7+ messages in thread* Re: [PATCH net-next 3/3] net/mlx5: Initialize bulk for single flow counters
2026-01-12 9:40 ` [PATCH net-next 3/3] net/mlx5: Initialize bulk for single flow counters Tariq Toukan
@ 2026-01-15 11:10 ` Paolo Abeni
0 siblings, 0 replies; 7+ messages in thread
From: Paolo Abeni @ 2026-01-15 11:10 UTC (permalink / raw)
To: Tariq Toukan
Cc: Saeed Mahameed, Leon Romanovsky, Mark Bloch, netdev, linux-rdma,
linux-kernel, Gal Pressman, Moshe Shemesh, Yevgeny Kliteynik,
David S. Miller, Eric Dumazet, Jakub Kicinski, Andrew Lunn
On 1/12/26 10:40 AM, Tariq Toukan wrote:
> @@ -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);
> +}
Not worthy a repost, but you could have avoided moving this function
placing it here in patch 1/3.
/P
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH net-next 0/3] net/mlx5: HWS single flow counter support
2026-01-12 9:40 [PATCH net-next 0/3] net/mlx5: HWS single flow counter support Tariq Toukan
` (2 preceding siblings ...)
2026-01-12 9:40 ` [PATCH net-next 3/3] net/mlx5: Initialize bulk for single flow counters Tariq Toukan
@ 2026-01-14 8:19 ` Simon Horman
2026-01-15 11:20 ` patchwork-bot+netdevbpf
4 siblings, 0 replies; 7+ messages in thread
From: Simon Horman @ 2026-01-14 8:19 UTC (permalink / raw)
To: Tariq Toukan
Cc: Eric Dumazet, Jakub Kicinski, Paolo Abeni, Andrew Lunn,
David S. Miller, Saeed Mahameed, Leon Romanovsky, Mark Bloch,
netdev, linux-rdma, linux-kernel, Gal Pressman, Moshe Shemesh,
Yevgeny Kliteynik
On Mon, Jan 12, 2026 at 11:40:22AM +0200, Tariq Toukan wrote:
> Hi,
>
> This small series refactors the flow counter bulk initialization code
> and extends it so that single flow counters are also usable by hardware
> steering (HWS) rules.
>
> Patches 1-2 refactor the bulk init path: first by factoring out common
> flow counter bulk initialization into mlx5_fc_bulk_init(), then by
> splitting the bitmap allocation into mlx5_fs_bulk_bitmap_alloc(), with
> no functional changes.
>
> Patch 3 initializes bulk data for counters allocated via
> mlx5_fc_single_alloc(), so they can be safely used by HWS rules.
Hi Tariq,
Overall this looks good to me.
Am I correct in thinking that there will
be follow-up patches to make HWS use counters?
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH net-next 0/3] net/mlx5: HWS single flow counter support
2026-01-12 9:40 [PATCH net-next 0/3] net/mlx5: HWS single flow counter support Tariq Toukan
` (3 preceding siblings ...)
2026-01-14 8:19 ` [PATCH net-next 0/3] net/mlx5: HWS single flow counter support Simon Horman
@ 2026-01-15 11:20 ` patchwork-bot+netdevbpf
4 siblings, 0 replies; 7+ messages in thread
From: patchwork-bot+netdevbpf @ 2026-01-15 11:20 UTC (permalink / raw)
To: Tariq Toukan
Cc: edumazet, kuba, pabeni, andrew+netdev, davem, saeedm, leon,
mbloch, netdev, linux-rdma, linux-kernel, gal, moshe, kliteyn
Hello:
This series was applied to netdev/net-next.git (main)
by Paolo Abeni <pabeni@redhat.com>:
On Mon, 12 Jan 2026 11:40:22 +0200 you wrote:
> Hi,
>
> This small series refactors the flow counter bulk initialization code
> and extends it so that single flow counters are also usable by hardware
> steering (HWS) rules.
>
> Patches 1-2 refactor the bulk init path: first by factoring out common
> flow counter bulk initialization into mlx5_fc_bulk_init(), then by
> splitting the bitmap allocation into mlx5_fs_bulk_bitmap_alloc(), with
> no functional changes.
>
> [...]
Here is the summary with links:
- [net-next,1/3] net/mlx5: fs, factor out flow counter bulk init
https://git.kernel.org/netdev/net-next/c/96e89982a68c
- [net-next,2/3] net/mlx5: fs, split bulk init
https://git.kernel.org/netdev/net-next/c/6a6c4dd7c019
- [net-next,3/3] net/mlx5: Initialize bulk for single flow counters
https://git.kernel.org/netdev/net-next/c/1c8910f50350
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 7+ messages in thread