net/mlx5: Skip disabled vports when setting max TX speed
Subsystems (4)
Tariq Toukan
maintainerPATCH 1/1 net/mlx5: Skip disabled vports when setting max TX speed
From: Or Har-Toov <[email protected]>
When setting vports max TX speed during LAG activation or bond state changes, the code iterates over all eswitch vports. However, some vports may not be enabled yet.
Skip vports that are not enabled to avoid sending FW commands for uninitialized vports. Save the LAG aggregated speed in the vport struct so it can be applied when the vport is enabled later.
--- .../net/ethernet/mellanox/mlx5/core/eswitch.c | 21 +++++++++++++++++++ .../net/ethernet/mellanox/mlx5/core/eswitch.h | 1 + .../net/ethernet/mellanox/mlx5/core/lag/lag.c | 5 +++++ 3 files changed, 27 insertions(+)
drivers/net/ethernet/mellanox/mlx5/core/eswitch.c +21 -0
@@ -908,6 +908,24 @@ static void esw_vport_cleanup(struct mlx5_eswitch *esw, struct mlx5_vport *vportesw_vport_cleanup_acl (esw, vport); } +static void mlx5_esw_vport_set_max_tx_speed (struct mlx5_eswitch *esw, +struct mlx5_vport *vport) +{ +int ret; + +if (!MLX5_CAP_ESW (esw->dev, esw_vport_state_max_tx_speed)) +return ; + + ret =mlx5_modify_vport_max_tx_speed (esw->dev, +MLX5_VPORT_STATE_OP_MOD_ESW_VPORT , + vport->vport, true, + vport->agg_max_tx_speed); +if (ret) +mlx5_core_dbg (esw->dev, +"Failed to set vport %d speed %d, err=%d\n" , + vport->vport, vport->agg_max_tx_speed, ret); +} +int mlx5_esw_vport_enable (struct mlx5_eswitch *esw,struct mlx5_vport *vport,enum mlx5_eswitch_vport_event enabled_events) {
@@ -948,6 +966,9 @@ int mlx5_esw_vport_enable(struct mlx5_eswitch *esw, struct mlx5_vport *vport, esw->enabled_vports++;esw_debug (esw->dev,"Enabled VPORT(%d)\n" , vport_num); + +if (vport->agg_max_tx_speed) +mlx5_esw_vport_set_max_tx_speed (esw, vport); done:mutex_unlock (&esw->state_lock);return ret;
drivers/net/ethernet/mellanox/mlx5/core/eswitch.h +1 -0
@@ -247,6 +247,7 @@ struct mlx5_vport {enum mlx5_eswitch_vport_event enabled_events;int index;struct mlx5_devlink_port *dl_port; +u32 agg_max_tx_speed; };struct mlx5_esw_indir_table ;
drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c +5 -0
@@ -1274,6 +1274,11 @@ static void mlx5_lag_modify_device_vports_speed(struct mlx5_core_dev *mdev,if (vport->vport ==MLX5_VPORT_UPLINK )continue ; + vport->agg_max_tx_speed = speed; + +if (!vport->enabled) +continue ; + ret =mlx5_modify_vport_max_tx_speed (mdev, op_mod, vport->vport, true, speed);if (ret)
base-commit: f5b2772d14884f4be9e718644f1203d4d0e6f0d6
Signature · 1 line
2.44.0
Jakub Kicinski
maintainerThis is an AI-generated review of your patch. The human sending this email has considered the AI review valid, or at least plausible.
---
net/mlx5: Skip disabled vports when setting max TX speed
This commit modifies the LAG activation process to skip setting the maximum TX speed for disabled vports, preventing firmware commands from being sent to uninitialized vports. It stores the aggregated speed in the vport structure so it can be applied later if the vport is enabled.
Quoted 3 lines
drivers/net/ethernet/mellanox/mlx5/core/eswitch.c +0
-0
[ ... ]
drivers/net/ethernet/mellanox/mlx5/core/eswitch.c int mlx5_esw_vport_enable(struct mlx5_eswitch *esw, struct mlx5_vport *vport, · line 970
Quoted 6 lines
drivers/net/ethernet/mellanox/mlx5/core/eswitch.c +2
-0@@ -948,6 +966,9 @@ int mlx5_esw_vport_enable(struct mlx5_eswitch *esw, struct mlx5_vport *vport, esw->enabled_vports++;esw_debug (esw->dev,"Enabled VPORT(%d)\n" , vport_num); + +if (vport->agg_max_tx_speed)
Could dynamically allocated vports bypass the active LAG QoS speed limits?
If a new vport is allocated dynamically after the LAG is already active, it appears agg_max_tx_speed would be zero-initialized. When this new vport is subsequently enabled here, the condition evaluates to false, which would skip the firmware speed update entirely.
drivers/net/ethernet/mellanox/mlx5/core/eswitch.c int mlx5_esw_vport_enable(struct mlx5_eswitch *esw, struct mlx5_vport *vport, · line 971
Quoted 1 line
drivers/net/ethernet/mellanox/mlx5/core/eswitch.c +1
-0+mlx5_esw_vport_set_max_tx_speed (esw, vport);
Does this introduce a race condition with mlx5_lag_modify_device_vports_speed?
If the LAG thread is concurrently updating the speed:
LAG thread (lockless):vport->agg_max_tx_speed = speed;
if (!vport->enabled)
continue;
ESW thread (with esw->state_lock):vport->enabled = true;
...
if (vport->agg_max_tx_speed)
mlx5_esw_vport_set_max_tx_speed(esw, vport);
Since there are no shared locks or explicit memory barriers, could CPU reordering allow the LAG thread to see a false enabled state while the ESW thread sees a zero agg_max_tx_speed, resulting in neither thread issuing the firmware command?
Quoted 2 lines
drivers/net/ethernet/mellanox/mlx5/core/eswitch.c +0
-0done:mutex_unlock (&esw->state_lock);
[ ... ]
Quoted 3 lines
drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c +0
-0
[ ... ]
drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c static void mlx5_lag_modify_device_vports_speed(struct mlx5_core_dev *mdev, · line 1279
Quoted 7 lines
drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c +3
-0@@ -1274,6 +1274,11 @@ static void mlx5_lag_modify_device_vports_speed(struct mlx5_core_dev *mdev,if (vport->vport ==MLX5_VPORT_UPLINK )continue ; + vport->agg_max_tx_speed = speed; + +if (!vport->enabled)
Is there a regression here regarding the lifetime of the vport pointer?
This loop locklessly iterates over the esw->vports xarray. Because the xarray iteration drops the RCU read lock before executing the loop body, and mlx5_esw_vport_free() calls kfree() synchronously without an RCU grace period, could a concurrent vport deletion cause these new field accesses to operate on freed memory?
drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c static void mlx5_lag_modify_device_vports_speed(struct mlx5_core_dev *mdev, · line 1283
Quoted 4 lines
drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c +2
-0+continue ; + ret =mlx5_modify_vport_max_tx_speed (mdev, op_mod, vport->vport, true, speed);
Does this code contain a time-of-check to time-of-use regression that is affected by the lockless architecture here?
Looking at mlx5_modify_vport_max_tx_speed(), it queries the firmware admin_state and writes it back without holding esw->state_lock. If the LAG thread reads an UP state, but mlx5_esw_vport_disable() concurrently disables the vport (setting the hardware state to DOWN), could the LAG thread accidentally overwrite the admin_state back to UP, effectively reverting the disable action?
Quoted 1 line
drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c +0
-0if (ret)
Signature · 1 line
pw-bot: cr