Skip to content

Commit aec4eab

Browse files
author
Saeed Mahameed
committed
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: Saeed Mahameed <saeedm@mellanox.com> Reviewed-by: Or Gerlitz <ogerlitz@mellanox.com>
1 parent 1b318a9 commit aec4eab

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

  • drivers/net/ethernet/mellanox/mlx5/core

‎drivers/net/ethernet/mellanox/mlx5/core/vxlan.c‎

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,10 @@
3939
struct mlx5_vxlan {
4040
struct mlx5_core_dev *mdev;
4141
spinlock_t lock; /* protect vxlan table */
42-
int num_ports;
4342
/* max_num_ports is usuallly 4, 16 buckets is more than enough */
4443
DECLARE_HASHTABLE(htable, 4);
44+
int num_ports;
45+
struct mutex sync_lock; /* sync add/del port HW operations */
4546
};
4647

4748
struct mlx5_vxlan_port {
@@ -115,17 +116,18 @@ int mlx5_vxlan_add_port(struct mlx5_vxlan *vxlan, u16 port)
115116
return 0;
116117
}
117118

119+
mutex_lock(&vxlan->sync_lock);
118120
if (vxlan->num_ports >= mlx5_vxlan_max_udp_ports(vxlan->mdev)) {
119121
mlx5_core_info(vxlan->mdev,
120122
"UDP port (%d) not offloaded, max number of UDP ports (%d) are already offloaded\n",
121123
port, mlx5_vxlan_max_udp_ports(vxlan->mdev));
122124
ret = -ENOSPC;
123-
return ret;
125+
goto unlock;
124126
}
125127

126128
ret = mlx5_vxlan_core_add_port_cmd(vxlan->mdev, port);
127129
if (ret)
128-
return ret;
130+
goto unlock;
129131

130132
vxlanp = kzalloc(sizeof(*vxlanp), GFP_KERNEL);
131133
if (!vxlanp) {
@@ -141,10 +143,14 @@ int mlx5_vxlan_add_port(struct mlx5_vxlan *vxlan, u16 port)
141143
spin_unlock_bh(&vxlan->lock);
142144

143145
vxlan->num_ports++;
146+
mutex_unlock(&vxlan->sync_lock);
144147
return 0;
145148

146149
err_delete_port:
147150
mlx5_vxlan_core_del_port_cmd(vxlan->mdev, port);
151+
152+
unlock:
153+
mutex_unlock(&vxlan->sync_lock);
148154
return ret;
149155
}
150156

@@ -154,6 +160,8 @@ int mlx5_vxlan_del_port(struct mlx5_vxlan *vxlan, u16 port)
154160
bool remove = false;
155161
int ret = 0;
156162

163+
mutex_lock(&vxlan->sync_lock);
164+
157165
spin_lock_bh(&vxlan->lock);
158166
vxlanp = mlx5_vxlan_lookup_port_locked(vxlan, port);
159167
if (!vxlanp) {
@@ -174,6 +182,9 @@ int mlx5_vxlan_del_port(struct mlx5_vxlan *vxlan, u16 port)
174182
kfree(vxlanp);
175183
vxlan->num_ports--;
176184
}
185+
186+
mutex_unlock(&vxlan->sync_lock);
187+
177188
return ret;
178189
}
179190

@@ -189,6 +200,7 @@ struct mlx5_vxlan *mlx5_vxlan_create(struct mlx5_core_dev *mdev)
189200
return ERR_PTR(-ENOMEM);
190201

191202
vxlan->mdev = mdev;
203+
mutex_init(&vxlan->sync_lock);
192204
spin_lock_init(&vxlan->lock);
193205
hash_init(vxlan->htable);
194206

0 commit comments

Comments
 (0)