net: bridge: fdb: consolidate port-VLAN cleanup

Deleting a port-VLAN currently takes the hash_lock twice and performs two
fdb ops. The first removes its automatically generated local entry and the
second deletes dynamic entries associated with the port and vid. Rename
br_fdb_delete_by_port() to br_fdb_cleanup_by_dst() and pass a bridge dst so
it can distinguish a port-VLAN from a raw port. This allows both operations
to be done during the same locked fdb walk.

Reviewed-by: Ido Schimmel <idosch@nvidia.com>
Signed-off-by: Nikolay Aleksandrov <razor@blackwall.org>
Link: https://patch.msgid.link/20260930071411.2786201-7-razor@blackwall.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
Nikolay Aleksandrov 2026-09-30 10:14:05 +03:00 committed by Jakub Kicinski
parent 8247ef7603
commit f0a349b921
8 changed files with 25 additions and 16 deletions

View File

@ -200,7 +200,7 @@ static int br_switchdev_event(struct notifier_block *unused,
case SWITCHDEV_FDB_FLUSH_TO_BRIDGE:
fdb_info = ptr;
/* Don't delete static entries */
br_fdb_delete_by_port(br, p, fdb_info->vid, 0);
br_fdb_cleanup_by_dst(br, br_port_to_dst(p), fdb_info->vid, 0);
break;
}

View File

@ -868,15 +868,16 @@ int br_fdb_delete_bulk(struct nlmsghdr *nlh, struct net_device *dev,
return 0;
}
/* Flush all entries referring to a specific port.
/* Clean up all entries referring to a specific destination.
* if do_all is set also flush static entries
* if vid is set delete all entries that match the vlan_id
*/
void br_fdb_delete_by_port(struct net_bridge *br,
const struct net_bridge_port *p,
u16 vid,
void br_fdb_cleanup_by_dst(struct net_bridge *br,
struct net_bridge_dst cleanup_dst, u16 vid,
int do_all)
{
const struct net_bridge_vlan *vlan = br_dst_vlan(cleanup_dst);
const struct net_bridge_port *p = br_dst_port(cleanup_dst);
struct net_bridge_fdb_entry *f;
struct hlist_node *tmp;
@ -885,6 +886,14 @@ void br_fdb_delete_by_port(struct net_bridge *br,
if (br_fdb_dst_port(f) != p)
continue;
if (vlan && f->key.vlan_id == vlan->vid &&
test_bit(BR_FDB_LOCAL, &f->flags) &&
!test_bit(BR_FDB_ADDED_BY_USER, &f->flags) &&
ether_addr_equal(f->key.addr.addr, p->dev->dev_addr)) {
fdb_delete_local(br, p, f);
continue;
}
if (!do_all)
if (test_bit(BR_FDB_STATIC, &f->flags) ||
(test_bit(BR_FDB_ADDED_BY_EXT_LEARN, &f->flags) &&

View File

@ -355,7 +355,7 @@ static void del_nbp(struct net_bridge_port *p)
netdev_reset_rx_headroom(dev);
nbp_vlan_flush(p);
br_fdb_delete_by_port(br, p, 0, 1);
br_fdb_cleanup_by_dst(br, br_port_to_dst(p), 0, 1);
switchdev_deferred_process();
nbp_backup_clear(p);
@ -390,7 +390,7 @@ void br_dev_delete(struct net_device *dev, struct list_head *head)
br_mst_uninit(br);
br_recalculate_neigh_suppress_enabled(br);
br_fdb_delete_by_port(br, NULL, 0, 1);
br_fdb_cleanup_by_dst(br, br_port_to_dst(NULL), 0, 1);
timer_shutdown_sync(&br->hello_timer);
timer_shutdown_sync(&br->topology_change_timer);
@ -696,7 +696,7 @@ int br_add_if(struct net_bridge *br, struct net_device *dev,
if (fdb_synced)
br_fdb_unsync_static(br, p);
list_del_rcu(&p->list);
br_fdb_delete_by_port(br, p, 0, 1);
br_fdb_cleanup_by_dst(br, br_port_to_dst(p), 0, 1);
nbp_update_port_count(br);
netdev_upper_dev_unlink(dev, br->dev);
err5:

View File

@ -1044,7 +1044,7 @@ static int br_setport(struct net_bridge_port *p, struct nlattr *tb[],
}
if (tb[IFLA_BRPORT_FLUSH])
br_fdb_delete_by_port(p->br, p, 0, 0);
br_fdb_cleanup_by_dst(p->br, br_port_to_dst(p), 0, 0);
#ifdef CONFIG_BRIDGE_IGMP_SNOOPING
if (tb[IFLA_BRPORT_MULTICAST_ROUTER]) {

View File

@ -983,8 +983,8 @@ void br_fdb_change_mac_address(struct net_bridge *br, const u8 *newaddr);
void br_fdb_cleanup(struct work_struct *work);
int br_fdb_toggle_local_vlan_0(struct net_bridge *br, bool on,
struct netlink_ext_ack *extack);
void br_fdb_delete_by_port(struct net_bridge *br,
const struct net_bridge_port *p, u16 vid, int do_all);
void br_fdb_cleanup_by_dst(struct net_bridge *br,
struct net_bridge_dst dst, u16 vid, int do_all);
struct net_bridge_fdb_entry *br_fdb_find_rcu(struct net_bridge *br,
const unsigned char *addr,
__u16 vid);

View File

@ -114,7 +114,7 @@ void br_stp_disable_port(struct net_bridge_port *p)
timer_delete(&p->hold_timer);
if (!rcu_access_pointer(p->backup_port))
br_fdb_delete_by_port(br, p, 0, 0);
br_fdb_cleanup_by_dst(br, br_port_to_dst(p), 0, 0);
br_multicast_disable_port(p);
br_configuration_update(br);

View File

@ -191,7 +191,8 @@ static BRPORT_ATTR(hold_timer, 0444, show_hold_timer, NULL);
static int store_flush(struct net_bridge_port *p, unsigned long v)
{
br_fdb_delete_by_port(p->br, p, 0, 0); // Don't delete local entry
/* Don't delete local entry */
br_fdb_cleanup_by_dst(p->br, br_port_to_dst(p), 0, 0);
return 0;
}
static BRPORT_ATTR(flush, 0200, NULL, store_flush);

View File

@ -870,7 +870,7 @@ int br_vlan_delete(struct net_bridge *br, u16 vid)
return -ENOENT;
br_fdb_find_delete_local(br, NULL, br->dev->dev_addr, vid);
br_fdb_delete_by_port(br, NULL, vid, 0);
br_fdb_cleanup_by_dst(br, br_port_to_dst(NULL), vid, 0);
vlan_tunnel_info_del(vg, v);
__vlan_del(v);
@ -1396,8 +1396,7 @@ int nbp_vlan_delete(struct net_bridge_port *port, u16 vid)
v = br_vlan_find(nbp_vlan_group(port), vid);
if (!v)
return -ENOENT;
br_fdb_find_delete_local(port->br, port, port->dev->dev_addr, vid);
br_fdb_delete_by_port(port->br, port, vid, 0);
br_fdb_cleanup_by_dst(port->br, br_vlan_to_dst(v), vid, 0);
__vlan_del(v);
return 0;