From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.160.199 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796529424; b=qiDlaROgC1r8ntzrXst5yNmxPE9fCuz/f1nrrUyaJrqRxJk8S5H5+HlJy4g4NpoGQHd0 /E5gMZJwoBYj4C/0A5rpjoHx7DA3hSdTIE4I7jY1VlC8n1V0uRZPqTVDapK4rJDPVJFuP GSyiaiXz4LUBOzKbJW363Ul6ri8T8U0ZbhuHNgoPF911xGbrL2yvMvEcGew2slVTTqMpb pG1KR9uF/2QyWBGuzTBoVKcInNxa9xZq7tXQ3nMC3gzvGn/LNK/9QSNIsRniklAw07FuZ wjSbgPTyRLKJL0uwueV1zni8EBrBA848vqVIrTVFfIeEa7/qOWg3SAkU+V575zfEHSg== 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=cDGfIMrYZaXEgPxUGy64bNlwvVlcDUtMW3TRBRpNBYCjsehf+bms84t3b8ISSy73awuv PntKDSvcLHEaNRE6Gyq0sOb/q6P7RakBn2Ic5h0m5DyP5Kf4zw+aVltfjoSDLh6JNHgYM qvB9Xopj9iy6UdB6/3cFqy4/S9HODiS55DTivbRuzWrVlAwr3c5DgLlxHQvQRSOpVInvX +noVFFOw2UP9KODHwBeHdciy97RHAnU0CrZjsiKovKjRugRtCCunqd+xJ6b69Mpcq1egX uxf+FT2j4cLx7rVc7smgIgasZQ6ClCpfLD0ZT7h3BjdrGUzdCwmkHq0vWsPSWqCfiSA== 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.199 Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) (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 C5874606A321 for ; Sun, 6 Dec 2026 03:57:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org C5874606A321 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-f199.google.com with SMTP id d75a77b69052e-5383c05fb2fso53358691cf.1 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=zVAxnNkKEe4P3KlIGyeHMBApdQCoRxcYeiJsRNtzjahKtIGsehQuUXbG6W4yUASfwn NToh/UqDLWtMzddv4OnRBMNoGed+MzZfuhGP1aeA3rTDwEWB96m+wgSho5yUHjyPvk1M 4s0R2Hp5MYEjvdCO3soJoECyqe+lZlJeBPwTW4WKSZb50sBkfskCOdOLyHq0y+ROW1sd X8svlrEFPmSWnOq0PQpo3x2oElS8rGxumlEknnkR+OtCD7ob8ltswiJXvIzRZWQwiRp4 bCdgZj6vPGKdYpfNrCLkfq+RzoNTtpW7lID5WD9/JWEUJTb8db8CV2Px/GFoz5TcRNUX XlAA== X-Forwarded-Encrypted: i=1; AL+hErEhhJa/EyevtY5WmsDFZvabXuQvZ9We3gU8F4l3qg+xBrIsZNr875LCSTSIHM/YEI2cA/ft+6s=@vger.kernel.org X-Gm-Message-State: APuU4Z/dsqtS5gd6nvC/xDIkDS7VBx8CmJXX+GLHRa75DN3AXVA/XvMq n5FtNKTlnafw2VQ0arR5A1z4TtdCdkxok90GH2y4lOHJdPdcRrsJcyqoiIGj/ioHGIAgtjzU29a Ew28zbfRZ8w== 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: netdev@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