From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.170 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796438996; b=xSWzi+JO0N2GWdl74Pl4BBBNfc1AlbQk4ujUbkU/aUFZdG47ONda2/af4j9HcsyvInjH 9GDPBCxlEoItBPV7FN7trNbTMvC85hmahSwi6RnZeWWe8hrJnyPTClVEIF9uEXjg3IkZV TXxiNuCCQj7Z2zvoRDO8WSewLUWVyAWYJKjO3cBy9IhnDYjK8IwMGx3pLzMkXsiVPwI1v 6ufRfmbBS+Zi+roA2eIVol2GTf5WdZBBvcpcwFxH7Q0tz4I0kcccmiM69KxrzYQXijowy b8r2M22J/0nbfv/QISigJIOqFouwAz/VrqWQgw8pAdVBGnjYSHMUOYJCTt4TetNeCaA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796438996; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding; bh=8rvhKhC1HZM46Mt6sL0oG/+VfoWdND08uuBs2UW+8QU=; b=Yc5mgBXJYEFJCBNblaKhJku0trCYYaO+w9ilB11+nYWJuP3fVAQwADc3wlTlNLY2lI+k MZgpxWiJttgkwJsaHY7PHa9Y3U49BJFWrtIa6fOjGJUlYtdIUHeAbqPBu37rVvELN9Rr1 HVck/iSf4xjCU2TDYxAtagrO4bFKd9ed/3+vvNSK8NNysvLYk33gY18ir4ogqmKwGdTZE 5NJ6jotfXWh1DEfC6CykBF4d9/BmmE0nL5aQy9+ZxsJnKNYhWx87/pXMI+t7rU58iojw5 aMK1U8KdzcgIh2pjv+0witef+o9bDTyF28fkuJVFbrWfMeEsiBZ6U27wLlq3eql8PSw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b="TV/ScPnx"; arc=none smtp.remote-ip=74.125.82.170 Received: from mail-dy1-f170.google.com (mail-dy1-f170.google.com [74.125.82.170]) (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 93C6B606A333 for ; Sat, 5 Dec 2026 02:49:56 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 93C6B606A333 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=TV/ScPnx Received: by mail-dy1-f170.google.com with SMTP id 5a478bee46e88-3866a784546so2218310eec.0 for ; Fri, 04 Dec 2026 18:49:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796438996; x=1797043796; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=8rvhKhC1HZM46Mt6sL0oG/+VfoWdND08uuBs2UW+8QU=; b=TV/ScPnx1Y3pbz1uXW8Yk011hH1HWu2lLnX8rn6g2jDNFYMinpo4zLS2ahAsavIQWD wpe355CK/gqWJqvA4RmHO4/G7vwdvlg6MovatozlwuS6FtPI46VxcyVJDDPo8Xh/CqKQ ob3nHbVoV2XVeHA2UpvgCNdF+2P/SNs1UrqnXaZpNFSYx1bOH6564CVZH8ukpukXXjpD amEZ951TJzMBmjT6IiaNF9/IXDwWN1LdvED/ytj1iho4VEma9Fi4Mni69okFRD3Nk3Yc mOh4RjHr3wWO4xkzTB7jC85c7qvMAZwVgEoqtYpo9/cHzTSOOVSIW+XQ8UgXb0gPX2Mr pkrA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796438996; x=1797043796; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=8rvhKhC1HZM46Mt6sL0oG/+VfoWdND08uuBs2UW+8QU=; b=K4+LVdYtirOvcNs3qBmNeGcY5mUGbFW51ovMvtCsydlhItJLHZjDX6HrRFsg3pOIrm EO0J3j1OdPXMrxY4XbNqkygbWSkR9p2uGmR2Ha1lGG/2lD7Y/Whbc9/93OIBCtqbPacZ BRqYIXSYhtrDk7BDk9LcxCMyOzCitF7reLSvNJX1wj52pppRPE7z568XmJcz8GB8Y/Tr K6NfIXqlDPla5FKmt7kJzEWh1I3WPkmOYcKhhZ3J+gXsal5y1wfoAvZXRfo9l6AlkzYm tTRy+Wx/B5CBeMy7xVfW6OflyB5c9kXaUM+XoecO9ilWtbEIpMmb1kjnHMP9jqfbN4sd Msyw== X-Forwarded-Encrypted: i=1; AL+hErHAqbwoQ8TqxhCXaYuDYgSc9Vhr4amgpI/E01LOM36of/RGJOd/NbkWJdwlHE7ruBqmlNpNRHs=@vger.kernel.org X-Gm-Message-State: AB4q+uGOFE/GXJ3/SrP16U6d/cwWpClDAcMNYMm5yru43FqAYVjCo8CL yVdnYhko6aCeriCo57Oh+1QgHJG616g1ZHv6qPp2E3br4ASScHVjmXju X-Gm-Gg: AZFdTZek8qgAtWYb6ghW1/g/nQimu5mmFxxxzh1phUX4Kq5WfT06OaUJMfFvDQ69QFb SLu2lchjtY6ihgQVgoefpIpDBLf82mSDVev2OaB6z8+wVxQAqr2xF7KaQ83kZKd8xv3hReAzWrE NVF+WEsLoql9sbSz5JjtWwOSQTH+ilwIiwmgFnGSQZWETu6C4zWqDKgTe1wy9EX51R1yISNm84u tcmlTJlhaN/A9Mz+k64bbK44Jt0wwaCDQl5duYtMHFBSv8xOxx2L5o2VqC1ei/auASzobyJMzMA hd3QxSFNY83YKega77/TH7/tIoAisJ2gyOt7iU55UqlpPxx058BOcmTPAM7XRWO3PrbGvJcbQzO O2tM3t06wg1YlTr4uUVF0bpcgR63Ga5YLDW4/UDMd8mTZxhe0xN/12sEpA2R3jkqjygQnnVhmmf P7vjZZeJtqQrbHSmuWIvDZVM0balFLlgnWruOmQNCzsWKFE49YwcG9V0GUt29fjXGQvqjzlB/ww 3aTMASa6IrYb9LPc/ia+IGECucyHBw8TX+8Uh3Wh/u+SjLHSdb9YVMn5tjtfWWhCZcI6jKOAl6T BLPlpIeG43E7kbiivZuZqDw5VzBPumT00t+HuRMqPIX708PdbrLZuUZNVZP90b2sNoslFwZ0hgc 1Mw== X-Received: by 2002:a05:7300:e122:b0:387:45c1:ddf5 with SMTP id 5a478bee46e88-387520b0f23mr3559123eec.10.1796438995567; Fri, 04 Dec 2026 18:49:55 -0800 (PST) Received: from samniyama.tailbcd61.ts.net ([76.20.4.3]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-387521bb368sm17797155eec.10.2026.12.04.18.49.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2026 18:49:55 -0800 (PST) From: Koral Ilgun To: Jiri Pirko , Nikolay Aleksandrov , Ido Schimmel , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: Willem de Bruijn , Simon Horman , Vladimir Oltean , Ioana Ciornei , Andrew Lunn , Daniel Machon , bridge@lists.linux.dev, netdev@vger.kernel.org, Koral Ilgun Subject: [PATCH net v3 2/3] net: bridge: switchdev: count an offload only after its hwdom is set Date: Fri, 4 Dec 2026 18:49:41 -0800 Message-ID: <20261205024943.3657727-3-koralilgun@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261205024943.3657727-1-koralilgun@gmail.com> References: <20261205024943.3657727-1-koralilgun@gmail.com> 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 Content-Transfer-Encoding: 8bit From: Koral Ilgun nbp_switchdev_add() sets offload_count to 1 before it calls nbp_switchdev_hwdom_set(), and keeps the count when that call fails with -EBUSY. br_switchdev_port_offload() then returns the error without nbp_switchdev_del(), so the port keeps a count for an offload that did not happen. A later offload from the same switch takes the offload_count branch, increments the count and returns 0, and the port never gets a hwdom. An offload from another switch is refused. On the current tree, only a port that br_add_if() is about to add can get -EBUSY. br_add_if() frees that port when the driver passes the error on. Before the previous patch, rocker only logged the error and kept its port in the bridge with the count, and its unoffload at the leave balanced the count. With this patch alone, that unoffload hits the WARN_ON() in nbp_switchdev_del(). The previous patch makes rocker fail the join, so the port does not stay in the bridge. A port that is already in the port list matches itself in nbp_switchdev_hwdom_set(). The next patch makes that function skip a port without a hwdom. Then a port that stays in the bridge can get -EBUSY when all hwdoms are busy: a LAG that is already a bridge port when its first switch port joins, or a VXLAN bridge port that mlxsw_sp_bridge_vxlan_join() offloads. Set offload_count only after nbp_switchdev_hwdom_set() succeeds. nbp_switchdev_hwdom_set() compares the ppid, so the ppid is still set before the call. The ppid stays set after the error. The next offload overwrites it, and with the next patch nbp_switchdev_hwdom_set() skips a port without a hwdom, so nothing reads it. An AI coding agent found the fault in a read of the source while it prepared the next patch. An AI code review agent then found that the first version of that patch on the list makes the fault reachable for a port that stays in the bridge. The refusal of a second switch and the mlxsw case come from a read of the source. Tested in a VM on dsa_loop with two local changes that do not go upstream: empty port_lag_join and port_lag_leave ops in dsa_loop, and a knob that makes nbp_switchdev_hwdom_set() return -EBUSY as if all hwdoms were busy. With the knob on, lan1 joins a bond that is already a bridge port, twice: ip link add br0 type bridge ip link add bond1 type bond mode balance-xor ip link set bond1 master br0 ip link set lan1 down ip link set lan1 master bond1 With the next patch alone, the first join fails with EBUSY and the bond keeps offload_count 1. The second join succeeds with hwdom 0, and the bond keeps hwdom 0 after the knob is off. With this patch below the next one, both joins fail with EBUSY and the count stays 0; with the knob off, the bond gets hwdom 1. A local trace printed the count and the hwdom. On the current tree, with or without this patch, the self match gives the bond hwdom 0 and the knob changes nothing. In the same VM, with the knob on, a port of a QEMU rocker device joins a bridge and then leaves it. With this patch alone, the join succeeds, rocker logs the error, and the leave hits the WARN_ON() in nbp_switchdev_del(). With the previous patch below this one, the join fails with EBUSY and the leave gives no WARN. No kernel selftest ran. This patch was prepared with Claude Code (Anthropic). It wrote the code change, this changelog and the reproducer, and ran the tests in the VM, under my direction; a separate model instance reviewed the patch. I reviewed the result and checked the test output. Fixes: 2f5dc00f7a3e ("net: bridge: switchdev: let drivers inform which bridge ports are offloaded") Signed-off-by: Koral Ilgun --- net/bridge/br_switchdev.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/net/bridge/br_switchdev.c b/net/bridge/br_switchdev.c index 10f3aea6a1f8..8de12d56452d 100644 --- a/net/bridge/br_switchdev.c +++ b/net/bridge/br_switchdev.c @@ -280,12 +280,13 @@ static int nbp_switchdev_add(struct net_bridge_port *p, } p->ppid = ppid; - p->offload_count = 1; err = nbp_switchdev_hwdom_set(p); if (err) return err; + p->offload_count = 1; + if (tx_fwd_offload) { set_bit(BR_TX_FWD_OFFLOAD_BIT, &p->flags); static_branch_inc(&br_switchdev_tx_fwd_offload); -- 2.43.0