mirror of
https://github.com/torvalds/linux.git
synced 2026-11-20 13:03:48 +00:00
net/mlx5e: Hold sync_lock while resetting VXLAN ports
mlx5_vxlan_reset_to_default() walks vxlan->htable without sync_lock
and calls mlx5_vxlan_del_port() for each user port. mlx5e_nic_disable()
and mlx5e_uplink_rep_disable() call it after rtnl_unlock(), so the
udp_tunnel_nic work can run mlx5e_vxlan_unset_port() at the same time.
If that removes and frees the entry saved as the next one in
hash_for_each_safe(), the walk then reads freed memory.
Hold sync_lock over the whole walk, and add __mlx5_vxlan_del_port() for
callers that already hold it.
Fixes: c5eb51adf0 ("net/mlx5e: Fix VXLAN synchronization after function reload")
Signed-off-by: Changyul Lee <[email protected]>
Reviewed-by: Tariq Toukan <[email protected]>
Link: https://patch.msgid.link/[email protected]
Signed-off-by: Jakub Kicinski <[email protected]>
This commit is contained in:
committed by
Jakub Kicinski
parent
2a324a58a0
commit
d61480a622
@@ -121,25 +121,29 @@ int mlx5_vxlan_add_port(struct mlx5_vxlan *vxlan, u16 port)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int mlx5_vxlan_del_port(struct mlx5_vxlan *vxlan, u16 port)
|
||||
static int __mlx5_vxlan_del_port(struct mlx5_vxlan *vxlan, u16 port)
|
||||
{
|
||||
struct mlx5_vxlan_port *vxlanp;
|
||||
int ret = 0;
|
||||
|
||||
mutex_lock(&vxlan->sync_lock);
|
||||
lockdep_assert_held(&vxlan->sync_lock);
|
||||
|
||||
vxlanp = vxlan_lookup_port(vxlan, port);
|
||||
if (WARN_ON(!vxlanp)) {
|
||||
ret = -ENOENT;
|
||||
goto out_unlock;
|
||||
}
|
||||
if (WARN_ON(!vxlanp))
|
||||
return -ENOENT;
|
||||
|
||||
hash_del_rcu(&vxlanp->hlist);
|
||||
synchronize_rcu();
|
||||
mlx5_vxlan_core_del_port_cmd(vxlan->mdev, port);
|
||||
kfree(vxlanp);
|
||||
return 0;
|
||||
}
|
||||
|
||||
out_unlock:
|
||||
int mlx5_vxlan_del_port(struct mlx5_vxlan *vxlan, u16 port)
|
||||
{
|
||||
int ret;
|
||||
|
||||
mutex_lock(&vxlan->sync_lock);
|
||||
ret = __mlx5_vxlan_del_port(vxlan, port);
|
||||
mutex_unlock(&vxlan->sync_lock);
|
||||
return ret;
|
||||
}
|
||||
@@ -185,12 +189,14 @@ void mlx5_vxlan_reset_to_default(struct mlx5_vxlan *vxlan)
|
||||
if (!mlx5_vxlan_allowed(vxlan))
|
||||
return;
|
||||
|
||||
mutex_lock(&vxlan->sync_lock);
|
||||
hash_for_each_safe(vxlan->htable, bkt, tmp, vxlanp, hlist) {
|
||||
/* Don't delete default UDP port added by the HW.
|
||||
* Remove only user configured ports
|
||||
*/
|
||||
if (vxlanp->udp_port == IANA_VXLAN_UDP_PORT)
|
||||
continue;
|
||||
mlx5_vxlan_del_port(vxlan, vxlanp->udp_port);
|
||||
__mlx5_vxlan_del_port(vxlan, vxlanp->udp_port);
|
||||
}
|
||||
mutex_unlock(&vxlan->sync_lock);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user