Skip to content

Commit 7afb5fb

Browse files
vladimirolteankuba-moo
authored andcommitted
net: dsa: clean up FDB, MDB, VLAN entries on unbind
As explained in many places such as commit b117e1e ("net: dsa: delete dsa_legacy_fdb_add and dsa_legacy_fdb_del"), DSA is written given the assumption that higher layers have balanced additions/deletions. As such, it only makes sense to be extremely vocal when those assumptions are violated and the driver unbinds with entries still present. But Ido Schimmel points out a very simple situation where that is wrong: https://lore.kernel.org/netdev/ZDazSM5UsPPjQuKr@shredder/ (also briefly discussed by me in the aforementioned commit). Basically, while the bridge bypass operations are not something that DSA explicitly documents, and for the majority of DSA drivers this API simply causes them to go to promiscuous mode, that isn't the case for all drivers. Some have the necessary requirements for bridge bypass operations to do something useful - see dsa_switch_supports_uc_filtering(). Although in tools/testing/selftests/net/forwarding/local_termination.sh, we made an effort to popularize better mechanisms to manage address filters on DSA interfaces from user space - namely macvlan for unicast, and setsockopt(IP_ADD_MEMBERSHIP) - through mtools - for multicast, the fact is that 'bridge fdb add ... self static local' also exists as kernel UAPI, and might be useful to someone, even if only for a quick hack. It seems counter-productive to block that path by implementing shim .ndo_fdb_add and .ndo_fdb_del operations which just return -EOPNOTSUPP in order to prevent the ndo_dflt_fdb_add() and ndo_dflt_fdb_del() from running, although we could do that. Accepting that cleanup is necessary seems to be the only option. Especially since we appear to be coming back at this from a different angle as well. Russell King is noticing that the WARN_ON() triggers even for VLANs: https://lore.kernel.org/netdev/[email protected]/ What happens in the bug report above is that dsa_port_do_vlan_del() fails, then the VLAN entry lingers on, and then we warn on unbind and leak it. This is not a straight revert of the blamed commit, but we now add an informational print to the kernel log (to still have a way to see that bugs exist), and some extra comments gathered from past years' experience, to justify the logic. Fixes: 0832cd9 ("net: dsa: warn if port lists aren't empty in dsa_port_teardown") Signed-off-by: Vladimir Oltean <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent ea08dfc commit 7afb5fb

File tree

1 file changed

+35
-3
lines changed

1 file changed

+35
-3
lines changed

net/dsa/dsa.c

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1478,12 +1478,44 @@ static int dsa_switch_parse(struct dsa_switch *ds, struct dsa_chip_data *cd)
14781478

14791479
static void dsa_switch_release_ports(struct dsa_switch *ds)
14801480
{
1481+
struct dsa_mac_addr *a, *tmp;
14811482
struct dsa_port *dp, *next;
1483+
struct dsa_vlan *v, *n;
14821484

14831485
dsa_switch_for_each_port_safe(dp, next, ds) {
1484-
WARN_ON(!list_empty(&dp->fdbs));
1485-
WARN_ON(!list_empty(&dp->mdbs));
1486-
WARN_ON(!list_empty(&dp->vlans));
1486+
/* These are either entries that upper layers lost track of
1487+
* (probably due to bugs), or installed through interfaces
1488+
* where one does not necessarily have to remove them, like
1489+
* ndo_dflt_fdb_add().
1490+
*/
1491+
list_for_each_entry_safe(a, tmp, &dp->fdbs, list) {
1492+
dev_info(ds->dev,
1493+
"Cleaning up unicast address %pM vid %u from port %d\n",
1494+
a->addr, a->vid, dp->index);
1495+
list_del(&a->list);
1496+
kfree(a);
1497+
}
1498+
1499+
list_for_each_entry_safe(a, tmp, &dp->mdbs, list) {
1500+
dev_info(ds->dev,
1501+
"Cleaning up multicast address %pM vid %u from port %d\n",
1502+
a->addr, a->vid, dp->index);
1503+
list_del(&a->list);
1504+
kfree(a);
1505+
}
1506+
1507+
/* These are entries that upper layers have lost track of,
1508+
* probably due to bugs, but also due to dsa_port_do_vlan_del()
1509+
* having failed and the VLAN entry still lingering on.
1510+
*/
1511+
list_for_each_entry_safe(v, n, &dp->vlans, list) {
1512+
dev_info(ds->dev,
1513+
"Cleaning up vid %u from port %d\n",
1514+
v->vid, dp->index);
1515+
list_del(&v->list);
1516+
kfree(v);
1517+
}
1518+
14871519
list_del(&dp->list);
14881520
kfree(dp);
14891521
}

0 commit comments

Comments
 (0)