From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.41 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== 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== 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 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 ; Thu, 3 Dec 2026 00:24:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org B340B606A337 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=e0U6Lqgk Received: by mail-dl1-f41.google.com with SMTP id a92af1059eb24-170135e43c7so8049620c88.0 for ; Wed, 02 Dec 2026 16:24:55 -0800 (PST) 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) 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) From: Koral Ilgun To: 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 , Jiri Pirko , Daniel Machon , bridge@lists.linux.dev, netdev@vger.kernel.org, Koral Ilgun 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 Message-ID: <20261203002451.517879-2-koralilgun@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261203002451.517879-1-koralilgun@gmail.com> References: <20261203002451.517879-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. 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 --- 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