Skip to content

Commit

Permalink
net/mlx5e: Block entering switchdev mode with ns inconsistency
Browse files Browse the repository at this point in the history
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: 7768d19 ("net/mlx5: E-Switch, Add control for encapsulation")
Signed-off-by: Gavin Li <[email protected]>
Reviewed-by: Gavi Teitz <[email protected]>
Signed-off-by: Saeed Mahameed <[email protected]>
  • Loading branch information
GavinLi-NV authored and Saeed Mahameed committed Mar 21, 2023
1 parent c83172b commit 662404b
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c
Original file line number Diff line number Diff line change
Expand Up @@ -3405,6 +3405,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)
{
Expand All @@ -3419,6 +3431,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) {
Expand Down

0 comments on commit 662404b

Please sign in to comment.