From: Koral Ilgun <kora…@adtran.com> ofdpa_port_bridge_join() sets bridge_dev, moves the port to the internal VLAN of the bridge, adds the untagged VLAN again and then calls switchdev_bridge_port_offload(). When ofdpa_port_vlan_add() or the offload fails, it returns the error and undoes nothing. rocker_netdevice_event() only logs the error and returns NOTIFY_DONE, so br_add_if() keeps the port in the bridge. At the leave, ofdpa_port_bridge_leave() calls switchdev_bridge_port_unoffload() for an offload that did not happen. When ofdpa_port_vlan_add() failed, the bridge never counted an offload of the port, and nbp_switchdev_del() hits WARN_ON(!p->offload_count). When the offload failed with -EBUSY because all hwdoms are busy, nbp_switchdev_add() keeps offload_count 1 today, so the leave is balanced. The next patch fixes that count, and the leave then hits the same WARN_ON(). Undo the join in ofdpa_port_bridge_join() when the VLAN add or the offload fails: give the port its own internal VLAN and untagged VLAN again, and clear bridge_dev. Return the error of a bridge join from rocker_netdevice_event() with notifier_from_errno(), so that __netdev_upper_dev_link() rolls back the link and br_add_if() fails. That rollback sends no event for the unlink, so rocker must undo its own state before it returns the error. A failure of the first ofdpa_port_vlan_del() in ofdpa_port_bridge_join() now also fails the join; that path has no undo, as before. The undo does not check the errors of its own calls, because it already returns the error of the join. The undo alone does not leave a working port. br_add_if() calls new_nbp() before it links the port, and new_nbp() sets the port state to BLOCKING and then DISABLED with SWITCHDEV_F_DEFER. del_nbp() runs switchdev_deferred_process() before the unlink, but the error path of br_add_if() does not, so both states reach rocker after the undo. ofdpa_port_attr_stp_state_set() applies them to the port that is no longer bridged, and the standalone port loses the ACL flows that pass ARP and link-local frames to the CPU. The deferred ageing time from br_init_port() reaches rocker too, and it sets the ageing time of the port, as each join does. Make ofdpa_port_attr_stp_state_set() ignore an STP state for a port that is not bridged. DSA has the same check: dsa_user_port_attr_set() returns -EOPNOTSUPP when dsa_port_offloads_bridge_port() is false. rocker returns 0, and in both cases the change is skipped without a message. Keep the OVS case as it is. ofdpa_port_ovs_changed() sets bridge_dev before the calls that can fail and does not undo it, so a returned error would leave bridge_dev at a master that the port did not join. rocker logged and dropped a join error already before the commit in the Fixes tag. That commit put in the offload and unoffload calls, and with them the WARN_ON() at the leave. Tested in QEMU (TCG) with a rocker device of one port, sw1p1, cabled through a QEMU hub to a virtio NIC in another network namespace. A local knob made nbp_switchdev_hwdom_set() return -EBUSY as if all hwdoms were busy: ip link add br1 type bridge ip link set sw1p1 master br1 # knob on ip link set sw1p1 nomaster With the next patch but without this one, the join succeeds, rocker logs "failed to reflect master linked (err -16)", and the leave hits the WARN_ON() in nbp_switchdev_del(). With this patch, the join fails with EBUSY, sw1p1 is not a port of br1, and the leave gives no WARN. Then a ping from sw1p1 as a standalone port to the virtio NIC passes 5 of 5, and sw1p1 joins br1 with the knob off, passes a ping through br1 and leaves without a WARN. Each kernel ran the test in three boots. Without the change to ofdpa_port_attr_stp_state_set(), the standalone ping lost 5 of 5 in each boot, and a dump of the QEMU rocker tables showed that the ARP and link-local ACL flows were gone. The failures of the first ofdpa_port_vlan_del() and of ofdpa_port_vlan_add(), and the OVS case, come from a read of the source. No kernel selftest ran. The Sashiko AI review of v2 of this series pointed out that the next patch makes the WARN_ON() reachable on rocker and that no patch of the series fixed it. Claude Code found the WARN_ON() after a failed ofdpa_port_vlan_add() in a read of the source. 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> --- drivers/net/ethernet/rocker/rocker_main.c | 8 +++++++- drivers/net/ethernet/rocker/rocker_ofdpa.c | 24 +++++++++++++++++++--- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/drivers/net/ethernet/rocker/rocker_main.c b/drivers/net/ethernet/rocker/rocker_main.c index 0fcd65fc0af7..e721b68625c6 100644 --- a/drivers/net/ethernet/rocker/rocker_main.c +++ b/drivers/net/ethernet/rocker/rocker_main.c @@ -3101,9 +3101,15 @@ static int rocker_netdevice_event(struct notifier_block *unused, err = rocker_world_port_master_linked(rocker_port, info->upper_dev, extack); - if (err) + if (err) { netdev_warn(dev, "failed to reflect master linked (err %d)\n", err); + /* Only the bridge join undoes its own state + * on an error. + */ + if (netif_is_bridge_master(info->upper_dev)) + return notifier_from_errno(err); + } } else { err = rocker_world_port_master_unlinked(rocker_port, info->upper_dev); diff --git a/drivers/net/ethernet/rocker/rocker_ofdpa.c b/drivers/net/ethernet/rocker/rocker_ofdpa.c index 1e0558bd78c3..4d59ad76dd17 100644 --- a/drivers/net/ethernet/rocker/rocker_ofdpa.c +++ b/drivers/net/ethernet/rocker/rocker_ofdpa.c @@ -2471,6 +2471,9 @@ static int ofdpa_port_attr_stp_state_set(struct rocker_port *rocker_port, { struct ofdpa_port *ofdpa_port = rocker_port->wpriv; + if (!ofdpa_port_is_bridged(ofdpa_port)) + return 0; + return ofdpa_port_stp_update(ofdpa_port, 0, state); } @@ -2583,10 +2586,25 @@ static int ofdpa_port_bridge_join(struct ofdpa_port *ofdpa_port, err = ofdpa_port_vlan_add(ofdpa_port, OFDPA_UNTAGGED_VID, 0); if (err) - return err; + goto err_vlan_add; + + err = switchdev_bridge_port_offload(dev, dev, NULL, NULL, NULL, + false, extack); + if (err) + goto err_bridge_port_offload; + + return 0; - return switchdev_bridge_port_offload(dev, dev, NULL, NULL, NULL, - false, extack); +err_bridge_port_offload: + ofdpa_port_vlan_del(ofdpa_port, OFDPA_UNTAGGED_VID, 0); +err_vlan_add: + ofdpa_port_internal_vlan_id_put(ofdpa_port, bridge->ifindex); + ofdpa_port->internal_vlan_id = + ofdpa_port_internal_vlan_id_get(ofdpa_port, + ofdpa_port->dev->ifindex); + ofdpa_port->bridge_dev = NULL; + ofdpa_port_vlan_add(ofdpa_port, OFDPA_UNTAGGED_VID, 0); + return err; } static int ofdpa_port_bridge_leave(struct ofdpa_port *ofdpa_port)
-- 2.43.0