public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] net/mlx5/core: Allocate ttc_params on heap
@ 2026-02-26 11:42 Cheng-Yang Chou
  2026-02-26 17:46 ` [PATCH v3] " Cheng-Yang Chou
  0 siblings, 1 reply; 5+ messages in thread
From: Cheng-Yang Chou @ 2026-02-26 11:42 UTC (permalink / raw)
  To: netdev, saeedm, tariqt, mbloch; +Cc: leon, jserv, charlie910417, yphbchou0911

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.

Signed-off-by: Po-Ying Chiu <charlie910417@gmail.com>
Signed-off-by: Cheng-Yang Chou <yphbchou0911@gmail.com>
Suggested-by: Leon Romanovsky <leon@kernel.org>
---
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/20260226092857.1583984-1-yphbchou0911@gmail.com/

 .../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(-)

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_rep.c b/drivers/net/ethernet/mellanox/mlx5/core/en_rep.c
index 1db4ecb2356f..c3a4dc2b4a1a 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_rep.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_rep.c
@@ -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;
 }
 
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c b/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c
index 1434b65d4746..b7525da60f92 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c
@@ -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);
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/lag/port_sel.c b/drivers/net/ethernet/mellanox/mlx5/core/lag/port_sel.c
index 16c7d16215c4..d4e7bd3c2bf4 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/lag/port_sel.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/lag/port_sel.c
@@ -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);
 }
 
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v3] net/mlx5/core: Allocate ttc_params on heap
  2026-02-26 11:42 [PATCH v2] net/mlx5/core: Allocate ttc_params on heap Cheng-Yang Chou
@ 2026-02-26 17:46 ` Cheng-Yang Chou
  2026-03-03 10:36   ` Cheng-Yang Chou
  2026-03-04  7:53   ` Tariq Toukan
  0 siblings, 2 replies; 5+ messages in thread
From: Cheng-Yang Chou @ 2026-02-26 17:46 UTC (permalink / raw)
  To: yphbchou0911; +Cc: charlie910417, jserv, leon, mbloch, netdev, saeedm, tariqt

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.

Signed-off-by: Po-Ying Chiu <charlie910417@gmail.com>
Signed-off-by: Cheng-Yang Chou <yphbchou0911@gmail.com>
Suggested-by: Leon Romanovsky <leon@kernel.org>
---
Changes in v3:
- Use tabs instead of spaces for indentation
- Link to v2: https://lore.kernel.org/all/20260226114219.2111793-1-yphbchou0911@gmail.com/

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/20260226092857.1583984-1-yphbchou0911@gmail.com/

 .../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(-)

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_rep.c b/drivers/net/ethernet/mellanox/mlx5/core/en_rep.c
index 1db4ecb2356f..c3a4dc2b4a1a 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_rep.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_rep.c
@@ -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;
 }
 
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c b/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c
index 1434b65d4746..b7525da60f92 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c
@@ -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);
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/lag/port_sel.c b/drivers/net/ethernet/mellanox/mlx5/core/lag/port_sel.c
index 16c7d16215c4..a8fc1b920e0e 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/lag/port_sel.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/lag/port_sel.c
@@ -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);
 }
 
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v3] net/mlx5/core: Allocate ttc_params on heap
  2026-02-26 17:46 ` [PATCH v3] " Cheng-Yang Chou
@ 2026-03-03 10:36   ` Cheng-Yang Chou
  2026-03-04  7:53   ` Tariq Toukan
  1 sibling, 0 replies; 5+ messages in thread
From: Cheng-Yang Chou @ 2026-03-03 10:36 UTC (permalink / raw)
  To: charlie910417, jserv, leon, mbloch, netdev, saeedm, tariqt

On Fri, Feb 27, 2026 at 01:46:01AM +0800, Cheng-Yang Chou wrote:
> 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.
> 
> Signed-off-by: Po-Ying Chiu <charlie910417@gmail.com>
> Signed-off-by: Cheng-Yang Chou <yphbchou0911@gmail.com>
> Suggested-by: Leon Romanovsky <leon@kernel.org>
> ---
> Changes in v3:
> - Use tabs instead of spaces for indentation
> - Link to v2: https://lore.kernel.org/all/20260226114219.2111793-1-yphbchou0911@gmail.com/
> 
> 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/20260226092857.1583984-1-yphbchou0911@gmail.com/
> 
>  .../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.

-- 
Thanks,
Cheng-Yang

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v3] net/mlx5/core: Allocate ttc_params on heap
  2026-02-26 17:46 ` [PATCH v3] " Cheng-Yang Chou
  2026-03-03 10:36   ` Cheng-Yang Chou
@ 2026-03-04  7:53   ` Tariq Toukan
  2026-03-14 17:30     ` Cheng-Yang Chou
  1 sibling, 1 reply; 5+ messages in thread
From: Tariq Toukan @ 2026-03-04  7:53 UTC (permalink / raw)
  To: Cheng-Yang Chou
  Cc: charlie910417, jserv, leon, mbloch, netdev, saeedm, tariqt



On 26/02/2026 19:46, Cheng-Yang Chou wrote:
> 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.
> 
> Signed-off-by: Po-Ying Chiu <charlie910417@gmail.com>
> Signed-off-by: Cheng-Yang Chou <yphbchou0911@gmail.com>
> Suggested-by: Leon Romanovsky <leon@kernel.org>
> ---

Reviewed-by: Tariq Toukan <tariqt@nvidia.com>
Thanks.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v3] net/mlx5/core: Allocate ttc_params on heap
  2026-03-04  7:53   ` Tariq Toukan
@ 2026-03-14 17:30     ` Cheng-Yang Chou
  0 siblings, 0 replies; 5+ messages in thread
From: Cheng-Yang Chou @ 2026-03-14 17:30 UTC (permalink / raw)
  To: Tariq Toukan
  Cc: charlie910417, jserv, leon, mbloch, netdev, saeedm, tariqt,
	chia7712

On Wed, Mar 04, 2026 at 09:53:15AM +0200, Tariq Toukan wrote:
> 
> 
> On 26/02/2026 19:46, Cheng-Yang Chou wrote:
> > 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.
> > 
> > Signed-off-by: Po-Ying Chiu <charlie910417@gmail.com>
> > Signed-off-by: Cheng-Yang Chou <yphbchou0911@gmail.com>
> > Suggested-by: Leon Romanovsky <leon@kernel.org>
> > ---
> 
> Reviewed-by: Tariq Toukan <tariqt@nvidia.com>
> 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.

-- 
Thanks,
Cheng-Yang

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-03-14 17:30 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-26 11:42 [PATCH v2] net/mlx5/core: Allocate ttc_params on heap Cheng-Yang Chou
2026-02-26 17:46 ` [PATCH v3] " Cheng-Yang Chou
2026-03-03 10:36   ` Cheng-Yang Chou
2026-03-04  7:53   ` Tariq Toukan
2026-03-14 17:30     ` Cheng-Yang Chou

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox