Commit 0c1cc8b2 authored by Gal Pressman's avatar Gal Pressman Committed by Saeed Mahameed

net/mlx5e: Prevent possible races in VXLAN control flow

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: b3f63c3d ("net/mlx5e: Add netdev support for VXLAN tunneling")
Signed-off-by: default avatarGal Pressman <galp@mellanox.com>
Signed-off-by: default avatarSaeed Mahameed <saeedm@mellanox.com>
parent 23f4cc2c
...@@ -88,6 +88,7 @@ static void mlx5e_vxlan_add_port(struct work_struct *work) ...@@ -88,6 +88,7 @@ static void mlx5e_vxlan_add_port(struct work_struct *work)
struct mlx5e_vxlan *vxlan; struct mlx5e_vxlan *vxlan;
int err; int err;
mutex_lock(&priv->state_lock);
vxlan = mlx5e_vxlan_lookup_port(priv, port); vxlan = mlx5e_vxlan_lookup_port(priv, port);
if (vxlan) { if (vxlan) {
atomic_inc(&vxlan->refcount); atomic_inc(&vxlan->refcount);
...@@ -117,6 +118,7 @@ static void mlx5e_vxlan_add_port(struct work_struct *work) ...@@ -117,6 +118,7 @@ static void mlx5e_vxlan_add_port(struct work_struct *work)
err_delete_port: err_delete_port:
mlx5e_vxlan_core_del_port_cmd(priv->mdev, port); mlx5e_vxlan_core_del_port_cmd(priv->mdev, port);
free_work: free_work:
mutex_unlock(&priv->state_lock);
kfree(vxlan_work); kfree(vxlan_work);
} }
...@@ -130,6 +132,7 @@ static void mlx5e_vxlan_del_port(struct work_struct *work) ...@@ -130,6 +132,7 @@ static void mlx5e_vxlan_del_port(struct work_struct *work)
struct mlx5e_vxlan *vxlan; struct mlx5e_vxlan *vxlan;
bool remove = false; bool remove = false;
mutex_lock(&priv->state_lock);
spin_lock_bh(&vxlan_db->lock); spin_lock_bh(&vxlan_db->lock);
vxlan = radix_tree_lookup(&vxlan_db->tree, port); vxlan = radix_tree_lookup(&vxlan_db->tree, port);
if (!vxlan) if (!vxlan)
...@@ -147,6 +150,7 @@ static void mlx5e_vxlan_del_port(struct work_struct *work) ...@@ -147,6 +150,7 @@ static void mlx5e_vxlan_del_port(struct work_struct *work)
mlx5e_vxlan_core_del_port_cmd(priv->mdev, port); mlx5e_vxlan_core_del_port_cmd(priv->mdev, port);
kfree(vxlan); kfree(vxlan);
} }
mutex_unlock(&priv->state_lock);
kfree(vxlan_work); kfree(vxlan_work);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment