net/mlx5: Lag, split aggregate speed into oper and max helpers
Subsystems (4)
Tariq Toukan
maintainerPATCH v2 1/1 net/mlx5: Lag, split aggregate speed into oper and max helpers
From: Or Har-Toov <[email protected]>
mlx5_lag_sum_devices_speed computes the LAG aggregate by summing oper speeds across all ports. This has two bugs.
First, it relies on the assumption that a port whose carrier is down will report an oper speed of zero and therefore not contribute to the sum. This assumption does not always hold: when the link partner disconnects the port transitions to DOWN state but firmware may still report a non-zero oper speed, causing the aggregate to include a port that is not actively carrying traffic.
Second, in active-backup mode only one port transmits at a time, so the aggregate should reflect a single port speed rather than the sum of all ports.
Fix this by splitting mlx5_lag_sum_devices_speed into two helpers. mlx5_lag_get_devices_oper_speed reflects the speed currently available:
it queries the vport state of each port and skips any port that is not UP, rather than relying on oper speed being zero. mlx5_lag_get_devices_max_speed is state-independent and returns the maximum achievable speed used as a fallback when speed is 0; for active-backup it takes the maximum single-port speed instead of the sum.
--- .../net/ethernet/mellanox/mlx5/core/lag/lag.c | 79 +++++++++++++------ 1 file changed, 57 insertions(+), 22 deletions(-)
V2:
- MPESW state check now goes through mlx5_query_vport_max_tx_speed(), propagating a failed FW query as an error instead of silently treating it as VPORT_STATE_DOWN.
- Take maximum single-port speed for max in active-backup instead of a sum.
V1:
https://lore.kernel.org/all/[email protected]/
drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c +57 -22
@@ -1432,30 +1432,40 @@ static bool mlx5_lag_should_disable_lag(struct mlx5_lag *ldev, bool do_bond) }#ifdef CONFIG_MLX5_ESWITCH -static int -mlx5_lag_sum_devices_speed (struct mlx5_lag *ldev,u32 *sum_speed, -int (*get_speed)(struct mlx5_core_dev *,u32 *)) +static int mlx5_lag_get_devices_oper_speed (struct mlx5_lag *ldev, +u32 *sum_speed) { -struct mlx5_core_dev *pf_mdev; -struct lag_func *pf;int pf_idx; -u32 speed; -int ret; *sum_speed =0 ;mlx5_ldev_for_each (pf_idx,0 , ldev) { +u8 opmod =MLX5_VPORT_STATE_OP_MOD_VNIC_VPORT ; +struct mlx5_core_dev *pf_mdev; +struct lag_func *pf; +u32 speed; +u8 state; +int ret; + pf =mlx5_lag_pf (ldev, pf_idx);if (!pf)continue ; pf_mdev = pf->dev;if (!pf_mdev)continue ; + ret =mlx5_query_vport_max_tx_speed (pf_mdev, opmod,0 ,0 , + &speed, &state); +if (ret) { +mlx5_core_dbg (pf_mdev,"State query failed (err=%d)\n" , + ret); +return ret; + } +if (state !=VPORT_STATE_UP ) +continue ; - ret =get_speed (pf_mdev, &speed); + ret =mlx5_port_oper_linkspeed (pf_mdev, &speed);if (ret) {mlx5_core_dbg (pf_mdev, -"Failed to get device speed using %ps. Device %s speed is not available (err=%d)\n" , - get_speed,dev_name (pf_mdev->device), +"Failed to get oper speed (err=%d)\n" , ret);return ret; }
@@ -1466,17 +1476,42 @@ mlx5_lag_sum_devices_speed(struct mlx5_lag *ldev, u32 *sum_speed,return 0 ; } -static int mlx5_lag_sum_devices_max_speed (struct mlx5_lag *ldev,u32 *max_speed) +static int mlx5_lag_get_devices_max_speed (struct mlx5_lag *ldev,u32 *max_speed) { -return mlx5_lag_sum_devices_speed (ldev, max_speed, - mlx5_port_max_linkspeed); -} +bool take_max; +int pf_idx; -static int mlx5_lag_sum_devices_oper_speed (struct mlx5_lag *ldev, -u32 *oper_speed) -{ -return mlx5_lag_sum_devices_speed (ldev, oper_speed, - mlx5_port_oper_linkspeed); + take_max = ldev->tracker.tx_type ==NETDEV_LAG_TX_TYPE_ACTIVEBACKUP ; +if (ldev->mode ==MLX5_LAG_MODE_MPESW ) + take_max = false; + + *max_speed =0 ; +mlx5_ldev_for_each (pf_idx,0 , ldev) { +struct mlx5_core_dev *pf_mdev; +struct lag_func *pf; +u32 speed; +int ret; + + pf =mlx5_lag_pf (ldev, pf_idx); +if (!pf) +continue ; + pf_mdev = pf->dev; +if (!pf_mdev) +continue ; + + ret =mlx5_port_max_linkspeed (pf_mdev, &speed); +if (ret) { +mlx5_core_dbg (pf_mdev, +"Failed to get max speed (err=%d)\n" , + ret); +return ret; + } + + *max_speed = take_max ? +max (*max_speed, speed) : *max_speed + speed; + } + +return 0 ; } static void mlx5_lag_modify_device_vports_speed(struct mlx5_core_dev *mdev,
@@ -1525,7 +1560,7 @@ void mlx5_lag_set_vports_agg_speed(struct mlx5_lag *ldev)int pf_idx;if (ldev->mode ==MLX5_LAG_MODE_MPESW ) { -if (mlx5_lag_sum_devices_oper_speed (ldev, &speed)) +if (mlx5_lag_get_devices_oper_speed (ldev, &speed))return ; }else { speed = ldev->tracker.bond_speed_mbps;
@@ -1533,8 +1568,8 @@ void mlx5_lag_set_vports_agg_speed(struct mlx5_lag *ldev)return ; } -/* If speed is not set, use the sum of max speeds of all PFs */ -if (!speed &&mlx5_lag_sum_devices_max_speed (ldev, &speed)) +/* If speed is not set, fall back to the max achievable speed */ +if (!speed &&mlx5_lag_get_devices_max_speed (ldev, &speed))return ; speed = speed /MLX5_MAX_TX_SPEED_UNIT ;
base-commit: 99b43ede9e355ba35244cc9470bf1819774ce39d
Signature · 1 line
2.44.0
[email protected]
AI reviewThis is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:
Hi!
This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:
- How the issue was discovered, e.g. hit in production, hit during development, syzbot report, manual code inspection, LLM or static analysis tool scan.
- Whether the issue was actually triggered, or is only theoretical (e.g. found by code inspection). If it was triggered please include the symptoms, like the stack trace or error messages.
- What hardware the change was tested on. For driver fixes please mention the device (and if relevant firmware version) used for testing, or say that the change was not tested on real hardware.
Please do not repost the series just to address the above. Instead, reply to this email with the missing information, so that reviewers can take it into account. If the series needs another revision for other reasons, please include the information in the commit messages then.
The evaluation is done by an LLM so it may be wrong, if you think that is the case please reply and explain.
Quoted 20 lines · On 30/09/2026 20:08, [email protected] wrote:
External email: Use caution opening links or attachments
Hi!
This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:
- How the issue was discovered, e.g. hit in production, hit during development, syzbot report, manual code inspection, LLM or static analysis tool scan.
- Whether the issue was actually triggered, or is only theoretical (e.g. found by code inspection). If it was triggered please include the symptoms, like the stack trace or error messages.
- What hardware the change was tested on. For driver fixes please mention the device (and if relevant firmware version) used for testing, or say that the change was not tested on real hardware.
Quoted 8 lines
Please do not repost the series just to address the above. Instead, reply to this email with the missing information, so that reviewers can take it into account. If the series needs another revision for other reasons, please include the information in the commit messages then.
The evaluation is done by an LLM so it may be wrong, if you think that is the case please reply and explain.
The bugs were discovered during integration and reproduced on a back-to-back ConnectX-8 setup.
The first bug (stale oper speed when link goes down) was observed: after the link partner disconnected, the aggregate TX speed reported to vports remained full speed because firmware still returned the last oper speed, causing vports to be rate-limited to the old aggregate speed.
The second bug (active-backup summing all port speeds instead of the active port's speed) was also triggered: in active-backup mode the computed aggregate was double the expected value since both port speeds were summed even though only one port was active.
[email protected]
AI reviewSashiko has reviewed this patch and found no issues. It looks great!
Quoted 24 lines
From: Or Har-Toov <[email protected]>
mlx5_lag_sum_devices_speedcomputes the LAG aggregate by summing oper speeds across all ports. This has two bugs.First, it relies on the assumption that a port whose carrier is down will report an oper speed of zero and therefore not contribute to the sum. This assumption does not always hold: when the link partner disconnects the port transitions to DOWN state but firmware may still report a non-zero oper speed, causing the aggregate to include a port that is not actively carrying traffic.
Second, in active-backup mode only one port transmits at a time, so the aggregate should reflect a single port speed rather than the sum of all ports.
Fix this by splitting
mlx5_lag_sum_devices_speedinto two helpers.mlx5_lag_get_devices_oper_speedreflects the speed currently available:
it queries the vport state of each port and skips any port that is not UP, rather than relying on oper speed being zero.mlx5_lag_get_devices_max_speedis state-independent and returns the maximum achievable speed used as a fallback when speed is 0; for active-backup it takes the maximum single-port speed instead of the sum.
Quoted 5 lines
Fixes 28ea6036dad2 ("net/mlx5: Handle port and vport speed change events in MPESW")Signed-off-by Or Har-Toov <[email protected]>Reviewed-by Shay Drori <[email protected]>Reviewed-by Mark Bloch <[email protected]>Signed-off-by Tariq Toukan <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:
Quoted 5 lines · On Wed, 30 Sep 2026 20:04:06 +0300 you wrote:
From: Or Har-Toov <[email protected]>
mlx5_lag_sum_devices_speedcomputes the LAG aggregate by summing oper speeds across all ports. This has two bugs.
Quoted 8 lines
First, it relies on the assumption that a port whose carrier is down will report an oper speed of zero and therefore not contribute to the sum. This assumption does not always hold: when the link partner disconnects the port transitions to DOWN state but firmware may still report a non-zero oper speed, causing the aggregate to include a port that is not actively carrying traffic.
[...]
Here is the summary with links:
- [net,V2] net/mlx5: Lag, split aggregate speed into oper and max helpers
https://git.kernel.org/netdev/net/c/fe4114221364
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html