mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Julius Bairaktaris <julius@bairaktaris.de>
To: Andrew Lunn <andrew@lunn.ch>, Vladimir Oltean <olteanv@gmail.com>,
	netdev@vger.kernel.org
Cc: "David S. Miller" <davem@davemloft.net>,
	"Eric Dumazet" <edumazet@kernel.org>,
	"Jakub Kicinski" <kuba@kernel.org>,
	"Paolo Abeni" <pabeni@redhat.com>,
	"Willem de Bruijn" <willemb@google.com>,
	"Simon Horman" <horms@kernel.org>,
	"Alvin Šipraga" <alvin.sipraga@analog.com>,
	"Linus Walleij" <linusw@kernel.org>,
	"Florian Fainelli" <florian.fainelli@broadcom.com>,
	"Pawel Dembicki" <paweldembicki@gmail.com>,
	"Tobias Waldekranz" <tobias@waldekranz.com>,
	"Daniel Golle" <daniel@makrotopia.org>,
	"Russell King" <linux@armlinux.org.uk>,
	linux-kernel@vger.kernel.org
Subject: [PATCH net 4/6] net: dsa: do not hand a switch a bridge number above its limit
Date: Sat, 28 Nov 2026 17:52:03 +0100	[thread overview]
Message-ID: <20261128165206.3248835-5-julius@bairaktaris.de> (raw)
In-Reply-To: <20261128165206.3248835-1-julius@bairaktaris.de>

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 ("Range of
offloadable bridges exceeded"), as a port that joins a new bridge
beyond the limit already is.

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@bairaktaris.de>
---
 net/dsa/dsa.c  |  5 +++++
 net/dsa/port.c | 10 ++++++++++
 2 files changed, 15 insertions(+)

diff --git a/net/dsa/dsa.c b/net/dsa/dsa.c
index 2771c34e840..1c2a29678ac 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 997e68cd215..9cb441d16de 100644
--- a/net/dsa/port.c
+++ b/net/dsa/port.c
@@ -426,6 +426,16 @@ 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 numbered the bridge beyond this
+		 * switch's limit, or left it without a number
+		 */
+		if (ds->max_num_bridges &&
+		    (!bridge->num || bridge->num > ds->max_num_bridges)) {
+			NL_SET_ERR_MSG_MOD(extack,
+					   "Range of offloadable bridges exceeded");
+			return -EOPNOTSUPP;
+		}
+
 		refcount_inc(&bridge->refcount);
 		/* Pairs with the READ_ONCE() of the datapath */
 		smp_store_release(&dp->bridge, bridge);
-- 
2.53.0


  parent reply	other threads:[~2026-11-28 16:52 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-28 16:51 [PATCH net 0/6] net: dsa: offload_fwd_mark on unbridged ports, bridge numbers across switches Julius Bairaktaris
2026-11-28 16:52 ` [PATCH net 1/6] net: dsa: free struct dsa_bridge after an RCU grace period Julius Bairaktaris
2026-11-28 16:52 ` [PATCH net 2/6] net: dsa: tag_sja1105, tag_vsc73xx_8021q: read the bridge once in xmit Julius Bairaktaris
2026-12-06  3:54   ` willemb
2026-11-28 16:52 ` [PATCH net 3/6] net: dsa: tag_dsa: send a marked frame of an unbridged port from the CPU Julius Bairaktaris
2026-12-06  3:55   ` willemb
2026-11-28 16:52 ` Julius Bairaktaris [this message]
2026-12-06  3:55   ` [PATCH net 4/6] net: dsa: do not hand a switch a bridge number above its limit willemb
2026-11-28 16:52 ` [PATCH net 5/6] net: dsa: do not take a bridge number past the end of the bitmap Julius Bairaktaris
2026-11-28 16:52 ` [PATCH net 6/6] net: dsa: keep a bridge number while another tree uses it Julius Bairaktaris
2026-12-06  3:57   ` willemb
2026-12-06  3:54 ` [PATCH net 0/6] net: dsa: offload_fwd_mark on unbridged ports, bridge numbers across switches willemb
2026-12-06 10:06   ` Julius Bairaktaris

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261128165206.3248835-5-julius@bairaktaris.de \
    --to=julius@bairaktaris.de \
    --cc=alvin.sipraga@analog.com \
    --cc=andrew@lunn.ch \
    --cc=daniel@makrotopia.org \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=florian.fainelli@broadcom.com \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linusw@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=netdev@vger.kernel.org \
    --cc=olteanv@gmail.com \
    --cc=pabeni@redhat.com \
    --cc=paweldembicki@gmail.com \
    --cc=tobias@waldekranz.com \
    --cc=willemb@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®