Patch "net/mlx5e: Block entering switchdev mode with ns inconsistency" has been added to the 6.2-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    net/mlx5e: Block entering switchdev mode with ns inconsistency

to the 6.2-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     net-mlx5e-block-entering-switchdev-mode-with-ns-inco.patch
and it can be found in the queue-6.2 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit 1221833f51f3c0baaaa195750ca3956e2132602c
Author: Gavin Li <gavinl@xxxxxxxxxx>
Date:   Thu Feb 9 12:48:52 2023 +0200

    net/mlx5e: Block entering switchdev mode with ns inconsistency
    
    [ Upstream commit 662404b24a4c4d839839ed25e3097571f5938b9b ]
    
    Upon entering switchdev mode, VF/SF representors are spawned in the
    devlink instance's net namespace, whereas the PF net device transforms
    into the uplink representor, remaining in the net namespace the PF net
    device was in. Therefore, if a PF net device's namespace is different from
    its parent devlink net namespace, entering switchdev mode can create an
    illegal situation where all representors sharing the same core device
    are NOT in the same net namespace.
    
    To avoid this issue, block entering switchdev mode for devices whose child
    netdev net namespace has diverged from the parent devlink's.
    
    Fixes: 7768d1971de6 ("net/mlx5: E-Switch, Add control for encapsulation")
    Signed-off-by: Gavin Li <gavinl@xxxxxxxxxx>
    Reviewed-by: Gavi Teitz <gavi@xxxxxxxxxx>
    Signed-off-by: Saeed Mahameed <saeedm@xxxxxxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c b/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c
index 3992bf6337ca0..0facc709f0e74 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c
@@ -3518,6 +3518,18 @@ static int esw_inline_mode_to_devlink(u8 mlx5_mode, u8 *mode)
 	return 0;
 }
 
+static bool esw_offloads_devlink_ns_eq_netdev_ns(struct devlink *devlink)
+{
+	struct net *devl_net, *netdev_net;
+	struct mlx5_eswitch *esw;
+
+	esw = mlx5_devlink_eswitch_get(devlink);
+	netdev_net = dev_net(esw->dev->mlx5e_res.uplink_netdev);
+	devl_net = devlink_net(devlink);
+
+	return net_eq(devl_net, netdev_net);
+}
+
 int mlx5_devlink_eswitch_mode_set(struct devlink *devlink, u16 mode,
 				  struct netlink_ext_ack *extack)
 {
@@ -3532,6 +3544,13 @@ int mlx5_devlink_eswitch_mode_set(struct devlink *devlink, u16 mode,
 	if (esw_mode_from_devlink(mode, &mlx5_mode))
 		return -EINVAL;
 
+	if (mode == DEVLINK_ESWITCH_MODE_SWITCHDEV &&
+	    !esw_offloads_devlink_ns_eq_netdev_ns(devlink)) {
+		NL_SET_ERR_MSG_MOD(extack,
+				   "Can't change E-Switch mode to switchdev when netdev net namespace has diverged from the devlink's.");
+		return -EPERM;
+	}
+
 	mlx5_lag_disable_change(esw->dev);
 	err = mlx5_esw_try_lock(esw);
 	if (err < 0) {



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux