mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: willemb@google.com
To: Julius Bairaktaris <julius@bairaktaris.de>,
	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: Re: [PATCH net 6/6] net: dsa: keep a bridge number while another tree uses it
Date: Sat, 05 Dec 2026 22:57:02 -0500	[thread overview]
Message-ID: <willemb.35851b693adf@google.com> (raw)
In-Reply-To: <20261128165206.3248835-7-julius@bairaktaris.de>

Julius Bairaktaris wrote:
> 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@bairaktaris.de>

   net/dsa/dsa.c:130-143, 184 (dsa_bridge_num_find / dsa_bridge_num_put):
   The new guard `if (dsa_bridge_num_find(bridge_dev) == bridge_num) return;`
   fails to enforce the commit message's invariant ("clear the bit only when  
no
   tree offloads the bridge any more") because dsa_bridge_num_find() returns
   immediately on the first tree in dsa_tree_list with a struct dsa_bridge  
for
   bridge_dev, even when that tree has bridge->num == 0 (any switch driver  
with
   ds->max_num_bridges == 0, which is most DSA drivers).
   Concrete failure with 3 trees in dsa_tree_list = [Tree 0 (max=0), Tree 1
   (max=7), Tree 2 (max=7)]:
   1. Tree 1 joins br0 -> bridge->num = 1 (bit 1 set).
   2. Tree 2 joins br0 -> dsa_bridge_num_find(br0) finds Tree 1 ->  
bridge->num = 1.
   3. Tree 0 joins br0 -> max == 0 -> bridge->num = 0.
   4. Tree 1's last port leaves br0 -> dsa_port_bridge_destroy() calls
      dsa_bridge_num_put(br0, 1) -> dsa_bridge_num_find(br0) hits Tree 0  
first
      and returns 0 without inspecting Tree 2 -> 0 == 1 is false ->  
clear_bit(1,
      &dsa_fwd_offloading_bridges) releases bit 1 while Tree 2 still  
offloads br0
      under number 1!
   5. Next bridge br1 allocates bit 1, colliding with br0 on Tree 2 (shared
      tag_8021q VLAN / mv88e6xxx PVT row / mxl862xx bridge slot).
   Root cause: commit d3eed0e57d5d accidentally dropped `&& dp->bridge_num`  
when
   rewriting dsa_bridge_num_find() to call dsa_tree_bridge_find(). Changing  
line
   138 of net/dsa/dsa.c from `if (bridge)` to `if (bridge && bridge->num)`  
fixes
   both dsa_bridge_num_put() and dsa_bridge_num_get().

   net/dsa/dsa.c:177 (Fixes trailer):
   Patch 6/6 cites `Fixes: f5e165e72b29 ("net: dsa: track unique bridge  
numbers
   across all DSA switch trees")`, but f5e165e72b29 (and 3f9bb0301d50)  
guarded
   clear_bit() with dsa_bridge_num_find(). It was commit d3eed0e57d5d ("net:  
dsa:
   keep the bridge_dev and bridge_num as part of the same structure") that  
removed
   the dsa_bridge_num_find() check in dsa_bridge_num_put() (and dropped
   `&& bridge->num` in dsa_bridge_num_find()). Update to `Fixes:  
d3eed0e57d5d`.

   net/dsa/dsa.c:184 (dsa_bridge_num_put -> dsa_bridge_num_find):
   dsa_tree_list and dst->ports are mutated under dsa2_mutex without  
rtnl_lock()
   (dsa_register_switch()/dsa_unregister_switch()), whereas  
dsa_bridge_num_get()
   and now dsa_bridge_num_put() walk dsa_tree_list under rtnl_lock() without
   dsa2_mutex (and taking dsa2_mutex under rtnl_lock() would invert lock  
order
   versus dsa_switch_shutdown()). Pre-existing race, not introduced here.

pw-bot: cr

  reply	other threads:[~2026-12-06  3:57 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 ` [PATCH net 4/6] net: dsa: do not hand a switch a bridge number above its limit Julius Bairaktaris
2026-12-06  3:55   ` 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 [this message]
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=willemb.35851b693adf@google.com \
    --to=willemb@google.com \
    --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=julius@bairaktaris.de \
    --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 \
    /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®