Article View: linux.kernel.netdev
Article #26054[PATCH net v2 1/2] net: bridge: switchdev: count an offload only after its hwdom is set
From: Koral Ilgun
Date: Thu, 03 Dec 2026 00:24
Date: Thu, 03 Dec 2026 00:24
89 lines
15034 bytes
15034 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. rocker only logs the error, so its port stays in the bridge
with the count, and its unoffload at the leave balances the count. With
this patch, that unoffload hits the WARN_ON() in nbp_switchdev_del().
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, the
mlxsw case and the rocker 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. 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:
<20261203002451.517879-2-koralilgun@gmail.com>Path:
mbox-mo1.pugleaf.net!srv.newsdeef.eu.MISMATCH!feed-us-txt.newsdeef.eu!feed-us-ny.newsdeef.eu!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-376155-linux-kernel-netdev=dewy.ruReferences:
<20261203002451.517879-1-koralilgun@gmail.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu.MISMATCH!feed-us-txt.newsdeef.eu!feed-us-ny.newsdeef.eu!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-376155-linux-kernel-netdev=dewy.ru
From: koralilgun@gmail.com (Koral Ilgun)
Newsgroups: linux.kernel.netdev
Subject: [PATCH net v2 1/2] net: bridge: switchdev: count an offload only after its hwdom is set
Date: Wed, 2 Dec 2026 16:24:50 -0800
Organization: Usenet Network
Message-ID: <20261203002451.517879-2-koralilgun@gmail.com>
References: <20261203002451.517879-1-koralilgun@gmail.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
logging-data="2096032"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:pbHGSKWwBkjfJ2KV/5j84d1jIQs= sha256:qMCj9aY1Ct5yM2Af6stLL+vwfeCHe4B78GdmU7ASDKY=
sha1:amnSOhUENtE9TPBGRsicU1DZOog= sha256:ozIzcEqha/BFYY8tLuZO9fw5RC1QPpNweu55TKiwmQw=
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 75D091177A3; Thu, 3 Dec 2026 03:25:13 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.049
X-Spam-Status: No, score=-3.049 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.249,
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 oAJVWrkqs30n;
Thu, 3 Dec 2026 03:25:10 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-376155-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 sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
by mail.dewy.ru (Postfix) with ESMTPS id 5C38511779E; Thu, 3 Dec 2026 03:25:02 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
by sea.lore.kernel.org (Postfix) with ESMTP id 2B8C12931B; Thu, 3 Dec 2026 00:24:57 +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=1796257497;
b=1lBUIR50FVelOJdYJZ3B8aQc3at/xFvqwiHm9NtFaiXslmVDteTOtLWsWiwRlcjcWtTw
7aop7iSS2weEhhrgxQ/Ptt21e6flfEI3ni1K8qylEGhYBMIyzP1vc11EkVOqDvtjjdrsT
yhtrTlvtUn+6/wvnbQ1YytLXSlKRDlC8sMqDR7wzPL7p+2luNQWuHLy/6Uro6LHPRVM00
9xODFCTYXdlL5TcBfclXK0zDawdOk10a+hHjw9JOS+UIeFe1KVC7O48Ny/kRc/TfVKOyr
aUy6s5UeQXYh4UVYQGAuW5fG+7vsXaNBk79GsWOeZrZR9qWZnFGX82Zv1qOzH0R/jww==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1796257497;
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=kUJE+zIwo1aVwM4gGxZ7uEY+qw3Q6gQolqTqi4blyp4=;
b=D7UTfBlLiF2xvsezeaBMKkCCZgEgUefOqOqHfCnTUB1p3EbKPOdItGlh78/A8ZVHZpIC
+3QaoRCcq8YRbv7LLAcmW5t0AIRSUrkBS+7mZqwYQLMH/ceYU96UT66PkgbMJ1jErgcyK
rRlWchUeG8NrBy6IuC4ImhJqvWA6+uBLwYPTHjNHkDXDsQE+rXVm0DjF0hA15L9bYfDFq
4gVrmaYVJznY6+82qtreHatGXrynNW6/eQQB6vQ74JM8vMeKQzH0hAI9AhJsQC1KsaDDv
j0t8QdhlIz20ZOomN4npvhTrIhStqJaeXTmuKnRXLlzWLgAwFuSrZ/bwo+GChSZJczg==
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=e0U6Lqgk;
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 E8C01606A330;
Thu, 3 Dec 2026 00:24:56 +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=e0U6Lqgk
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.41
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
t=1796257496;
b=z0OrPETJy6/5RrvMuYq8oA19moUrUUWh1kVweP0Jbgzhj49BR/y+O+BqWkpb+HIPieI9
w6b66Muq3WcVsETspl9GQn0PZ50UzcxrB8Xg/a5mwSXkaZcl+1LTm8OY7XiBGbIOhu+JN
O1Pk8wo/yn+dtfmMqjXNHFHXltrjWhEbKn1XPm82VUzhaokCzVvruPb00Mg/lGsNaSsZV
IiJ7bQt3sdoixK+NaqtpiCOchmxFqk41YnMaYkW7CifyLWKHTjKBe8rHFz6A5QreJCBp0
xfd+IUAZ1Vwu1+Dxt+tEcGfTf8insTGBmFWMzbALS6C3aC7+eQG+LH+VvwQ/K91/+CQ==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1796257496;
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=kUJE+zIwo1aVwM4gGxZ7uEY+qw3Q6gQolqTqi4blyp4=;
b=bKHCil8IHZ/ih2XItLwZ/wUAXi2UinUDf27GMJ4Dbzgq31PAnsR3akN74dWmFBQ1vA88
fK/1uFpsm8L76IP6LRl2lb/vFelgn8A9Dnj4at0qDSoESYhU6MVsqM/nvPkGQEFHvjT0s
zlCC9TgCInFVFizAFYtRDsalOB43WPxGM+WXB59y0zfAyrcftGRdprEBvP63becqZKdEd
HS0241tWSy8Hq0OkM0+O0DynydHM0DIXE3QEyDDmxC23OkcyqcFOdDe5u17mWLL1Xsr5d
C1F1zSjMLVA6zYpq+D3GyAUfpL/A+p0jEK0Lr1LYhv9b4D19clwCNlCxMshiUg78vYQ==
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=e0U6Lqgk;
arc=none smtp.remote-ip=74.125.82.41
X-Received: from mail-dl1-f41.google.com (mail-dl1-f41.google.com [74.125.82.41])
(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 B340B606A337
for <netdev@vger.kernel.org>; Thu, 3 Dec 2026 00:24:55 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org B340B606A337
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-dl1-f41.google.com with SMTP id a92af1059eb24-170135e43c7so8049620c88.0
for <netdev@vger.kernel.org>; Wed, 02 Dec 2026 16:24:55 -0800 (PST)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20260707; t=1796257495; x=1796862295; 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=kUJE+zIwo1aVwM4gGxZ7uEY+qw3Q6gQolqTqi4blyp4=;
b=e0U6LqgkSQtrbjdUD6PYRmJgNzXkMcEygA4JsKeukhVNCBpZ3byB1Mk2PjzeuxelJ0
M4Wki9lj97CT9Ean0fHL7L56/iRksxLgJC34mEDz6pb1TBKu2fV6mJbxPIgXd8+b16oH
GrTiQtpk6JuPAYH/SHMmyXO56J+it2cby4IerQymHb++hSKEUJwBYY9G2+jfTNcUYyfJ
QdTI0cij50JQcgWRpSS5HLTxV7AAwn9jPix4JuYMKX+OLc0X7l0dQfwBBNcxHS60BfSd
CWkOUw8fYRWwuk91mmrdsdMtNgdEef1MIeBNTE1XIh7san0XenXP984Oe7r92c3yp5Or
tiVA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20260707; t=1796257495; x=1796862295;
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=kUJE+zIwo1aVwM4gGxZ7uEY+qw3Q6gQolqTqi4blyp4=;
b=UNnsjlHvRPjJesLU7v5+jiZv9H8d0gTh+9mcvi5EFfqmYYDdcs8xOQKsK1YzEzSGwG
WVKPwqfBq8o/6lWbHlMN3IdI8IY3Ei3bKkjeogHiRLx3qaiFmFtdH5/yP3IdFEeyVWo9
VTe3rbbxJ0XPPlPDii3Gv8nmwzVa8EEsVh38h8W4IDTZCjy4VY6hmOEP/WhzrHTAvuER
rhIbTe8AsQwDkrGxex6w66BMjvmXnUCrHiuR2X2/zT4HpoeEQ0/cyy5YoH7gZDfSGuR1
iN90MBlCwOKYlR5+DTYvqbASK+EHbk0e/mmaMRAbIiocMUR4bN6ofeRDs87Eugriv53F
Ohlg==
X-Forwarded-Encrypted: i=1; AL+hErEUAF/+aFtT4+NXNWVZfk3sfWQKliTlcWHBJzzhAQL2ejbNkeOUpaFpVHb/tOjUyNgIyWOyZ48=@vger.kernel.org
X-Gm-Message-State: APuU4Z+zDdV6SXFT4p+72WJpPDy/MQfJixuY+Hy0jnlAwOrtLRMG91u2
1EXyMkWE0d99vJIg7WV98AfpNJdpALS0R10E5lm+h/9qoEMGxUtiN9oc
X-Gm-Gg: AZFdTZeznaoj8j+JxkWOXtBSNTODNwdns3PZZWw7qClE0croHrG9rBtVcftjdADswrD
gOqB/uSxkQQKlBHf7sqFeW3/v4I0rTMdhQFHdlGi7dWE33taH/csE1tSH3rxxKpNrcGxrw3xBO3
gpKn7DHxQHfQw67qpovgK6XQW1hQx7SHR1z3cbFLvvyqe641vU9w2AN1d9X4cdaqP+65hTqcxxf
p83UjqgmrgZZI6YZNzkTf5Pynou5FWp0ZsRksf/5nmTf55Cr1tgnkvp0zNuNhJKUCIEMU+kDEs3
4/uvmiUPnxkohFpd8oJoZl8RhHPgA5bplXcgIMAFZr4kBCkOE6+9LL4cBw6+5/DtBjCI+TD2VBC
MiuuSQC1WrugJfRJasIsIG5CJ6nQHJKp0cs4LFw1bwFuouP9a6255yBUyLuRzT8DVbBaBwWAbDS
aEkMzMLSVh2R/Ya8h+fLKXy/DkvMNaNYa0YZH9C9UBXmH2aOPlmPSaTRgAoV0jc0HjitZYo7e3t
/xw7eXmA3jiSaFZwECLL4DGZSn+Q9zdGNCQNc38ifFWnKdIeJ1KK1H3c+cM9EcB23dpPh7PeJDc
QUA23OHYChCjkMCeLWm4XEeUT4b/GYGrHvOhwojSAUTkhiN2V95MdZghxzHXc3CE4hw5Wll4CUv
o
X-Received: by 2002:a05:7022:ea46:20b0:1b5:23c0:4f15 with SMTP id a92af1059eb24-1b556918196mr39558831c88.39.1796257494694;
Wed, 02 Dec 2026 16:24:54 -0800 (PST)
X-Received: from samniyama.tailbcd61.ts.net ([76.20.4.3])
by smtp.gmail.com with ESMTPSA id a92af1059eb24-1b55684c85fsm152631634c88.14.2026.12.02.16.24.53
(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
Wed, 02 Dec 2026 16:24:54 -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@lunn.ch>,
Jiri Pirko <jiri@resnulli.us>,
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: <20261203002451.517879-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