Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.
Critical: 0 · High: 1 · Medium: 0 · 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] In mlx5_lag_rescan_devices_locked_filter()
(drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c), this patch…
--
net/mlx5: LAG, drop MLX5_MAX_PORTS scratch array from device rescan
This commit removes the devs[MLX5_MAX_PORTS] array from
mlx5_lag_rescan_devices_locked_filter(). The post-unlock rescan loop now
walks the LAG members again with mlx5_lag_for_each(). The commit message
describes this as having no functional change.
quoted hunk ↗ jump to hunk
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c b/drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c
index a7b12353b7225..3e88b3f51612e 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c
[ ... ]
quoted hunk ↗ jump to hunk
@@ -1356,12 +1354,16 @@ static void mlx5_lag_rescan_devices_locked_filter(struct mlx5_lag *ldev,
fn->dev->priv.flags &= ~MLX5_PRIV_FLAGS_DISABLE_IB_ADEV;
else
fn->dev->priv.flags |= MLX5_PRIV_FLAGS_DISABLE_IB_ADEV;
- devs[num_devs++] = fn->dev;
}
mlx5_lag_drop_lock_for_reps(ldev, filter);
- for (i = 0; i < num_devs; i++)
- mlx5_rescan_drivers_locked(devs[i]);
+ mlx5_lag_for_each(i, 0, ldev, filter) {
+ fn = mlx5_lag_fn(ldev, i);
+ if (fn->dev->priv.flags & MLX5_PRIV_FLAGS_DISABLE_ALL_ADEV)
+ continue;
+
+ mlx5_rescan_drivers_locked(fn->dev);
+ }
[Severity: High]
This loop now walks ldev->fns after mlx5_lag_drop_lock_for_reps() has
released ldev->lock. Can a concurrent SD member removal free a lag_fn
while the walk is in progress?
On each step, mlx5_get_next_lag_func() reads xarray entries and fn->dev.
mlx5_lag_fn() then does an xa_load(), and the loop dereferences
fn->dev->priv.flags. The only thing guarding membership while the lock is
dropped is ldev->mode_changes_in_progress. The comment in
mlx5_lag_drop_lock_for_reps() says:
/* Keep PF membership stable while ldev->lock is dropped. Device add
* and remove paths observe mode_changes_in_progress and retry.
*/
The SD paths in lib/sd.c don't appear to check that counter, though.
sd_lag_cleanup() takes the lock directly:
mutex_lock(&ldev->lock);
mlx5_sd_for_each_secondary(i, primary, pos)
mlx5_ldev_remove_mdev(ldev, pos);
mlx5_ldev_remove_mdev() then frees the entry right away, with no RCU
deferral:
fn->dev = NULL;
dev->priv.lag = NULL;
xa_erase(&ldev->fns, fn->idx);
kfree(fn);
sd_lag_cleanup() is serialized only by sd->devcom. For
MLX5_LAG_FILTER_ALL, this function runs under the HCA devcom instead.
mlx5_do_bond_work() takes only the HCA devcom trylock plus ldev->lock, and
not mlx5_mpesw_sd_devcoms_lock(). It reaches this function as follows:
mlx5_do_bond_work()
mlx5_do_bond()
mlx5_lag_shared_fdb_create(ldev, ..., MLX5_LAG_MODE_SRIOV, 0)
mlx5_lag_remove_devices_filter(ldev, MLX5_LAG_FILTER_ALL)
mlx5_lag_rescan_devices_locked_filter()
mlx5_disable_lag() -> mlx5_lag_shared_fdb_destroy(ldev, 0) reaches it the
same way. Group id 0 maps to MLX5_LAG_FILTER_ALL, which matches every
member, SD secondaries included.
At the same time, removing an SD member's eth aux driver can run:
mlx5e_remove() / mlx5e_suspend()
mlx5_sd_cleanup()
sd_lag_cleanup()
mlx5_ldev_remove_mdev()
This removal can come from a sysfs unbind of mlx5_core.eth.N. It can also
come from a reload of an SD secondary whose hca_devcom_comp is NULL or in a
different component. Neither case holds the HCA devcom that the bond work
holds.
If that happens, mlx5_get_next_lag_func() could read fn->dev from a freed
lag_fn. mlx5_lag_fn() could also return NULL after xa_erase(), and the
loop would then dereference it.
The old loop touched only the devs[] core_dev pointers once the lock was
dropped. Those pointers stay valid across an aux unbind, so lag_fn and
xarray state was never accessed without the lock.
A similar question applies to sd_lag_init(), which also takes ldev->lock
without checking mode_changes_in_progress and calls mlx5_ldev_add_mdev().
Could the second loop then rescan a newly added member whose
MLX5_PRIV_FLAGS_DISABLE_IB_ADEV flag the first loop never updated?
Given the above, is the "no functional change" statement in the commit
message accurate?
Would it be safer to keep a snapshot taken under the lock? For example, a
dynamically sized array, or a reference on each core_dev collected before
mlx5_lag_drop_lock_for_reps().
As far as I can tell, the last patch in the series doesn't touch this
function or the SD paths, so this would still be present at the end of the
series.
mlx5_lag_retake_lock_after_reps(ldev);
}
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261116103010.1129666-1-tariqt%40nvidia.com