Re: [PATCH net-next V2 10/10] net/mlx5: LAG, do not add a device to an already-active virt LAG
From: Shay Drory
Date: Thu Nov 19 2026 - 03:58:54 EST
On Wed, 18 Nov 2026 10:32:00 +0000, netdev-bot+sashiko@xxxxxxxxxx wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential
> issue(s) to consider.
>
> Critical: 0 · High: 0 (1) · 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).
>
> - [Medium] In this tree, both parts of the patch hit a predicate
> mismatch.
>
> Pre-existing issues:
> - [High] This problem wasn't introduced by this patch, but the patch now
> cleans up the HCA devcom component on its own new -EOPNOTSUPP path…
>
> --
>
> net/mlx5: LAG, do not add a device to an already-active virt LAG
>
> This patch stops a virt LAG capable function from joining a LAG whose mode
> is already active. In that case __mlx5_lag_dev_add_mdev() returns
> -EOPNOTSUPP, and mlx5_lag_add_mdev() then unregisters the HCA devcom
> component. The patch also makes mlx5_esw_offloads_devcom_init() skip eswitch
> devcom registration for a non-PF virt LAG capable function that has no ldev.
>
> > diff --git a/drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c b/drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c
> > index 3e88b3f51612e..abcab76fced0b 100644
> > --- a/drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c
> > +++ b/drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c
> > @@ -2448,6 +2448,11 @@ static int __mlx5_lag_dev_add_mdev(struct mlx5_core_dev *dev)
> > mutex_unlock(&ldev->lock);
> > return -EAGAIN;
> > }
> > +
> > + if (mlx5_virt_lag_is_supported(dev) && __mlx5_lag_is_active(ldev)) {
> > + mutex_unlock(&ldev->lock);
> > + return -EOPNOTSUPP;
> > + }
>
> [Severity: Medium]
>
> Can this condition ever be true in this tree?
>
> mlx5_lag_add_mdev() is the only caller of __mlx5_lag_dev_add_mdev(). It
> returns early unless mlx5_lag_is_supported() passes:
>
> mlx5_lag_add_mdev() {
> if (!mlx5_lag_is_supported(dev))
> return;
> ...
> }
>
> mlx5_lag_is_supported() requires num_lag_ports >= 2:
>
> if (!MLX5_CAP_GEN(dev, vport_group_manager) ||
> !MLX5_CAP_GEN(dev, lag_master) ||
> MLX5_CAP_GEN(dev, num_lag_ports) < 2 ||
> ...
>
> mlx5_virt_lag_is_supported(), on the other hand, requires
> num_lag_ports < 2:
>
> if (!MLX5_CAP_GEN(dev, multi_uplink_eswitch) ||
> !MLX5_CAP_GEN(dev, lag_master) ||
> MLX5_CAP_GEN(dev, num_lag_ports) >= 2)
> return false;
>
> No device can satisfy both, so this -EOPNOTSUPP return and the new cleanup
> branch in mlx5_lag_add_mdev() look unreachable.
>
> The commit message says:
>
> "mlx5_ldev_add_mdev() would add a newly probed device to the LAG even
> when the LAG is already active"
>
> Can that happen today for a virt LAG capable function? If this check only
> prepares for a later series that enables virt LAG, could the commit message
> say so?
No, not in this series, and that is intended. As the cover letter says,
this series only prepares the LAG core. The follow-up series admits virt
LAG capable functions in mlx5_lag_add_mdev(), and only then can the check
fire.
> The same mismatch seems to affect the eswitch change. A non-PF virt LAG
> capable function never reaches mlx5_ldev_add_mdev() here, because
> sd_lag_init() only handles PF SD secondaries. So dev->priv.lag stays NULL
> for it, and mlx5_virt_lag_nonmember() is always true:
>
> static inline bool mlx5_virt_lag_nonmember(struct mlx5_core_dev *dev)
> {
> return mlx5_virt_lag_is_supported(dev) && !mlx5_lag_dev(dev);
> }
>
> As a result, the new early return in mlx5_esw_offloads_devcom_init() fires
> for every such VF/SF eswitch:
>
> if (!mlx5_core_is_pf(esw->dev) && mlx5_virt_lag_nonmember(esw->dev))
> return;
>
> Before this patch, a VF/SF eswitch with merged_eswitch would register
> MLX5_DEVCOM_ESW_OFFLOADS and send ESW_OFFLOADS_DEVCOM_PAIR. The existing
> MLX5_VPORT_MANAGER() / !mlx5_lag_is_supported() gate further down does not
> stop a non-PF, because MLX5_VPORT_MANAGER() requires mlx5_core_is_pf().
>
> Does this drop eswitch devcom pairing for those VF/SF eswitches? That would
> contradict "it is a no-op for existing configurations".
No existing VF/SF passes mlx5_virt_lag_is_supported(). New FW will allow
a VF/SF to report multi_uplink_eswitch and lag_master with
num_lag_ports < 2, so the skip changes nothing for existing
configurations.
For such a VF/SF, skipping the pairing outside a LAG is intended. It
manages its own nested E-switch, and it pairs with other E-switches only
as a member of the virt LAG's shared FDB.
> The commit message also limits the devcom change to "such a device", meaning
> one rejected from an active LAG. The condition, however, matches any virt LAG
> capable VF/SF that has no ldev.
>
> Once virt LAG joins are allowed, devices that are left out because
> mlx5_lag_dev_alloc(), mlx5_ldev_add_mdev() or
> mlx5_lag_register_hca_devcom_comp() failed would also be treated as
> non-members. Is that intended?
Yes. Whatever the reason the device was left out, it is not a LAG member,
so it must not pair with the LAG members' E-switches.
> > mlx5_ldev_get(ldev);
> > err = mlx5_ldev_add_mdev(ldev, dev, 0);
> > if (err) {
> > @@ -2536,6 +2541,10 @@ void mlx5_lag_add_mdev(struct mlx5_core_dev *dev)
> > err = __mlx5_lag_dev_add_mdev(dev);
> > mlx5_devcom_comp_unlock(dev->priv.hca_devcom_comp);
> >
> > + if (err == -EOPNOTSUPP) {
> > + mlx5_lag_unregister_hca_devcom_comp(dev);
> > + return;
> > + }
>
> [Severity: High]
>
> This isn't a bug introduced by this patch, but this new path unregisters the
> HCA devcom component, while the nearby failure paths in
> __mlx5_lag_dev_add_mdev() still leave it registered.
>
> If no peer ldev exists and mlx5_lag_dev_alloc() or mlx5_ldev_add_mdev()
> fails, __mlx5_lag_dev_add_mdev() returns 0 with dev->priv.lag still NULL:
>
> if (!ldev) {
> ldev = mlx5_lag_dev_alloc(dev);
> if (!ldev) {
> mlx5_core_err(dev, "Failed to alloc lag dev\n");
> return 0;
> }
> err = mlx5_ldev_add_mdev(ldev, dev, 0);
> if (err) {
> mlx5_core_err(dev, "Failed to add mdev to lag dev\n");
> mlx5_ldev_put(ldev);
> return 0;
> }
> return 0;
> }
>
> mlx5_lag_add_mdev() treats that as success, sends LAG_DEVCOM_PAIR and keeps
> dev->priv.hca_devcom_comp. On teardown, mlx5_lag_remove_mdev() returns
> before it reaches mlx5_lag_unregister_hca_devcom_comp():
>
> ldev = mlx5_lag_dev(dev);
> if (!ldev)
> return;
>
> The comp_dev's data still points at this mlx5_core_dev. Does that comp_dev
> stay on the shared component list after the core dev is freed?
>
> If so, a peer with the same key that probes or reloads would get the freed
> dev back from mlx5_devcom_get_next_peer_data() in __mlx5_lag_dev_add_mdev().
> It would then call mlx5_lag_dev(tmp_dev) on freed memory.
>
> A peer's LAG_DEVCOM_PAIR/UNPAIR event would likewise call
> mlx5_lag_devcom_event() with the freed dev. That reads dev->priv.lag and can
> call mutex_lock() on a garbage ldev.
>
> Could the component also be unregistered on those allocation failure paths?
>
> > if (err) {
> > msleep(100);
> > goto recheck;
>
> [ ... ]
>
> --
> Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261116103010.1129666-1-tariqt%40nvidia.com