Netdev List
 help / color / mirror / Atom feed
From: Julius Bairaktaris <julius@bairaktaris.de>
To: Nikolay Aleksandrov <razor@blackwall.org>,
	Ido Schimmel <idosch@nvidia.com>
Cc: netdev@vger.kernel.org, bridge@lists.linux.dev,
	"David S . Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@kernel.org>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Simon Horman <horms@kernel.org>,
	Vladimir Oltean <olteanv@gmail.com>,
	Vladimir Oltean <vladimir.oltean@nxp.com>,
	Jesse Brandeburg <jbrandeb@kernel.org>
Subject: [PATCH net-next v2 1/2] net: bridge: withdraw the switchdev entry of an fdb entry made dynamic
Date: Sun, 22 Nov 2026 20:21:17 +0100	[thread overview]
Message-ID: <20261122192118.1204290-2-julius@bairaktaris.de> (raw)
In-Reply-To: <20261122192118.1204290-1-julius@bairaktaris.de>

Since commit 927cdea5d209 ("net: bridge: switchdev: don't notify FDB
entries with "master dynamic""), br_switchdev_fdb_notify() reports
neither the addition nor the deletion of an entry that the user added
without NUD_PERMANENT or NUD_NOARP. The user can turn an entry that
switchdev was told about, a learned one or a static one, into such an
entry: fdb_add_entry() does it for "bridge fdb replace ... master
dynamic", and __fdb_update() for "bridge fdb replace ... master use"
(NTF_USE), which marks a learned entry as added by the user. The
drivers then keep the entry they were given, and since its later
deletion is not reported either, they keep it after the bridge has
dropped it.

Report the deletion of the old entry to switchdev before either path
makes it one that is no longer reported, as br_fdb_update() does before
an entry moves to another port; br_switchdev_fdb_notify() tests the old
flags, so only an entry that was reported is withdrawn. Entries with
the extern_learn flag stay reported and are left alone. The NTF_USE
branch is only reached from netlink: the packet path passes no
BR_FDB_ADDED_BY_USER to br_fdb_update().

Clear the offloaded flag of the entry with the withdrawal. Drivers set
it once they have programmed an entry and do not clear it when they
delete one, so the entry, which stays in the bridge, would otherwise
still be shown as offloaded, and matched as such by "bridge fdb flush",
after the hardware dropped it. br_fdb_offloaded_set() now assigns the
flag instead of testing and toggling it, so a driver report that runs
beside the clear in the NTF_USE path, which does not hold hash_lock,
cannot invert it.

Found by an LLM review of the series "net: dsa: fix host fdb
refcount when an entry roams".

In QEMU with KASAN and dsa_loop given FDB operations and
assisted learning, a static entry on a dsa_loop port and an address
learned on a veth port of the bridge, which is a host address on the
CPU port, are offloaded. Without this change, "bridge fdb replace
<addr> dev lan1 master dynamic" on the first, and "... dev vA master
dynamic" or "... dev vA master use" on the second, delete nothing from
the switch and the entries are still shown as offloaded, in 3 of 3
boots for each command. With it, each command deletes the address from
the switch and the entry is no longer shown as offloaded, in 3 of 3
boots for each.

Signed-off-by: Julius Bairaktaris <julius@bairaktaris.de>
---
v2:
- net-next instead of net, so without the Fixes: tag; the commit that
  introduced the filter is named in the first paragraph (Nikolay).
- Clear the offloaded flag with the withdrawal: a "master static" entry
  the driver had offloaded kept it after "replace ... master dynamic"
  deleted the entry from the hardware (Nikolay). br_fdb_offloaded_set()
  assigns the flag instead of toggling it, so the clear cannot be
  inverted by a concurrent report.
- Call br_switchdev_fdb_notify() directly, no helper (Nikolay).
- Drop the comments in __fdb_update() (Nikolay).

v1: https://lore.kernel.org/netdev/20261121191638.1724620-1-julius@bairaktaris.de/

 net/bridge/br_fdb.c | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/net/bridge/br_fdb.c b/net/bridge/br_fdb.c
index b601245ad923..4af091c19244 100644
--- a/net/bridge/br_fdb.c
+++ b/net/bridge/br_fdb.c
@@ -1005,6 +1005,7 @@ static void __fdb_update(struct net_bridge *br,
 	struct net_bridge_port *old_port;
 	struct net_bridge_dst old_dst;
 	bool fdb_modified = false;
+	bool roamed = false;
 	unsigned long now;
 
 	/* attempt to update an entry for a local interface */
@@ -1032,6 +1033,7 @@ static void __fdb_update(struct net_bridge *br,
 			br_switchdev_fdb_notify(br, fdb, RTM_DELNEIGH);
 			br_fdb_dst_write(fdb, dst);
 			fdb_modified = true;
+			roamed = true;
 			/* take over HW learned entry */
 			if (unlikely(test_bit(BR_FDB_ADDED_BY_EXT_LEARN,
 					      &fdb->flags)))
@@ -1049,6 +1051,12 @@ static void __fdb_update(struct net_bridge *br,
 	}
 
 	if (unlikely(test_bit(BR_FDB_ADDED_BY_USER, &flags))) {
+		if (!test_bit(BR_FDB_STATIC, &fdb->flags) &&
+		    !test_bit(BR_FDB_ADDED_BY_EXT_LEARN, &fdb->flags)) {
+			if (!roamed)
+				br_switchdev_fdb_notify(br, fdb, RTM_DELNEIGH);
+			clear_bit(BR_FDB_OFFLOADED, &fdb->flags);
+		}
 		set_bit(BR_FDB_ADDED_BY_USER, &fdb->flags);
 		if (test_and_clear_bit(BR_FDB_DYNAMIC_LEARNED, &fdb->flags))
 			atomic_dec(&br->fdb_n_learned);
@@ -1262,6 +1270,12 @@ static int fdb_add_entry(struct net_bridge *br, struct net_bridge_dst dst,
 		if (flags & NLM_F_EXCL)
 			return -EEXIST;
 
+		if (!(state & (NUD_PERMANENT | NUD_NOARP)) &&
+		    !test_bit(BR_FDB_ADDED_BY_EXT_LEARN, &fdb->flags)) {
+			br_switchdev_fdb_notify(br, fdb, RTM_DELNEIGH);
+			clear_bit(BR_FDB_OFFLOADED, &fdb->flags);
+		}
+
 		old_dst = br_fdb_dst_read(fdb);
 		modified = fdb_update_dst(fdb, old_dst, dst);
 
@@ -1706,8 +1720,8 @@ void br_fdb_offloaded_set(struct net_bridge *br, struct net_bridge_port *p,
 	spin_lock_bh(&br->hash_lock);
 
 	fdb = br_fdb_find(br, addr, vid);
-	if (fdb && offloaded != test_bit(BR_FDB_OFFLOADED, &fdb->flags))
-		change_bit(BR_FDB_OFFLOADED, &fdb->flags);
+	if (fdb)
+		assign_bit(BR_FDB_OFFLOADED, &fdb->flags, offloaded);
 
 	spin_unlock_bh(&br->hash_lock);
 }
-- 
2.53.0


  reply	other threads:[~2026-11-22 19:21 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-22 19:21 [PATCH net-next v2 0/2] net: bridge: switchdev state of fdb entries made dynamic or roamed Julius Bairaktaris
2026-11-22 19:21 ` Julius Bairaktaris [this message]
2026-11-23 19:23   ` [PATCH net-next v2 1/2] net: bridge: withdraw the switchdev entry of an fdb entry made dynamic netdev-bot+sashiko
2026-11-22 19:21 ` [PATCH net-next v2 2/2] net: bridge: clear the offloaded flag of an fdb entry that roams Julius Bairaktaris
2026-11-23 19:23   ` netdev-bot+sashiko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261122192118.1204290-2-julius@bairaktaris.de \
    --to=julius@bairaktaris.de \
    --cc=bridge@lists.linux.dev \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=horms@kernel.org \
    --cc=idosch@nvidia.com \
    --cc=jbrandeb@kernel.org \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=olteanv@gmail.com \
    --cc=pabeni@redhat.com \
    --cc=razor@blackwall.org \
    --cc=vladimir.oltean@nxp.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox