mirror of
https://github.com/torvalds/linux.git
synced 2026-05-23 14:42:08 +02:00
vxlan: Convert FDB garbage collection to RCU
Instead of holding the FDB hash lock when traversing the FDB linked list during garbage collection, use RCU and only acquire the lock for entries that need to be removed (aged out). Avoid races by using hlist_unhashed() to check that the entry has not been removed from the list by another thread. Note that vxlan_fdb_destroy() uses hlist_del_init_rcu() to remove an entry from the list which should cause list_unhashed() to return true. Reviewed-by: Petr Machata <petrm@nvidia.com> Signed-off-by: Ido Schimmel <idosch@nvidia.com> Link: https://patch.msgid.link/20250415121143.345227-10-idosch@nvidia.com Reviewed-by: Nikolay Aleksandrov <razor@blackwall.org> Signed-off-by: Paolo Abeni <pabeni@redhat.com>
This commit is contained in:
parent
7aa0dc750d
commit
a6d04f8937
|
|
@ -2819,14 +2819,13 @@ static void vxlan_cleanup(struct timer_list *t)
|
|||
{
|
||||
struct vxlan_dev *vxlan = from_timer(vxlan, t, age_timer);
|
||||
unsigned long next_timer = jiffies + FDB_AGE_INTERVAL;
|
||||
struct hlist_node *n;
|
||||
struct vxlan_fdb *f;
|
||||
|
||||
if (!netif_running(vxlan->dev))
|
||||
return;
|
||||
|
||||
spin_lock(&vxlan->hash_lock);
|
||||
hlist_for_each_entry_safe(f, n, &vxlan->fdb_list, fdb_node) {
|
||||
rcu_read_lock();
|
||||
hlist_for_each_entry_rcu(f, &vxlan->fdb_list, fdb_node) {
|
||||
unsigned long timeout;
|
||||
|
||||
if (f->state & (NUD_PERMANENT | NUD_NOARP))
|
||||
|
|
@ -2837,15 +2836,19 @@ static void vxlan_cleanup(struct timer_list *t)
|
|||
|
||||
timeout = READ_ONCE(f->updated) + vxlan->cfg.age_interval * HZ;
|
||||
if (time_before_eq(timeout, jiffies)) {
|
||||
netdev_dbg(vxlan->dev, "garbage collect %pM\n",
|
||||
f->eth_addr);
|
||||
f->state = NUD_STALE;
|
||||
vxlan_fdb_destroy(vxlan, f, true, true);
|
||||
spin_lock(&vxlan->hash_lock);
|
||||
if (!hlist_unhashed(&f->fdb_node)) {
|
||||
netdev_dbg(vxlan->dev, "garbage collect %pM\n",
|
||||
f->eth_addr);
|
||||
f->state = NUD_STALE;
|
||||
vxlan_fdb_destroy(vxlan, f, true, true);
|
||||
}
|
||||
spin_unlock(&vxlan->hash_lock);
|
||||
} else if (time_before(timeout, next_timer)) {
|
||||
next_timer = timeout;
|
||||
}
|
||||
}
|
||||
spin_unlock(&vxlan->hash_lock);
|
||||
rcu_read_unlock();
|
||||
|
||||
mod_timer(&vxlan->age_timer, next_timer);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user