Re: [PATCH net-next V2 06/10] net/mlx5: LAG, rename PF naming to fn

From
netdev-bot+sashiko@kernel.org
Date
2026-11-18 10:31:57
Also in
linux-rdma, lkml
Reply to
Tariq Toukan, 2026-11-16
Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] The commit message misstates what this patch renames.

Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but it is still
  present at the end of the series.

--

net/mlx5: LAG, rename PF naming to fn

This commit renames the LAG member bookkeeping from PF naming to fn. The
ldev->pfs xarray becomes ldev->fns, the mlx5_lag_pf*() helpers become
mlx5_lag_fn*(), and the pf locals become fn. The rename prepares for virt
LAG, where LAG members will not always be physical functions.
Rename the xarray to ldev->fns, the helpers to mlx5_lag_fn*(), and the
locals to fn, so the naming matches struct lag_fn.
[Severity: Low]
Is this description accurate? struct lag_fn doesn't exist before this
patch. The patch creates it by renaming the struct in lag.h:

-struct lag_func {
+struct lag_fn {

It also renames a field of struct mlx5_lag:

-	u8			  max_funcs;
+	u8			  max_fns;

The commit message mentions neither rename.

The patch also makes a few small changes that are not renames:

  - a new esw local in mlx5_lag_drop_rule_cleanup()
  - dev0/dev1 moved above the switch in mlx5_lag_set_port_affinity()
  - new mdev/affinity locals in mlx5_lag_create_port_sel_table() and
    __mlx5_lag_modify_definers_destinations()

Could the commit message mention these as well?

A few spots look like they were missed by the rename. The pf_idx and
pf_mdev locals remain in mlx5_lag_get_devices_oper_speed(),
mlx5_lag_get_devices_max_speed(), mlx5_lag_set_vports_agg_speed() and
mlx5_lag_reset_vports_speed():

	mlx5_ldev_for_each(pf_idx, 0, ldev) {
		...
		pf_mdev = fn->dev;

mlx5_get_next_lag_func() and mlx5_get_pre_lag_func() walk the renamed fns
xarray but keep their old names.

In mlx5_lag_mpesw_port_change_event(), the local now has the same name as
the struct tag. The container_of() continuation lines are still aligned for
the old, longer name:

	struct lag_fn *lag_fn = container_of(mlx5_nb,
						 struct lag_fn,
						 port_change_nb);

Was that intended?
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 cbef6ab1e38a8..74e7e7161c95d 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
@@ -2390,24 +2392,24 @@ int mlx5_ldev_add_mdev(struct mlx5_lag *ldev,
 void mlx5_ldev_remove_mdev(struct mlx5_lag *ldev,
 			   struct mlx5_core_dev *dev)
 {
[ ... ]
quoted hunk ↗ jump to hunk
-	pf->dev = NULL;
+	fn->dev = NULL;
 	dev->priv.lag = NULL;
-	xa_erase(&ldev->pfs, pf->idx);
-	kfree(pf);
+	xa_erase(&ldev->fns, fn->idx);
+	kfree(fn);
 }
[Severity: High]
This is a pre-existing issue and was not introduced by this patch. Since
this code is being touched: is it safe to free the lag_fn here while
readers holding only lag_lock may still be using it?

mlx5_ldev_remove_mdev() runs with only ldev->lock held. It is called from:

  - mlx5_unload()->mlx5_lag_remove_mdev()
  - sd_lag_cleanup()
  - the error path of sd_lag_init()

It erases the entry and frees it right away with kfree(). There is no RCU
grace period, and lag_lock is not taken.

Several exported helpers walk the same ldev->fns xarray while holding only
lag_lock, without ldev->lock. For example:

mlx5_lag_get_next_peer_mdev() {
	spin_lock_irqsave(&lag_lock, flags);
	...
	mlx5_lag_for_each(idx, *i, ldev, mlx5_lag_get_filter(ldev, dev)) {
		fn = mlx5_lag_fn(ldev, idx);
		if (fn->dev != dev)
			break;
	}
	...
	fn = mlx5_lag_fn(ldev, idx);
	peer_dev = fn->dev;
	...
}

mlx5_lag_is_master(), mlx5_lag_is_shared_fdb() and mlx5_lag_is_sd() read
fn->dev, fn->group_id and fn->sd_fdb_active through mlx5_lag_get_filter()
and mlx5_lag_fn_by_dev(). mlx5_lag_get_slave_port() and
mlx5_lag_active_backup_get_netdev() also dereference entries while holding
only lag_lock.

Can this interleaving happen between two devices in the same ldev?

CPU0 (peer device A)             CPU1 (device B unload)
mlx5_esw_is_owner()
  mlx5_lag_is_master()
    spin_lock_irqsave(&lag_lock)
    mlx5_lag_get_filter()
      mlx5_lag_fn_by_dev()
        xa_for_each() loads fn
                                 mlx5_lag_remove_mdev()
                                   mutex_lock(&ldev->lock)
                                   mlx5_ldev_remove_mdev()
                                     xa_erase(&ldev->fns, fn->idx)
                                     kfree(fn)
        fn->dev == dev   <- reads freed memory

If mlx5_lag_get_next_peer_mdev() hits the same window, it returns the stale
fn->dev to its caller as a peer mlx5_core_dev pointer.

The baseline already has the same xa_erase() and kfree() in
mlx5_ldev_remove_mdev(), and nothing later in the series changes this.

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261116103010.1129666-1-tariqt%40nvidia.com
Thread (17 messages) 17 messages, 2 authors, last reply 8h ago
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help