From: Koral Ilgun <kora…@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 <kora…@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