[PATCH net 6/6] net: dsa: keep a bridge number while another tree uses it
From: Julius Bairaktaris
Date: Sat Nov 28 2026 - 11:52:54 EST
Bridge numbers are unique across all DSA trees, and a bridge spanning
ports of two trees gets one number, which both trees use.
dsa_port_bridge_destroy() puts the number when the last port of its
own tree leaves the bridge, and dsa_bridge_num_put() clears the bit
unconditionally, so the number is free while the other tree still
offloads the bridge under it. The next bridge that gets a number then
gets the same one: on a tag_8021q switch both bridges share a VLAN, on
mv88e6xxx a cross-chip PVT row, and frames of one reach the ports of
the other.
Clear the bit only when no tree offloads the bridge any more.
Found by an LLM review (Claude), and reproduced in QEMU with dsa_loop.
Fixes: f5e165e72b29 ("net: dsa: track unique bridge numbers across all DSA switch trees")
Signed-off-by: Julius Bairaktaris <julius@xxxxxxxxxxxxxx>
---
net/dsa/dsa.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/net/dsa/dsa.c b/net/dsa/dsa.c
index 67b5d2c42fb..bcb398615fc 100644
--- a/net/dsa/dsa.c
+++ b/net/dsa/dsa.c
@@ -177,10 +177,13 @@ unsigned int dsa_bridge_num_get(const struct net_device *bridge_dev, int max)
void dsa_bridge_num_put(const struct net_device *bridge_dev,
unsigned int bridge_num)
{
- /* Since we refcount bridges, we know that when we call this function
- * it is no longer in use, so we can just go ahead and remove it from
- * the bit mask.
+ /* The bridge is no longer offloaded by the tree that calls this, but
+ * the number is global: another tree may still offload the bridge
+ * under it.
*/
+ if (dsa_bridge_num_find(bridge_dev) == bridge_num)
+ return;
+
clear_bit(bridge_num, &dsa_fwd_offloading_bridges);
}
--
2.53.0