net/mlx5e: Take RTNL lock before triggering netdev notifiers
[linux-2.6-block.git] / drivers / net / ethernet / mellanox / mlx5 / core / en_rep.c
index 2fdb8895aecd7b601316ffd385e04e5b7d63d64d..5ca9bc337dc6ae8f24501786b4653ef1839c06d1 100644 (file)
@@ -769,6 +769,7 @@ static int mlx5e_rep_max_nch_limit(struct mlx5_core_dev *mdev)
 
 static void mlx5e_build_rep_params(struct net_device *netdev)
 {
+       const bool take_rtnl = netdev->reg_state == NETREG_REGISTERED;
        struct mlx5e_priv *priv = netdev_priv(netdev);
        struct mlx5e_rep_priv *rpriv = priv->ppriv;
        struct mlx5_eswitch_rep *rep = rpriv->rep;
@@ -794,8 +795,15 @@ static void mlx5e_build_rep_params(struct net_device *netdev)
        /* RQ */
        mlx5e_build_rq_params(mdev, params);
 
+       /* If netdev is already registered (e.g. move from nic profile to uplink,
+        * RTNL lock must be held before triggering netdev notifiers.
+        */
+       if (take_rtnl)
+               rtnl_lock();
        /* update XDP supported features */
        mlx5e_set_xdp_feature(netdev);
+       if (take_rtnl)
+               rtnl_unlock();
 
        /* CQ moderation params */
        params->rx_dim_enabled = MLX5_CAP_GEN(mdev, cq_moderation);