Re: [PATCH net-next v3 3/3] net: sparx5: keep router legs in sync with the bridge
From: Jens Emil Schulz Østergaard
Date: Mon Nov 23 2026 - 03:56:21 EST
On Fri Nov 20, 2026 at 8:19 AM CET, netdev-bot+sashiko wrote:
> Thank you for your contribution! Sashiko AI review found 4 potential
> issue(s) to consider.
>
> Critical: 0 · High: 1 (1) · Medium: 1 · Low: 2
>
> If you believe none of the issues are legitimate, please reply to each
> issue of Medium severity or higher and explain why the AI is wrong.
> If any of them are legitimate and you plan to respin, please let patchwork
> know by including "pw-bot: cr" as a separate line at the end of your reply
> (one such reply per series is enough).
>
> - [High] sparx5_rr_legs_reconcile() now walks
> netdev_for_each_upper_dev_rcu(sparx5->hw_bridge_dev, ...) from the…
> - [Medium] Contrary to the commit message, a router leg can be lost while
> its upper is down.
> - [Low] In sparx5_rr_router_init() the new comment says "The exported
> helpers use leg_list once sparx5->router is set".
> - [Low] The function comment above sparx5_rr_bridge_legs_flush() still
> reads "Tear down the router legs of a bridge that is no longer…
>
> Pre-existing issues:
> - [High] This problem wasn't introduced by this patch, but this patch
> extends the affected code.
>
> --
>
> net: sparx5: keep router legs in sync with the bridge
>
> This commit makes the sparx5 L3 router legs follow later changes to the
> bridge and the vlan upper. A leg is destroyed when vlan filtering is
> disabled, when the bridge moves to a non-802.1Q protocol, when the upper
> is linked to a master, or when the upper's MAC changes. Ingress routing
> on a leg is limited to when the upper is up and the bridge carries the
> vid tagged, and the reconcile now also creates legs for eligible uppers
> of the offloaded bridge.
>
>> diff --git a/drivers/net/ethernet/microchip/sparx5/sparx5_router.c b/drivers/net/ethernet/microchip/sparx5/sparx5_router.c
>> index 26aeee17733cd..7412db7a6e7b4 100644
>> --- a/drivers/net/ethernet/microchip/sparx5/sparx5_router.c
>> +++ b/drivers/net/ethernet/microchip/sparx5/sparx5_router.c
>
> [ ... ]
>
>> @@ -568,19 +650,66 @@ static void sparx5_rr_router_legs_flush(struct sparx5 *sparx5)
>
> [ ... ]
>
>> +void sparx5_rr_legs_reconcile(struct sparx5 *sparx5)
>> {
>> struct sparx5_rr_router_leg *leg, *tmp;
>> + struct net_device *bridge, *dev;
>> struct sparx5_router *router;
>> + struct list_head *iter;
>>
>> ASSERT_RTNL();
>>
>> router = sparx5->router;
>> + if (!router)
>> + return;
>>
>> mutex_lock(&router->lock);
>> list_for_each_entry_safe(leg, tmp, &router->leg_list, leg_list_node) {
>> - if (sparx5_rr_dev_addr_list_empty(leg->dev))
>> + if (sparx5_rr_dev_addr_list_empty(leg->dev) ||
>> + !sparx5_rr_dev_real_is_vlan_aware(sparx5, leg->dev)) {
>> sparx5_rr_router_leg_destroy(leg);
>> + continue;
>> + }
>
> [Severity: Medium]
> The commit message says:
>
> "A leg with an IPv4 address is kept while the upper is down, so it is
> available again when the interface comes back up."
>
> Does this still hold if the bridge MAC changes while a NET_ADDR_STOLEN vlan
> upper is down?
>
> When the bridge sends NETDEV_CHANGEADDR, vlan_device_event() in
> net/8021q/vlan.c skips uppers that are not IFF_UP. A down upper therefore
> keeps the old MAC, and sparx5_rr_dev_real_is_vlan_aware() then fails here:
>
> if (dev->addr_assign_type != NET_ADDR_STOLEN ||
> !ether_addr_equal(dev->dev_addr, vlan_rdev->dev_addr))
> return false;
>
> On the next reconcile, the new check above destroys the down upper's IPv4
> leg and frees its VMID.
>
> Unrelated events can queue that reconcile: an inet6addr UP/DOWN on any vlan
> device, a bridge vlan add or del, or the VLAN_FILTERING attr that is sent
> when a sparx5 port joins. For example, a port with a lower MAC joins the
> bridge. That queues the reconcile, and br_stp_recalculate_bridge_id()
> changes the bridge MAC before the reconcile runs.
>
> Suppose the bridge MAC then changes back before the upper comes up, for
> example because the port leaves again or after ip link set br0 address
> <old>. What recreates the leg then? The bridge NETDEV_CHANGEADDR in
> sparx5_rr_netdevice_event() does not queue a reconcile, because
> is_vlan_dev(bridge) is false:
>
> case NETDEV_CHANGEADDR:
> mutex_lock(&router->lock);
> if (sparx5_rr_bridge_has_legs(sparx5, dev))
> sparx5_rr_leg_base_mac_set(sparx5, dev->dev_addr);
> mutex_unlock(&router->lock);
> if (is_vlan_dev(dev))
> sparx5_rr_legs_reconcile_schedule(sparx5);
>
> When the upper is later brought up, the MACs already match, so no
> CHANGEADDR is sent. The NETDEV_UP case only refreshes an existing leg. The
> IPv4 address already exists, so the validator does not run either. With
> IPv6 disabled on the upper (disable_ipv6, or addr_gen_mode none), no
> link-local NETDEV_UP arrives.
>
> Wouldn't the upper then stay without a leg until something unrelated
> triggers a reconcile?
>
> Now take the case where the upper comes up while the bridge still has the
> new MAC. vlan_dev_open()->vlan_dev_inherit_address() does queue a reconcile.
> But if another upper has taken the freed VMID in the meantime, creating the
> leg fails, and only a ratelimited warning is printed.
>
This is right. A NET_ADDR_STOLEN upper which is down keeps the old MAC
when the bridge MAC changes, so a reconcile in that window destroys its
leg. If the MAC is back to the old value when the upper comes up it
is not requeued. v4 queues the reconcile on NETDEV_UP of a vlan upper of
the offloaded bridge that has no leg.
>> +
>> + bridge = vlan_dev_real_dev(leg->dev);
>> + leg->vlan_present = sparx5_rr_bridge_vlan_present(bridge,
>> + leg->vid);
>> + sparx5_rr_leg_hw_uc_update(sparx5, leg);
>> + }
>> +
>> + bridge = sparx5->hw_bridge_dev;
>> + if (!bitmap_empty(sparx5->bridge_mask, SPX5_PORTS) && bridge) {
>> + netdev_for_each_upper_dev_rcu(bridge, dev, iter) {
>
> [Severity: High]
> Can this walk a bridge that has already been freed during driver removal?
>
> The driver holds no reference on hw_bridge_dev. Only
> sparx5_port_bridge_leave() clears hw_bridge_dev and bridge_mask, and it runs
> from the main sparx5 netdevice notifier on NETDEV_CHANGEUPPER. Before this
> patch, the reconcile walked only leg_list, whose entries hold netdev
> references.
>
> mchp_sparx5_remove() unregisters that notifier before the router notifiers:
>
> sparx5_unregister_notifier_blocks(sparx5);
> sparx5_rr_router_deinit(sparx5);
>
> Suppose ip link del br0 runs in that window. del_nbp() unlinks the ports,
> but hw_bridge_dev and bridge_mask stay set. The router notifiers are still
> registered, so addrconf_ifdown() on the bridge's vlan uppers can, for
> example, send inet6addr NETDEV_DOWN, and sparx5_rr_inet6addr_event() queues
> legs_work. After rtnl_unlock(), netdev_run_todo() frees the bridge.
>
> legs_work can then run, including during the drain in
> sparx5_rr_router_deinit(), while sparx5->router is still set:
>
> destroy_workqueue(router->sparx5_router_owq);
> sparx5_rr_router_legs_flush(sparx5);
> sparx5_rr_router_hw_deinit(sparx5);
> sparx5->router = NULL;
>
> The bridge_mask/hw_bridge_dev check passes on this stale state, and
> netdev_for_each_upper_dev_rcu() reads the adj_list of the freed bridge.
> Could a garbage dev then reach __sparx5_rr_inetaddr_event(), which may call
> netdev_hold() on it and program hardware?
>
I think this is correct, but it needs a bridge del racing with driver
removal. mchp_sparx5_remove() unregisters the notifiers that maintain
hw_bridge_dev and bridge_mask before the router stops, so router work
can run on stale bridge state. The next version tears the router down
before the notifier blocks: its notifiers are unregistered and the work
disabled first, and sparx5->router is cleared under RTNL.
>> @@ -683,6 +705,7 @@ static int sparx5_handle_port_vlan_del(struct net_device *dev,
>> switchdev_blocking_nb);
>>
>> sparx5_mact_forget(sparx5, dev->broadcast, vid);
>> + sparx5_rr_bridge_vlan_clear(sparx5, dev, vid);
>> return 0;
>> }
>
> [Severity: High]
> This is a pre-existing issue that this patch did not introduce, but the
> patch extends the affected branches. The bridge-master paths of
> sparx5_handle_port_vlan_add() and sparx5_handle_port_vlan_del() never check
> dev == sparx5->hw_bridge_dev, or the netns. The switchdev blocking notifier
> chain is global.
>
> Can a software-only bridge in another namespace remove the broadcast entry
> here? The bridge sends master VLAN add/del notifications for every bridge.
> A user with CAP_NET_ADMIN only in its own user namespace can run:
>
> ip link add br0 type bridge
> bridge vlan add vid X dev br0 self
> bridge vlan del vid X dev br0 self
>
> sparx5_mact_forget() then deletes the chip-wide (ff:ff:ff:ff:ff:ff, X)
> entry that points at PGID_BCAST. PGID_BCAST is the only flood group that
> sparx5_start() sets up with CPU copy enabled. After that, broadcasts on vid
> X of the offloaded bridge no longer reach the CPU, so ARP fails for host
> interfaces and for the router legs on that vid.
>
> The new sparx5_rr_bridge_vlan_clear() and
> sparx5_rr_legs_reconcile_schedule() calls are added to the same unfiltered
> branches. Would an early check like this be appropriate?
>
> if (dev != sparx5->hw_bridge_dev)
> return 0;
Preexisting, but correct, the bridge master vlan add and del paths act
on any bridge. The calls this patch adds there only touch legs of the
bridge passed in, and the reconcile is idempotent, so it does not add to
this. I do not think this should be fixed in this series.
pw-bot: cr