Netdev List
 help / color / mirror / Atom feed
* [PATCH net-next] net: dsa: report a deleted FDB entry as no longer offloaded
@ 2026-11-22 17:44 Julius Bairaktaris
  2026-11-23 17:44 ` netdev-bot+sashiko
  0 siblings, 1 reply; 2+ messages in thread
From: Julius Bairaktaris @ 2026-11-22 17:44 UTC (permalink / raw)
  To: Andrew Lunn, Vladimir Oltean
  Cc: Nikolay Aleksandrov, Ido Schimmel, netdev, bridge,
	David S . Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Simon Horman

dsa_user_switchdev_event_work() reports SWITCHDEV_FDB_OFFLOADED with
offloaded=true once it has added an FDB entry to the switch, and reports
nothing once it has deleted one. The bridge sets BR_FDB_OFFLOADED on the
entry when it gets the report, so an entry that the bridge keeps after
DSA deleted it from the switch is still shown as offloaded, and matched
as such by "bridge fdb flush ... offloaded", while the switch no longer
holds it.

The bridge keeps such an entry when the address moves: an address
learned on a foreign port of the bridge, which DSA installs as a host
address on the CPU port when the switch asks for assisted learning, is
deleted from the CPU port when it is then learned on a user port, where
DSA does not install it. The flag is also left set when an addition is
still queued while the bridge withdraws the entry: the work items run in
order on the ordered DSA workqueue, so the addition reports the entry
as offloaded after the bridge withdrew it, and the deletion queued
behind it reports nothing.

Report offloaded=false when a deletion the bridge asked for succeeds.
Such a deletion reaches every DSA port that can hold the entry: the
user port it is on, each port of a LAG, or for a host address each user
port in the bridge. The reports come from the work items in the order
the switch was changed, so the last one for an entry gives the state
the switch was left in. A deletion replayed for one port that leaves
the bridge or a LAG is not reported, since a host address or a LAG
entry can still be held for the other ports. When the last port of the
switch leaves, the flag of the entries it held stays set, as before.
DSA's reports are ordered against each other, not against those of
another switchdev driver in the same bridge: a deletion still queued
here can clear the flag that driver set on an entry re-created on one
of its ports, as a queued addition could already set it.

The addition has been reported since commit c9eb3e0f8701 ("net: dsa: Add
support for learning FDB through notification"); a deletion never was.

Found by an LLM review of v1 of "net: bridge: withdraw the
switchdev entry of an fdb entry made dynamic".

In QEMU with KASAN, with dsa_loop given FDB operations and assisted
learning on the CPU port, and a tc mirred redirect that delivers frames
to a dsa_loop user port (test-only setup): an address learned on a veth
port of the bridge and then on the user port, and a static entry on the
user port that is deleted while its addition is still queued (dsa_loop
delays it by 500 ms) and whose address is then learned on that port, are
both still shown as offloaded without this change, in 3 of 3 boots
each. With it, neither is, in 3 of 3 boots each, and a host address
that stays on the CPU port when one of two user ports leaves the bridge
is still shown as offloaded, in 3 of 3 boots.

Signed-off-by: Julius Bairaktaris <julius@bairaktaris.de>
---
This depends on "[PATCH net] net: dsa: hold the device a queued FDB event
is reported to" (https://lore.kernel.org/netdev/20261122173347.791590-1-julius@bairaktaris.de/,
the prerequisite-patch-id below), which keeps the device alive that the
report added here goes to.

Trigger: an address that DSA installed as a host address moves to a
user port, or an entry is withdrawn while its addition is still queued.
Impact: a wrong "offload" flag in the bridge's view only. CVSS 3.1 0.0.
Until the fix: the flag goes when the entry is deleted or ages out.

I used Claude (Anthropic) to help write these patches.

 net/dsa/user.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/net/dsa/user.c b/net/dsa/user.c
index 5e72fb34e308..7bcf8d3b5fcd 100644
--- a/net/dsa/user.c
+++ b/net/dsa/user.c
@@ -44,6 +44,7 @@ struct dsa_switchdev_event_work {
 	unsigned char addr[ETH_ALEN];
 	u16 vid;
 	bool host_addr;
+	bool replayed;
 };
 
 enum dsa_standalone_event {
@@ -3629,13 +3630,14 @@ static int dsa_user_netdevice_event(struct notifier_block *nb,
 }
 
 static void
-dsa_fdb_offload_notify(struct dsa_switchdev_event_work *switchdev_work)
+dsa_fdb_offload_notify(struct dsa_switchdev_event_work *switchdev_work,
+		       bool offloaded)
 {
 	struct switchdev_notifier_fdb_info info = {};
 
 	info.addr = switchdev_work->addr;
 	info.vid = switchdev_work->vid;
-	info.offloaded = true;
+	info.offloaded = offloaded;
 	call_switchdev_notifiers(SWITCHDEV_FDB_OFFLOADED,
 				 switchdev_work->orig_dev, &info.info, NULL);
 }
@@ -3668,7 +3670,7 @@ static void dsa_user_switchdev_event_work(struct work_struct *work)
 				dp->index, addr, vid, err);
 			break;
 		}
-		dsa_fdb_offload_notify(switchdev_work);
+		dsa_fdb_offload_notify(switchdev_work, true);
 		break;
 
 	case SWITCHDEV_FDB_DEL_TO_DEVICE:
@@ -3682,8 +3684,13 @@ static void dsa_user_switchdev_event_work(struct work_struct *work)
 			dev_err(ds->dev,
 				"port %d failed to delete %pM vid %d from fdb: %d\n",
 				dp->index, addr, vid, err);
+			break;
 		}
-
+		/* A deletion replayed for this port alone, as it leaves the
+		 * bridge or a LAG, can leave the entry held for other ports
+		 */
+		if (!switchdev_work->replayed)
+			dsa_fdb_offload_notify(switchdev_work, false);
 		break;
 	}
 
@@ -3774,6 +3781,7 @@ static int dsa_user_fdb_event(struct net_device *dev,
 	ether_addr_copy(switchdev_work->addr, fdb_info->addr);
 	switchdev_work->vid = fdb_info->vid;
 	switchdev_work->host_addr = host_addr;
+	switchdev_work->replayed = !!ctx;
 
 	dsa_schedule_work(&switchdev_work->work);
 

base-commit: eb6d6c80d35449c27471b1874f13066c09a8964d
prerequisite-patch-id: 7d26d57478287c871bcb5eb5837534cf4a2b48a3
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-23 17:45 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-22 17:44 [PATCH net-next] net: dsa: report a deleted FDB entry as no longer offloaded Julius Bairaktaris
2026-11-23 17:44 ` netdev-bot+sashiko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox