Skip to contentSkip to conversation

mlx5e misc fixes 2025-11-09

PATCH Applied Tariq Toukan 4 participants 9 messages Nov 9, 2025 – Nov 23, 2025

Subsystems (6)
lore
Share & tools
lore

Tariq Toukan

author maintainer
#0 lore raw

cover mlx5e misc fixes 2025-11-09

Hi,

This patchset provides misc bug fixes from the team to the mlx5 Eth driver.

Thanks,
Tariq.

Carolina Jubran (1):
net/mlx5e: Fix missing error assignment in mlx5e_xfrm_add_state()

Cosmin Ratiu (1):
net/mlx5e: Trim the length of the num_doorbell error

Gal Pressman (3):
net/mlx5e: Fix maxrate wraparound in threshold between units net/mlx5e: Fix wraparound in rate limiting for values above 255 Gbps net/mlx5e: Fix potentially misleading debug message

 .../net/ethernet/mellanox/mlx5/core/devlink.c |  2 +-
 .../mellanox/mlx5/core/en_accel/ipsec.c       |  3 +-
 .../ethernet/mellanox/mlx5/core/en_dcbnl.c    | 33 ++++++++++++++++---
 3 files changed, 31 insertions(+), 7 deletions(-)

base-commit: 96a9178a29a6b84bb632ebeb4e84cf61191c73d5

Signature · 1 line
2.31.1
author maintainer
#1 lore raw

PATCH 1/5 net/mlx5e: Fix missing error assignment in mlx5e_xfrm_add_state()

From: Carolina Jubran <[email protected]>

Assign the return value of mlx5_eswitch_block_mode() to 'err' before checking it to avoid returning an uninitialized error code.

---
 drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec.c +2 -1
index 0a4fb8c92268..35d9530037a6 100644
@@ -804,7 +804,8 @@ static int mlx5e_xfrm_add_state(struct net_device *dev,
 		goto err_xfrm;
 	}
 
-	if (mlx5_eswitch_block_mode(priv->mdev))
+	err = mlx5_eswitch_block_mode(priv->mdev);
+	if (err)
 		goto unblock_ipsec;
 
 	if (x->props.mode == XFRM_MODE_TUNNEL &&
Signature · 1 line
2.31.1
author maintainer
#2 lore raw

PATCH 2/5 net/mlx5e: Trim the length of the num_doorbell error

In reply to Tariq Toukan

From: Cosmin Ratiu <[email protected]>

When trying to set num_doorbells to a value greater than the max number of channels, the error message was going over the netlink limit of 80 chars, truncating the most important part of the message, the number of channels.

Fix that by trimming the length a bit.

Fixes 11bbcfb7668c ("net/mlx5e: Use the 'num_doorbells' devlink param")
---
 drivers/net/ethernet/mellanox/mlx5/core/devlink.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/mellanox/mlx5/core/devlink.c +1 -1
index fceea83abbd7..887adf4807d1 100644
@@ -541,7 +541,7 @@ static int mlx5_devlink_num_doorbells_validate(struct devlink *devlink, u32 id,
 	max_num_channels = mlx5e_get_max_num_channels(mdev);
 	if (val32 > max_num_channels) {
 		NL_SET_ERR_MSG_FMT_MOD(extack,
-				       "Requested num_doorbells (%u) exceeds maximum number of channels (%u)",
+				       "Requested num_doorbells (%u) exceeds max number of channels (%u)",
 				       val32, max_num_channels);
 		return -EINVAL;
 	}
Signature · 1 line
2.31.1
author maintainer
#3 lore raw

PATCH 3/5 net/mlx5e: Fix maxrate wraparound in threshold between units

In reply to Tariq Toukan

From: Gal Pressman <[email protected]>

The previous calculation used roundup() which caused an overflow for rates between 25.5Gbps and 26Gbps.
For example, a rate of 25.6Gbps would result in using 100Mbps units with value of 256, which would overflow the 8 bits field.

Simplify the upper_limit_mbps calculation by removing the unnecessary roundup, and adjust the comparison to use <= to correctly handle the boundary condition.

Fixes d8880795dabf ("net/mlx5e: Implement DCBNL IEEE max rate")
---
 drivers/net/ethernet/mellanox/mlx5/core/en_dcbnl.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en_dcbnl.c +3 -2
index d166c0d5189e..345614471052 100644
@@ -595,18 +595,19 @@ static int mlx5e_dcbnl_ieee_setmaxrate(struct net_device *netdev,
 	struct mlx5_core_dev *mdev = priv->mdev;
 	u8 max_bw_value[IEEE_8021QAZ_MAX_TCS];
 	u8 max_bw_unit[IEEE_8021QAZ_MAX_TCS];
-	__u64 upper_limit_mbps = roundup(255 * MLX5E_100MB, MLX5E_1GB);
+	__u64 upper_limit_mbps;
 	int i;
 
 	memset(max_bw_value, 0, sizeof(max_bw_value));
 	memset(max_bw_unit, 0, sizeof(max_bw_unit));
+	upper_limit_mbps = 255 * MLX5E_100MB;
 
 	for (i = 0; i <= mlx5_max_tc(mdev); i++) {
 		if (!maxrate->tc_maxrate[i]) {
 			max_bw_unit[i]  = MLX5_BW_NO_LIMIT;
 			continue;
 		}
-		if (maxrate->tc_maxrate[i] < upper_limit_mbps) {
+		if (maxrate->tc_maxrate[i] <= upper_limit_mbps) {
 			max_bw_value[i] = div_u64(maxrate->tc_maxrate[i],
 						  MLX5E_100MB);
 			max_bw_value[i] = max_bw_value[i] ? max_bw_value[i] : 1;
Signature · 1 line
2.31.1
author maintainer
#4 lore raw

PATCH 4/5 net/mlx5e: Fix wraparound in rate limiting for values above 255 Gbps

In reply to Tariq Toukan

From: Gal Pressman <[email protected]>

Add validation to reject rates exceeding 255 Gbps that would overflow the 8 bits max bandwidth field.

Fixes d8880795dabf ("net/mlx5e: Implement DCBNL IEEE max rate")
---
 drivers/net/ethernet/mellanox/mlx5/core/en_dcbnl.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
drivers/net/ethernet/mellanox/mlx5/core/en_dcbnl.c +9 -1
index 345614471052..d88a48210fdc 100644
@@ -596,11 +596,13 @@ static int mlx5e_dcbnl_ieee_setmaxrate(struct net_device *netdev,
 	u8 max_bw_value[IEEE_8021QAZ_MAX_TCS];
 	u8 max_bw_unit[IEEE_8021QAZ_MAX_TCS];
 	__u64 upper_limit_mbps;
+	__u64 upper_limit_gbps;
 	int i;
 
 	memset(max_bw_value, 0, sizeof(max_bw_value));
 	memset(max_bw_unit, 0, sizeof(max_bw_unit));
 	upper_limit_mbps = 255 * MLX5E_100MB;
+	upper_limit_gbps = 255 * MLX5E_1GB;
 
 	for (i = 0; i <= mlx5_max_tc(mdev); i++) {
 		if (!maxrate->tc_maxrate[i]) {
@@ -612,10 +614,16 @@ static int mlx5e_dcbnl_ieee_setmaxrate(struct net_device *netdev,
 						  MLX5E_100MB);
 			max_bw_value[i] = max_bw_value[i] ? max_bw_value[i] : 1;
 			max_bw_unit[i]  = MLX5_100_MBPS_UNIT;
-		} else {
+		} else if (max_bw_value[i] <= upper_limit_gbps) {
 			max_bw_value[i] = div_u64(maxrate->tc_maxrate[i],
 						  MLX5E_1GB);
 			max_bw_unit[i]  = MLX5_GBPS_UNIT;
+		} else {
+			netdev_err(netdev,
+				   "tc_%d maxrate %llu Kbps exceeds limit %llu\n",
+				   i, maxrate->tc_maxrate[i],
+				   upper_limit_gbps);
+			return -EINVAL;
 		}
 	}
 
Signature · 1 line
2.31.1
#5 lore raw

Re: [PATCH net 4/5] net/mlx5e: Fix wraparound in rate limiting for values above 255 Gbps

Quoted 2 lines · Gal Pressman

Add validation to reject rates exceeding 255 Gbps that would overflow the 8 bits max bandwidth field.

Hi Gal, Tariq, Paolo,

While reviewing this commit (43b27d1bd88a) for backporting, I believe I've found a logic error in the validation condition.

The issue is on line 617:

    } else if (max_bw_value[i] <= upper_limit_gbps) {
        max_bw_value[i] = div_u64(maxrate->tc_maxrate[i], MLX5E_1GB);
        max_bw_unit[i]  = MLX5_GBPS_UNIT;

Here, max_bw_value[i] is used in the condition before it's assigned in this branch. This appears to be a copy-paste error from the previous commit a7bf4d5063c7 ("net/mlx5e: Fix maxrate wraparound in threshold between units").

The condition should check the input value maxrate->tc_maxrate[i], not the output variable max_bw_value[i]:

    } else if (maxrate->tc_maxrate[i] <= upper_limit_gbps) {

This matches the pattern used in the first branch:

    if (maxrate->tc_maxrate[i] <= upper_limit_mbps) {
        max_bw_value[i] = div_u64(maxrate->tc_maxrate[i], MLX5E_100MB);
        ...
    }

Impact:
-------
The current code will compare an uninitialized (or stale from previous iteration) max_bw_value[i] against upper_limit_gbps, rather than comparing the actual requested rate. This means:

1. For rates between 25.5 Gbps and 255 Gbps:
- If max_bw_value[i] happens to be 0 (from memset), the condition

     (0 <= 255000000000) is true, incorrectly allowing the GBPS path

- The rate gets converted to Gbps units, which may be correct by accident

2. The validation in the else clause that rejects rates > 255 Gbps may never trigger correctly if max_bw_value[i] from a previous iteration is small enough

3. For i > 0, max_bw_value[i] contains the computed value from the previous TC, leading to incorrect branching logic

This makes the overflow validation unreliable and could allow rates that should be rejected, or reject rates that should be accepted.

Suggested fix:
--------------

drivers/net/ethernet/mellanox/mlx5/core/en_dcbnl.c +1 -1
index d88a48210fdc..XXXXXXXX 100644
@@ -614,7 +614,7 @@ static int mlx5e_dcbnl_ieee_setmaxrate(struct net_device *netdev,
 						  MLX5E_100MB);
 			max_bw_value[i] = max_bw_value[i] ? max_bw_value[i] : 1;
 			max_bw_unit[i]  = MLX5_100_MBPS_UNIT;
-		} else if (max_bw_value[i] <= upper_limit_gbps) {
+		} else if (maxrate->tc_maxrate[i] <= upper_limit_gbps) {
 			max_bw_value[i] = div_u64(maxrate->tc_maxrate[i],
 						  MLX5E_1GB);
 			max_bw_unit[i]  = MLX5_GBPS_UNIT;

Let me know if you'd like me to send a formal patch for this.

Thanks,
--
Danielle Costantino
Meta Platforms, Inc.
Flagged by Claude Code with https://github.com/masoncl/review-prompts/

#6 lore raw

Re: [PATCH net 4/5] net/mlx5e: Fix wraparound in rate limiting for values above 255 Gbps

Quoted 31 lines · Danielle Costantino
Quoted 2 lines · Gal Pressman

Add validation to reject rates exceeding 255 Gbps that would overflow the 8 bits max bandwidth field.

Hi Gal, Tariq, Paolo,

While reviewing this commit (43b27d1bd88a) for backporting, I believe I've found a logic error in the validation condition.

The issue is on line 617:

    } else if (max_bw_value[i] <= upper_limit_gbps) {
        max_bw_value[i] = div_u64(maxrate->tc_maxrate[i], MLX5E_1GB);
        max_bw_unit[i]  = MLX5_GBPS_UNIT;

Suggested fix:
--------------

drivers/net/ethernet/mellanox/mlx5/core/en_dcbnl.c +1 -1
index d88a48210fdc..XXXXXXXX 100644
@@ -614,7 +614,7 @@ static int mlx5e_dcbnl_ieee_setmaxrate(struct net_device *netdev,
 						  MLX5E_100MB);
 			max_bw_value[i] = max_bw_value[i] ? max_bw_value[i] : 1;
 			max_bw_unit[i]  = MLX5_100_MBPS_UNIT;
-		} else if (max_bw_value[i] <= upper_limit_gbps) {
+		} else if (maxrate->tc_maxrate[i] <= upper_limit_gbps) {
 			max_bw_value[i] = div_u64(maxrate->tc_maxrate[i],
 						  MLX5E_1GB);
 			max_bw_unit[i]  = MLX5_GBPS_UNIT;
Quoted 1 line

Let me know if you'd like me to send a formal patch for this.

Hi Danielle,
Your fix is correct, please submit a patch.

Thanks for catching this!

author maintainer
#7 lore raw

PATCH 5/5 net/mlx5e: Fix potentially misleading debug message

In reply to Tariq Toukan

From: Gal Pressman <[email protected]>

Change the debug message to print the correct units instead of always assuming Gbps, as the value can be in either 100 Mbps or 1 Gbps units.

Fixes 5da8bc3effb6 ("net/mlx5e: DCBNL, Add debug messages log")
---
 .../net/ethernet/mellanox/mlx5/core/en_dcbnl.c | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en_dcbnl.c +16 -2
index d88a48210fdc..9b93da4d52f6 100644
@@ -598,6 +598,19 @@ static int mlx5e_dcbnl_ieee_setmaxrate(struct net_device *netdev,
 	__u64 upper_limit_mbps;
 	__u64 upper_limit_gbps;
 	int i;
+	struct {
+		int scale;
+		const char *units_str;
+	} units[] = {
+		[MLX5_100_MBPS_UNIT] = {
+			.scale = 100,
+			.units_str = "Mbps",
+		},
+		[MLX5_GBPS_UNIT] = {
+			.scale = 1,
+			.units_str = "Gbps",
+		},
+	};
 
 	memset(max_bw_value, 0, sizeof(max_bw_value));
 	memset(max_bw_unit, 0, sizeof(max_bw_unit));
@@ -628,8 +641,9 @@ static int mlx5e_dcbnl_ieee_setmaxrate(struct net_device *netdev,
 	}
 
 	for (i = 0; i < IEEE_8021QAZ_MAX_TCS; i++) {
-		netdev_dbg(netdev, "%s: tc_%d <=> max_bw %d Gbps\n",
-			   __func__, i, max_bw_value[i]);
+		netdev_dbg(netdev, "%s: tc_%d <=> max_bw %u %s\n", __func__, i,
+			   max_bw_value[i] * units[max_bw_unit[i]].scale,
+			   units[max_bw_unit[i]].units_str);
 	}
 
 	return mlx5_modify_port_ets_rate_limit(mdev, max_bw_value, max_bw_unit);
Signature · 1 line
2.31.1
#8 lore raw
In reply to Tariq Toukan
This series was applied to netdev/net.git (main) by Paolo Abeni <[email protected]>:

Hello:

This series was applied to netdev/net.git (main)
by Paolo Abeni <[email protected]>:

Quoted 9 lines · On Sun, 9 Nov 2025 11:37:48 +0200 you wrote:

Hi,

This patchset provides misc bug fixes from the team to the mlx5 Eth driver.

Thanks,
Tariq.

[...]

Here is the summary with links:
- [net,1/5] net/mlx5e: Fix missing error assignment in mlx5e_xfrm_add_state()

    https://git.kernel.org/netdev/net/c/0bcd5b3b50cc
  - [net,2/5] net/mlx5e: Trim the length of the num_doorbell error
    https://git.kernel.org/netdev/net/c/2dc768c05217
  - [net,3/5] net/mlx5e: Fix maxrate wraparound in threshold between units
    https://git.kernel.org/netdev/net/c/a7bf4d5063c7
  - [net,4/5] net/mlx5e: Fix wraparound in rate limiting for values above 255 Gbps
    https://git.kernel.org/netdev/net/c/43b27d1bd88a
  - [net,5/5] net/mlx5e: Fix potentially misleading debug message
    https://git.kernel.org/netdev/net/c/9fcc2b6c1052

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html