From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.160.197 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796529424; b=XU/+y3qddHCRNq/WkxkkLwgECns3d3Tqiw2R819SaPG+1k1I1nUJezedw+ZI6tYCxpsz VN3vFr5HL3NOmdAFtS+mw4Ym2AmqaVj+grKfKWWeGh80DVVk5aESLJJDgx/0LWd9Z09ZM FGfx/z8kRZX+VCxmd6ZRePipTtZGb/QYylo5U2gJ67MjnUm2npZl6Ez8AzR1szd8xywVQ eH4DfMKLQYa2jIUNP+ym1vP+FZS+3ajRBycttcXtYKl2Pyt4K4g7ooftWm4M2zKoJJhMA ghQP+K98xTyriPsLc0NL85tC8XyiESCX3lSzxjer841Cs58Dt69XmhnVnIVkkqiPvtA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796529424; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Received:Date:In-Reply-To: Mime-Version:References:Message-ID:Subject:From:To:Cc:Content-Type; bh=EjNz+1Aysrhv3G6a8Cin+O4WOnGP+CBD3FB6uZDhKAY=; b=MODWM6Kz2/IuUy4qEOSFsL+KPpKA4RXdDeANuz60qaVgqpI4cLFUMcMLs+hgslfDBqS+ KA1JTy3Agk4Z+YQecwXmCtei3yXDpBkjn+n4HgVDMjk4o36lbXF2DU8UBlZPnpHtBktB9 mLiN0eorxYioCdr3g6+DM4Ge3dWXZT8nMIUyhX0UVluY35afTL0HGHlRGwInRhWjkuqQq gBjH9ITXVLLMduNIu/cFImowJelyaJgkKNiaNbAc21YMP/rrY62+Al+1xe6IfwIKpgs/Q wZWJJ5pk6lmciR2gQPIAuvhtFQRUJFzmua9HYQpO2TLewkZ0Du7yJ5uJKwPkMXM675w== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=google.com; spf=pass smtp.mailfrom=flex--willemb.bounces.google.com; dkim=pass header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=WMg6vbRT; arc=none smtp.remote-ip=209.85.160.197 Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C121B606A31F for ; Sun, 6 Dec 2026 03:57:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org C121B606A31F Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--willemb.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=WMg6vbRT Received: by mail-qt1-f197.google.com with SMTP id d75a77b69052e-55ba5fccc4aso50730201cf.2 for ; Sat, 05 Dec 2026 19:57:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796529423; x=1797134223; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=EjNz+1Aysrhv3G6a8Cin+O4WOnGP+CBD3FB6uZDhKAY=; b=WMg6vbRTqth0U+Ep6w9vJiehOskLWqyqHRQk3AFgt2o3dkbtu3jwreFn62Wy1wjImX hdZjQaoS+16oVjyxrrXSwfRxkEkG+rUS47YwtaFd/BVAjL5S21b8GIKuEbsJCPVwaE9P 8ye1jdGRh7ukxx+m8PiWa6gvX/IHP5qrqDm3KlhTmNzTJ9TOPpH8F7Le90rYhwvLi6kV HYIlnbNj+0mhltqJsGBYay4e1jBWrWUBysOqS1HcZJzFwbj4ihLRhedJvBQfnsCkmo1y Ntz+MXMBOIKn8LfV4pvuA/gGvgFP3IIUGEqEMLBqb2Dkc8XN3S2PBrzJrWblERPMnjOl 0qkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796529423; x=1797134223; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=EjNz+1Aysrhv3G6a8Cin+O4WOnGP+CBD3FB6uZDhKAY=; b=gJWboMNRVaA26X8noJeLNx7+49PtysdMtfTDM6y4nF+EiSjkL1xfB5Cj6YSQiyaO8P F1uVjUIWj2pK+Od6CZfVFqPTPeAInP3vG09s+Rem1AUVmXRHZ0WJHpXBynJY6w0AqjEg Q8qoAnwOiRUACzWk77zHrIRudyYG91OU4W/ryDEkHlaUhtyL9i7wKnI1T6wf3w8iqkO/ vXaGn5maaEJeVP7RXoMl98tSD4A1mGYsSRljVYInw1iDz5YkHFR9LCThrMNJ/8r90bUo fD4avF3YV/GFwWNKuyYJVvr0CZ+DeeONnaxGYd/KEh0pvQ3HHthICXM/DQ/n5Zos+bCM UiMQ== X-Forwarded-Encrypted: i=1; AL+hErFb4vv4GqSlIFdVN9zBuIXAu6vOioiv69xLKo65yfpEfSoMGfxV61bIpR57taWPnnd58am5sbc3HZL9NqQ=@vger.kernel.org X-Gm-Message-State: APuU4Z/NB/PNEt0DlaqGn9DB0ifDRFATLiHpk1sP1XGPiVGvpZHDOAqf HZQ+m17RglcI4q7mwMyrUoaOx0rf5fBsKxaaTwdIMiuIlrF0UT1sXUEzfZHQniZbUexKY4QZPFX vVIr5aW8YuQ== X-Received: from qtqu2.prod.google.com ([2002:ac8:7502:0:b0:55b:93df:d22b]) (user=willemb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:622a:1650:b0:535:15a9:2516 with SMTP id d75a77b69052e-55e38d63984mr114615891cf.53.1796529422587; Sat, 05 Dec 2026 19:57:02 -0800 (PST) Date: Sat, 05 Dec 2026 22:57:02 -0500 In-Reply-To: <20261128165206.3248835-7-julius@bairaktaris.de> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 References: <20261128165206.3248835-1-julius@bairaktaris.de> <20261128165206.3248835-7-julius@bairaktaris.de> Message-ID: Subject: Re: [PATCH net 6/6] net: dsa: keep a bridge number while another tree uses it From: willemb@google.com To: Julius Bairaktaris , Andrew Lunn , Vladimir Oltean , netdev@vger.kernel.org Cc: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Willem de Bruijn , Simon Horman , "=?UTF-8?B?QWx2aW4gxaBpcHJhZ2E=?=" , Linus Walleij , Florian Fainelli , Pawel Dembicki , Tobias Waldekranz , Daniel Golle , Russell King , linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8"; format=flowed; delsp=yes 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 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