Bridge numbers are unique across all DSA trees, and each switch tells dsa_bridge_num_get() the largest number it can use (max_num_bridges). The limit is checked only when the bridge gets its number. A switch that joins a bridge which another switch, with a larger limit, has numbered already gets that number unchecked. With an mv88e6xxx tree (limit up to 31) or an mxl862xx tree (48) beside a sja1105 or vsc73xx tree (DSA_TAG_8021Q_MAX_NUM_BRIDGES, 7) and eight or more offloaded bridges, the tag_8021q switch encodes number 9 in the three VBID bits of its bridge VLAN (dsa_tag_8021q_bridge_vid()), so bridge 9 gets the VLAN of bridge 1 and the two share a broadcast domain in the switch. An mxl862xx tree beside an mv88e6xxx one with 32 or more bridges overflows the device field of the DSA header in the same way. Return 0 for a number beyond the limit in that case too. Refuse the same in dsa_port_bridge_create() when the bridge is found in the tree, where another switch of the tree may have numbered it beyond this switch's limit, or not at all: an mv88e6xxx chip without a PVT has max_num_bridges 0 and leaves the bridge at number 0, which a chip with a PVT would take. The port is then bridged in software, with its own extack message for the unnumbered case. Which ports are offloaded then depends on the order in which they join. The bridge is not renumbered for the later port: the ports that joined earlier were set up with number 0, and a new number would have to reach all of them. Fixes: f5e165e72b29 ("net: dsa: track unique bridge numbers across all DSA switch trees") Signed-off-by: Julius Bairaktaris --- v2 (v1 4/6): own extack message for a bridge that another switch of the tree offloads without a number, and a sentence on join order (Sashiko); applies to net without v1 1/6. net/dsa/dsa.c | 5 +++++ net/dsa/port.c | 15 +++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/net/dsa/dsa.c b/net/dsa/dsa.c index 3c11d22ca776..9c2cb9ed2966 100644 --- a/net/dsa/dsa.c +++ b/net/dsa/dsa.c @@ -163,6 +163,11 @@ unsigned int dsa_bridge_num_get(const struct net_device *bridge_dev, int max) return 0; set_bit(bridge_num, &dsa_fwd_offloading_bridges); + } else if (bridge_num > max) { + /* A switch with a larger limit, maybe in another tree, numbered + * this bridge already, beyond what this switch can encode + */ + return 0; } return bridge_num; diff --git a/net/dsa/port.c b/net/dsa/port.c index 1f5536c0dffc..f71dfd78bf7c 100644 --- a/net/dsa/port.c +++ b/net/dsa/port.c @@ -426,6 +426,21 @@ static int dsa_port_bridge_create(struct dsa_port *dp, bridge = dsa_tree_bridge_find(ds->dst, br); if (bridge) { + /* Another switch of the tree offloads the bridge without a + * number, or under one beyond this switch's limit + */ + if (ds->max_num_bridges && !bridge->num) { + NL_SET_ERR_MSG_MOD(extack, + "Bridge offloaded without a number by another switch of the tree"); + return -EOPNOTSUPP; + } + + if (ds->max_num_bridges && bridge->num > ds->max_num_bridges) { + NL_SET_ERR_MSG_MOD(extack, + "Range of offloadable bridges exceeded"); + return -EOPNOTSUPP; + } + refcount_inc(&bridge->refcount); dp->bridge = bridge; return 0; -- 2.53.0