net/mlx5/core: Allocate ttc_params on heap
PATCH v2 1/1 net/mlx5/core: Allocate ttc_params on heap
The ttc_params structure is too large to be allocated on the stack, triggering warnings for exceeding the 1024-byte frame size limit. Consuming excessive stack space risks causing stack overflows.
Allocate the structure dynamically to maintain safe stack boundaries.
---
Changes in v2:
- Use kzalloc_obj() instead of kzalloc() to align with the new memory allocation API introduced in v7.0-rc1 (Leon Romanovsky)
- Link to v1: https://lore.kernel.org/all/[email protected]/
.../net/ethernet/mellanox/mlx5/core/en_rep.c | 15 +++++++++---- .../net/ethernet/mellanox/mlx5/core/en_tc.c | 15 ++++++++++--- .../mellanox/mlx5/core/lag/port_sel.c | 22 ++++++++++++++----- 3 files changed, 39 insertions(+), 13 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en_rep.c +11 -4
@@ -966,27 +966,34 @@ static int mlx5e_create_rep_ttc_table(struct mlx5e_priv *priv) {struct mlx5e_rep_priv *rpriv = priv->ppriv;struct mlx5_eswitch_rep *rep = rpriv->rep; -struct ttc_params ttc_params = {}; +struct ttc_params *ttc_params;int err; + ttc_params =kzalloc_obj (*ttc_params); +if (!ttc_params) +return -ENOMEM ; +mlx5e_fs_set_ns (priv->fs,mlx5_get_flow_namespace (priv->mdev,MLX5_FLOW_NAMESPACE_KERNEL ), false);/* The inner_ttc in the ttc params is intentionally not set */ -mlx5e_set_ttc_params (priv->fs, priv->rx_res, &ttc_params, false, false); +mlx5e_set_ttc_params (priv->fs, priv->rx_res, ttc_params, false, false);if (rep->vport !=MLX5_VPORT_UPLINK )/* To give uplik rep TTC a lower level for chaining from root ft */ - ttc_params.ft_attr.level =MLX5E_TTC_FT_LEVEL +1 ; + ttc_params->ft_attr.level =MLX5E_TTC_FT_LEVEL +1 ; -mlx5e_fs_set_ttc (priv->fs,mlx5_create_ttc_table (priv->mdev, &ttc_params), false); +mlx5e_fs_set_ttc (priv->fs,mlx5_create_ttc_table (priv->mdev, ttc_params), false);if (IS_ERR (mlx5e_fs_get_ttc (priv->fs, false))) { err =PTR_ERR (mlx5e_fs_get_ttc (priv->fs, false));netdev_err (priv->netdev,"Failed to create rep ttc table, err=%d\n" , err); +kfree (ttc_params);return err; } + +kfree (ttc_params);return 0 ; }
drivers/net/ethernet/mellanox/mlx5/core/en_tc.c +12 -3
@@ -855,7 +855,7 @@ static void mlx5e_hairpin_set_ttc_params(struct mlx5e_hairpin *hp,static int mlx5e_hairpin_rss_init (struct mlx5e_hairpin *hp) {struct mlx5e_priv *priv = hp->func_priv; -struct ttc_params ttc_params; +struct ttc_params *ttc_params;struct mlx5_ttc_table *ttc;int err;
@@ -867,8 +867,14 @@ static int mlx5e_hairpin_rss_init(struct mlx5e_hairpin *hp)if (err) goto err_create_indirect_tirs; -mlx5e_hairpin_set_ttc_params (hp, &ttc_params); - hp->ttc =mlx5_create_ttc_table (priv->mdev, &ttc_params); + ttc_params =kzalloc_obj (*ttc_params); +if (!ttc_params) { + err = -ENOMEM ; + goto err_alloc_ttc_params; + } + +mlx5e_hairpin_set_ttc_params (hp, ttc_params); + hp->ttc =mlx5_create_ttc_table (priv->mdev, ttc_params);if (IS_ERR (hp->ttc)) { err =PTR_ERR (hp->ttc); goto err_create_ttc_table;
@@ -879,9 +885,12 @@ static int mlx5e_hairpin_rss_init(struct mlx5e_hairpin *hp) hp->num_channels, mlx5_get_ttc_flow_table(ttc)->id); +kfree (ttc_params);return 0 ; err_create_ttc_table: +kfree (ttc_params); +err_alloc_ttc_params:mlx5e_hairpin_destroy_indirect_tirs (hp); err_create_indirect_tirs:mlx5e_rqt_destroy (&hp->indir_rqt);
drivers/net/ethernet/mellanox/mlx5/core/lag/port_sel.c +16 -6
@@ -514,15 +514,20 @@ static int mlx5_lag_create_ttc_table(struct mlx5_lag *ldev) {int first_idx =mlx5_lag_get_dev_index_by_seq (ldev,MLX5_LAG_P1 );struct mlx5_lag_port_sel *port_sel = &ldev->port_sel; -struct ttc_params ttc_params = {}; +struct ttc_params *ttc_params;struct mlx5_core_dev *dev;if (first_idx <0 )return -EINVAL ; + ttc_params =kzalloc_obj (*ttc_params); +if (!ttc_params) +return -ENOMEM ; + dev = ldev->pf[first_idx].dev; -mlx5_lag_set_outer_ttc_params (ldev, &ttc_params); - port_sel->outer.ttc =mlx5_create_ttc_table (dev, &ttc_params); +mlx5_lag_set_outer_ttc_params (ldev, ttc_params); + port_sel->outer.ttc =mlx5_create_ttc_table (dev, ttc_params); +kfree (ttc_params);return PTR_ERR_OR_ZERO (port_sel->outer.ttc); }
@@ -530,15 +535,20 @@ static int mlx5_lag_create_inner_ttc_table(struct mlx5_lag *ldev) {int first_idx =mlx5_lag_get_dev_index_by_seq (ldev,MLX5_LAG_P1 );struct mlx5_lag_port_sel *port_sel = &ldev->port_sel; -struct ttc_params ttc_params = {}; +struct ttc_params *ttc_params;struct mlx5_core_dev *dev;if (first_idx <0 )return -EINVAL ; + ttc_params =kzalloc_obj (*ttc_params); +if (!ttc_params) +return -ENOMEM ; + dev = ldev->pf[first_idx].dev; -mlx5_lag_set_inner_ttc_params (ldev, &ttc_params); - port_sel->inner.ttc =mlx5_create_inner_ttc_table (dev, &ttc_params); +mlx5_lag_set_inner_ttc_params (ldev, ttc_params); + port_sel->inner.ttc =mlx5_create_inner_ttc_table (dev, ttc_params); +kfree (ttc_params);return PTR_ERR_OR_ZERO (port_sel->inner.ttc); }
Signature · 1 line
2.48.1
PATCH v3 1/1 net/mlx5/core: Allocate ttc_params on heap
The ttc_params structure is too large to be allocated on the stack, triggering warnings for exceeding the 1024-byte frame size limit. Consuming excessive stack space risks causing stack overflows.
Allocate the structure dynamically to maintain safe stack boundaries.
---
Changes in v3:
- Use tabs instead of spaces for indentation
- Link to v2: https://lore.kernel.org/all/[email protected]/
Changes in v2:
- Use kzalloc_obj() instead of kzalloc() to align with the new memory allocation API introduced in v7.0-rc1 (Leon Romanovsky)
- Link to v1: https://lore.kernel.org/all/[email protected]/
.../net/ethernet/mellanox/mlx5/core/en_rep.c | 15 +++++++++---- .../net/ethernet/mellanox/mlx5/core/en_tc.c | 15 ++++++++++--- .../mellanox/mlx5/core/lag/port_sel.c | 22 ++++++++++++++----- 3 files changed, 39 insertions(+), 13 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en_rep.c +11 -4
@@ -966,27 +966,34 @@ static int mlx5e_create_rep_ttc_table(struct mlx5e_priv *priv) {struct mlx5e_rep_priv *rpriv = priv->ppriv;struct mlx5_eswitch_rep *rep = rpriv->rep; -struct ttc_params ttc_params = {}; +struct ttc_params *ttc_params;int err; + ttc_params =kzalloc_obj (*ttc_params); +if (!ttc_params) +return -ENOMEM ; +mlx5e_fs_set_ns (priv->fs,mlx5_get_flow_namespace (priv->mdev,MLX5_FLOW_NAMESPACE_KERNEL ), false);/* The inner_ttc in the ttc params is intentionally not set */ -mlx5e_set_ttc_params (priv->fs, priv->rx_res, &ttc_params, false, false); +mlx5e_set_ttc_params (priv->fs, priv->rx_res, ttc_params, false, false);if (rep->vport !=MLX5_VPORT_UPLINK )/* To give uplik rep TTC a lower level for chaining from root ft */ - ttc_params.ft_attr.level =MLX5E_TTC_FT_LEVEL +1 ; + ttc_params->ft_attr.level =MLX5E_TTC_FT_LEVEL +1 ; -mlx5e_fs_set_ttc (priv->fs,mlx5_create_ttc_table (priv->mdev, &ttc_params), false); +mlx5e_fs_set_ttc (priv->fs,mlx5_create_ttc_table (priv->mdev, ttc_params), false);if (IS_ERR (mlx5e_fs_get_ttc (priv->fs, false))) { err =PTR_ERR (mlx5e_fs_get_ttc (priv->fs, false));netdev_err (priv->netdev,"Failed to create rep ttc table, err=%d\n" , err); +kfree (ttc_params);return err; } + +kfree (ttc_params);return 0 ; }
drivers/net/ethernet/mellanox/mlx5/core/en_tc.c +12 -3
@@ -855,7 +855,7 @@ static void mlx5e_hairpin_set_ttc_params(struct mlx5e_hairpin *hp,static int mlx5e_hairpin_rss_init (struct mlx5e_hairpin *hp) {struct mlx5e_priv *priv = hp->func_priv; -struct ttc_params ttc_params; +struct ttc_params *ttc_params;struct mlx5_ttc_table *ttc;int err;
@@ -867,8 +867,14 @@ static int mlx5e_hairpin_rss_init(struct mlx5e_hairpin *hp)if (err) goto err_create_indirect_tirs; -mlx5e_hairpin_set_ttc_params (hp, &ttc_params); - hp->ttc =mlx5_create_ttc_table (priv->mdev, &ttc_params); + ttc_params =kzalloc_obj (*ttc_params); +if (!ttc_params) { + err = -ENOMEM ; + goto err_alloc_ttc_params; + } + +mlx5e_hairpin_set_ttc_params (hp, ttc_params); + hp->ttc =mlx5_create_ttc_table (priv->mdev, ttc_params);if (IS_ERR (hp->ttc)) { err =PTR_ERR (hp->ttc); goto err_create_ttc_table;
@@ -879,9 +885,12 @@ static int mlx5e_hairpin_rss_init(struct mlx5e_hairpin *hp) hp->num_channels, mlx5_get_ttc_flow_table(ttc)->id); +kfree (ttc_params);return 0 ; err_create_ttc_table: +kfree (ttc_params); +err_alloc_ttc_params:mlx5e_hairpin_destroy_indirect_tirs (hp); err_create_indirect_tirs:mlx5e_rqt_destroy (&hp->indir_rqt);
drivers/net/ethernet/mellanox/mlx5/core/lag/port_sel.c +16 -6
@@ -514,15 +514,20 @@ static int mlx5_lag_create_ttc_table(struct mlx5_lag *ldev) {int first_idx =mlx5_lag_get_dev_index_by_seq (ldev,MLX5_LAG_P1 );struct mlx5_lag_port_sel *port_sel = &ldev->port_sel; -struct ttc_params ttc_params = {}; +struct ttc_params *ttc_params;struct mlx5_core_dev *dev;if (first_idx <0 )return -EINVAL ; + ttc_params =kzalloc_obj (*ttc_params); +if (!ttc_params) +return -ENOMEM ; + dev = ldev->pf[first_idx].dev; -mlx5_lag_set_outer_ttc_params (ldev, &ttc_params); - port_sel->outer.ttc =mlx5_create_ttc_table (dev, &ttc_params); +mlx5_lag_set_outer_ttc_params (ldev, ttc_params); + port_sel->outer.ttc =mlx5_create_ttc_table (dev, ttc_params); +kfree (ttc_params);return PTR_ERR_OR_ZERO (port_sel->outer.ttc); }
@@ -530,15 +535,20 @@ static int mlx5_lag_create_inner_ttc_table(struct mlx5_lag *ldev) {int first_idx =mlx5_lag_get_dev_index_by_seq (ldev,MLX5_LAG_P1 );struct mlx5_lag_port_sel *port_sel = &ldev->port_sel; -struct ttc_params ttc_params = {}; +struct ttc_params *ttc_params;struct mlx5_core_dev *dev;if (first_idx <0 )return -EINVAL ; + ttc_params =kzalloc_obj (*ttc_params); +if (!ttc_params) +return -ENOMEM ; + dev = ldev->pf[first_idx].dev; -mlx5_lag_set_inner_ttc_params (ldev, &ttc_params); - port_sel->inner.ttc =mlx5_create_inner_ttc_table (dev, &ttc_params); +mlx5_lag_set_inner_ttc_params (ldev, ttc_params); + port_sel->inner.ttc =mlx5_create_inner_ttc_table (dev, ttc_params); +kfree (ttc_params);return PTR_ERR_OR_ZERO (port_sel->inner.ttc); }
Signature · 1 line
2.48.1
Quoted 19 lines · Cheng-Yang Chou
The
ttc_paramsstructure is too large to be allocated on the stack, triggering warnings for exceeding the 1024-byte frame size limit. Consuming excessive stack space risks causing stack overflows.Allocate the structure dynamically to maintain safe stack boundaries.
Signed-off-by Po-Ying Chiu <[email protected]>Signed-off-by Cheng-Yang Chou <[email protected]>Suggested-by Leon Romanovsky <[email protected]>---
Changes in v3:
- Use tabs instead of spaces for indentation
- Link to v2: https://lore.kernel.org/all/[email protected]/Changes in v2:
- Usekzalloc_obj()instead ofkzalloc()to align with the new memory allocation API introduced in v7.0-rc1 (Leon Romanovsky)
- Link to v1: https://lore.kernel.org/all/[email protected]/
Quoted 4 lines
.../net/ethernet/mellanox/mlx5/core/en_rep.c | 15 +++++++++---- .../net/ethernet/mellanox/mlx5/core/en_tc.c | 15 ++++++++++--- .../mellanox/mlx5/core/lag/port_sel.c | 22 ++++++++++++++----- 3 files changed, 39 insertions(+), 13 deletions(-)
Gentle ping.
Please let me know if any changes are needed.
Signature · 2 lines
Thanks, Cheng-Yang
Quoted 10 lines · Cheng-Yang Chou
The
ttc_paramsstructure is too large to be allocated on the stack, triggering warnings for exceeding the 1024-byte frame size limit. Consuming excessive stack space risks causing stack overflows.Allocate the structure dynamically to maintain safe stack boundaries.
Signed-off-by Po-Ying Chiu <[email protected]>Signed-off-by Cheng-Yang Chou <[email protected]>Suggested-by Leon Romanovsky <[email protected]>---
Thanks.
Quoted 9 lines · Tariq Toukan
Quoted 6 lines · Cheng-Yang Chou
The
ttc_paramsstructure is too large to be allocated on the stack, triggering warnings for exceeding the 1024-byte frame size limit. Consuming excessive stack space risks causing stack overflows.Allocate the structure dynamically to maintain safe stack boundaries.
Quoted 8 lines
Quoted 4 lines
Signed-off-by Po-Ying Chiu <[email protected]>Signed-off-by Cheng-Yang Chou <[email protected]>Suggested-by Leon Romanovsky <[email protected]>---
Reviewed-by Tariq Toukan <[email protected]>Thanks.
Hi,
Just a gentle ping on this patch.
Please let me know if there are any further comments or if anything else is needed from my side.
Signature · 2 lines
Thanks, Cheng-Yang