]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
net/mlx5e: Prevent entering switchdev mode with inconsistent netns
authorJianbo Liu <jianbol@nvidia.com>
Sun, 28 Sep 2025 21:25:18 +0000 (00:25 +0300)
committerJakub Kicinski <kuba@kernel.org>
Wed, 1 Oct 2025 00:21:14 +0000 (17:21 -0700)
commit06fdc45f16c392dc3394c67e7c17ae63935715d3
tree98f58565cb4cc6d028e1c2dcb61eef3ea5c04b4f
parent906154caa7d3d750d47cd18f9349b75b77e12854
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>
drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c