public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
From: Cheng-Yang Chou <yphbchou0911@gmail.com>
To: netdev@vger.kernel.org, saeedm@nvidia.com, tariqt@nvidia.com,
	mbloch@nvidia.com
Cc: jserv@ccns.ncku.edu.tw, charlie910417@gmail.com, yphbchou0911@gmail.com
Subject: [PATCH 1/1] net/mlx5/core: Allocate ttc_params on heap
Date: Thu, 26 Feb 2026 17:28:55 +0800	[thread overview]
Message-ID: <20260226092857.1583984-2-yphbchou0911@gmail.com> (raw)
In-Reply-To: <20260226092857.1583984-1-yphbchou0911@gmail.com>

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>
---
 .../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 6eec88fa6d10..8e3862f5b563 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(sizeof(*ttc_params), GFP_KERNEL);
+        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 424786f489ec..83a6fd052155 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(sizeof(*ttc_params), GFP_KERNEL);
+	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 d832a12ffec0..69fc596e9188 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(sizeof(*ttc_params), GFP_KERNEL);
+        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(sizeof(*ttc_params), GFP_KERNEL);
+        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


  reply	other threads:[~2026-02-26  9:29 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-26  9:28 [PATCH 0/1] net/mlx5/core: Fix stack frame size warnings Cheng-Yang Chou
2026-02-26  9:28 ` Cheng-Yang Chou [this message]
2026-02-26 10:05   ` [PATCH 1/1] net/mlx5/core: Allocate ttc_params on heap Leon Romanovsky
2026-02-26 10:33     ` Cheng-Yang Chou
2026-02-26 18:15   ` Simon Horman
2026-02-27  2:38     ` Cheng-Yang Chou

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260226092857.1583984-2-yphbchou0911@gmail.com \
    --to=yphbchou0911@gmail.com \
    --cc=charlie910417@gmail.com \
    --cc=jserv@ccns.ncku.edu.tw \
    --cc=mbloch@nvidia.com \
    --cc=netdev@vger.kernel.org \
    --cc=saeedm@nvidia.com \
    --cc=tariqt@nvidia.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox