Article View: linux.kernel.netdev
Article #27214[PATCH net v3 2/3] net: bridge: switchdev: count an offload only after its hwdom is set
From: Koral Ilgun
Date: Sat, 05 Dec 2026 02:49
Date: Sat, 05 Dec 2026 02:49
98 lines
15126 bytes
15126 bytes
From: Koral Ilgun <koral.ilgun@adtran.com>
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 <koral.ilgun@adtran.com>
---
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
Technical Details
Message-ID:
<20261205024943.3657727-3-koralilgun@gmail.com>Path:
mbox-mo1.pugleaf.net!news-wdc.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!peer01.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!feeder.usenetexpress.com!tr3.eu1.usenetexpress.com!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-377798-linux-kernel-netdev=dewy.ruReferences:
<20261205024943.3657727-1-koralilgun@gmail.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-wdc.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!peer01.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!feeder.usenetexpress.com!tr3.eu1.usenetexpress.com!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-377798-linux-kernel-netdev=dewy.ru From: koralilgun@gmail.com (Koral Ilgun) Newsgroups: linux.kernel.netdev 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 Organization: Usenet Network Message-ID: <20261205024943.3657727-3-koralilgun@gmail.com> References: <20261205024943.3657727-1-koralilgun@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="2938559"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:+mryxHbxnVWY3o72SBO51Ine3lE= sha256:bxqhBgs4rsilkYfeoVzJByRsSllhOQY5Z9/C6sVUkyQ= sha1:LxJwRTeG+cx+MIJYBOioVeyTRE4= sha256:HagnUrAbkbLTXj7bk/WJxbVl34JAQ3YSCLLdQ9hF6NQ= List-ID: <netdev.vger.kernel.org> X-Mailpost-Empty-Hdrs: X-Spam-Level X-Received: from localhost (localhost [127.0.0.1]) by mail.dewy.ru (Postfix) with ESMTP id 451B7117D4D; Sat, 5 Dec 2026 05:50:15 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.297 X-Spam-Status: No, score=-3.297 tagged_above=-9999 required=6.31 tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.001, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.001, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001] autolearn=ham autolearn_force=no X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key) header.d=gmail.com X-Received: from mail.dewy.ru ([127.0.0.1]) by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id QXD5z_zOJkUe; Sat, 5 Dec 2026 05:50:13 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=104.64.211.4; helo=sin.lore.kernel.org; envelope-from=netdev+bounces-377798-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=gmail.com X-Received: from sin.lore.kernel.org (sin.lore.kernel.org [104.64.211.4]) by mail.dewy.ru (Postfix) with ESMTPS id B471D117D49; Sat, 5 Dec 2026 05:50:03 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sin.lore.kernel.org (Postfix) with ESMTP id 8AC6D2ED33; Sat, 5 Dec 2026 02:50:00 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796438997; b=iDIdF/l0PuCppkHcmXUPiqc5AWjuzCZx9/UrkcwukGuzukhMwpGn1vcLtTAfizd3vZrv A/2gn5hnAOPRDyRjEMRCXtjQzv5AohXCDJNr2XK5IwfzBDR1rBCTUYa1EfsxP9ao2X0kW 4G6V2wsPqnoDrv2RAXBzThF27haHRAZDiA7fFP5kFdotiQnlLR7VhicRrpV8Vx8fMjolD A7CFj8h65ORra7eEsd8n+9n1ln9GX80hnCi4xYf2Lhn3ipO1j/+iCoEiJhI07esb/H/Mf zfa2MnAPyvwrV042heuEs/vkgVrUGFknld2az3f1IZNRfUzE9bCbU5pLzxUx8+dHhCg== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796438997; h=X-Original-To:Received: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:X-Mailing-List:List-Id:List-Post: List-Help:List-Subscribe:List-Unsubscribe:List-Owner:Precedence: MIME-Version:Content-Transfer-Encoding; bh=8rvhKhC1HZM46Mt6sL0oG/+VfoWdND08uuBs2UW+8QU=; b=mPh0qfmdfIgicI7yQBYWaaNcyKfTQ3M/EWKu1C5AhKDijLch63jMZ8r80A+TUOBhLq4G X+u1i6GAxvhFd4VIxKZXQSc4ZMPLlR6uYODThMdBVI+S5VEGaH+fP+ND5GfUbnqyDENYC pmRR2h80KvJJz8BvswQ+Al5Y6YOBLd0jarxy4aX8ewp7/ziUaLTdtiD0JJATrcocg5FB0 MFWdE7nSLdpx3zi+k/RYFHvKPc2sIcsGj5cJlvphIc63alC8/UefHd5hejYwJT9tgQkxg wVsnWTx1Rx5A6ZXaW7o06FmEAUZXgrLPtVOvT8sZhH9FBf+ipHV2gMLvbBpY3jpqcrw== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b="TV/ScPnx"; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BD83E606A336; Sat, 5 Dec 2026 02:49:57 +0000 (UTC) X-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 X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.170 X-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== X-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== X-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 X-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 <netdev@vger.kernel.org>; Sat, 5 Dec 2026 02:49:56 +0000 (UTC) X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 93C6B606A333 X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com X-Received: by mail-dy1-f170.google.com with SMTP id 5a478bee46e88-3866a784546so2218310eec.0 for <netdev@vger.kernel.org>; Fri, 04 Dec 2026 18:49:56 -0800 (PST) X-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) X-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) X-Cc: Willem de Bruijn <willemb@google.com>, Simon Horman <horms@kernel.org>, Vladimir Oltean <vladimir.oltean@nxp.com>, Ioana Ciornei <ioana.ciornei@nxp.com>, Andrew Lunn <andrew+netdev@lunn.ch>, Daniel Machon <daniel.machon@microchip.com>, bridge@lists.linux.dev, netdev@vger.kernel.org, Koral Ilgun <koral.ilgun@adtran.com> X-Mailer: git-send-email 2.43.0 X-In-Reply-To: <20261205024943.3657727-1-koralilgun@gmail.com> X-Mailing-List: netdev@vger.kernel.org X-List-Post: <mailto:netdev@vger.kernel.org> X-List-Help: <mailto:netdev+help@vger.kernel.org> X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org> X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org> X-List-Owner: <mailto:netdev+owner@vger.kernel.org> X-Precedence: list X-Received-Bytes: 14929