Commit 23f4cc2c authored by Gal Pressman's avatar Gal Pressman Committed by Saeed Mahameed

net/mlx5e: Add refcount to VXLAN structure

A refcount mechanism must be implemented in order to prevent unwanted
scenarios such as:
- Open an IPv4 VXLAN interface
- Open an IPv6 VXLAN interface (different socket)
- Remove one of the interfaces

With current implementation, the UDP port will be removed from our VXLAN
database and turn off the offloads for the other interface, which is
still active.
The reference count mechanism will only allow UDP port removals once all
consumers are gone.

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 63235141
...@@ -88,8 +88,11 @@ static void mlx5e_vxlan_add_port(struct work_struct *work) ...@@ -88,8 +88,11 @@ static void mlx5e_vxlan_add_port(struct work_struct *work)
struct mlx5e_vxlan *vxlan; struct mlx5e_vxlan *vxlan;
int err; int err;
if (mlx5e_vxlan_lookup_port(priv, port)) vxlan = mlx5e_vxlan_lookup_port(priv, port);
if (vxlan) {
atomic_inc(&vxlan->refcount);
goto free_work; goto free_work;
}
if (mlx5e_vxlan_core_add_port_cmd(priv->mdev, port)) if (mlx5e_vxlan_core_add_port_cmd(priv->mdev, port))
goto free_work; goto free_work;
...@@ -99,6 +102,7 @@ static void mlx5e_vxlan_add_port(struct work_struct *work) ...@@ -99,6 +102,7 @@ static void mlx5e_vxlan_add_port(struct work_struct *work)
goto err_delete_port; goto err_delete_port;
vxlan->udp_port = port; vxlan->udp_port = port;
atomic_set(&vxlan->refcount, 1);
spin_lock_bh(&vxlan_db->lock); spin_lock_bh(&vxlan_db->lock);
err = radix_tree_insert(&vxlan_db->tree, vxlan->udp_port, vxlan); err = radix_tree_insert(&vxlan_db->tree, vxlan->udp_port, vxlan);
...@@ -116,32 +120,33 @@ static void mlx5e_vxlan_add_port(struct work_struct *work) ...@@ -116,32 +120,33 @@ static void mlx5e_vxlan_add_port(struct work_struct *work)
kfree(vxlan_work); kfree(vxlan_work);
} }
static void __mlx5e_vxlan_core_del_port(struct mlx5e_priv *priv, u16 port) static void mlx5e_vxlan_del_port(struct work_struct *work)
{ {
struct mlx5e_vxlan_work *vxlan_work =
container_of(work, struct mlx5e_vxlan_work, work);
struct mlx5e_priv *priv = vxlan_work->priv;
struct mlx5e_vxlan_db *vxlan_db = &priv->vxlan; struct mlx5e_vxlan_db *vxlan_db = &priv->vxlan;
u16 port = vxlan_work->port;
struct mlx5e_vxlan *vxlan; struct mlx5e_vxlan *vxlan;
bool remove = false;
spin_lock_bh(&vxlan_db->lock); spin_lock_bh(&vxlan_db->lock);
vxlan = radix_tree_delete(&vxlan_db->tree, port); vxlan = radix_tree_lookup(&vxlan_db->tree, port);
spin_unlock_bh(&vxlan_db->lock);
if (!vxlan) if (!vxlan)
return; goto out_unlock;
mlx5e_vxlan_core_del_port_cmd(priv->mdev, vxlan->udp_port);
kfree(vxlan);
}
static void mlx5e_vxlan_del_port(struct work_struct *work) if (atomic_dec_and_test(&vxlan->refcount)) {
{ radix_tree_delete(&vxlan_db->tree, port);
struct mlx5e_vxlan_work *vxlan_work = remove = true;
container_of(work, struct mlx5e_vxlan_work, work); }
struct mlx5e_priv *priv = vxlan_work->priv;
u16 port = vxlan_work->port;
__mlx5e_vxlan_core_del_port(priv, port); out_unlock:
spin_unlock_bh(&vxlan_db->lock);
if (remove) {
mlx5e_vxlan_core_del_port_cmd(priv->mdev, port);
kfree(vxlan);
}
kfree(vxlan_work); kfree(vxlan_work);
} }
...@@ -171,12 +176,11 @@ void mlx5e_vxlan_cleanup(struct mlx5e_priv *priv) ...@@ -171,12 +176,11 @@ void mlx5e_vxlan_cleanup(struct mlx5e_priv *priv)
struct mlx5e_vxlan *vxlan; struct mlx5e_vxlan *vxlan;
unsigned int port = 0; unsigned int port = 0;
spin_lock_bh(&vxlan_db->lock); /* Lockless since we are the only radix-tree consumers, wq is disabled */
while (radix_tree_gang_lookup(&vxlan_db->tree, (void **)&vxlan, port, 1)) { while (radix_tree_gang_lookup(&vxlan_db->tree, (void **)&vxlan, port, 1)) {
port = vxlan->udp_port; port = vxlan->udp_port;
spin_unlock_bh(&vxlan_db->lock); radix_tree_delete(&vxlan_db->tree, port);
__mlx5e_vxlan_core_del_port(priv, (u16)port); mlx5e_vxlan_core_del_port_cmd(priv->mdev, port);
spin_lock_bh(&vxlan_db->lock); kfree(vxlan);
} }
spin_unlock_bh(&vxlan_db->lock);
} }
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
#include "en.h" #include "en.h"
struct mlx5e_vxlan { struct mlx5e_vxlan {
atomic_t refcount;
u16 udp_port; u16 udp_port;
}; };
......
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