106 lines
3.9 KiB
Diff
106 lines
3.9 KiB
Diff
From e372fb3a61e3df224c1a4e95424e8124dbd9dbef Mon Sep 17 00:00:00 2001
|
|
From: Kamal Heib <kheib@redhat.com>
|
|
Date: Sun, 19 Apr 2026 18:24:31 -0400
|
|
Subject: [PATCH] net/mlx5e: Prevent entering switchdev mode with inconsistent
|
|
netns
|
|
|
|
JIRA: https://redhat.atlassian.net/browse/RHEL-169055
|
|
|
|
commit 06fdc45f16c392dc3394c67e7c17ae63935715d3
|
|
Author: Jianbo Liu <jianbol@nvidia.com>
|
|
Date: Mon Sep 29 00:25:18 2025 +0300
|
|
|
|
net/mlx5e: Prevent entering switchdev mode with inconsistent netns
|
|
|
|
When a PF enters switchdev mode, its netdevice becomes the uplink
|
|
representor but remains in its current network namespace. All other
|
|
representors (VFs, SFs) are created in the netns of the devlink
|
|
instance.
|
|
|
|
If the PF's netns has been moved and differs from the devlink's netns,
|
|
enabling switchdev mode would create a state where the OVS control
|
|
plane (ovs-vsctl) cannot manage the switch because the PF uplink
|
|
representor and the other representors are split across different
|
|
namespaces.
|
|
|
|
To prevent this inconsistent configuration, block the request to enter
|
|
switchdev mode if the PF netdevice's netns does not match the netns of
|
|
its devlink instance.
|
|
|
|
As part of this change, the PF's netns is first marked as immutable.
|
|
This prevents race conditions where the netns could be changed after
|
|
the check is performed but before the mode transition is complete, and
|
|
it aligns the PF's behavior with that of the final uplink representor.
|
|
|
|
Signed-off-by: Jianbo Liu <jianbol@nvidia.com>
|
|
Reviewed-by: Cosmin Ratiu <cratiu@nvidia.com>
|
|
Reviewed-by: Jiri Pirko <jiri@nvidia.com>
|
|
Reviewed-by: Dragos Tatulea <dtatulea@nvidia.com>
|
|
Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
|
|
Link: https://patch.msgid.link/1759094723-843774-3-git-send-email-tariqt@nvidia.com
|
|
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
|
|
|
|
Signed-off-by: Kamal Heib <kheib@redhat.com>
|
|
|
|
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c b/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c
|
|
index b8ec55929ab1..52c3de24bea3 100644
|
|
--- a/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c
|
|
+++ b/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c
|
|
@@ -3774,6 +3774,29 @@ void mlx5_eswitch_unblock_mode(struct mlx5_core_dev *dev)
|
|
up_write(&esw->mode_lock);
|
|
}
|
|
|
|
+/* Returns false only when uplink netdev exists and its netns is different from
|
|
+ * devlink's netns. True for all others so entering switchdev mode is allowed.
|
|
+ */
|
|
+static bool mlx5_devlink_netdev_netns_immutable_set(struct devlink *devlink,
|
|
+ bool immutable)
|
|
+{
|
|
+ struct mlx5_core_dev *mdev = devlink_priv(devlink);
|
|
+ struct net_device *netdev;
|
|
+ bool ret;
|
|
+
|
|
+ netdev = mlx5_uplink_netdev_get(mdev);
|
|
+ if (!netdev)
|
|
+ return true;
|
|
+
|
|
+ rtnl_lock();
|
|
+ netdev->netns_immutable = immutable;
|
|
+ ret = net_eq(dev_net(netdev), devlink_net(devlink));
|
|
+ rtnl_unlock();
|
|
+
|
|
+ mlx5_uplink_netdev_put(mdev, netdev);
|
|
+ return ret;
|
|
+}
|
|
+
|
|
int mlx5_devlink_eswitch_mode_set(struct devlink *devlink, u16 mode,
|
|
struct netlink_ext_ack *extack)
|
|
{
|
|
@@ -3816,6 +3839,14 @@ int mlx5_devlink_eswitch_mode_set(struct devlink *devlink, u16 mode,
|
|
esw->eswitch_operation_in_progress = true;
|
|
up_write(&esw->mode_lock);
|
|
|
|
+ if (mode == DEVLINK_ESWITCH_MODE_SWITCHDEV &&
|
|
+ !mlx5_devlink_netdev_netns_immutable_set(devlink, true)) {
|
|
+ NL_SET_ERR_MSG_MOD(extack,
|
|
+ "Can't change E-Switch mode to switchdev when netdev net namespace has diverged from the devlink's.");
|
|
+ err = -EINVAL;
|
|
+ goto skip;
|
|
+ }
|
|
+
|
|
if (mode == DEVLINK_ESWITCH_MODE_LEGACY)
|
|
esw->dev->priv.flags |= MLX5_PRIV_FLAGS_SWITCH_LEGACY;
|
|
mlx5_eswitch_disable_locked(esw);
|
|
@@ -3834,6 +3865,8 @@ int mlx5_devlink_eswitch_mode_set(struct devlink *devlink, u16 mode,
|
|
}
|
|
|
|
skip:
|
|
+ if (mode == DEVLINK_ESWITCH_MODE_SWITCHDEV && err)
|
|
+ mlx5_devlink_netdev_netns_immutable_set(devlink, false);
|
|
down_write(&esw->mode_lock);
|
|
esw->eswitch_operation_in_progress = false;
|
|
unlock:
|
|
--
|
|
2.50.1 (Apple Git-155)
|
|
|