Skip to content

Commit

Permalink
net/mlx5e: Prevent possible races in VXLAN control flow
Browse files Browse the repository at this point in the history
When calling add/remove VXLAN port, a lock must be held in order to
prevent race scenarios when more than one add/remove happens at the
same time.
Fix by holding our state_lock (mutex) as done by all other parts of the
driver.
Note that the spinlock protecting the radix-tree is still needed in
order to synchronize radix-tree access from softirq context.

Fixes: b3f63c3 ("net/mlx5e: Add netdev support for VXLAN tunneling")
Signed-off-by: Gal Pressman <galp@mellanox.com>
Signed-off-by: Saeed Mahameed <saeedm@mellanox.com>
  • Loading branch information
Gal Pressman authored and Saeed Mahameed committed Dec 19, 2017
1 parent 23f4cc2 commit 0c1cc8b
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions drivers/net/ethernet/mellanox/mlx5/core/vxlan.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ static void mlx5e_vxlan_add_port(struct work_struct *work)
struct mlx5e_vxlan *vxlan;
int err;

mutex_lock(&priv->state_lock);
vxlan = mlx5e_vxlan_lookup_port(priv, port);
if (vxlan) {
atomic_inc(&vxlan->refcount);
Expand Down Expand Up @@ -117,6 +118,7 @@ static void mlx5e_vxlan_add_port(struct work_struct *work)
err_delete_port:
mlx5e_vxlan_core_del_port_cmd(priv->mdev, port);
free_work:
mutex_unlock(&priv->state_lock);
kfree(vxlan_work);
}

Expand All @@ -130,6 +132,7 @@ static void mlx5e_vxlan_del_port(struct work_struct *work)
struct mlx5e_vxlan *vxlan;
bool remove = false;

mutex_lock(&priv->state_lock);
spin_lock_bh(&vxlan_db->lock);
vxlan = radix_tree_lookup(&vxlan_db->tree, port);
if (!vxlan)
Expand All @@ -147,6 +150,7 @@ static void mlx5e_vxlan_del_port(struct work_struct *work)
mlx5e_vxlan_core_del_port_cmd(priv->mdev, port);
kfree(vxlan);
}
mutex_unlock(&priv->state_lock);
kfree(vxlan_work);
}

Expand Down

0 comments on commit 0c1cc8b

Please sign in to comment.