mlx5: Support HWS flow meter/sampler actions in FS core
Subsystems (5)
Tariq Toukan
maintainercover mlx5: Support HWS flow meter/sampler actions in FS core
Hi,
This series by Moshe adds support for flow meter and flow sampler HW Steering actions in FS core level. As these actions can be shared by multiple rules, these patches use refcounts to manage the HWS actions sharing in FS core level.
Regards,
Tariq
Moshe Shemesh (3):
net/mlx5: fs, add API for sharing HWS action by refcount net/mlx5: fs, add support for flow meters HWS action net/mlx5: fs, add support for dest flow sampler HWS action
.../ethernet/mellanox/mlx5/core/en/tc/meter.c | 5 + .../ethernet/mellanox/mlx5/core/en/tc/meter.h | 13 + .../mellanox/mlx5/core/eswitch_offloads.c | 1 + .../net/ethernet/mellanox/mlx5/core/fs_core.h | 8 +- .../mellanox/mlx5/core/steering/hws/fs_hws.c | 231 +++++++++++++++++- .../mellanox/mlx5/core/steering/hws/fs_hws.h | 24 ++ .../mlx5/core/steering/hws/fs_hws_pools.c | 41 +--- include/linux/mlx5/fs.h | 1 + 8 files changed, 272 insertions(+), 52 deletions(-)
base-commit: 8ef890df4031121a94407c84659125cbccd3fdbe
Signature · 1 line
2.45.0
Tariq Toukan
maintainerPATCH 1/3 net/mlx5: fs, add API for sharing HWS action by refcount
From: Moshe Shemesh <[email protected]>
Counters HWS actions are shared using refcount, to create action on demand by flow steering rule and destroy only when no rules are using the action. The method is extensible to other HWS action types, such as flow meter and sampler actions, in the downstream patches.
Add an API to facilitate the reuse of get/put logic for HWS actions shared by refcount.
--- .../net/ethernet/mellanox/mlx5/core/fs_core.h | 8 +-- .../mellanox/mlx5/core/steering/hws/fs_hws.c | 57 +++++++++++++++++++ .../mellanox/mlx5/core/steering/hws/fs_hws.h | 17 ++++++ .../mlx5/core/steering/hws/fs_hws_pools.c | 41 ++----------- 4 files changed, 81 insertions(+), 42 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/fs_core.h +1 -7
@@ -341,16 +341,10 @@ struct mlx5_fc {u64 lastbytes; }; -struct mlx5_fc_bulk_hws_data { -struct mlx5hws_action *hws_action; -struct mutex lock;/* protects hws_action */ -refcount_t hws_action_refcount; -}; -struct mlx5_fc_bulk {struct mlx5_fs_bulk fs_bulk;u32 base_id; -struct mlx5_fc_bulk_hws_data hws_data; +struct mlx5_fs_hws_data hws_data;struct mlx5_fc fcs[]; };
drivers/net/ethernet/mellanox/mlx5/core/steering/hws/fs_hws.c +57 -0
63 lines not on this page · raw message
drivers/net/ethernet/mellanox/mlx5/core/steering/hws/fs_hws.h +17 -0
@@ -58,6 +58,23 @@ struct mlx5_fs_hws_rule {int num_fs_actions; }; +struct mlx5_fs_hws_data { +struct mlx5hws_action *hws_action; +struct mutex lock;/* protects hws_action */ +refcount_t hws_action_refcount; +}; + +struct mlx5_fs_hws_create_action_ctx { +enum mlx5hws_action_type actions_type; +struct mlx5hws_context *hws_ctx; +u32 id; +}; + +struct mlx5hws_action * +mlx5_fs_get_hws_action (struct mlx5_fs_hws_data *fs_hws_data, +struct mlx5_fs_hws_create_action_ctx *create_ctx); +void mlx5_fs_put_hws_action (struct mlx5_fs_hws_data *fs_hws_data); +#ifdef CONFIG_MLX5_HW_STEERING bool mlx5_fs_hws_is_supported (struct mlx5_core_dev *dev);
drivers/net/ethernet/mellanox/mlx5/core/steering/hws/fs_hws_pools.c +6 -35
52 lines not on this page · raw message
Signature · 1 line
2.45.0
Re: [PATCH net-next 1/3] net/mlx5: fs, add API for sharing HWS action by refcount
Quoted 7 lines · Tariq Toukan
From: Moshe Shemesh <[email protected]>
Counters HWS actions are shared using refcount, to create action on demand by flow steering rule and destroy only when no rules are using the action. The method is extensible to other HWS action types, such as flow meter and sampler actions, in the downstream patches.
Quoted 7 lines
Add an API to facilitate the reuse of get/put logic for HWS actions shared by refcount.
Signed-off-by Moshe Shemesh <[email protected]>Reviewed-by Mark Bloch <[email protected]>Signed-off-by Tariq Toukan <[email protected]>---
Tariq Toukan
maintainerPATCH 2/3 net/mlx5: fs, add support for flow meters HWS action
In reply to Tariq ToukanFrom: Moshe Shemesh <[email protected]>
Add support for HW Steering action of flow meter range. Flow meters range can use one HWS action for the whole range. Thus, share a cached HWS action among rules that use same flow meter object range. Hold refcount for each rule using the cached action.
--- .../ethernet/mellanox/mlx5/core/en/tc/meter.c | 5 + .../ethernet/mellanox/mlx5/core/en/tc/meter.h | 13 ++ .../mellanox/mlx5/core/eswitch_offloads.c | 1 + .../mellanox/mlx5/core/steering/hws/fs_hws.c | 120 ++++++++++++++++-- .../mellanox/mlx5/core/steering/hws/fs_hws.h | 5 + include/linux/mlx5/fs.h | 1 + 6 files changed, 135 insertions(+), 10 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en/tc/meter.c +5 -0
@@ -593,3 +593,8 @@ mlx5e_tc_meter_get_stats(struct mlx5e_flow_meter_handle *meter, *drops = packets2; *lastuse =max_t (u64, lastuse1, lastuse2); } + +int mlx5e_flow_meter_get_base_id (struct mlx5e_flow_meter_handle *meter) +{ +return meter->meters_obj->base_id; +}
drivers/net/ethernet/mellanox/mlx5/core/en/tc/meter.h +13 -0
@@ -72,4 +72,17 @@ void mlx5e_tc_meter_get_stats(struct mlx5e_flow_meter_handle *meter, u64 *bytes, u64 *packets, u64 *drops, u64 *lastuse); +#if IS_ENABLED (CONFIG_MLX5_CLS_ACT ) + +int mlx5e_flow_meter_get_base_id (struct mlx5e_flow_meter_handle *meter); + +#else /* CONFIG_MLX5_CLS_ACT */ + +static inline int +mlx5e_flow_meter_get_base_id (struct mlx5e_flow_meter_handle *meter) +{ +return 0 ; +} +#endif /* CONFIG_MLX5_CLS_ACT */ +#endif /* __MLX5_EN_FLOW_METER_H__ */
drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c +1 -0
@@ -648,6 +648,7 @@ esw_setup_meter(struct mlx5_flow_attr *attr, struct mlx5_flow_act *flow_act) meter = attr->meter_attr.meter; flow_act->exe_aso.type = attr->exe_aso_type; flow_act->exe_aso.object_id = meter->obj_id; + flow_act->exe_aso.base_id =mlx5e_flow_meter_get_base_id (meter); flow_act->exe_aso.flow_meter.meter_idx = meter->idx; flow_act->exe_aso.flow_meter.init_color =MLX5_FLOW_METER_COLOR_GREEN ;/* use metadata reg 5 for packet color */
drivers/net/ethernet/mellanox/mlx5/core/steering/hws/fs_hws.c +110 -10
204 lines not on this page · raw message
drivers/net/ethernet/mellanox/mlx5/core/steering/hws/fs_hws.h +5 -0
@@ -22,6 +22,7 @@ struct mlx5_fs_hws_actions_pool {struct xarray table_dests;struct xarray vport_vhca_dests;struct xarray vport_dests; +struct xarray aso_meters; };struct mlx5_fs_hws_context {
@@ -49,6 +50,7 @@ struct mlx5_fs_hws_rule_action {struct mlx5hws_action *action;union {struct mlx5_fc *counter; +struct mlx5_exe_aso *exe_aso; }; };
@@ -68,6 +70,9 @@ struct mlx5_fs_hws_create_action_ctx {enum mlx5hws_action_type actions_type;struct mlx5hws_context *hws_ctx;u32 id; +union { +u8 return_reg_id; + }; }; struct mlx5hws_action *
include/linux/mlx5/fs.h +1 -0
@@ -240,6 +240,7 @@ void mlx5_destroy_flow_group(struct mlx5_flow_group *fg);struct mlx5_exe_aso {u32 object_id; +int base_id;u8 type;u8 return_reg_id;union {
Signature · 1 line
2.45.0
Re: [PATCH net-next 2/3] net/mlx5: fs, add support for flow meters HWS action
Quoted 11 lines · Tariq Toukan
From: Moshe Shemesh <[email protected]>
Add support for HW Steering action of flow meter range. Flow meters range can use one HWS action for the whole range. Thus, share a cached HWS action among rules that use same flow meter object range. Hold refcount for each rule using the cached action.
Signed-off-by Moshe Shemesh <[email protected]>Reviewed-by Mark Bloch <[email protected]>Signed-off-by Tariq Toukan <[email protected]>---
Tariq Toukan
maintainerPATCH 3/3 net/mlx5: fs, add support for dest flow sampler HWS action
In reply to Tariq ToukanFrom: Moshe Shemesh <[email protected]>
Add support for HW Steering action of flow sampler destination. For each flow sampler created cache the hws action by sampler id as a key. Hold refcount for each rule using the cached action.
--- .../mellanox/mlx5/core/steering/hws/fs_hws.c | 54 +++++++++++++++++++ .../mellanox/mlx5/core/steering/hws/fs_hws.h | 2 + 2 files changed, 56 insertions(+)
drivers/net/ethernet/mellanox/mlx5/core/steering/hws/fs_hws.c +54 -0
@@ -67,6 +67,7 @@ static int mlx5_fs_init_hws_actions_pool(struct mlx5_core_dev *dev,xa_init (&hws_pool->vport_dests);xa_init (&hws_pool->vport_vhca_dests);xa_init (&hws_pool->aso_meters); +xa_init (&hws_pool->sample_dests);return 0 ; cleanup_insert_hdr:
@@ -94,6 +95,9 @@ static void mlx5_fs_cleanup_hws_actions_pool(struct mlx5_fs_hws_context *fs_ctx)struct mlx5_fs_pool *pool;unsigned long i; +xa_for_each (&hws_pool->sample_dests, i, fs_hws_data) +kfree (fs_hws_data); +xa_destroy (&hws_pool->sample_dests);xa_for_each (&hws_pool->aso_meters, i, fs_hws_data)kfree (fs_hws_data);xa_destroy (&hws_pool->aso_meters);
@@ -528,6 +532,42 @@ static void mlx5_fs_put_action_aso_meter(struct mlx5_fs_hws_context *fs_ctx,return mlx5_fs_put_hws_action (meter_hws_data); } +static struct mlx5hws_action * +mlx5_fs_get_dest_action_sampler (struct mlx5_fs_hws_context *fs_ctx, +struct mlx5_flow_rule *dst) +{ +struct mlx5_fs_hws_create_action_ctx create_ctx; +struct mlx5hws_context *ctx = fs_ctx->hws_ctx; +struct mlx5_fs_hws_data *sampler_hws_data; +u32 id = dst->dest_attr.sampler_id; +struct xarray *sampler_xa; + + sampler_xa = &fs_ctx->hws_pool.sample_dests; + sampler_hws_data =mlx5_fs_get_cached_hws_data (sampler_xa, id); +if (!sampler_hws_data) +return NULL ; + + create_ctx.hws_ctx = ctx; + create_ctx.actions_type =MLX5HWS_ACTION_TYP_SAMPLER ; + create_ctx.id = id; + +return mlx5_fs_get_hws_action (sampler_hws_data, &create_ctx); +} + +static void mlx5_fs_put_dest_action_sampler (struct mlx5_fs_hws_context *fs_ctx, +u32 sampler_id) +{ +struct mlx5_fs_hws_data *sampler_hws_data; +struct xarray *sampler_xa; + + sampler_xa = &fs_ctx->hws_pool.sample_dests; + sampler_hws_data =xa_load (sampler_xa, sampler_id); +if (!sampler_hws_data) +return ; + +mlx5_fs_put_hws_action (sampler_hws_data); +} +static struct mlx5hws_action * mlx5_fs_create_action_dest_array(struct mlx5hws_context *ctx, struct mlx5hws_action_dest_attr *dests,
@@ -602,6 +642,9 @@ mlx5_fs_create_hws_action(struct mlx5_fs_hws_create_action_ctx *create_ctx) create_ctx->id, create_ctx->return_reg_id, flags); +case MLX5HWS_ACTION_TYP_SAMPLER : +return mlx5hws_action_create_flow_sampler (create_ctx->hws_ctx, + create_ctx->id, flags);default :return NULL ; }
@@ -662,6 +705,9 @@ static void mlx5_fs_destroy_fs_action(struct mlx5_flow_root_namespace *ns,case MLX5HWS_ACTION_TYP_ASO_METER :mlx5_fs_put_action_aso_meter (fs_ctx, fs_action->exe_aso);break ; +case MLX5HWS_ACTION_TYP_SAMPLER : +mlx5_fs_put_dest_action_sampler (fs_ctx, fs_action->sampler_id); +break ;default :mlx5hws_action_destroy (fs_action->action); }
@@ -939,6 +985,14 @@ static int mlx5_fs_fte_get_hws_actions(struct mlx5_flow_root_namespace *ns, dest_action =mlx5_fs_get_dest_action_vport (fs_ctx, dst, type_uplink);break ; +case MLX5_FLOW_DESTINATION_TYPE_FLOW_SAMPLER : + dest_action = +mlx5_fs_get_dest_action_sampler (fs_ctx, + dst); + fs_actions[num_fs_actions].action = dest_action; + fs_actions[num_fs_actions++].sampler_id = + dst->dest_attr.sampler_id; +break ;default : err = -EOPNOTSUPP ; goto free_actions;
drivers/net/ethernet/mellanox/mlx5/core/steering/hws/fs_hws.h +2 -0
@@ -23,6 +23,7 @@ struct mlx5_fs_hws_actions_pool {struct xarray vport_vhca_dests;struct xarray vport_dests;struct xarray aso_meters; +struct xarray sample_dests; };struct mlx5_fs_hws_context {
@@ -51,6 +52,7 @@ struct mlx5_fs_hws_rule_action {union {struct mlx5_fc *counter;struct mlx5_exe_aso *exe_aso; +u32 sampler_id; }; };
Signature · 1 line
2.45.0
Re: [PATCH net-next 3/3] net/mlx5: fs, add support for dest flow sampler HWS action
Quoted 9 lines · Tariq Toukan
From: Moshe Shemesh <[email protected]>
Add support for HW Steering action of flow sampler destination. For each flow sampler created cache the hws action by sampler id as a key. Hold refcount for each rule using the cached action.
Signed-off-by Moshe Shemesh <[email protected]>Reviewed-by Mark Bloch <[email protected]>Signed-off-by Tariq Toukan <[email protected]>
This series was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:
Quoted 8 lines · On Sun, 9 Mar 2025 20:07:40 +0200 you wrote:
Hi,
This series by Moshe adds support for flow meter and flow sampler HW Steering actions in FS core level. As these actions can be shared by multiple rules, these patches use refcounts to manage the HWS actions sharing in FS core level.
[...]
Here is the summary with links:
- [net-next,1/3] net/mlx5: fs, add API for sharing HWS action by refcount
https://git.kernel.org/netdev/net-next/c/cc2cc56fc6e6 - [net-next,2/3] net/mlx5: fs, add support for flow meters HWS action https://git.kernel.org/netdev/net-next/c/82d3639ef7dc - [net-next,3/3] net/mlx5: fs, add support for dest flow sampler HWS action https://git.kernel.org/netdev/net-next/c/32e658c84b6d
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html