net/mlx5: fixes for LAG max_tx_speed update flow
Subsystems (6)
Tariq Toukan
maintainerv2 cover net/mlx5: fixes for LAG max_tx_speed update flow
Hi,
Commit 50f1d188c580 ("net/mlx5: Propagate LAG effective max_tx_speed to vports") added a mechanism that computes the aggregated LAG TX speed and programs it into each vport's max_tx_speed via MODIFY_VPORT_STATE. This series fixes bugs found in that flow.
The bugs:
1. The aggregate was not limited by the NIC's PCIe bandwidth. It was taken from the bond speed, which is calculated from PTYS, and PTYS is not bounded by the PCI bandwidth of the NIC. FW initializes max_tx_speed to the minimum of the port speed and the PCIe bandwidth, so modifying it with a value computed by different rules changes the meaning of the field rather than updating it.
2. RoCE LAG never told the RDMA layer about speed changes. The NIC is considered to be in a bare metal configuration, without a valid or enabled eswitch, so there are no VF, SF or PF rep vports to modify and no event of speed change was raised.
3. LAG teardown did not reset the vport speeds correctly. It wrote back the oper speed of the link, which reads 0 for a down link, and FW ignores max_tx_speed=0 as "not provided", so the aggregate stayed on the vports. With the link up, it replaced the max_tx_speed of a vport with the speed of the link instead of the value the vport had before the LAG, for example when FW limits it by the PCIe bandwidth.
Patch #1 caches the TX-enabled aggregate speed and programs that into
the vports, instead of reading it back from the bond netdev.
Patch #2 limits the aggregated TX speed by the NIC's PCIe bandwidth.
Patch #3 notifies the RDMA layer of LAG aggregate speed changes via a
new driver event.
Patch #4 saves the max_tx_speed of each vport when it is enabled and
restores it at LAG teardown, with a link-derived fallback when no value was saved or the link is down. It fixes bug 3.
Regards,
Tariq
V2:
- Patch "cache and use TX-enabled aggregate speed for vports": only TX-enabled, link-up ports from the LAG tracker are counted in non-MPESW modes, which was part of the split patch in v1 and moved here, mlx5_lag_update_agg_speed() now returns int and propagates query errors, the cached speed starts as unknown and a failed measurement invalidates it, so that mlx5_lag_query_aggregated_speed() returns -ENODATA instead of a zero speed.
- Patch "limit aggregated TX speed by PCIe bandwidth": the aggregate is clamped as a whole rather than clamping each port's speed to its own PCIe bandwidth before summing, which could let the total reach a multiple of a shared link's real bandwidth. Only ports that contribute to the aggregate are counted. In Socket Direct the bandwidths of the mdevs of a port are summed, and a bandwidth that cannot be read fails the calculation instead of skipping the clamp.
- Patch "notify IB uplink on LAG aggregate speed change": the event is raised whenever the cached aggregate changes, in any LAG mode, and the commit message describes the gap it closes.
- New patch: "Lag, save and restore vport max_tx_speed across LAG".
V1:
https://lore.kernel.org/all/[email protected]/
Or Har-Toov (4):
{RDMA,net}/mlx5: cache and use TX-enabled aggregate speed for vports net/mlx5: Lag, limit aggregated TX speed by PCIe bandwidth {RDMA,net}/mlx5: notify IB uplink on LAG aggregate speed change net/mlx5: Lag, save and restore vport max_tx_speed across LAG
drivers/infiniband/hw/mlx5/main.c | 12 +- .../net/ethernet/mellanox/mlx5/core/esw/qos.c | 1 + .../net/ethernet/mellanox/mlx5/core/eswitch.c | 22 ++ .../net/ethernet/mellanox/mlx5/core/eswitch.h | 1 + .../net/ethernet/mellanox/mlx5/core/lag/lag.c | 251 +++++++++++++++--- .../net/ethernet/mellanox/mlx5/core/lag/lag.h | 17 +- drivers/pci/pci.c | 16 ++ include/linux/mlx5/device.h | 1 + include/linux/mlx5/driver.h | 2 +- include/linux/pci.h | 2 + 10 files changed, 291 insertions(+), 34 deletions(-)
base-commit: f4377bf85887f57b59abb5479f7660a81ffe4449
Signature · 1 line
2.44.0
Tariq Toukan
maintainerPATCH v2 1/4 {RDMA,net}/mlx5: cache and use TX-enabled aggregate speed for vports
From: Or Har-Toov <[email protected]>
Cache aggregate TX-enabled speed we calculated, and use it instead of querying the bond speed so we can, in the following patch, limit it by the PCI bandwidth.
The bond speed takes the calculation from PTYS, and PTYS is not bounded by the PCI bandwidth of the NIC.
The max-speed fallback in mlx5_lag_set_vports_agg_speed() is local to VF/SF vport rate-limit programming; agg_speed_mbps stores operational speed only, and mlx5_lag_query_aggregated_speed() correctly returns zero when all member links are down.
Until the aggregate has been measured, or after a failed measurement, mlx5_lag_query_aggregated_speed() returns -ENODATA.
--- drivers/infiniband/hw/mlx5/main.c | 2 +- .../net/ethernet/mellanox/mlx5/core/esw/qos.c | 1 + .../net/ethernet/mellanox/mlx5/core/lag/lag.c | 86 +++++++++++++++---- .../net/ethernet/mellanox/mlx5/core/lag/lag.h | 16 +++- include/linux/mlx5/driver.h | 2 +- 5 files changed, 84 insertions(+), 23 deletions(-)
v1:
https://lore.kernel.org/all/[email protected]/
Changes in v2:
- Count only TX-enabled, link-up ports from the LAG tracker for non-MPESW modes; MPESW keeps the vport state check
- mlx5_lag_update_agg_speed() returns an error, and mlx5_lag_set_vports_agg_speed() bails out on failure instead of using the previous cached speed; the #else stub checks the return too
- Stop exporting mlx5_lag_query_bond_speed(), which has no users outside mlx5_core
- Describe in the changelog what mlx5_lag_query_aggregated_speed() returns when all member links are down
- Start agg_speed_mbps as SPEED_UNKNOWN and reset it to SPEED_UNKNOWN on teardown; mlx5_lag_query_aggregated_speed() returns -ENODATA instead of a zero speed until the first successful measurement
- A failed measurement invalidates the cached speed
drivers/infiniband/hw/mlx5/main.c +1 -1
@@ -1654,7 +1654,7 @@ static int mlx5_ib_query_port_speed_from_bond(struct mlx5_ib_dev *dev,u32 bond_speed;int err; - err =mlx5_lag_query_bond_speed (mdev, &bond_speed); + err =mlx5_lag_query_aggregated_speed (mdev, &bond_speed);if (err)return err;
drivers/net/ethernet/mellanox/mlx5/core/esw/qos.c +1 -0
@@ -5,6 +5,7 @@#include "lib/mlx5.h" #include "esw/qos.h" #include "en/port.h" +#include "lag/lag.h" #define CREATE_TRACE_POINTS #include "diag/qos_tracepoint.h"
drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c +67 -19
142 lines not on this page · raw message
drivers/net/ethernet/mellanox/mlx5/core/lag/lag.h +14 -2
@@ -99,6 +99,7 @@ struct mlx5_lag {/* Protect lag fields/state changes */ struct mutex lock;struct lag_mpesw lag_mpesw; +u32 agg_speed_mbps; }; static inline struct mlx5_lag *
@@ -258,12 +259,23 @@ void mlx5_lag_rescan_dev_locked(struct mlx5_lag *ldev,void mlx5_lag_add_devices_filter (struct mlx5_lag *ldev,u32 filter);struct mlx5_devcom_comp_dev *mlx5_lag_get_devcom_comp (struct mlx5_lag *ldev); +int mlx5_lag_update_agg_speed (struct mlx5_lag *ldev); +void mlx5_lag_reset_agg_speed (struct mlx5_lag *ldev); +int mlx5_lag_query_bond_speed (struct mlx5_core_dev *dev,u32 *speed); +#ifdef CONFIG_MLX5_ESWITCH void mlx5_lag_set_vports_agg_speed (struct mlx5_lag *ldev);void mlx5_lag_reset_vports_speed (struct mlx5_lag *ldev);#else -static inline void mlx5_lag_set_vports_agg_speed (struct mlx5_lag *ldev) {} -static inline void mlx5_lag_reset_vports_speed (struct mlx5_lag *ldev) {} +static inline void mlx5_lag_set_vports_agg_speed (struct mlx5_lag *ldev) +{ +mlx5_lag_update_agg_speed (ldev); +} + +static inline void mlx5_lag_reset_vports_speed (struct mlx5_lag *ldev) +{ +mlx5_lag_reset_agg_speed (ldev); +}#endif static inline bool mlx5_lag_is_supported (struct mlx5_core_dev *dev)
include/linux/mlx5/driver.h +1 -1
@@ -1154,7 +1154,7 @@ int mlx5_cmd_destroy_vport_lag(struct mlx5_core_dev *dev);bool mlx5_lag_is_roce (struct mlx5_core_dev *dev);bool mlx5_lag_is_sriov (struct mlx5_core_dev *dev);bool mlx5_lag_is_active (struct mlx5_core_dev *dev); -int mlx5_lag_query_bond_speed (struct mlx5_core_dev *dev,u32 *speed); +int mlx5_lag_query_aggregated_speed (struct mlx5_core_dev *dev,u32 *speed);bool mlx5_lag_mode_is_hash (struct mlx5_core_dev *dev);bool mlx5_lag_is_master (struct mlx5_core_dev *dev);bool mlx5_lag_is_shared_fdb (struct mlx5_core_dev *dev);
Signature · 1 line
2.44.0
[email protected]
AI reviewRe: [PATCH net V2 1/4] {RDMA,net}/mlx5: cache and use TX-enabled aggregate speed for vports
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] net/mlx5: lag: missing agg_speed_mbps reset on MPESW and mode-change teardown --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] net/mlx5: lag: missing agg_speed_mbps reset on MPESW and mode-change teardown --
commit ce16ef57f040ab430add649db26c3f383cbab840
Author: Or Har-Toov <[email protected]>
{RDMA,net}/mlx5: cache and use TX-enabled aggregate speed for vports
This commit caches the calculated operational TX-enabled aggregate speed in struct mlx5_lag and exposes mlx5_lag_query_aggregated_speed() to query it instead of the bond speed. It also resets the cached speed to SPEED_UNKNOWN via mlx5_lag_reset_agg_speed() when resetting vports speed.
Quoted 4 lines
drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c +0
-0
[ ... ]
drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c void mlx5_lag_reset_vports_speed(struct mlx5_lag *ldev) · line 1631
Quoted 8 lines
drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c +1
-0@@ -1594,6 +1625,7 @@ void mlx5_lag_reset_vports_speed(struct mlx5_lag *ldev)int pf_idx;int ret; +mlx5_lag_reset_agg_speed (ldev);mlx5_ldev_for_each (pf_idx,0 , ldev) { pf =mlx5_lag_pf (ldev, pf_idx);if (!pf)
[Severity: Medium]
Does calling mlx5_lag_reset_agg_speed() only from mlx5_lag_reset_vports_speed() miss resetting ldev->agg_speed_mbps (and vport speeds) when LAG is torn down via MPESW disable or mode changes?
Currently, mlx5_lag_reset_vports_speed() is only called from mlx5_do_bond() when mlx5_lag_should_disable_lag() returns true:
drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c:mlx5_do_bond() {
...
} else if (mlx5_lag_should_disable_lag(ldev, do_bond)) {
mlx5_lag_reset_vports_speed(ldev);
mlx5_disable_lag(ldev);
}
}where mlx5_lag_should_disable_lag() checks:
return !do_bond && __mlx5_lag_is_active(ldev) && ldev->mode != MLX5_LAG_MODE_MPESW;
When MPESW LAG is enabled via mlx5_lag_enable_mpesw() -> mlx5_lag_shared_fdb_create(), mlx5_lag_set_vports_agg_speed() populates ldev->agg_speed_mbps (and mlx5_mpesw_speed_update_work() updates it). However, when MPESW is torn down via mlx5_lag_disable_mpesw():
drivers/net/ethernet/mellanox/mlx5/core/lag/mpesw.c:mlx5_lag_disable_mpesw() {
if (ldev->mode != MLX5_LAG_MODE_MPESW)
return;
mlx5_mpesw_metadata_cleanup(ldev);
mlx5_lag_shared_fdb_destroy(ldev, MLX5_LAG_FILTER_ALL);
if (mlx5_lag_has_sd_group(ldev))
mlx5_mpesw_restore_sd_fdb(ldev);
}neither mlx5_lag_reset_vports_speed() nor mlx5_lag_reset_agg_speed() is called, and mlx5_lag_should_disable_lag() explicitly excludes MLX5_LAG_MODE_MPESW.
Similarly, during eswitch mode or SR-IOV changes, mlx5_lag_disable_change() disables an active LAG directly without calling mlx5_lag_reset_vports_speed() or mlx5_lag_reset_agg_speed():
drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c:mlx5_lag_disable_change() {
...
ldev->mode_changes_in_progress++;
if (__mlx5_lag_is_active(ldev)) {
if (ldev->mode == MLX5_LAG_MODE_MPESW)
mlx5_lag_disable_mpesw(ldev);
else
mlx5_disable_lag(ldev);
}
}Because mlx5_disable_lag() -> mlx5_deactivate_lag() clears ldev->mode to MLX5_LAG_MODE_NONE, when mlx5_lag_enable_change() later runs mlx5_do_bond(), __mlx5_lag_is_active(ldev) is already false. If do_bond is false (for example, if mlx5_lag_check_prereq(ldev) is now false after a mode change or if the bond was removed during the transition), mlx5_lag_should_disable_lag() evaluates to false and the reset never runs.
Wouldn't this leave a stale speed in ldev->agg_speed_mbps (and stale vport rate limits) after teardown, causing mlx5_lag_query_aggregated_speed() to return the old speed instead of -ENODATA, and in the subsequent patch ("{RDMA,net}/mlx5: notify IB uplink on LAG aggregate speed change") causing mlx5_lag_update_agg_speed() to compare against the stale old_speed and suppress IB_EVENT_DEVICE_SPEED_CHANGE if LAG is re-activated at the same aggregate speed?
[ ... ]
Quoted 3 lines
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Re: [PATCH net V2 1/4] {RDMA,net}/mlx5: cache and use TX-enabled aggregate speed for vports
Quoted 102 lines · On 23/10/2026 22:32, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] net/mlx5: lag: missingagg_speed_mbpsreset on MPESW and mode-change teardown --commit
ce16ef57f040ab430add649db26c3f383cbab840
Author: Or Har-Toov <[email protected]>{RDMA,net}/mlx5: cache and use TX-enabled aggregate speed for vports
This commit caches the calculated operational TX-enabled aggregate speed in struct
mlx5_lagand exposesmlx5_lag_query_aggregated_speed()to query it instead of the bond speed. It also resets the cached speed toSPEED_UNKNOWNviamlx5_lag_reset_agg_speed()when resetting vports speed.Quoted 4 lines
drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c +0
-0[ ... ]
drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c void mlx5_lag_reset_vports_speed(struct mlx5_lag *ldev) · line 1631
Quoted 8 lines
drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c +1
-0@@ -1594,6 +1625,7 @@ void mlx5_lag_reset_vports_speed(struct mlx5_lag *ldev)int pf_idx;int ret; +mlx5_lag_reset_agg_speed (ldev);mlx5_ldev_for_each (pf_idx,0 , ldev) { pf =mlx5_lag_pf (ldev, pf_idx);if (!pf)[Severity: Medium]
Does callingmlx5_lag_reset_agg_speed()only frommlx5_lag_reset_vports_speed()miss resettingldev->agg_speed_mbps(and vport speeds) when LAG is torn down via MPESW disable or mode changes?Currently,
mlx5_lag_reset_vports_speed()is only called frommlx5_do_bond()whenmlx5_lag_should_disable_lag()returns true:drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c:mlx5_do_bond() { ... } else if (mlx5_lag_should_disable_lag(ldev, do_bond)) { mlx5_lag_reset_vports_speed(ldev); mlx5_disable_lag(ldev); } }where
mlx5_lag_should_disable_lag()checks:return !do_bond && __mlx5_lag_is_active(ldev) && ldev->mode != MLX5_LAG_MODE_MPESW;When MPESW LAG is enabled via
mlx5_lag_enable_mpesw()->mlx5_lag_shared_fdb_create(),mlx5_lag_set_vports_agg_speed()populatesldev->agg_speed_mbps(andmlx5_mpesw_speed_update_work()updates it). However, when MPESW is torn down viamlx5_lag_disable_mpesw():drivers/net/ethernet/mellanox/mlx5/core/lag/mpesw.c:mlx5_lag_disable_mpesw() { if (ldev->mode != MLX5_LAG_MODE_MPESW) return; mlx5_mpesw_metadata_cleanup(ldev); mlx5_lag_shared_fdb_destroy(ldev, MLX5_LAG_FILTER_ALL); if (mlx5_lag_has_sd_group(ldev)) mlx5_mpesw_restore_sd_fdb(ldev); }neither
mlx5_lag_reset_vports_speed()normlx5_lag_reset_agg_speed()is called, andmlx5_lag_should_disable_lag()explicitly excludesMLX5_LAG_MODE_MPESW.Similarly, during eswitch mode or SR-IOV changes,
mlx5_lag_disable_change()disables an active LAG directly without callingmlx5_lag_reset_vports_speed()ormlx5_lag_reset_agg_speed():drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c:mlx5_lag_disable_change() { ... ldev->mode_changes_in_progress++; if (__mlx5_lag_is_active(ldev)) { if (ldev->mode == MLX5_LAG_MODE_MPESW) mlx5_lag_disable_mpesw(ldev); else mlx5_disable_lag(ldev); } }Because
mlx5_disable_lag()->mlx5_deactivate_lag()clearsldev->modetoMLX5_LAG_MODE_NONE, whenmlx5_lag_enable_change()later runsmlx5_do_bond(),__mlx5_lag_is_active(ldev)is already false. Ifdo_bondis false (for example, ifmlx5_lag_check_prereq(ldev)is now false after a mode change or if the bond was removed during the transition),mlx5_lag_should_disable_lag()evaluates to false and the reset never runs.Wouldn't this leave a stale speed in
ldev->agg_speed_mbps(and stale vport rate limits) after teardown, causingmlx5_lag_query_aggregated_speed()to return the old speed instead of-ENODATA, and in the subsequent patch ("{RDMA,net}/mlx5: notify IB uplink on LAG aggregate speed change") causingmlx5_lag_update_agg_speed()to compare against the staleold_speedand suppressIB_EVENT_DEVICE_SPEED_CHANGEif LAG is re-activated at the same aggregate speed?
Quoted 2 lines
[ ... ]
A fix for the MPESW was sent in https://lore.kernel.org/all/[email protected]/
I will send a V3 for this series and add also the MPESW fix
Quoted 6 lines
Quoted 3 lines
--
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
[email protected]
AI reviewRe: [PATCH net V2 1/4] {RDMA,net}/mlx5: cache and use TX-enabled aggregate speed for vports
In reply to Tariq ToukanThank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 2 · Low: 1
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [Medium] The new ldev->agg_speed_mbps cache is invalidated on only one teardown path, and it is filled only after the IB device is exposed.
- [Medium] For regular (non-MPESW) RoCE/SRIOV LAG, the patch replaces the bond's ethtool-derived speed (tracker.bond_speed_mbps) with a sum of…
- [Low] In non-MPESW mode, mlx5_lag_get_devices_oper_speed() now reads the live ldev->tracker.netdev_state[pf_idx].tx_enabled/link_up for…
--
{RDMA,net}/mlx5: cache and use TX-enabled aggregate speed for vports
This patch caches the aggregate operational speed of the TX-enabled LAG ports in ldev->agg_speed_mbps. VF/SF vport max_tx_speed is now programmed from that cache instead of from the bond speed. The exported mlx5_lag_query_bond_speed() is replaced by mlx5_lag_query_aggregated_speed(), which the mlx5 IB driver uses for port speed queries and which returns -ENODATA until a measurement succeeds.
Quoted 4 lines
drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c +0
-0
[ ... ]
Quoted 17 lines
drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c +5
-8@@ -1452,15 +1453,21 @@ static int mlx5_lag_get_devices_oper_speed(struct mlx5_lag *ldev, 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 ) +if (mpesw) { + ret =mlx5_query_vport_max_tx_speed (pf_mdev, opmod,0 , +0 , &speed, &state); +if (ret) { + mlx5_core_dbg(pf_mdev,
drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c static int mlx5_lag_get_devices_oper_speed(struct mlx5_lag *ldev, · line 1470
Quoted 10 lines
drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c +9
-0+"State query failed (err=%d)\n" , + ret); +return ret; + } +if (state !=VPORT_STATE_UP ) +continue ; + }else if (!ldev->tracker.netdev_state[pf_idx].tx_enabled || + !ldev->tracker.netdev_state[pf_idx].link_up) {continue ; + }
[Severity: Low]
Can these live reads of ldev->tracker race with mlx5_lag_netdev_event()? The notifier publishes the whole tracker while holding only RTNL:
ldev->tracker = tracker;
This code runs from mlx5_do_bond_work() under ldev->lock and the devcom lock, but without RTNL. The lockdep_assert_held(&ldev->lock) in mlx5_lag_update_agg_speed() therefore does not exclude the writer.
Between the tx_enabled/link_up reads for different ports, mlx5_port_oper_linkspeed() issues a PTYS command that sleeps. During an active-backup failover:
bond work netdev notifier (RTNL)
port 0: tx_enabled, count it mlx5_port_oper_linkspeed() sleeps
ldev->tracker = tracker (port 0 off, port 1 on)
port 1: tx_enabled, count it
Would the aggregate then cover both ports, even though only one of them was TX-enabled at any given moment? That value goes to RDMA and into the VF/SF vport max_tx_speed, and it stays there until the requeued bond work recomputes it.
mlx5_do_bond() already takes a snapshot with tracker = ldev->tracker for activate/modify. Could the speed calculation use that same snapshot?
drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c static int mlx5_lag_get_devices_oper_speed(struct mlx5_lag *ldev, · line 1472
Quoted 2 lines
drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c +0
-0ret =mlx5_port_oper_linkspeed (pf_mdev, &speed);
[Severity: Medium]
For non-MPESW RoCE/SRIOV LAG, this replaces tracker.bond_speed_mbps, which came from the netdevs' ethtool link speed, with a sum of mlx5_port_oper_linkspeed() results. Does that lose the fallbacks the old source had?
mlx5_port_oper_linkspeed() picks the PTYS encoding only from mlx5_ptys_ext_supported(). When no known bit is set, it returns success with a speed of 0:
ext = mlx5_ptys_ext_supported(mdev); err = mlx5_port_query_eth_proto(mdev, 1, ext, &eproto); ... for (i = 0; i < max_size; ++i) if (eproto.oper & MLX5E_PROT_MASK(i)) oper_speed = max(oper_speed, table[i].speed); *speed = oper_speed; return 0;
The old source had two fallbacks:
- mlx5e_ethtool_get_link_ksettings() falls back to the legacy eth_proto_admin/eth_proto_oper when the extended admin field is zero.
- get_link_properties() falls back to 100 * data_rate_oper when the bitmap cannot be decoded.
The legacy admin case looks reachable through mlx5e_ethtool_set_link_ksettings(). On ext-capable hardware with autoneg enabled, advertising only legacy modes writes the legacy admin field.
In that configuration, would an up, TX-enabled member contribute 0 Mbps, with the result cached as a successful measurement? RDMA would then under-report the port speed. If the whole aggregate is 0, the VF/SF vports would get the max-capability fallback instead of the operational speed.
This assumes firmware reports oper only in the legacy field in that configuration. That assumption comes from the ethtool code's handling, not from a firmware specification.
Quoted 1 line
drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c +0
-0if (ret) {
[ ... ]
drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c void mlx5_lag_reset_vports_speed(struct mlx5_lag *ldev) · line 1628
Quoted 5 lines
drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c +1
-0@@ -1594,6 +1625,7 @@ void mlx5_lag_reset_vports_speed(struct mlx5_lag *ldev)int pf_idx;int ret; +mlx5_lag_reset_agg_speed (ldev);
[Severity: Medium]
Is this the only teardown path that invalidates agg_speed_mbps? mlx5_lag_reset_vports_speed() is only called from the disable branch of mlx5_do_bond():
} else if (mlx5_lag_should_disable_lag(ldev, do_bond)) {
mlx5_lag_reset_vports_speed(ldev);
mlx5_disable_lag(ldev);
}Other teardown paths do not appear to reset the cache. One example is mlx5_lag_disable_change(), reached on eswitch disable or mode change:
if (__mlx5_lag_is_active(ldev)) {
if (ldev->mode == MLX5_LAG_MODE_MPESW)
mlx5_lag_disable_mpesw(ldev);
else
mlx5_disable_lag(ldev);
}The MPESW disable work also calls mlx5_lag_disable_mpesw(), and the shared FDB path goes through mlx5_lag_shared_fdb_destroy()->mlx5_deactivate_lag(). Neither path touches agg_speed_mbps.
On activation, mlx5_do_bond() calls mlx5_activate_lag() and then mlx5_lag_rescan_dev_locked(ldev, dev0, true) before mlx5_lag_set_vports_agg_speed() fills the cache. mlx5_lag_shared_fdb_create() also rescans and reloads the IB reps before it refreshes the speed.
mlx5_lag_query_aggregated_speed() reads agg_speed_mbps without a lock, and its IB caller only checks the LAG mode. Could a uverbs QUERY_PORT_SPEED in that window return the previous LAG instance's aggregate as valid data? On a first activation, it would get -ENODATA instead.
This seems to contradict the commit message:
"Until the aggregate has been measured, or after a failed measurement, mlx5_lag_query_aggregated_speed() returns -ENODATA."
It also contradicts the v2 changelog note about resetting the cache to SPEED_UNKNOWN on teardown.
Later patches in the series do not appear to change this. mlx5_lag_reset_agg_speed() is still reachable only through the disable branch of mlx5_do_bond(). In "notify IB uplink on LAG aggregate speed change", the stale value also feeds the speed != old_speed check.
Quoted 1 line
drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c +0
-0mlx5_ldev_for_each (pf_idx,0 , ldev) {
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261022193053.3815866-1-tariqt%40nvidia.com
Re: [PATCH net V2 1/4] {RDMA,net}/mlx5: cache and use TX-enabled aggregate speed for vports
Quoted 137 lines · On 26/10/2026 22:32, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 2 · Low: 1
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [Medium] The new
ldev->agg_speed_mbpscache is invalidated on only one teardown path, and it is filled only after the IB device is exposed.
- [Medium] For regular (non-MPESW) RoCE/SRIOV LAG, the patch replaces the bond's ethtool-derived speed (tracker.bond_speed_mbps) with a sum of…
- [Low] In non-MPESW mode,mlx5_lag_get_devices_oper_speed()now reads the live ldev->tracker.netdev_state[pf_idx].tx_enabled/link_up for…--
{RDMA,net}/mlx5: cache and use TX-enabled aggregate speed for vports
This patch caches the aggregate operational speed of the TX-enabled LAG ports in
ldev->agg_speed_mbps. VF/SF vportmax_tx_speedis now programmed from that cache instead of from the bond speed. The exportedmlx5_lag_query_bond_speed()is replaced bymlx5_lag_query_aggregated_speed(), which the mlx5 IB driver uses for port speed queries and which returns-ENODATAuntil a measurement succeeds.Quoted 4 lines
drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c +0
-0[ ... ]
Quoted 17 lines
drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c +5
-8@@ -1452,15 +1453,21 @@ static int mlx5_lag_get_devices_oper_speed(struct mlx5_lag *ldev, 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 ) +if (mpesw) { + ret =mlx5_query_vport_max_tx_speed (pf_mdev, opmod,0 , +0 , &speed, &state); +if (ret) { + mlx5_core_dbg(pf_mdev,drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c static int mlx5_lag_get_devices_oper_speed(struct mlx5_lag *ldev, · line 1470
Quoted 10 lines
drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c +9
-0+"State query failed (err=%d)\n" , + ret); +return ret; + } +if (state !=VPORT_STATE_UP ) +continue ; + }else if (!ldev->tracker.netdev_state[pf_idx].tx_enabled || + !ldev->tracker.netdev_state[pf_idx].link_up) {continue ; + }[Severity: Low]
Can these live reads of
ldev->trackerrace withmlx5_lag_netdev_event()? The notifier publishes the whole tracker while holding only RTNL:ldev->tracker = tracker;This code runs from
mlx5_do_bond_work()underldev->lockand the devcom lock, but without RTNL. Thelockdep_assert_held(&ldev->lock)inmlx5_lag_update_agg_speed()therefore does not exclude the writer.Between the tx_enabled/link_up reads for different ports,
mlx5_port_oper_linkspeed()issues a PTYS command that sleeps. During an active-backup failover:bond work netdev notifier (RTNL)
port 0:tx_enabled, count itmlx5_port_oper_linkspeed()sleeps
ldev->tracker= tracker (port 0 off, port 1 on)
port 1:tx_enabled, count itWould the aggregate then cover both ports, even though only one of them was TX-enabled at any given moment? That value goes to RDMA and into the VF/SF vport
max_tx_speed, and it stays there until the requeued bond work recomputes it.
mlx5_do_bond()already takes a snapshot with tracker =ldev->trackerfor activate/modify. Could the speed calculation use that same snapshot?drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c static int mlx5_lag_get_devices_oper_speed(struct mlx5_lag *ldev, · line 1472
Quoted 2 lines
drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c +0
-0ret =mlx5_port_oper_linkspeed (pf_mdev, &speed);[Severity: Medium]
For non-MPESW RoCE/SRIOV LAG, this replaces tracker.bond_speed_mbps, which came from the netdevs' ethtool link speed, with a sum of
mlx5_port_oper_linkspeed()results. Does that lose the fallbacks the old source had?
mlx5_port_oper_linkspeed()picks the PTYS encoding only frommlx5_ptys_ext_supported(). When no known bit is set, it returns success with a speed of 0:ext = mlx5_ptys_ext_supported(mdev); err = mlx5_port_query_eth_proto(mdev, 1, ext, &eproto); ... for (i = 0; i < max_size; ++i) if (eproto.oper & MLX5E_PROT_MASK(i)) oper_speed = max(oper_speed, table[i].speed); *speed = oper_speed; return 0;The old source had two fallbacks:
-
mlx5e_ethtool_get_link_ksettings()falls back to the legacy eth_proto_admin/eth_proto_oper when the extended admin field is zero.
-get_link_properties()falls back to 100 *data_rate_operwhen the bitmap cannot be decoded.The legacy admin case looks reachable through
mlx5e_ethtool_set_link_ksettings(). On ext-capable hardware with autoneg enabled, advertising only legacy modes writes the legacy admin field.In that configuration, would an up, TX-enabled member contribute 0 Mbps, with the result cached as a successful measurement? RDMA would then under-report the port speed. If the whole aggregate is 0, the VF/SF vports would get the max-capability fallback instead of the operational speed.
Quoted 4 lines
This assumes firmware reports oper only in the legacy field in that configuration. That assumption comes from the ethtool code's handling, not from a firmware specification.
will fix in V3
Quoted 53 lines
Quoted 1 line
drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c +0
-0if (ret) {[ ... ]
drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c void mlx5_lag_reset_vports_speed(struct mlx5_lag *ldev) · line 1628
Quoted 5 lines
drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c +1
-0@@ -1594,6 +1625,7 @@ void mlx5_lag_reset_vports_speed(struct mlx5_lag *ldev)int pf_idx;int ret; +mlx5_lag_reset_agg_speed (ldev);[Severity: Medium]
Is this the only teardown path that invalidates
agg_speed_mbps?mlx5_lag_reset_vports_speed()is only called from the disable branch ofmlx5_do_bond():} else if (mlx5_lag_should_disable_lag(ldev, do_bond)) { mlx5_lag_reset_vports_speed(ldev); mlx5_disable_lag(ldev); }Other teardown paths do not appear to reset the cache. One example is
mlx5_lag_disable_change(), reached on eswitch disable or mode change:if (__mlx5_lag_is_active(ldev)) { if (ldev->mode == MLX5_LAG_MODE_MPESW) mlx5_lag_disable_mpesw(ldev); else mlx5_disable_lag(ldev); }The MPESW disable work also calls
mlx5_lag_disable_mpesw(), and the shared FDB path goes through mlx5_lag_shared_fdb_destroy()->mlx5_deactivate_lag(). Neither path touchesagg_speed_mbps.On activation,
mlx5_do_bond()callsmlx5_activate_lag()and thenmlx5_lag_rescan_dev_locked(ldev, dev0, true)beforemlx5_lag_set_vports_agg_speed()fills the cache.mlx5_lag_shared_fdb_create()also rescans and reloads the IB reps before it refreshes the speed.
mlx5_lag_query_aggregated_speed()readsagg_speed_mbpswithout a lock, and its IB caller only checks the LAG mode. Could a uverbsQUERY_PORT_SPEEDin that window return the previous LAG instance's aggregate as valid data? On a first activation, it would get-ENODATAinstead.This seems to contradict the commit message:
"Until the aggregate has been measured, or after a failed measurement,
mlx5_lag_query_aggregated_speed()returns-ENODATA."
Quoted 8 lines
It also contradicts the v2 changelog note about resetting the cache to
SPEED_UNKNOWNon teardown.Later patches in the series do not appear to change this.
mlx5_lag_reset_agg_speed()is still reachable only through the disable branch ofmlx5_do_bond(). In "notify IB uplink on LAG aggregate speed change", the stale value also feeds the speed !=old_speedcheck.
already replied in another mail
Quoted 6 lines
drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c void mlx5_lag_reset_vports_speed(struct mlx5_lag *ldev) · line 1629
Quoted 1 line
drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c +0
-0mlx5_ldev_for_each (pf_idx,0 , ldev) {[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261022193053.3815866-1-tariqt%40nvidia.com
Tariq Toukan
maintainerPATCH v2 2/4 net/mlx5: Lag, limit aggregated TX speed by PCIe bandwidth
In reply to Tariq ToukanFrom: Or Har-Toov <[email protected]>
FW initializes max_tx_speed to the minimum of the port speed and the PCI bandwidth. Modifying it with a value computed by different rules changes the meaning of the field rather than updating it.
Limit the aggregated LAG TX speed by the PCIe bandwidth. Clamping each uplink separately and then summing could let the aggregate reach a multiple of the link's real bandwidth, so clamp the sum once instead, counting only the ports that contribute to it.
This assumes the bonded PFs share a single PCIe link, which holds when they are functions of the same device. In Socket Direct, each port spans multiple mdevs on separate PCIe links, so the PCIe budget for that port is the sum of its mdevs' PCIe bandwidths. Where Socket Direct ports do not have equal PCIe budgets, the aggregate is clamped to the narrowest port, which under-reports rather than over-reports the available bandwidth.
pcie_bandwidth_mbps() reads the endpoint link only, without traversing upstream bridges, and uses the nominal per-lane transfer rate times the link width, without encoding overhead. FW initializes max_tx_speed from the same endpoint-only link status, so using the same calculation keeps the clamp consistent with the value FW programs before LAG. Ethernet speeds and max_tx_speed are likewise nominal rates, so the comparison is like for like. A more accurate bandwidth estimate would make the aggregate differ from the per-vport value FW sets up for the same link.
If the PCIe bandwidth of a contributing port cannot be read, the speed calculation fails instead of returning an unclamped or partial result. A device that has no Link Status register, an RC integrated endpoint, has no PCIe budget to apply and is not clamped.
--- .../net/ethernet/mellanox/mlx5/core/lag/lag.c | 79 ++++++++++++++++++- drivers/pci/pci.c | 16 ++++ include/linux/pci.h | 2 + 3 files changed, 95 insertions(+), 2 deletions(-)
v1: https://lore.kernel.org/all/[email protected]/
Changes in v2:
- Clamp the aggregate sum once by the narrowest PCIe link instead of clamping each uplink before summing, which could let the aggregate exceed the real bandwidth
- Document the shared PCIe link assumption in the changelog
- Add pcie_bandwidth_mbps() to drivers/pci/pci.c, which reads PCI_EXP_LNKSTA once and decodes both speed and width from that value, avoiding a race between separate reads of speed and width
- In Socket Direct, sum the PCIe bandwidths of all mdevs in the same port group instead of taking the minimum, since those links are independent
- Fail the aggregate and max speed calculations when a PCIe bandwidth cannot be read, instead of skipping the clamp; an RC integrated endpoint has no Link Status and is not clamped
drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c +77 -2
@@ -1432,10 +1432,55 @@ static bool mlx5_lag_should_disable_lag(struct mlx5_lag *ldev, bool do_bond) ldev->mode !=MLX5_LAG_MODE_MPESW ; } +static int mlx5_lag_dev_pcie_bw (struct mlx5_core_dev *dev,u32 *bw) +{ +if (pci_pcie_type (dev->pdev) ==PCI_EXP_TYPE_RC_END ) { + *bw =U32_MAX ; +return 0 ; + } + + *bw =pcie_bandwidth_mbps (dev->pdev); +return *bw ?0 : -EIO ; +} + +static int mlx5_lag_port_pcie_bw (struct mlx5_lag *ldev,struct lag_func *port, +u32 *bw) +{ +struct lag_func *member; +bool unlimited = false; +u32 member_bw; +int idx; +int err; + +if (!port->group_id) +return mlx5_lag_dev_pcie_bw (port->dev, bw); + + *bw =0 ; +mlx5_lag_for_each (idx,0 , ldev, port->group_id) { + member =mlx5_lag_pf (ldev, idx); +if (!member) +continue ; + + err =mlx5_lag_dev_pcie_bw (member->dev, &member_bw); +if (err) +return err; + +if (member_bw ==U32_MAX ) + unlimited = true; +else + *bw += member_bw; + } + +if (unlimited) + *bw =U32_MAX ; +return 0 ; +} +static int mlx5_lag_get_devices_oper_speed (struct mlx5_lag *ldev,u32 *sum_speed) {bool mpesw = ldev->mode ==MLX5_LAG_MODE_MPESW ; +u32 pci_bw =U32_MAX ;int pf_idx; *sum_speed =0 ;
@@ -1443,6 +1488,7 @@ static int mlx5_lag_get_devices_oper_speed(struct mlx5_lag *ldev,u8 opmod =MLX5_VPORT_STATE_OP_MOD_VNIC_VPORT ;struct mlx5_core_dev *pf_mdev;struct lag_func *pf; +u32 dev_pci_bw;u32 speed;u8 state;int ret;
@@ -1477,9 +1523,20 @@ static int mlx5_lag_get_devices_oper_speed(struct mlx5_lag *ldev,return ret; } + ret =mlx5_lag_port_pcie_bw (ldev, pf, &dev_pci_bw); +if (ret) { +mlx5_core_dbg (pf_mdev, +"Failed to get PCIe bandwidth (err=%d)\n" , + ret); +return ret; + } + + pci_bw =min (pci_bw, dev_pci_bw); *sum_speed += speed; } + *sum_speed =min (*sum_speed, pci_bw); +return 0 ; }
@@ -1510,6 +1567,7 @@ void mlx5_lag_reset_agg_speed(struct mlx5_lag *ldev)#ifdef CONFIG_MLX5_ESWITCH static int mlx5_lag_get_devices_max_speed (struct mlx5_lag *ldev,u32 *max_speed) { +u32 pci_bw =U32_MAX ;bool take_max;int pf_idx;
@@ -1521,6 +1579,7 @@ static int mlx5_lag_get_devices_max_speed(struct mlx5_lag *ldev, u32 *max_speed)mlx5_ldev_for_each (pf_idx,0 , ldev) {struct mlx5_core_dev *pf_mdev;struct lag_func *pf; +u32 dev_pci_bw;u32 speed;int ret;
@@ -1539,10 +1598,26 @@ static int mlx5_lag_get_devices_max_speed(struct mlx5_lag *ldev, u32 *max_speed)return ret; } - *max_speed = take_max ? -max (*max_speed, speed) : *max_speed + speed; + ret =mlx5_lag_port_pcie_bw (ldev, pf, &dev_pci_bw); +if (ret) { +mlx5_core_dbg (pf_mdev, +"Failed to get PCIe bandwidth (err=%d)\n" , + ret); +return ret; + } + +if (take_max) { + speed =min (speed, dev_pci_bw); + *max_speed =max (*max_speed, speed); + }else { + pci_bw =min (pci_bw, dev_pci_bw); + *max_speed += speed; + } } +if (!take_max) + *max_speed =min (*max_speed, pci_bw); +return 0 ; }
drivers/pci/pci.c +16 -0
@@ -6006,6 +6006,22 @@ int pcie_link_speed_mbps(struct pci_dev *pdev) }EXPORT_SYMBOL (pcie_link_speed_mbps); +u32 pcie_bandwidth_mbps (struct pci_dev *pdev) +{ +u16 lnksta; +u32 width; +int speed; + +if (pcie_capability_read_word (pdev,PCI_EXP_LNKSTA , &lnksta)) +return 0 ; + speed =pcie_dev_speed_mbps (to_pcie_link_speed (lnksta)); +if (speed <=0 ) +return 0 ; + width =FIELD_GET (PCI_EXP_LNKSTA_NLW , lnksta); +return speed * width; +} +EXPORT_SYMBOL_GPL (pcie_bandwidth_mbps); +/** * pcie_bandwidth_available - determine minimum link settings of a PCIe * device and its bandwidth limitation
include/linux/pci.h +2 -0
@@ -1479,6 +1479,8 @@ u32 pcie_bandwidth_available(struct pci_dev *dev, struct pci_dev **limiting_dev,enum pci_bus_speed *speed, enum pcie_link_width *width);int pcie_link_speed_mbps (struct pci_dev *pdev); +u32 pcie_bandwidth_mbps (struct pci_dev *pdev); +void pcie_print_link_status (struct pci_dev *dev);int pcie_reset_flr (struct pci_dev *dev,bool probe);int pcie_flr (struct pci_dev *dev);
Signature · 1 line
2.44.0
[email protected]
AI reviewRe: [PATCH net V2 2/4] net/mlx5: Lag, limit aggregated TX speed by PCIe bandwidth
Sashiko has reviewed this patch and found no issues.
Quoted 15 lines
From: Or Har-Toov <[email protected]>
FW initializes
max_tx_speedto the minimum of the port speed and the PCI bandwidth. Modifying it with a value computed by different rules changes the meaning of the field rather than updating it.Limit the aggregated LAG TX speed by the PCIe bandwidth. Clamping each uplink separately and then summing could let the aggregate reach a multiple of the link's real bandwidth, so clamp the sum once instead, counting only the ports that contribute to it.
This assumes the bonded PFs share a single PCIe link, which holds when they are functions of the same device. In Socket Direct, each port spans multiple mdevs on separate PCIe links, so the PCIe budget for that port is the sum of its mdevs' PCIe bandwidths. Where Socket Direct ports do
Quoted 6 lines
[ ... ]Fixes 50f1d188c580 ("net/mlx5: Propagate LAG effective max_tx_speed to vports")Signed-off-by Or Har-Toov <[email protected]>Reviewed-by Mark Bloch <[email protected]>Reviewed-by Shay Drori <[email protected]>Signed-off-by Tariq Toukan <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Re: [PATCH net V2 2/4] net/mlx5: Lag, limit aggregated TX speed by PCIe bandwidth
In reply to Tariq ToukanQuoted 53 lines · Tariq Toukan
From: Or Har-Toov <[email protected]>
FW initializes
max_tx_speedto the minimum of the port speed and the PCI bandwidth. Modifying it with a value computed by different rules changes the meaning of the field rather than updating it.Limit the aggregated LAG TX speed by the PCIe bandwidth. Clamping each uplink separately and then summing could let the aggregate reach a multiple of the link's real bandwidth, so clamp the sum once instead, counting only the ports that contribute to it.
This assumes the bonded PFs share a single PCIe link, which holds when they are functions of the same device. In Socket Direct, each port spans multiple mdevs on separate PCIe links, so the PCIe budget for that port is the sum of its mdevs' PCIe bandwidths. Where Socket Direct ports do not have equal PCIe budgets, the aggregate is clamped to the narrowest port, which under-reports rather than over-reports the available bandwidth.
pcie_bandwidth_mbps()reads the endpoint link only, without traversing upstream bridges, and uses the nominal per-lane transfer rate times the link width, without encoding overhead. FW initializesmax_tx_speedfrom the same endpoint-only link status, so using the same calculation keeps the clamp consistent with the value FW programs before LAG. Ethernet speeds andmax_tx_speedare likewise nominal rates, so the comparison is like for like. A more accurate bandwidth estimate would make the aggregate differ from the per-vport value FW sets up for the same link.If the PCIe bandwidth of a contributing port cannot be read, the speed calculation fails instead of returning an unclamped or partial result. A device that has no Link Status register, an RC integrated endpoint, has no PCIe budget to apply and is not clamped.
Fixes 50f1d188c580 ("net/mlx5: Propagate LAG effective max_tx_speed to vports")Signed-off-by Or Har-Toov <[email protected]>Reviewed-by Mark Bloch <[email protected]>Reviewed-by Shay Drori <[email protected]>Signed-off-by Tariq Toukan <[email protected]>...
drivers/pci/pci.c +5
-0@@ -6006,6 +6006,22 @@ int pcie_link_speed_mbps(struct pci_dev *pdev) }EXPORT_SYMBOL (pcie_link_speed_mbps); +u32 pcie_bandwidth_mbps (struct pci_dev *pdev) +{ +u16 lnksta; +u32 width; +int speed;
drivers/pci/pci.c int pcie_link_speed_mbps(struct pci_dev *pdev) · line 6023
Quoted 10 lines
drivers/pci/pci.c +10
-0+ +if (pcie_capability_read_word (pdev,PCI_EXP_LNKSTA , &lnksta)) +return 0 ; + speed =pcie_dev_speed_mbps (to_pcie_link_speed (lnksta)); +if (speed <=0 ) +return 0 ; + width =FIELD_GET (PCI_EXP_LNKSTA_NLW , lnksta); +return speed * width; +} +EXPORT_SYMBOL_GPL (pcie_bandwidth_mbps);
Can you split this into its own patch?
It looks like cxl_pci_get_bandwidth() and maybe even pcie_bandwidth_available() could be refactored to use this.
Quoted 19 lines
drivers/pci/pci.c +0
-0/** * pcie_bandwidth_available - determine minimum link settings of a PCIe * device and its bandwidth limitation include/linux/pci.h +2
-0@@ -1479,6 +1479,8 @@ u32 pcie_bandwidth_available(struct pci_dev *dev, struct pci_dev **limiting_dev,enum pci_bus_speed *speed, enum pcie_link_width *width);int pcie_link_speed_mbps (struct pci_dev *pdev); +u32 pcie_bandwidth_mbps (struct pci_dev *pdev); +void pcie_print_link_status (struct pci_dev *dev);int pcie_reset_flr (struct pci_dev *dev,bool probe);int pcie_flr (struct pci_dev *dev);Signature · 1 line
2.44.0
Re: [PATCH net V2 2/4] net/mlx5: Lag, limit aggregated TX speed by PCIe bandwidth
Quoted 70 lines · Bjorn Helgaas
External email: Use caution opening links or attachments
Quoted 53 lines · Tariq Toukan
From: Or Har-Toov <[email protected]>
FW initializes
max_tx_speedto the minimum of the port speed and the PCI bandwidth. Modifying it with a value computed by different rules changes the meaning of the field rather than updating it.Limit the aggregated LAG TX speed by the PCIe bandwidth. Clamping each uplink separately and then summing could let the aggregate reach a multiple of the link's real bandwidth, so clamp the sum once instead, counting only the ports that contribute to it.
This assumes the bonded PFs share a single PCIe link, which holds when they are functions of the same device. In Socket Direct, each port spans multiple mdevs on separate PCIe links, so the PCIe budget for that port is the sum of its mdevs' PCIe bandwidths. Where Socket Direct ports do not have equal PCIe budgets, the aggregate is clamped to the narrowest port, which under-reports rather than over-reports the available bandwidth.
pcie_bandwidth_mbps()reads the endpoint link only, without traversing upstream bridges, and uses the nominal per-lane transfer rate times the link width, without encoding overhead. FW initializesmax_tx_speedfrom the same endpoint-only link status, so using the same calculation keeps the clamp consistent with the value FW programs before LAG. Ethernet speeds andmax_tx_speedare likewise nominal rates, so the comparison is like for like. A more accurate bandwidth estimate would make the aggregate differ from the per-vport value FW sets up for the same link.If the PCIe bandwidth of a contributing port cannot be read, the speed calculation fails instead of returning an unclamped or partial result. A device that has no Link Status register, an RC integrated endpoint, has no PCIe budget to apply and is not clamped.
Fixes 50f1d188c580 ("net/mlx5: Propagate LAG effective max_tx_speed to vports")Signed-off-by Or Har-Toov <[email protected]>Reviewed-by Mark Bloch <[email protected]>Reviewed-by Shay Drori <[email protected]>Signed-off-by Tariq Toukan <[email protected]>...
drivers/pci/pci.c +5
-0@@ -6006,6 +6006,22 @@ int pcie_link_speed_mbps(struct pci_dev *pdev) }EXPORT_SYMBOL (pcie_link_speed_mbps); +u32 pcie_bandwidth_mbps (struct pci_dev *pdev) +{ +u16 lnksta; +u32 width; +int speed;drivers/pci/pci.c int pcie_link_speed_mbps(struct pci_dev *pdev) · line 6023
Quoted 10 lines
drivers/pci/pci.c +10
-0+ +if (pcie_capability_read_word (pdev,PCI_EXP_LNKSTA , &lnksta)) +return 0 ; + speed =pcie_dev_speed_mbps (to_pcie_link_speed (lnksta)); +if (speed <=0 ) +return 0 ; + width =FIELD_GET (PCI_EXP_LNKSTA_NLW , lnksta); +return speed * width; +} +EXPORT_SYMBOL_GPL (pcie_bandwidth_mbps);Can you split this into its own patch?
Quoted 3 lines
It looks like
cxl_pci_get_bandwidth()and maybe evenpcie_bandwidth_available()could be refactored to use this.
will do
Quoted 19 lines
Quoted 19 lines
drivers/pci/pci.c +0
-0/** * pcie_bandwidth_available - determine minimum link settings of a PCIe * device and its bandwidth limitation include/linux/pci.h +2
-1@@ -1479,6 +1479,8 @@ u32 pcie_bandwidth_available(struct pci_dev *dev, struct pci_dev **limiting_dev,enum pci_bus_speed *speed, enum pcie_link_width *width);int pcie_link_speed_mbps (struct pci_dev *pdev); +u32 pcie_bandwidth_mbps (struct pci_dev *pdev); +void pcie_print_link_status (struct pci_dev *dev);int pcie_reset_flr (struct pci_dev *dev,bool probe);int pcie_flr (struct pci_dev *dev); --2.44.0
[email protected]
AI reviewRe: [PATCH net V2 2/4] net/mlx5: Lag, limit aggregated TX speed by PCIe bandwidth
In reply to Tariq ToukanThank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 2
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [Medium] mlx5_lag_dev_pcie_bw() (drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c) skips the PCIe…
- [Low] This mlx5 'Fixes:' patch adds a new exported PCI core API, pcie_bandwidth_mbps() in drivers/pci/pci.c, declared in…
- [Low] Concern: at this commit, mlx5_lag_reset_vports_speed() (lag.c), called from mlx5_do_bond() when LAG is disabled, still writes each…
--
net/mlx5: Lag, limit aggregated TX speed by PCIe bandwidth
This patch clamps the aggregated LAG TX speed, and the max speed sent to vports, by the PCIe bandwidth of the ports that contribute to it. In Socket Direct groups, the bandwidth of each mdev is summed per port. It also adds a new PCI core helper, pcie_bandwidth_mbps(). If the PCIe bandwidth cannot be read, the speed calculation now fails, except for RC integrated endpoints.
Quoted 8 lines
drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c +0
-0@@ -1432,10 +1432,55 @@ static bool mlx5_lag_should_disable_lag(struct mlx5_lag *ldev, bool do_bond) ldev->mode !=MLX5_LAG_MODE_MPESW ; }
drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c static bool mlx5_lag_should_disable_lag(struct mlx5_lag *ldev, bool do_bond) · line 1444
Quoted 10 lines
drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c +10
-0+static int mlx5_lag_dev_pcie_bw (struct mlx5_core_dev *dev,u32 *bw) +{ +if (pci_pcie_type (dev->pdev) ==PCI_EXP_TYPE_RC_END ) { + *bw =U32_MAX ; +return 0 ; + } + + *bw =pcie_bandwidth_mbps (dev->pdev); +return *bw ?0 : -EIO ; +}
[Severity: Medium]
PCI_EXP_TYPE_RC_END is the only case exempted here. What happens for a bonded PF where pci_is_pcie() is false? One example is a VFIO-assigned PF on a conventional PCI segment of a q35 guest, where the Express capability is hidden.
In that case pcie_capability_reg_implemented() returns false, so the LNKSTA read reports success and leaves the value at 0:
drivers/pci/access.c:pcie_capability_read_word() {
*val = 0;
...
if (pcie_capability_reg_implemented(dev, pos)) {
...
}
...
return 0;
}CLS 0 maps to PCI_SPEED_UNKNOWN, so pcie_dev_speed_mbps() returns -EINVAL and pcie_bandwidth_mbps() returns 0. Since pcie_flags_reg is 0, pci_pcie_type() reports PCI_EXP_TYPE_ENDPOINT. The RC_END check does not match, and this function returns -EIO. The same thing happens for any CLS value from 7 to 0xF, which pcie_link_speed[] maps to PCI_SPEED_UNKNOWN.
If so, wouldn't mlx5_lag_get_devices_oper_speed() and mlx5_lag_get_devices_max_speed() fail on every call?
mlx5_do_bond()
mlx5_lag_set_vports_agg_speed()
mlx5_lag_update_agg_speed()
mlx5_lag_get_devices_oper_speed()
mlx5_lag_port_pcie_bw()
mlx5_lag_dev_pcie_bw() <- -EIOmlx5_lag_update_agg_speed() then stores SPEED_UNKNOWN:
err = mlx5_lag_get_devices_oper_speed(ldev, &speed);
if (err) {
WRITE_ONCE(ldev->agg_speed_mbps, SPEED_UNKNOWN);
return err;
}Because of this, mlx5_lag_set_vports_agg_speed() returns early and never propagates vport max_tx_speed. mlx5_lag_query_aggregated_speed() also returns -ENODATA to mlx5_ib_query_port_speed_from_bond(), both for RoCE LAG and for the SR-IOV LAG uplink rep. Before this patch these paths returned a valid speed.
The commit message says:
A device that has no Link Status register, an RC integrated endpoint, has no PCIe budget to apply and is not clamped.
pcie_bandwidth_mbps() returns the same 0 whether Link Status is missing, the read failed, or the CLS encoding is unknown, so callers cannot tell these cases apart. Should the "not clamped" case cover every device without an implemented Link Status register, not just RC_END?
The later patch in this series, "net/mlx5: Lag, save and restore vport max_tx_speed across LAG", treats pcie_bandwidth_mbps() == 0 as "no clamp" in mlx5_lag_get_restore_speed(). That does not match the -EIO handling here.
[ ... ]
Quoted 1 line
drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c +0
-0@@ -1539,10 +1598,26 @@ static int mlx5_lag_get_devices_max_speed(struct mlx5_lag *ldev, u32 *max_speed)
[ ... ]
Quoted 4 lines
drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c +4
-0+if (take_max) { + speed =min (speed, dev_pci_bw); + *max_speed =max (*max_speed, speed); + }else {
drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c static int mlx5_lag_get_devices_max_speed(struct mlx5_lag *ldev, u32 *max_speed) · line 1622
Quoted 10 lines
drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c +6
-0+ pci_bw =min (pci_bw, dev_pci_bw); + *max_speed += speed; + } } +if (!take_max) + *max_speed =min (*max_speed, pci_bw); +return 0 ; }
[Severity: Low]
The commit message says FW programs max_tx_speed as the minimum of port speed and PCIe bandwidth, and that writing a value computed by other rules changes the meaning of the field. At this commit, the LAG disable path still writes an unclamped value:
mlx5_do_bond()
mlx5_lag_should_disable_lag()
mlx5_lag_reset_vports_speed()
drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c:mlx5_lag_reset_vports_speed() {
...
ret = mlx5_port_oper_linkspeed(mdev, &speed);
...
speed = speed / MLX5_MAX_TX_SPEED_UNIT;
mlx5_lag_modify_device_vports_speed(mdev, speed);
...
}After LAG teardown, can vports end up with a max_tx_speed above the PCIe link bandwidth?
The last patch in this series, "net/mlx5: Lag, save and restore vport max_tx_speed across LAG", rewrites mlx5_lag_reset_vports_speed(). It restores the per-vport value that FW programmed, and its fallback in mlx5_lag_get_restore_speed() is clamped by pcie_bandwidth_mbps(). So this only affects the bisection window between this patch and that one.
Quoted 13 lines
drivers/pci/pci.c +5
-0@@ -6006,6 +6006,22 @@ int pcie_link_speed_mbps(struct pci_dev *pdev) }EXPORT_SYMBOL (pcie_link_speed_mbps); +u32 pcie_bandwidth_mbps (struct pci_dev *pdev) +{ +u16 lnksta; +u32 width; +int speed;
drivers/pci/pci.c int pcie_link_speed_mbps(struct pci_dev *pdev) · line 6023
Quoted 10 lines
drivers/pci/pci.c +10
-0+ +if (pcie_capability_read_word (pdev,PCI_EXP_LNKSTA , &lnksta)) +return 0 ; + speed =pcie_dev_speed_mbps (to_pcie_link_speed (lnksta)); +if (speed <=0 ) +return 0 ; + width =FIELD_GET (PCI_EXP_LNKSTA_NLW , lnksta); +return speed * width; +} +EXPORT_SYMBOL_GPL (pcie_bandwidth_mbps);
[Severity: Low]
This isn't a bug, but this mlx5 Fixes: patch adds a new exported PCI core API with no kernel-doc, and the commit has no Acked-by from the PCI maintainer.
The name is close to pcie_bandwidth_available(), whose kernel-doc also says it returns Mb/s, but the two behave differently. pcie_bandwidth_available() walks upstream bridges and subtracts encoding overhead:
next_bw = next_width * PCIE_SPEED2MBS_ENC(next_speed);
pcie_bandwidth_mbps() returns the nominal rate times width for the endpoint link only. It also returns 0 on any failure, while pcie_link_speed_mbps() just above returns a negative errno.
Could the nominal, endpoint-only behaviour and the 0-on-error convention be documented in a kernel-doc comment here, instead of only in the changelog?
Is EXPORT_SYMBOL_GPL intentional? The neighbouring pcie_link_speed_mbps() and pcie_bandwidth_available() both use EXPORT_SYMBOL.
The include/linux/pci.h hunk also adds a stray blank line after the new declaration.
mlx5's en/params.c already compares link speed against pcie_bandwidth_available(). With this patch the same driver has two different definitions of the PCIe budget.
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261022193053.3815866-1-tariqt%40nvidia.com
Tariq Toukan
maintainerPATCH v2 3/4 {RDMA,net}/mlx5: notify IB uplink on LAG aggregate speed change
In reply to Tariq ToukanFrom: Or Har-Toov <[email protected]>
In switchdev LAG, a link-state change fires two IB_EVENT_DEVICE_SPEED_CHANGE events: the physical port fires immediately with the port state change, and once the LAG reconverges and pushes the new aggregate speed to every vport via MODIFY_VPORT_STATE, FW fires a PORT_CHANGE event per vport, which is how VF consumers learn the aggregate actually changed.
The uplink vport is deliberately skipped when pushing the aggregate speed, so the IB uplink device never gets a second event once the aggregate has settled. In RoCE LAG there are no VF vports at all, so nothing fires after reconvergence.
Raise IB_EVENT_DEVICE_SPEED_CHANGE from the LAG layer, in mlx5_lag_update_agg_speed(), right after the cached aggregate is updated. That cache is where the IB layer now takes the effective speed from, so a consumer that queries after receiving the event is guaranteed to read the new value.
blocking_notifier_call_chain() holds the blocking_notifier_head rwsem for the full duration of lag_event(); blocking_notifier_chain_unregister() in mlx5_eth_lag_cleanup() takes the write side and cannot return until any in-flight callback has completed, so no event can be dispatched to a freed device after unregistration.
--- drivers/infiniband/hw/mlx5/main.c | 10 ++++++++++ .../net/ethernet/mellanox/mlx5/core/lag/lag.c | 20 +++++++++++++++++++ .../net/ethernet/mellanox/mlx5/core/lag/lag.h | 1 + include/linux/mlx5/device.h | 1 + 4 files changed, 32 insertions(+)
drivers/infiniband/hw/mlx5/main.c +10 -0
@@ -3690,6 +3690,16 @@ static int lag_event(struct notifier_block *nb, unsigned long event, void *data)rdma_roce_rescan_port (ibdev, portnum +1 ); }break ; +case MLX5_DRIVER_EVENT_LAG_SPEED_CHANGE : { +struct ib_event speed_event = {}; + +if (!dev->ib_active) +break ; + speed_event.device = ibdev; + speed_event.event =IB_EVENT_DEVICE_SPEED_CHANGE ; +ib_dispatch_event (&speed_event); +break ; + }default :return NOTIFY_DONE ; }
drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c +20 -0
@@ -1540,8 +1540,24 @@ static int mlx5_lag_get_devices_oper_speed(struct mlx5_lag *ldev,return 0 ; } +void mlx5_lag_notify_speed_change (struct mlx5_lag *ldev) +{ +struct lag_func *pf; +int idx; + + idx =mlx5_lag_get_dev_index_by_seq (ldev,MLX5_LAG_P1 ); +if (idx <0 ) +return ; + pf =mlx5_lag_pf (ldev, idx); +if (!pf) +return ; +blocking_notifier_call_chain (&pf->dev->priv.lag_nh, +MLX5_DRIVER_EVENT_LAG_SPEED_CHANGE ,NULL ); +} +int mlx5_lag_update_agg_speed (struct mlx5_lag *ldev) { +u32 old_speed;u32 speed;int err;
@@ -1553,7 +1569,11 @@ int mlx5_lag_update_agg_speed(struct mlx5_lag *ldev)return err; } + old_speed =READ_ONCE (ldev->agg_speed_mbps);WRITE_ONCE (ldev->agg_speed_mbps, speed); +if (speed != old_speed) +mlx5_lag_notify_speed_change (ldev); +return 0 ; }
drivers/net/ethernet/mellanox/mlx5/core/lag/lag.h +1 -0
@@ -259,6 +259,7 @@ void mlx5_lag_rescan_dev_locked(struct mlx5_lag *ldev,void mlx5_lag_add_devices_filter (struct mlx5_lag *ldev,u32 filter);struct mlx5_devcom_comp_dev *mlx5_lag_get_devcom_comp (struct mlx5_lag *ldev); +void mlx5_lag_notify_speed_change (struct mlx5_lag *ldev);int mlx5_lag_update_agg_speed (struct mlx5_lag *ldev);void mlx5_lag_reset_agg_speed (struct mlx5_lag *ldev);int mlx5_lag_query_bond_speed (struct mlx5_core_dev *dev,u32 *speed);
include/linux/mlx5/device.h +1 -0
@@ -374,6 +374,7 @@ enum mlx5_driver_event {MLX5_DRIVER_EVENT_AFFILIATION_DONE ,MLX5_DRIVER_EVENT_AFFILIATION_REMOVED ,MLX5_DRIVER_EVENT_ACTIVE_BACKUP_LAG_CHANGE_LOWERSTATE , + MLX5_DRIVER_EVENT_LAG_SPEED_CHANGE, }; enum {
Signature · 1 line
2.44.0
[email protected]
AI reviewRe: [PATCH net V2 3/4] {RDMA,net}/mlx5: notify IB uplink on LAG aggregate speed change
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] RDMA/mlx5: use-after-free of ib_device from lag_event() on teardown - [Medium] net/mlx5: LAG speed…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] RDMA/mlx5: use-after-free of ib_device from lag_event() on teardown
- [Medium] net/mlx5: LAG speed change notified before updating eswitch vport speeds --
commit 5dd9a6a9f1014a459afa674b27b22373d933dc51
Author: Or Har-Toov <[email protected]>
{RDMA,net}/mlx5: notify IB uplink on LAG aggregate speed change
This commit adds MLX5_DRIVER_EVENT_LAG_SPEED_CHANGE to notify the mlx5 IB driver when the cached LAG aggregate speed changes, dispatching IB_EVENT_DEVICE_SPEED_CHANGE to RDMA consumers.
Quoted 8 lines
drivers/infiniband/hw/mlx5/main.c +0
-0@@ -3690,6 +3690,16 @@ static int lag_event(struct notifier_block *nb, unsigned long event, void *data)rdma_roce_rescan_port (ibdev, portnum +1 ); }break ;
drivers/infiniband/hw/mlx5/main.c static int lag_event(struct notifier_block *nb, unsigned long event, void *data) · line 3702
Quoted 10 lines
drivers/infiniband/hw/mlx5/main.c +10
-0+case MLX5_DRIVER_EVENT_LAG_SPEED_CHANGE : { +struct ib_event speed_event = {}; + +if (!dev->ib_active) +break ; + speed_event.device = ibdev; + speed_event.event =IB_EVENT_DEVICE_SPEED_CHANGE ; +ib_dispatch_event (&speed_event); +break ; + }
[Severity: High]
Can this race with __mlx5_ib_remove() and cause a use-after-free of struct ib_device on ib_wq?
In drivers/infiniband/core/cache.c, ib_dispatch_event() does not deliver the event synchronously inside lag_event(). Instead, it queues a work item with an unreferenced pointer to ibdev onto ib_wq:
drivers/infiniband/core/cache.c:ib_dispatch_event() {
...
INIT_WORK(&work->work, ib_generic_event_task);
work->event = *event;
...
queue_work(ib_wq, &work->work);
}The RDMA core drains ib_wq during ib_unregister_device() via __ib_unregister_device() -> ib_cache_cleanup_one() -> flush_workqueue(ib_wq), which runs in MLX5_IB_STAGE_IB_REG cleanup.
However, in drivers/infiniband/hw/mlx5/main.c, dev->lag_events is unregistered in mlx5_eth_lag_cleanup() under MLX5_IB_STAGE_ROCE, which is an earlier stage than MLX5_IB_STAGE_IB_REG and therefore runs after MLX5_IB_STAGE_IB_REG during the reverse-order teardown loop in __mlx5_ib_remove():
drivers/infiniband/hw/mlx5/main.c:__mlx5_ib_remove() {
dev->ib_active = false;
/* Number of stages to cleanup */
while (stage) {
stage--;
if (profile->stage[stage].cleanup)
profile->stage[stage].cleanup(dev);
}
kfree(dev->port);
ib_dealloc_device(&dev->ib_dev);
}If lag_event() on ldev->wq checks dev->ib_active just before __mlx5_ib_remove() sets dev->ib_active = false, __mlx5_ib_remove() can complete MLX5_IB_STAGE_IB_REG cleanup (including flush_workqueue(ib_wq)) before lag_event() calls ib_dispatch_event(&speed_event).
When MLX5_IB_STAGE_ROCE cleanup then calls mlx5_eth_lag_cleanup() -> mlx5e_lag_event_unregister() -> blocking_notifier_chain_unregister(), it only waits for lag_event() to finish queuing the work item, not for ib_wq to execute it. __mlx5_ib_remove() then calls ib_dealloc_device(&dev->ib_dev) while ib_generic_event_task() is still pending on ib_wq, so ib_generic_event_task() -> ib_dispatch_event_clients() in drivers/infiniband/core/device.c can dereference event->device after it has been freed.
Quoted 33 lines
drivers/infiniband/hw/mlx5/main.c +0
-0default :return NOTIFY_DONE ; }drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c +16
-0@@ -1540,8 +1540,24 @@ static int mlx5_lag_get_devices_oper_speed(struct mlx5_lag *ldev,return 0 ; } +void mlx5_lag_notify_speed_change (struct mlx5_lag *ldev) +{ +struct lag_func *pf; +int idx; + + idx =mlx5_lag_get_dev_index_by_seq (ldev,MLX5_LAG_P1 ); +if (idx <0 ) +return ; + pf =mlx5_lag_pf (ldev, idx); +if (!pf) +return ; +blocking_notifier_call_chain (&pf->dev->priv.lag_nh, +MLX5_DRIVER_EVENT_LAG_SPEED_CHANGE ,NULL ); +} +int mlx5_lag_update_agg_speed (struct mlx5_lag *ldev) { +u32 old_speed;u32 speed;int err;
drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c int mlx5_lag_update_agg_speed(struct mlx5_lag *ldev) · line 1578
Quoted 10 lines
drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c +4
-0@@ -1553,7 +1569,11 @@ int mlx5_lag_update_agg_speed(struct mlx5_lag *ldev)return err; } + old_speed =READ_ONCE (ldev->agg_speed_mbps);WRITE_ONCE (ldev->agg_speed_mbps, speed); +if (speed != old_speed) +mlx5_lag_notify_speed_change (ldev); +return 0 ; }
[Severity: Medium]
In switchdev mode, does notifying here fire IB_EVENT_DEVICE_SPEED_CHANGE before the eswitch vport speeds have been updated in firmware?
In drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c, mlx5_lag_set_vports_agg_speed() calls mlx5_lag_update_agg_speed() before iterating over the PFs to update the vport speeds via mlx5_lag_modify_device_vports_speed():
drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c:mlx5_lag_set_vports_agg_speed() {
if (mlx5_lag_update_agg_speed(ldev))
return;
...
mlx5_ldev_for_each(pf_idx, 0, ldev) {
...
mlx5_lag_modify_device_vports_speed(mdev, speed);
}
}On the switchdev representor ib_device, mlx5_ib_query_port_speed_rep() in drivers/infiniband/hw/mlx5/main.c only reads the cached bond speed for the uplink representor port, while non-uplink VF/SF representor ports on the same ib_device query MLX5_VPORT_STATE_OP_MOD_ESW_VPORT from firmware:
drivers/infiniband/hw/mlx5/main.c:mlx5_ib_query_port_speed_rep() {
if (rep->vport == MLX5_VPORT_UPLINK) {
if (mlx5_lag_is_sriov(mdev))
return mlx5_ib_query_port_speed_from_bond(dev,
port_num,
speed);
return mlx5_ib_query_port_speed_from_port(dev, port_num,
speed);
}
op_mod = MLX5_VPORT_STATE_OP_MOD_ESW_VPORT;
return mlx5_ib_query_port_speed_from_vport(dev->mdev, op_mod,
rep->vport, true, speed, dev,
port_num);
}If a consumer of the switchdev representor ib_device queries port speeds upon receiving IB_EVENT_DEVICE_SPEED_CHANGE, could non-uplink representor ports still return the old max_tx_speed from firmware because mlx5_lag_modify_device_vports_speed() has not finished yet?
[ ... ]
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
[email protected]
AI reviewRe: [PATCH net V2 3/4] {RDMA,net}/mlx5: notify IB uplink on LAG aggregate speed change
In reply to Tariq ToukanThank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider.
Critical: 0 · High: 2 · Medium: 1 · Low: 0
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [High] The fix does not reach the IB uplink device in non-shared-FDB switchdev (SRIOV) LAG, although the commit message says it fixes the…
- [High] Use-after-free of struct ib_device through async event work queued by the new MLX5_DRIVER_EVENT_LAG_SPEED_CHANGE handler.
- [Medium] net/mlx5: LAG speed change notified before updating eswitch vport speeds
--
{RDMA,net}/mlx5: notify IB uplink on LAG aggregate speed change
This patch raises IB_EVENT_DEVICE_SPEED_CHANGE on the IB uplink device when the cached LAG aggregate speed changes. mlx5_lag_update_agg_speed() now calls a new helper, mlx5_lag_notify_speed_change(). The helper sends MLX5_DRIVER_EVENT_LAG_SPEED_CHANGE on the P1 PF's lag_nh chain, and lag_event() in mlx5_ib turns it into an IB async event.
Quoted 6 lines
drivers/infiniband/hw/mlx5/main.c +0
-0@@ -3690,6 +3690,16 @@ static int lag_event(struct notifier_block *nb, unsigned long event, void *data)rdma_roce_rescan_port (ibdev, portnum +1 );
drivers/infiniband/hw/mlx5/main.c static int lag_event(struct notifier_block *nb, unsigned long event, void *data) · line 3700
Quoted 10 lines
drivers/infiniband/hw/mlx5/main.c +8
-0}break ; +case MLX5_DRIVER_EVENT_LAG_SPEED_CHANGE : { +struct ib_event speed_event = {}; + +if (!dev->ib_active) +break ; + speed_event.device = ibdev; + speed_event.event =IB_EVENT_DEVICE_SPEED_CHANGE ; +ib_dispatch_event (&speed_event);
[Severity: High]
Can the work queued here outlive the ib_device?
ib_dispatch_event() copies the event, including the raw ibdev pointer, into an ib_update_work and queues it on ib_wq. It takes no reference on the device. Nothing synchronizes the dev->ib_active check with __mlx5_ib_remove():
__mlx5_ib_remove() {
dev->ib_active = false;
/* Number of stages to cleanup */
while (stage) {
stage--;
if (profile->stage[stage].cleanup)
profile->stage[stage].cleanup(dev);
}
kfree(dev->port);
ib_dealloc_device(&dev->ib_dev);
}The stages are cleaned up in reverse order. In pf_profile and raw_eth_profile, MLX5_IB_STAGE_IB_REG comes after MLX5_IB_STAGE_ROCE. That means ib_unregister_device() runs first, including its last flush_workqueue(ib_wq) in ib_cache_cleanup_one(). Only after that does mlx5_eth_lag_cleanup()->mlx5e_lag_event_unregister() run.
One possible ordering:
CPU1 (bond work or mlx5_mpesw_speed_update_work, holding ldev->lock) mlx5_lag_update_agg_speed()
mlx5_lag_notify_speed_change()
blocking_notifier_call_chain() /* down_read(&lag_nh.rwsem) */
lag_event()
sees dev->ib_active == true
<preempted>CPU2 (rmmod mlx5_ib or auxiliary unbind)__mlx5_ib_remove()
dev->ib_active = false;
mlx5_ib_stage_ib_reg_cleanup()
ib_unregister_device() /* last ib_wq flush */
mlx5_eth_lag_cleanup()
mlx5e_lag_event_unregister()
blocking_notifier_chain_unregister() /* waits on rwsem */
CPU1
ib_dispatch_event()
queue_work(ib_wq, &work->work);
up_read(&lag_nh.rwsem)CPU2
ib_dealloc_device()
... ib_device_release()
kfree_rcu(dev, rcu_head);ib_wq workerib_generic_event_task()
ib_dispatch_event_clients()
down_read(&event->device->event_handler_rwsem); /* freed */
The commit message says:
blocking_notifier_chain_unregister() in mlx5_eth_lag_cleanup() takes the write side and cannot return until any in-flight callback has completed, so no event can be dispatched to a freed device after unregistration.
The rwsem waits for lag_event() to return. Does it also wait for the ib_wq work that lag_event() queued? Nothing seems to flush ib_wq after mlx5e_lag_event_unregister().
The existing mlx5_ib_event path seems to avoid this, because its DEVICE_NOTIFIER stage is torn down before IB_REG. The last patch in this series doesn't appear to change this path.
Quoted 16 lines
drivers/infiniband/hw/mlx5/main.c +2
-0+break ; + }default :return NOTIFY_DONE ; }drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c +3
-0@@ -1540,8 +1540,24 @@ static int mlx5_lag_get_devices_oper_speed(struct mlx5_lag *ldev,return 0 ; } +void mlx5_lag_notify_speed_change (struct mlx5_lag *ldev) +{ +struct lag_func *pf;
drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c static int mlx5_lag_get_devices_oper_speed(struct mlx5_lag *ldev, · line 1555
Quoted 10 lines
drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c +10
-0+int idx; + + idx =mlx5_lag_get_dev_index_by_seq (ldev,MLX5_LAG_P1 ); +if (idx <0 ) +return ; + pf =mlx5_lag_pf (ldev, idx); +if (!pf) +return ; +blocking_notifier_call_chain (&pf->dev->priv.lag_nh, +MLX5_DRIVER_EVENT_LAG_SPEED_CHANGE ,NULL );
[Severity: Medium]
Is the event sent before the vports it describes have been updated?
mlx5_lag_set_vports_agg_speed() calls mlx5_lag_update_agg_speed() first. Only after that does it walk the PFs and push the new max_tx_speed to each eswitch vport with MODIFY_VPORT_STATE:
mlx5_lag_set_vports_agg_speed() {
if (mlx5_lag_update_agg_speed(ldev))
return;
...
mlx5_ldev_for_each(pf_idx, 0, ldev) {
...
mlx5_lag_modify_device_vports_speed(mdev, speed);
}
}With this patch, mlx5_lag_update_agg_speed() calls mlx5_lag_notify_speed_change() as soon as agg_speed_mbps is written. So lag_event() queues IB_EVENT_DEVICE_SPEED_CHANGE on ib_wq while the FW vport state still holds the old speed. This applies to mlx5_do_bond(), mlx5_mpesw_speed_update_work() and mlx5_lag_shared_fdb_create(), which all go through mlx5_lag_set_vports_agg_speed().
On the switchdev representor ib_device, only the uplink port reads the cached aggregate. The VF/SF representor ports on the same ib_device query FW instead:
mlx5_ib_query_port_speed_rep() {
if (rep->vport == MLX5_VPORT_UPLINK) {
if (mlx5_lag_is_sriov(mdev))
return mlx5_ib_query_port_speed_from_bond(...);
...
}
op_mod = MLX5_VPORT_STATE_OP_MOD_ESW_VPORT;
return mlx5_ib_query_port_speed_from_vport(dev->mdev, op_mod,
rep->vport, ...);
}A consumer could handle the event and query ports 2..N before the mlx5_lag_modify_device_vports_speed() loop has finished. It would then read a stale max_tx_speed. I couldn't find anything that raises a second IB_EVENT_DEVICE_SPEED_CHANGE on the representor ib_device once the loop completes. In that case the stale value would be all the consumer ever sees for that change.
The commit message says:
That cache is where the IB layer now takes the effective speed from, so a consumer that queries after receiving the event is guaranteed to read the new value.
That holds for the uplink port. Does it hold for the other representor ports on the same device?
Could the notification be sent from mlx5_lag_set_vports_agg_speed() after the vport loop, instead of from mlx5_lag_update_agg_speed()? Or is there a reason the event has to be raised before the vports are updated? Any callers of mlx5_lag_update_agg_speed() outside mlx5_lag_set_vports_agg_speed(), such as RoCE LAG, would presumably still need their own notification.
[Severity: High]
Does this event reach the IB uplink device in switchdev (SRIOV) LAG when shared FDB is not used? That is the case when mlx5_lag_shared_fdb_supported() returns false and mlx5_do_bond() takes the mlx5_activate_lag(..., MLX5_LAG_MODE_SRIOV, false) branch.
The event only goes to P1's lag_nh. mlx5_eth_lag_init() registers lag_events only if LAG is already active when the IB device initializes:
mlx5_eth_lag_init() {
...
ns = mlx5_get_flow_namespace(mdev, MLX5_FLOW_NAMESPACE_LAG);
if (!ns || !mlx5_lag_is_active(mdev))
return 0;
...
mlx5e_lag_event_register(dev);
...
}IB reps are loaded when switchdev mode is enabled, which is before the bond forms. The non-shared-FDB branch of mlx5_do_bond() doesn't reload or rescan the IB devices. Only the RoCE LAG and shared FDB paths do:
mlx5_do_bond() {
...
if (!shared_fdb)
mlx5_lag_set_vports_agg_speed(ldev);
} else if (mlx5_lag_should_modify_lag(ldev, do_bond)) {
mlx5_modify_lag(ldev, &tracker);
mlx5_lag_set_vports_agg_speed(ldev);
...
}mlx5_create_lag() also reinitializes the chain when LAG is activated, which drops any earlier subscriber:
BLOCKING_INIT_NOTIFIER_HEAD(&dev0->priv.lag_nh);
Without shared FDB, mlx5_ib_vport_rep_load() also leaves lag_master pointing at the PF itself. So each PF's uplink IB device has ibdev->mdev set to its own PF. A P2 uplink device would subscribe to P2's lag_nh, if it subscribed at all, so an event sent only to P1 could not reach it.
These uplink devices still report the cached aggregate, because mlx5_ib_query_port_speed_rep() doesn't check for shared FDB:
if (rep->vport == MLX5_VPORT_UPLINK) {
if (mlx5_lag_is_sriov(mdev))
return mlx5_ib_query_port_speed_from_bond(dev,
port_num,
speed);In this setup, wouldn't the uplink IB device still get only the immediate physical-port event, possibly before agg_speed_mbps is updated, and nothing once the aggregate settles? That is the behavior the commit message says it fixes:
The uplink vport is deliberately skipped when pushing the aggregate speed, so the IB uplink device never gets a second event once the aggregate has settled.
Could the notification go through a chain on each PF that every mlx5_ib device is always subscribed to, instead of only P1's lag_nh? The later patch in this series, "net/mlx5: Lag, save and restore vport max_tx_speed across LAG", doesn't appear to touch the notification path.
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261022193053.3815866-1-tariqt%40nvidia.com
Tariq Toukan
maintainerPATCH v2 4/4 net/mlx5: Lag, save and restore vport max_tx_speed across LAG
In reply to Tariq ToukanFrom: Or Har-Toov <[email protected]>
mlx5_lag_reset_vports_speed() queries the oper link speed at LAG teardown and writes it back to each vport. When the link is down at that moment, mlx5_port_oper_linkspeed() returns 0, which FW treats as "not provided" and ignores, leaving the aggregate rate limit on the vports after teardown.
Save each vport's max_tx_speed when the vport is enabled, before the LAG aggregate or a deferred aggregate replay can overwrite it. While a LAG is active, only a vport with a pending aggregate is saved, as FW may already hold the aggregate for any other vport. Restore the saved value per vport at teardown instead of querying the oper speed, and update agg_max_tx_speed to the pre-LAG value so disabled vports replay the correct rate when they are later enabled. A vport keeps its saved value after teardown, as it is the baseline for the next LAG, and for a disabled vport it is also the pending restore value.
If the max_tx_speed of a vport could not be saved, it stays zero and mlx5_lag_get_restore_speed() falls back to a link-derived speed at teardown. The aggregate is still applied to such a vport.
This also covers the case where the oper speed query fails and the PF is skipped entirely, leaving the aggregate in FW and in agg_max_tx_speed, as raised in the AI review of v1 of "net/mlx5: Lag, reset vport speed on teardown". It is unrelated to that patch, so it is fixed here separately.
Firmware never returns zero as a configured max_tx_speed; zero means "not supported", so using it as a sentinel for "not yet saved" is safe.
A vport disabled for the entire LAG period was never assigned a per-vport rate limit, so no original speed exists to restore; deferring through agg_max_tx_speed on re-enable is correct.
--- .../net/ethernet/mellanox/mlx5/core/eswitch.c | 22 ++++++ .../net/ethernet/mellanox/mlx5/core/eswitch.h | 1 + .../net/ethernet/mellanox/mlx5/core/lag/lag.c | 68 ++++++++++++++++--- 3 files changed, 81 insertions(+), 10 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/eswitch.c +22 -0
@@ -935,6 +935,27 @@ static void esw_vport_cleanup(struct mlx5_eswitch *esw, struct mlx5_vport *vportesw_vport_cleanup_acl (esw, vport); } +static void mlx5_esw_vport_save_max_tx_speed (struct mlx5_eswitch *esw, +struct mlx5_vport *vport) +{ +u16 op_mod =MLX5_VPORT_STATE_OP_MOD_ESW_VPORT ; +int ret; + +if (!MLX5_CAP_ESW (esw->dev, esw_vport_state_max_tx_speed) || + vport->vport ==MLX5_VPORT_UPLINK || vport->max_tx_speed) +return ; + +if (mlx5_lag_is_active (esw->dev) && !vport->agg_max_tx_speed) +return ; + + ret =mlx5_query_vport_max_tx_speed (esw->dev, op_mod, vport->vport, + true, &vport->max_tx_speed,NULL ); +if (ret) +mlx5_core_dbg (esw->dev, +"Failed to save vport %d max tx speed, err=%d\n" , + vport->vport, ret); +} +static void mlx5_esw_vport_set_max_tx_speed (struct mlx5_eswitch *esw,struct mlx5_vport *vport) {
@@ -999,6 +1020,7 @@ 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); +mlx5_esw_vport_save_max_tx_speed (esw, vport);if (vport->agg_max_tx_speed)mlx5_esw_vport_set_max_tx_speed (esw, vport); done:
drivers/net/ethernet/mellanox/mlx5/core/eswitch.h +1 -0
@@ -261,6 +261,7 @@ struct mlx5_vport {int index;struct mlx5_devlink_port *dl_port;u32 agg_max_tx_speed; +u32 max_tx_speed; };struct mlx5_esw_indir_table ;
drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c +58 -10
86 lines not on this page · raw message
Signature · 1 line
2.44.0
[email protected]
AI reviewRe: [PATCH net V2 4/4] net/mlx5: Lag, save and restore vport max_tx_speed across LAG
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider: - [High] net/mlx5: broken LAG state check in mlx5_esw_vport_save_max_tx_speed() - [Medium] net/mlx5…
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] net/mlx5: broken LAG state check in mlx5_esw_vport_save_max_tx_speed()
- [Medium] net/mlx5: unreset aggregate speed in mlx5_lag_reset_vports_speed()
- [Medium] net/mlx5: single-PF PCIe bandwidth clamp in mlx5_lag_get_restore_speed() --
commit a16b0bd296f6ec7da26bed226c7219e07a503e4a
Author: Or Har-Toov <[email protected]>
net/mlx5: Lag, save and restore vport max_tx_speed across LAG
This commit saves each vport's max_tx_speed when enabled so the original rate limit can be restored on lag teardown even if the link is down. If the rate was not saved, teardown falls back to a link-derived speed.
Quoted 13 lines
drivers/net/ethernet/mellanox/mlx5/core/eswitch.c +5
-0@@ -935,6 +935,27 @@ static void esw_vport_cleanup(struct mlx5_eswitch *esw, struct mlx5_vport *vportesw_vport_cleanup_acl (esw, vport); } +static void mlx5_esw_vport_save_max_tx_speed (struct mlx5_eswitch *esw, +struct mlx5_vport *vport) +{ +u16 op_mod =MLX5_VPORT_STATE_OP_MOD_ESW_VPORT ; +int ret;
drivers/net/ethernet/mellanox/mlx5/core/eswitch.c static void esw_vport_cleanup(struct mlx5_eswitch *esw, struct mlx5_vport *vport · line 952
Quoted 10 lines
drivers/net/ethernet/mellanox/mlx5/core/eswitch.c +10
-0+ +if (!MLX5_CAP_ESW (esw->dev, esw_vport_state_max_tx_speed) || + vport->vport ==MLX5_VPORT_UPLINK || vport->max_tx_speed) +return ; + +if (mlx5_lag_is_active (esw->dev) && !vport->agg_max_tx_speed) +return ; + + ret =mlx5_query_vport_max_tx_speed (esw->dev, op_mod, vport->vport, + true, &vport->max_tx_speed,NULL );
[Severity: High]
Does the check on mlx5_lag_is_active(esw->dev) and !vport->agg_max_tx_speed in mlx5_esw_vport_save_max_tx_speed() match how vport->agg_max_tx_speed is maintained across the driver?
In drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c, mlx5_lag_modify_device_vports_speed() sets vport->agg_max_tx_speed = speed on every vport and leaves it non-zero after programming firmware:
mlx5_lag_modify_device_vports_speed() {
...
vport->agg_max_tx_speed = speed;
if (!vport->enabled)
continue;
ret = mlx5_modify_vport_max_tx_speed(mdev, op_mod,
vport->vport, true, speed);
...
}Similarly, mlx5_esw_vport_set_max_tx_speed() in drivers/net/ethernet/mellanox/mlx5/core/eswitch.c writes vport->agg_max_tx_speed to firmware on vport enable without clearing vport->agg_max_tx_speed. As a result, while lag is active, vports whose firmware has already been overwritten with the aggregate speed still have a non-zero vport->agg_max_tx_speed.
Meanwhile, mlx5_lag_is_active() in drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c returns true when Socket Direct shared fdb is active, even when no lag bond is active and vport->agg_max_tx_speed is 0:
drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c:mlx5_lag_is_active() {
...
res = ldev && (__mlx5_lag_is_active(ldev) ||
__mlx5_lag_is_sd_active(ldev, dev));
...
}When switching a Socket Direct device to switchdev mode via mlx5_sd_eswitch_mode_set() -> mlx5_sd_activate_shared_fdb() -> mlx5_lag_shared_fdb_create() in drivers/net/ethernet/mellanox/mlx5/core/lag/shared_fdb.c, pf->sd_fdb_active is set to true without calling mlx5_lag_set_vports_agg_speed():
mlx5_lag_shared_fdb_create() {
...
mlx5_lag_for_each(i, 0, ldev, filter) {
pf = mlx5_lag_pf(ldev, i);
pf->sd_fdb_active = true;
}
...
if (filter == MLX5_LAG_FILTER_PORTS || filter == MLX5_LAG_FILTER_ALL)
mlx5_lag_set_vports_agg_speed(ldev);
}The same state (mlx5_lag_is_active(esw->dev) returning true while vport->agg_max_tx_speed is 0 and firmware still holds the pre-lag speed) also occurs during lag activation in mlx5_lag_shared_fdb_create() when ldev->lock is dropped inside mlx5_lag_reload_ib_reps_from_locked() before mlx5_lag_set_vports_agg_speed() runs, if mlx5_lag_update_agg_speed() fails, or when creating adjacent vports via mlx5_esw_adj_vport_create().
If a vport is enabled in any of those states (or if the initial mlx5_query_vport_max_tx_speed() call fails), vport->max_tx_speed remains 0. Once lag applies the aggregate speed to firmware (setting vport->agg_max_tx_speed != 0) and that vport is later disabled and re-enabled while lag is active, won't mlx5_esw_vport_save_max_tx_speed() see vport->max_tx_speed == 0 and vport->agg_max_tx_speed != 0, query firmware, and overwrite vport->max_tx_speed with the active lag aggregate rate?
[ ... ]
Quoted 19 lines
drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c +11
-0@@ -1712,11 +1712,37 @@ void mlx5_lag_set_vports_agg_speed(struct mlx5_lag *ldev) } } +static int mlx5_lag_get_restore_speed (struct mlx5_core_dev *mdev, +struct mlx5_vport *vport,u32 *speed) +{ +u32 pci_bw; + +if (vport->max_tx_speed) { + *speed = vport->max_tx_speed; +return 0 ; + } + + *speed =0 ;
drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c void mlx5_lag_set_vports_agg_speed(struct mlx5_lag *ldev) · line 1735
Quoted 10 lines
drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c +10
-0+mlx5_port_oper_linkspeed (mdev, speed); +if (!*speed &&mlx5_port_max_linkspeed (mdev, speed)) +return -ENODATA ; + + pci_bw =pcie_bandwidth_mbps (mdev->pdev); +if (pci_bw) + *speed =min (*speed, pci_bw); + *speed /=MLX5_MAX_TX_SPEED_UNIT ; +return 0 ; +}
[Severity: Medium]
On Socket Direct devices where a single physical port spans multiple pcie functions in the same group (port->group_id), calling pcie_bandwidth_mbps(mdev->pdev) in mlx5_lag_get_restore_speed() only checks a single function's pcie bandwidth.
Earlier in drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c, mlx5_lag_port_pcie_bw() sums the bandwidth across all member functions in the Socket Direct group:
drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c:mlx5_lag_port_pcie_bw() {
...
if (!port->group_id)
return mlx5_lag_dev_pcie_bw(port->dev, bw);
*bw = 0;
mlx5_lag_for_each(idx, 0, ldev, port->group_id) {
member = mlx5_lag_pf(ldev, idx);
if (!member)
continue;
err = mlx5_lag_dev_pcie_bw(member->dev, &member_bw);
...
}Should mlx5_lag_get_restore_speed() use mlx5_lag_port_pcie_bw() instead of pcie_bandwidth_mbps(mdev->pdev) so that Socket Direct ports are not clamped to a single function's pcie bandwidth on fallback restore?
Quoted 53 lines
drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c +30
-10+void mlx5_lag_reset_vports_speed (struct mlx5_lag *ldev) { +u16 op_mod =MLX5_VPORT_STATE_OP_MOD_ESW_VPORT ;struct mlx5_core_dev *mdev; +struct mlx5_eswitch *esw; +struct mlx5_vport *vport;struct lag_func *pf; -u32 speed; +u32 restore_speed; +unsigned long i;int pf_idx;int ret;@@ -1728,17 +1754,39 @@ void mlx5_lag_reset_vports_speed(struct mlx5_lag *ldev) mdev = pf->dev;if (!mdev)continue ; - - ret =mlx5_port_oper_linkspeed (mdev, &speed); -if (ret) { -mlx5_core_dbg (mdev, -"Failed to reset vports speed for device %s. Oper speed is not available (err=%d)\n" , -dev_name (mdev->device), ret); + esw = mdev->priv.eswitch; +if (!esw || !MLX5_CAP_ESW (mdev, esw_vport_state_max_tx_speed))continue ; - } - speed = speed /MLX5_MAX_TX_SPEED_UNIT ; -mlx5_lag_modify_device_vports_speed (mdev, speed); +mutex_lock (&esw->state_lock); +mlx5_esw_for_each_vport (esw, i, vport) { +if (!vport || vport->vport ==MLX5_VPORT_UPLINK ) +continue ; + +if (!vport->enabled) { + vport->agg_max_tx_speed = vport->max_tx_speed; +continue ; + } + +if (mlx5_lag_get_restore_speed (mdev, vport, + &restore_speed)) { + vport->agg_max_tx_speed =0 ; +continue ; + } + + ret =mlx5_modify_vport_max_tx_speed (mdev, op_mod, + vport->vport, + true, + restore_speed); +if (ret) { + mlx5_core_dbg(mdev,
drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c void mlx5_lag_reset_vports_speed(struct mlx5_lag *ldev) · line 1792
Quoted 10 lines
drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c +7
-0+"Failed to restore vport %d max tx speed, err=%d\n" , + vport->vport, ret); + continue; + } + vport->agg_max_tx_speed =0 ; + } +mutex_unlock (&esw->state_lock); } }#endif
[Severity: Medium]
What happens in mlx5_lag_reset_vports_speed() if a vport was enabled while lag was active (so firmware was programmed with the aggregate speed), its baseline vport->max_tx_speed was not saved (remaining 0), and the vport is then disabled before lag teardown?
When mlx5_lag_reset_vports_speed() runs, the !vport->enabled branch sets vport->agg_max_tx_speed = vport->max_tx_speed (0) instead of computing a fallback speed via mlx5_lag_get_restore_speed(). When that vport is later re-enabled after lag teardown in mlx5_esw_vport_enable():
drivers/net/ethernet/mellanox/mlx5/core/eswitch.c:mlx5_esw_vport_enable() {
...
mlx5_esw_vport_save_max_tx_speed(esw, vport);
if (vport->agg_max_tx_speed)
mlx5_esw_vport_set_max_tx_speed(esw, vport);
...
}mlx5_esw_vport_save_max_tx_speed() sees vport->max_tx_speed == 0 and !mlx5_lag_is_active(esw->dev), queries firmware (which still holds the unrestored lag aggregate speed), and saves the aggregate speed into vport->max_tx_speed, while skipping mlx5_esw_vport_set_max_tx_speed() because vport->agg_max_tx_speed is 0.
Also, for an enabled vport, if mlx5_modify_vport_max_tx_speed() fails in mlx5_lag_reset_vports_speed(), the error path continues before updating vport->agg_max_tx_speed. Won't that leave the stale lag aggregate rate in vport->agg_max_tx_speed, causing a subsequent disable and re-enable of the vport outside of lag to replay the old lag aggregate speed into firmware?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
[email protected]
AI reviewRe: [PATCH net V2 4/4] net/mlx5: Lag, save and restore vport max_tx_speed across LAG
In reply to Tariq ToukanThank you for your contribution! Sashiko AI review found 7 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 7 potential issue(s) to consider.
Critical: 0 · High: 1 · Medium: 5 · Low: 1
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [High] mlx5_esw_vport_save_max_tx_speed() (eswitch.c:948) treats a non- zero agg_max_tx_speed during an active LAG as meaning the aggregate is…
- [Medium] The new restore logic only runs on one LAG teardown path.
- [Medium] vport->max_tx_speed is read from FW only once per mlx5_vport object, because of the || vport->max_tx_speed) return; early return…
- [Medium] In mlx5_lag_reset_vports_speed(), when mlx5_modify_vport_max_tx_speed() fails for an enabled vport, the loop…
- [Medium] mlx5_lag_reset_vports_speed() records agg_max_tx_speed = 0 in two cases where FW still holds the LAG aggregate.
- [Medium] The save gate in mlx5_esw_vport_save_max_tx_speed() uses mlx5_lag_is_active(), which reads ldev->mode under lag_lock.
- [Low] The fallback in mlx5_lag_get_restore_speed() clamps with the raw per-device pcie_bandwidth_mbps(mdev->pdev).
--
net/mlx5: Lag, save and restore vport max_tx_speed across LAG
This commit reads each vport's max_tx_speed from FW when the vport is enabled. At LAG teardown it writes that saved value back per vport, instead of writing the oper link speed. If nothing was saved, it falls back to a link-derived speed clamped by PCIe bandwidth, and disabled vports get their saved value as agg_max_tx_speed for the next enable.
Quoted 7 lines
drivers/net/ethernet/mellanox/mlx5/core/eswitch.c +0
-0@@ -935,6 +935,27 @@ static void esw_vport_cleanup(struct mlx5_eswitch *esw, struct mlx5_vport *vportesw_vport_cleanup_acl (esw, vport); }
drivers/net/ethernet/mellanox/mlx5/core/eswitch.c static void esw_vport_cleanup(struct mlx5_eswitch *esw, struct mlx5_vport *vport · line 946
Quoted 10 lines
drivers/net/ethernet/mellanox/mlx5/core/eswitch.c +9
-0+static void mlx5_esw_vport_save_max_tx_speed (struct mlx5_eswitch *esw, +struct mlx5_vport *vport) +{ +u16 op_mod =MLX5_VPORT_STATE_OP_MOD_ESW_VPORT ; +int ret; + +if (!MLX5_CAP_ESW (esw->dev, esw_vport_state_max_tx_speed) || + vport->vport ==MLX5_VPORT_UPLINK || vport->max_tx_speed) +return ;
[Severity: Medium]
Once vport->max_tx_speed is non-zero, this returns early. Nothing in the patch ever sets it back to 0. Can the saved value go stale?
The mlx5_vport objects are allocated once, in mlx5_esw_vports_init() from mlx5_init_once(). They survive devlink reload, fw_activate, sync reset and health recovery, because mlx5_load_one_devl_locked() only runs mlx5_function_setup() and mlx5_load().
After such a reset, FW may recompute its per-vport default (the lower of port speed and PCIe bandwidth). If the PCIe link or port speed has changed, mlx5_lag_get_restore_speed() still uses the old saved value at the next teardown.
For disabled vports, the old value is copied into agg_max_tx_speed. Since that field is never cleared, mlx5_esw_vport_enable() writes it on every later enable, even when no LAG is configured.
Should max_tx_speed be reset on reload/reset, or read again from FW when no LAG is active?
drivers/net/ethernet/mellanox/mlx5/core/eswitch.c static void esw_vport_cleanup(struct mlx5_eswitch *esw, struct mlx5_vport *vport · line 949
Quoted 3 lines
drivers/net/ethernet/mellanox/mlx5/core/eswitch.c +3
-0+ +if (mlx5_lag_is_active (esw->dev) && !vport->agg_max_tx_speed) +return ;
[Severity: High]
This check reads a non-zero agg_max_tx_speed during an active LAG as "the aggregate is pending and FW still holds the original". Is that always the case?
mlx5_lag_modify_device_vports_speed() sets agg_max_tx_speed for every vport. For enabled vports it also writes the aggregate to FW right away:
vport->agg_max_tx_speed = speed;
if (!vport->enabled)
continue;
ret = mlx5_modify_vport_max_tx_speed(mdev, op_mod, vport->vport, true, speed);Nothing clears agg_max_tx_speed once it has been applied. mlx5_esw_vport_disable() doesn't touch agg_max_tx_speed or max_tx_speed either.
So take a vport with max_tx_speed == 0 while FW already holds the aggregate. That state is reachable in two ways:
- An earlier save query failed (only logged at debug level).
- The vport was enabled while mlx5_lag_is_active() was true and agg_max_tx_speed was 0, so the save was skipped. One example is an SD-only shared FDB: __mlx5_lag_is_sd_active() makes mlx5_lag_is_active() return true, but no aggregate is applied. A later aggregate, for example from MPESW enable, then lands on the enabled vport.
If that vport is disabled and re-enabled while the LAG is still active, this check passes. The query then stores the FW aggregate in vport->max_tx_speed.
At teardown, mlx5_lag_get_restore_speed() returns that value and the aggregate is written back. Because max_tx_speed is never reset, every later LAG cycle restores the same wrong baseline.
That seems to contradict the commit message:
If the max_tx_speed of a vport could not be saved, it stays zero and mlx5_lag_get_restore_speed() falls back to a link-derived speed at teardown.
Is a separate marker needed here, one that can tell "aggregate pending" apart from "aggregate applied"?
[Severity: Medium]
Does mlx5_lag_is_active() stay consistent with agg_max_tx_speed here?
mlx5_lag_is_active() reads ldev->mode under lag_lock. ldev->mode is written under ldev->lock only, in mlx5_activate_lag() and mlx5_deactivate_lag(). agg_max_tx_speed and the FW aggregate are written in a separate esw->state_lock section.
On activation, mlx5_do_bond()->mlx5_lag_shared_fdb_create() sets the mode and drops ldev->lock for rep rescans and reloads. Only after that does it call mlx5_lag_set_vports_agg_speed().
A vport can be enabled in that window. One way is mlx5_eswitch_enable() when the FDB already exists: toggle_lag is false, so mlx5_lag_disable_change() doesn't serialize it. SF/ECPF function changes are another way. Such a vport sees an active LAG with agg_max_tx_speed == 0. It skips the save even though FW still holds the original, and then receives the aggregate.
On teardown, mlx5_do_bond() does:
mlx5_lag_reset_vports_speed(ldev);
mlx5_disable_lag(ldev);The mode is still set after mlx5_lag_reset_vports_speed() drops state_lock. A vport enabled in that window also skips the save.
Either way, the vport ends up with max_tx_speed == 0 while FW holds the aggregate. Isn't that the precondition for the saved-baseline problem described above?
Quoted 8 lines
drivers/net/ethernet/mellanox/mlx5/core/eswitch.c +8
-0+ + ret =mlx5_query_vport_max_tx_speed (esw->dev, op_mod, vport->vport, + true, &vport->max_tx_speed,NULL ); +if (ret) +mlx5_core_dbg (esw->dev, +"Failed to save vport %d max tx speed, err=%d\n" , + vport->vport, ret); +}
[ ... ]
Quoted 16 lines
drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c +8
-0@@ -1712,11 +1712,37 @@ void mlx5_lag_set_vports_agg_speed(struct mlx5_lag *ldev) } } +static int mlx5_lag_get_restore_speed (struct mlx5_core_dev *mdev, +struct mlx5_vport *vport,u32 *speed) +{ +u32 pci_bw; + +if (vport->max_tx_speed) { + *speed = vport->max_tx_speed; +return 0 ;
drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c void mlx5_lag_set_vports_agg_speed(struct mlx5_lag *ldev) · line 1732
Quoted 10 lines
drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c +10
-0+ } + + *speed =0 ; +mlx5_port_oper_linkspeed (mdev, speed); +if (!*speed &&mlx5_port_max_linkspeed (mdev, speed)) +return -ENODATA ; + + pci_bw =pcie_bandwidth_mbps (mdev->pdev); +if (pci_bw) + *speed =min (*speed, pci_bw);
[Severity: Low]
This might not be an issue, but the fallback clamps with the per-device pcie_bandwidth_mbps(mdev->pdev). The aggregate path uses mlx5_lag_port_pcie_bw() instead, which sums bandwidth across Socket-Direct group members and treats RC_END as unlimited.
The restore value is per vport, and the FW default is described as coming from the endpoint's own link status. So the per-device clamp may be intended. For RC_END, pcie_bandwidth_mbps() returns 0 and the if (pci_bw) check skips the clamp.
Could a short comment explain why the per-device value is used here rather than the SD-aware helper?
Quoted 3 lines
drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c +3
-0+ *speed /=MLX5_MAX_TX_SPEED_UNIT ; +return 0 ; +}
[ ... ]
Quoted 9 lines
drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c +0
-5@@ -1728,17 +1754,39 @@ void mlx5_lag_reset_vports_speed(struct mlx5_lag *ldev) mdev = pf->dev;if (!mdev)continue ; - - ret =mlx5_port_oper_linkspeed (mdev, &speed); -if (ret) { - mlx5_core_dbg(mdev, - "Failed to reset vports speed for device %s. Oper speed is not available (err=%d)\n",
drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c void mlx5_lag_reset_vports_speed(struct mlx5_lag *ldev) · line 1762
Quoted 10 lines
drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c +4
-4- dev_name(mdev->device), ret); + esw = mdev->priv.eswitch; +if (!esw || !MLX5_CAP_ESW (mdev, esw_vport_state_max_tx_speed))continue ; - } - speed = speed /MLX5_MAX_TX_SPEED_UNIT ; -mlx5_lag_modify_device_vports_speed (mdev, speed); +mutex_lock (&esw->state_lock); +mlx5_esw_for_each_vport (esw, i, vport) {
[Severity: Medium]mlx5_lag_reset_vports_speed() is only called from the mlx5_lag_should_disable_lag() branch of mlx5_do_bond(). That predicate excludes MPESW:
return !do_bond && __mlx5_lag_is_active(ldev) &&
ldev->mode != MLX5_LAG_MODE_MPESW;Should the other teardown paths restore vport speeds as well?
mlx5_lag_disable_change() goes straight to mlx5_lag_disable_mpesw() or mlx5_disable_lag(). It is called from mlx5_eswitch_enable(), mlx5_eswitch_disable() and the devlink eswitch mode change.
Explicit MPESW disable goes through mlx5_mpesw_work()->mlx5_lag_disable_mpesw()->mlx5_lag_shared_fdb_destroy(), and doesn't restore either.
The aggregate is still applied when these LAGs come up, through mlx5_lag_shared_fdb_create()->mlx5_lag_set_vports_agg_speed() and mlx5_mpesw_speed_update_work().
After those teardowns, FW and agg_max_tx_speed both still hold the aggregate. mlx5_esw_vport_enable() writes it again on every later enable.
With the new save step, a vport whose max_tx_speed is still 0 then reads the leftover aggregate from FW and keeps it as its saved original. Every later mlx5_do_bond() teardown then restores the aggregate.
The missing restore calls on these paths were already there before this patch. But the commit message says the saved value is restored "at teardown", and the interaction with the new save step is new.
drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c void mlx5_lag_reset_vports_speed(struct mlx5_lag *ldev) · line 1775
Quoted 13 lines
drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c +13
-0+if (!vport || vport->vport ==MLX5_VPORT_UPLINK ) +continue ; + +if (!vport->enabled) { + vport->agg_max_tx_speed = vport->max_tx_speed; +continue ; + } + +if (mlx5_lag_get_restore_speed (mdev, vport, + &restore_speed)) { + vport->agg_max_tx_speed =0 ; +continue ; + }
[Severity: Medium]
Both of these branches set agg_max_tx_speed to 0 without writing FW. Could FW still hold the aggregate in either case?
For a disabled vport with max_tx_speed == 0, the pending restore is dropped. That vport may have been enabled partway through the LAG without a saved value (the mlx5_lag_is_active() check skipped the save, or the query failed). It then received the aggregate and was disabled before teardown.
The patch already assumes FW keeps max_tx_speed across a vport disable. That is why disabled vports get a replay value.
For an enabled vport, mlx5_lag_get_restore_speed() returns -ENODATA when nothing was saved and the PTYS query fails.
In both cases, the next mlx5_esw_vport_enable() after the LAG is gone sees max_tx_speed == 0 and an inactive LAG. It queries FW and saves the leftover aggregate as the original.
Before this patch, disabled vports got agg_max_tx_speed set to the oper speed, so re-enabling them corrected FW.
The commit message covers "a vport disabled for the entire LAG period". Does the same reasoning hold for a vport that was disabled partway through the LAG?
drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c void mlx5_lag_reset_vports_speed(struct mlx5_lag *ldev) · line 1786
Quoted 11 lines
drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c +11
-0+ + ret =mlx5_modify_vport_max_tx_speed (mdev, op_mod, + vport->vport, + true, + restore_speed); +if (ret) { +mlx5_core_dbg (mdev, +"Failed to restore vport %d max tx speed, err=%d\n" , + vport->vport, ret); +continue ; + }
[Severity: Medium]
If mlx5_modify_vport_max_tx_speed() fails here, agg_max_tx_speed keeps the LAG aggregate. Is that intended?
Before, mlx5_lag_modify_device_vports_speed() set agg_max_tx_speed to the teardown speed before trying the FW write. A later enable would then retry with a non-LAG value.
Now, on a later enable with no LAG active, mlx5_esw_vport_enable() runs:
if (vport->agg_max_tx_speed)
mlx5_esw_vport_set_max_tx_speed(esw, vport);which writes the stale aggregate to FW again. If max_tx_speed is still 0, the save step runs first and records the aggregate still in FW as the baseline.
That looks like the state the commit message says is fixed:
leaving the aggregate in FW and in agg_max_tx_speed
Would setting vport->agg_max_tx_speed = restore_speed in this failure branch let the next enable retry the restore?
Quoted 3 lines
drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c +3
-0+ vport->agg_max_tx_speed =0 ; + } +mutex_unlock (&esw->state_lock);
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261022193053.3815866-1-tariqt%40nvidia.com
Re: [PATCH net V2 4/4] net/mlx5: Lag, save and restore vport max_tx_speed across LAG
Quoted 265 lines · On 26/10/2026 22:32, [email protected] wrote:
External email: Use caution opening links or attachments
Thank you for your contribution! Sashiko AI review found 7 potential issue(s) to consider.
Critical: 0 · High: 1 · Medium: 5 · Low: 1
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [High]
mlx5_esw_vport_save_max_tx_speed()(eswitch.c:948) treats a non- zeroagg_max_tx_speedduring an active LAG as meaning the aggregate is…
- [Medium] The new restore logic only runs on one LAG teardown path.
- [Medium]vport->max_tx_speedis read from FW only once permlx5_vportobject, because of the|| vport->max_tx_speed) return;early return…
- [Medium] Inmlx5_lag_reset_vports_speed(), whenmlx5_modify_vport_max_tx_speed()fails for an enabled vport, the loop…
- [Medium]mlx5_lag_reset_vports_speed()recordsagg_max_tx_speed= 0 in two cases where FW still holds the LAG aggregate.
- [Medium] The save gate inmlx5_esw_vport_save_max_tx_speed()usesmlx5_lag_is_active(), which readsldev->modeunderlag_lock.
- [Low] The fallback inmlx5_lag_get_restore_speed()clamps with the raw per-devicepcie_bandwidth_mbps(mdev->pdev).--
net/mlx5: Lag, save and restore vport
max_tx_speedacross LAGThis commit reads each vport's
max_tx_speedfrom FW when the vport is enabled. At LAG teardown it writes that saved value back per vport, instead of writing the oper link speed. If nothing was saved, it falls back to a link-derived speed clamped by PCIe bandwidth, and disabled vports get their saved value asagg_max_tx_speedfor the next enable.Quoted 7 lines
drivers/net/ethernet/mellanox/mlx5/core/eswitch.c +0
-0@@ -935,6 +935,27 @@ static void esw_vport_cleanup(struct mlx5_eswitch *esw, struct mlx5_vport *vportesw_vport_cleanup_acl (esw, vport); }drivers/net/ethernet/mellanox/mlx5/core/eswitch.c static void esw_vport_cleanup(struct mlx5_eswitch *esw, struct mlx5_vport *vport · line 946
Quoted 10 lines
drivers/net/ethernet/mellanox/mlx5/core/eswitch.c +9
-0+static void mlx5_esw_vport_save_max_tx_speed (struct mlx5_eswitch *esw, +struct mlx5_vport *vport) +{ +u16 op_mod =MLX5_VPORT_STATE_OP_MOD_ESW_VPORT ; +int ret; + +if (!MLX5_CAP_ESW (esw->dev, esw_vport_state_max_tx_speed) || + vport->vport ==MLX5_VPORT_UPLINK || vport->max_tx_speed) +return ;[Severity: Medium]
Oncevport->max_tx_speedis non-zero, this returns early. Nothing in the patch ever sets it back to 0. Can the saved value go stale?The
mlx5_vportobjects are allocated once, inmlx5_esw_vports_init()frommlx5_init_once(). They survive devlink reload,fw_activate, sync reset and health recovery, becausemlx5_load_one_devl_locked()only runsmlx5_function_setup()andmlx5_load().After such a reset, FW may recompute its per-vport default (the lower of port speed and PCIe bandwidth). If the PCIe link or port speed has changed,
mlx5_lag_get_restore_speed()still uses the old saved value at the next teardown.For disabled vports, the old value is copied into
agg_max_tx_speed. Since that field is never cleared,mlx5_esw_vport_enable()writes it on every later enable, even when no LAG is configured.Should
max_tx_speedbe reset on reload/reset, or read again from FW when no LAG is active?drivers/net/ethernet/mellanox/mlx5/core/eswitch.c static void esw_vport_cleanup(struct mlx5_eswitch *esw, struct mlx5_vport *vport · line 949
Quoted 3 lines
drivers/net/ethernet/mellanox/mlx5/core/eswitch.c +3
-0+ +if (mlx5_lag_is_active (esw->dev) && !vport->agg_max_tx_speed) +return ;[Severity: High]
This check reads a non-zeroagg_max_tx_speedduring an active LAG as "the aggregate is pending and FW still holds the original". Is that always the case?
mlx5_lag_modify_device_vports_speed()setsagg_max_tx_speedfor every vport. For enabled vports it also writes the aggregate to FW right away:vport->agg_max_tx_speed = speed; if (!vport->enabled) continue; ret = mlx5_modify_vport_max_tx_speed(mdev, op_mod, vport->vport, true, speed);Nothing clears
agg_max_tx_speedonce it has been applied.mlx5_esw_vport_disable()doesn't touchagg_max_tx_speedormax_tx_speedeither.So take a vport with
max_tx_speed== 0 while FW already holds the aggregate. That state is reachable in two ways:- An earlier save query failed (only logged at debug level).
- The vport was enabled whilemlx5_lag_is_active()was true andagg_max_tx_speedwas 0, so the save was skipped. One example is an SD-only shared FDB:__mlx5_lag_is_sd_active()makesmlx5_lag_is_active()return true, but no aggregate is applied. A later aggregate, for example from MPESW enable, then lands on the enabled vport.If that vport is disabled and re-enabled while the LAG is still active, this check passes. The query then stores the FW aggregate in
vport->max_tx_speed.At teardown,
mlx5_lag_get_restore_speed()returns that value and the aggregate is written back. Becausemax_tx_speedis never reset, every later LAG cycle restores the same wrong baseline.That seems to contradict the commit message:
If the
max_tx_speedof a vport could not be saved, it stays zero andmlx5_lag_get_restore_speed()falls back to a link-derived speed at teardown.Is a separate marker needed here, one that can tell "aggregate pending" apart from "aggregate applied"?
[Severity: Medium]
Doesmlx5_lag_is_active()stay consistent withagg_max_tx_speedhere?
mlx5_lag_is_active()readsldev->modeunderlag_lock.ldev->modeis written underldev->lockonly, inmlx5_activate_lag()andmlx5_deactivate_lag().agg_max_tx_speedand the FW aggregate are written in a separateesw->state_locksection.On activation, mlx5_do_bond()->mlx5_lag_shared_fdb_create() sets the mode and drops
ldev->lockfor rep rescans and reloads. Only after that does it callmlx5_lag_set_vports_agg_speed().A vport can be enabled in that window. One way is
mlx5_eswitch_enable()when the FDB already exists:toggle_lagis false, somlx5_lag_disable_change()doesn't serialize it. SF/ECPF function changes are another way. Such a vport sees an active LAG withagg_max_tx_speed== 0. It skips the save even though FW still holds the original, and then receives the aggregate.On teardown,
mlx5_do_bond()does:mlx5_lag_reset_vports_speed(ldev); mlx5_disable_lag(ldev);The mode is still set after
mlx5_lag_reset_vports_speed()dropsstate_lock. A vport enabled in that window also skips the save.Either way, the vport ends up with
max_tx_speed== 0 while FW holds the aggregate. Isn't that the precondition for the saved-baseline problem described above?Quoted 8 lines
drivers/net/ethernet/mellanox/mlx5/core/eswitch.c +8
-0+ + ret =mlx5_query_vport_max_tx_speed (esw->dev, op_mod, vport->vport, + true, &vport->max_tx_speed,NULL ); +if (ret) +mlx5_core_dbg (esw->dev, +"Failed to save vport %d max tx speed, err=%d\n" , + vport->vport, ret); +}[ ... ]
Quoted 16 lines
drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c +8
-0@@ -1712,11 +1712,37 @@ void mlx5_lag_set_vports_agg_speed(struct mlx5_lag *ldev) } } +static int mlx5_lag_get_restore_speed (struct mlx5_core_dev *mdev, +struct mlx5_vport *vport,u32 *speed) +{ +u32 pci_bw; + +if (vport->max_tx_speed) { + *speed = vport->max_tx_speed; +return 0 ;drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c void mlx5_lag_set_vports_agg_speed(struct mlx5_lag *ldev) · line 1732
Quoted 10 lines
drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c +10
-0+ } + + *speed =0 ; +mlx5_port_oper_linkspeed (mdev, speed); +if (!*speed &&mlx5_port_max_linkspeed (mdev, speed)) +return -ENODATA ; + + pci_bw =pcie_bandwidth_mbps (mdev->pdev); +if (pci_bw) + *speed =min (*speed, pci_bw);[Severity: Low]
This might not be an issue, but the fallback clamps with the per-devicepcie_bandwidth_mbps(mdev->pdev). The aggregate path usesmlx5_lag_port_pcie_bw()instead, which sums bandwidth across Socket-Direct group members and treatsRC_ENDas unlimited.The restore value is per vport, and the FW default is described as coming from the endpoint's own link status. So the per-device clamp may be intended. For
RC_END,pcie_bandwidth_mbps()returns 0 and the if (pci_bw) check skips the clamp.Could a short comment explain why the per-device value is used here rather than the SD-aware helper?
Quoted 3 lines
drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c +3
-0+ *speed /=MLX5_MAX_TX_SPEED_UNIT ; +return 0 ; +}[ ... ]
Quoted 9 lines
drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c +0
-5@@ -1728,17 +1754,39 @@ void mlx5_lag_reset_vports_speed(struct mlx5_lag *ldev) mdev = pf->dev;if (!mdev)continue ; - - ret =mlx5_port_oper_linkspeed (mdev, &speed); -if (ret) { - mlx5_core_dbg(mdev, - "Failed to reset vports speed for device %s. Oper speed is not available (err=%d)\n",drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c void mlx5_lag_reset_vports_speed(struct mlx5_lag *ldev) · line 1762
Quoted 10 lines
drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c +4
-4- dev_name(mdev->device), ret); + esw = mdev->priv.eswitch; +if (!esw || !MLX5_CAP_ESW (mdev, esw_vport_state_max_tx_speed))continue ; - } - speed = speed /MLX5_MAX_TX_SPEED_UNIT ; -mlx5_lag_modify_device_vports_speed (mdev, speed); +mutex_lock (&esw->state_lock); +mlx5_esw_for_each_vport (esw, i, vport) {[Severity: Medium]
mlx5_lag_reset_vports_speed()is only called from themlx5_lag_should_disable_lag()branch ofmlx5_do_bond(). That predicate excludes MPESW:return !do_bond && __mlx5_lag_is_active(ldev) && ldev->mode != MLX5_LAG_MODE_MPESW;Should the other teardown paths restore vport speeds as well?
mlx5_lag_disable_change()goes straight tomlx5_lag_disable_mpesw()ormlx5_disable_lag(). It is called frommlx5_eswitch_enable(),mlx5_eswitch_disable()and the devlink eswitch mode change.Explicit MPESW disable goes through mlx5_mpesw_work()->mlx5_lag_disable_mpesw()->mlx5_lag_shared_fdb_destroy(), and doesn't restore either.
The aggregate is still applied when these LAGs come up, through mlx5_lag_shared_fdb_create()->mlx5_lag_set_vports_agg_speed() and
mlx5_mpesw_speed_update_work().After those teardowns, FW and
agg_max_tx_speedboth still hold the aggregate.mlx5_esw_vport_enable()writes it again on every later enable.
Quoted 8 lines
With the new save step, a vport whose
max_tx_speedis still 0 then reads the leftover aggregate from FW and keeps it as its saved original. Every latermlx5_do_bond()teardown then restores the aggregate.The missing restore calls on these paths were already there before this patch. But the commit message says the saved value is restored "at teardown", and the interaction with the new save step is new.
Will be fixed in a different patch that will be added to the V3 of this series (calling mlx5_lag_reset_vports_speed in MPESW teardown.
Quoted 87 lines
Quoted 4 lines
drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c +3
-0+if (!vport || vport->vport ==MLX5_VPORT_UPLINK ) +continue ; +drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c void mlx5_lag_reset_vports_speed(struct mlx5_lag *ldev) · line 1775
Quoted 10 lines
drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c +10
-0+if (!vport->enabled) { + vport->agg_max_tx_speed = vport->max_tx_speed; +continue ; + } + +if (mlx5_lag_get_restore_speed (mdev, vport, + &restore_speed)) { + vport->agg_max_tx_speed =0 ; +continue ; + }[Severity: Medium]
Both of these branches setagg_max_tx_speedto 0 without writing FW. Could FW still hold the aggregate in either case?For a disabled vport with
max_tx_speed== 0, the pending restore is dropped. That vport may have been enabled partway through the LAG without a saved value (themlx5_lag_is_active()check skipped the save, or the query failed). It then received the aggregate and was disabled before teardown.The patch already assumes FW keeps
max_tx_speedacross a vport disable. That is why disabled vports get a replay value.For an enabled vport,
mlx5_lag_get_restore_speed()returns-ENODATAwhen nothing was saved and the PTYS query fails.In both cases, the next
mlx5_esw_vport_enable()after the LAG is gone seesmax_tx_speed== 0 and an inactive LAG. It queries FW and saves the leftover aggregate as the original.Before this patch, disabled vports got
agg_max_tx_speedset to the oper speed, so re-enabling them corrected FW.The commit message covers "a vport disabled for the entire LAG period". Does the same reasoning hold for a vport that was disabled partway through the LAG?
drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c void mlx5_lag_reset_vports_speed(struct mlx5_lag *ldev) · line 1786
Quoted 11 lines
drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c +11
-0+ + ret =mlx5_modify_vport_max_tx_speed (mdev, op_mod, + vport->vport, + true, + restore_speed); +if (ret) { +mlx5_core_dbg (mdev, +"Failed to restore vport %d max tx speed, err=%d\n" , + vport->vport, ret); +continue ; + }[Severity: Medium]
Ifmlx5_modify_vport_max_tx_speed()fails here,agg_max_tx_speedkeeps the LAG aggregate. Is that intended?Before,
mlx5_lag_modify_device_vports_speed()setagg_max_tx_speedto the teardown speed before trying the FW write. A later enable would then retry with a non-LAG value.Now, on a later enable with no LAG active,
mlx5_esw_vport_enable()runs:if (vport->agg_max_tx_speed) mlx5_esw_vport_set_max_tx_speed(esw, vport);which writes the stale aggregate to FW again. If
max_tx_speedis still 0, the save step runs first and records the aggregate still in FW as the baseline.That looks like the state the commit message says is fixed:
leaving the aggregate in FW and in
agg_max_tx_speedWould setting
vport->agg_max_tx_speed=restore_speedin this failure branch let the next enable retry the restore?drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c void mlx5_lag_reset_vports_speed(struct mlx5_lag *ldev) · line 1789
Quoted 3 lines
drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c +3
-0+ vport->agg_max_tx_speed =0 ; + } +mutex_unlock (&esw->state_lock);[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261022193053.3815866-1-tariqt%40nvidia.com
[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 19 lines · On 22/10/2026 22:37, [email protected] wrote:
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.
Hi,
Bugs 1 and 2 were found during internal integration and testing of the flow added by 50f1d188c580 ("net/mlx5: Propagate LAG effective max_tx_speed to vports"). Bug 3 was found by sashiko.
All three were reproduced on CX8.
Or