Commit aec4eab9 authored by Saeed Mahameed's avatar Saeed Mahameed

net/mlx5e: Vxlan, add sync lock for add/del vxlan port

Vxlan API can and will be called from different mlx5 modules, we should
not count on mlx5e private state lock only, hence we introduce a vxlan
private mutex to sync between add/del vxlan port operations.
Signed-off-by: default avatarSaeed Mahameed <saeedm@mellanox.com>
Reviewed-by: default avatarOr Gerlitz <ogerlitz@mellanox.com>
parent 1b318a92
...@@ -39,9 +39,10 @@ ...@@ -39,9 +39,10 @@
struct mlx5_vxlan { struct mlx5_vxlan {
struct mlx5_core_dev *mdev; struct mlx5_core_dev *mdev;
spinlock_t lock; /* protect vxlan table */ spinlock_t lock; /* protect vxlan table */
int num_ports;
/* max_num_ports is usuallly 4, 16 buckets is more than enough */ /* max_num_ports is usuallly 4, 16 buckets is more than enough */
DECLARE_HASHTABLE(htable, 4); DECLARE_HASHTABLE(htable, 4);
int num_ports;
struct mutex sync_lock; /* sync add/del port HW operations */
}; };
struct mlx5_vxlan_port { struct mlx5_vxlan_port {
...@@ -115,17 +116,18 @@ int mlx5_vxlan_add_port(struct mlx5_vxlan *vxlan, u16 port) ...@@ -115,17 +116,18 @@ int mlx5_vxlan_add_port(struct mlx5_vxlan *vxlan, u16 port)
return 0; return 0;
} }
mutex_lock(&vxlan->sync_lock);
if (vxlan->num_ports >= mlx5_vxlan_max_udp_ports(vxlan->mdev)) { if (vxlan->num_ports >= mlx5_vxlan_max_udp_ports(vxlan->mdev)) {
mlx5_core_info(vxlan->mdev, mlx5_core_info(vxlan->mdev,
"UDP port (%d) not offloaded, max number of UDP ports (%d) are already offloaded\n", "UDP port (%d) not offloaded, max number of UDP ports (%d) are already offloaded\n",
port, mlx5_vxlan_max_udp_ports(vxlan->mdev)); port, mlx5_vxlan_max_udp_ports(vxlan->mdev));
ret = -ENOSPC; ret = -ENOSPC;
return ret; goto unlock;
} }
ret = mlx5_vxlan_core_add_port_cmd(vxlan->mdev, port); ret = mlx5_vxlan_core_add_port_cmd(vxlan->mdev, port);
if (ret) if (ret)
return ret; goto unlock;
vxlanp = kzalloc(sizeof(*vxlanp), GFP_KERNEL); vxlanp = kzalloc(sizeof(*vxlanp), GFP_KERNEL);
if (!vxlanp) { if (!vxlanp) {
...@@ -141,10 +143,14 @@ int mlx5_vxlan_add_port(struct mlx5_vxlan *vxlan, u16 port) ...@@ -141,10 +143,14 @@ int mlx5_vxlan_add_port(struct mlx5_vxlan *vxlan, u16 port)
spin_unlock_bh(&vxlan->lock); spin_unlock_bh(&vxlan->lock);
vxlan->num_ports++; vxlan->num_ports++;
mutex_unlock(&vxlan->sync_lock);
return 0; return 0;
err_delete_port: err_delete_port:
mlx5_vxlan_core_del_port_cmd(vxlan->mdev, port); mlx5_vxlan_core_del_port_cmd(vxlan->mdev, port);
unlock:
mutex_unlock(&vxlan->sync_lock);
return ret; return ret;
} }
...@@ -154,6 +160,8 @@ int mlx5_vxlan_del_port(struct mlx5_vxlan *vxlan, u16 port) ...@@ -154,6 +160,8 @@ int mlx5_vxlan_del_port(struct mlx5_vxlan *vxlan, u16 port)
bool remove = false; bool remove = false;
int ret = 0; int ret = 0;
mutex_lock(&vxlan->sync_lock);
spin_lock_bh(&vxlan->lock); spin_lock_bh(&vxlan->lock);
vxlanp = mlx5_vxlan_lookup_port_locked(vxlan, port); vxlanp = mlx5_vxlan_lookup_port_locked(vxlan, port);
if (!vxlanp) { if (!vxlanp) {
...@@ -174,6 +182,9 @@ int mlx5_vxlan_del_port(struct mlx5_vxlan *vxlan, u16 port) ...@@ -174,6 +182,9 @@ int mlx5_vxlan_del_port(struct mlx5_vxlan *vxlan, u16 port)
kfree(vxlanp); kfree(vxlanp);
vxlan->num_ports--; vxlan->num_ports--;
} }
mutex_unlock(&vxlan->sync_lock);
return ret; return ret;
} }
...@@ -189,6 +200,7 @@ struct mlx5_vxlan *mlx5_vxlan_create(struct mlx5_core_dev *mdev) ...@@ -189,6 +200,7 @@ struct mlx5_vxlan *mlx5_vxlan_create(struct mlx5_core_dev *mdev)
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
vxlan->mdev = mdev; vxlan->mdev = mdev;
mutex_init(&vxlan->sync_lock);
spin_lock_init(&vxlan->lock); spin_lock_init(&vxlan->lock);
hash_init(vxlan->htable); hash_init(vxlan->htable);
......
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