* [PATCH net] net: bridge: withdraw the switchdev entry of an fdb entry made dynamic
@ 2026-11-21 19:16 Julius Bairaktaris
2026-11-22 10:58 ` Nikolay Aleksandrov
2026-11-25 0:18 ` netdev-bot+sashiko
0 siblings, 2 replies; 4+ messages in thread
From: Julius Bairaktaris @ 2026-11-21 19:16 UTC (permalink / raw)
To: Nikolay Aleksandrov, Ido Schimmel
Cc: netdev, bridge, David S . Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Willem de Bruijn, Simon Horman, Vladimir Oltean,
Vladimir Oltean, Jesse Brandeburg
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(). The offloaded flag of the
entry stays as the drivers report it.
Found while reviewing how DSA tracks host addresses for bridge FDB
entries. In QEMU with KASAN and dsa_loop given FDB operations and
assisted learning, an address learned on a veth port of the bridge is a
host address on the CPU port. After "bridge fdb replace <addr> dev vA
master dynamic", or "... master use", and the deletion of the entry,
net keeps the address on the CPU port in 3 of 3 boots for each command;
with this change it is deleted at the replace in 3 of 3 boots for each.
Fixes: 927cdea5d209 ("net: bridge: switchdev: don't notify FDB entries with "master dynamic"")
Signed-off-by: Julius Bairaktaris <julius@bairaktaris.de>
---
I used Claude (Anthropic) to help write these patches.
net/bridge/br_fdb.c | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
diff --git a/net/bridge/br_fdb.c b/net/bridge/br_fdb.c
index b601245ad923..377ca8341029 100644
--- a/net/bridge/br_fdb.c
+++ b/net/bridge/br_fdb.c
@@ -996,6 +996,16 @@ static bool __fdb_mark_active(struct net_bridge_fdb_entry *fdb)
test_and_clear_bit(BR_FDB_NOTIFY_INACTIVE, &fdb->flags));
}
+/* Called before @fdb becomes an entry that the user added as dynamic, which
+ * br_switchdev_fdb_notify() does not report: report the deletion of the entry
+ * switchdev was told about, if it was
+ */
+static void fdb_switchdev_hide(struct net_bridge *br,
+ const struct net_bridge_fdb_entry *fdb)
+{
+ br_switchdev_fdb_notify(br, fdb, RTM_DELNEIGH);
+}
+
static void __fdb_update(struct net_bridge *br,
struct net_bridge_fdb_entry *fdb,
struct net_bridge_port *source,
@@ -1005,6 +1015,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 +1043,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)))
@@ -1048,7 +1060,12 @@ static void __fdb_update(struct net_bridge *br,
}
}
+ /* Only from netlink (NTF_USE), with the user's flag in @flags */
if (unlikely(test_bit(BR_FDB_ADDED_BY_USER, &flags))) {
+ /* After a roam the deletion was reported above */
+ if (!roamed && !test_bit(BR_FDB_STATIC, &fdb->flags) &&
+ !test_bit(BR_FDB_ADDED_BY_EXT_LEARN, &fdb->flags))
+ fdb_switchdev_hide(br, fdb);
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 +1279,10 @@ 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))
+ fdb_switchdev_hide(br, fdb);
+
old_dst = br_fdb_dst_read(fdb);
modified = fdb_update_dst(fdb, old_dst, dst);
base-commit: d5b89d55a322b632e2b465b392a4c1d9d338db9c
--
2.53.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH net] net: bridge: withdraw the switchdev entry of an fdb entry made dynamic
2026-11-21 19:16 [PATCH net] net: bridge: withdraw the switchdev entry of an fdb entry made dynamic Julius Bairaktaris
@ 2026-11-22 10:58 ` Nikolay Aleksandrov
2026-11-22 19:22 ` Julius Bairaktaris
2026-11-25 0:18 ` netdev-bot+sashiko
1 sibling, 1 reply; 4+ messages in thread
From: Nikolay Aleksandrov @ 2026-11-22 10:58 UTC (permalink / raw)
To: Julius Bairaktaris, Ido Schimmel
Cc: netdev, bridge, David S . Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Willem de Bruijn, Simon Horman, Vladimir Oltean,
Vladimir Oltean, Jesse Brandeburg
On 21/11/2026 21:16, Julius Bairaktaris wrote:
> 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(). The offloaded flag of the
> entry stays as the drivers report it.
>
> Found while reviewing how DSA tracks host addresses for bridge FDB
> entries. In QEMU with KASAN and dsa_loop given FDB operations and
> assisted learning, an address learned on a veth port of the bridge is a
> host address on the CPU port. After "bridge fdb replace <addr> dev vA
> master dynamic", or "... master use", and the deletion of the entry,
> net keeps the address on the CPU port in 3 of 3 boots for each command;
> with this change it is deleted at the replace in 3 of 3 boots for each.
>
> Fixes: 927cdea5d209 ("net: bridge: switchdev: don't notify FDB entries with "master dynamic"")
> Signed-off-by: Julius Bairaktaris <julius@bairaktaris.de>
> ---
> I used Claude (Anthropic) to help write these patches.
>
> net/bridge/br_fdb.c | 21 +++++++++++++++++++++
> 1 file changed, 21 insertions(+)
>
I think this has never worked, so this patch can go to net-next.
A few nits below.
> diff --git a/net/bridge/br_fdb.c b/net/bridge/br_fdb.c
> index b601245ad923..377ca8341029 100644
> --- a/net/bridge/br_fdb.c
> +++ b/net/bridge/br_fdb.c
> @@ -996,6 +996,16 @@ static bool __fdb_mark_active(struct net_bridge_fdb_entry *fdb)
> test_and_clear_bit(BR_FDB_NOTIFY_INACTIVE, &fdb->flags));
> }
>
> +/* Called before @fdb becomes an entry that the user added as dynamic, which
> + * br_switchdev_fdb_notify() does not report: report the deletion of the entry
> + * switchdev was told about, if it was
> + */
> +static void fdb_switchdev_hide(struct net_bridge *br,
> + const struct net_bridge_fdb_entry *fdb)
> +{
> + br_switchdev_fdb_notify(br, fdb, RTM_DELNEIGH);
> +}
This helper isn't helpful. Just call br_switchdev_fdb_notify directly.
> +
> static void __fdb_update(struct net_bridge *br,
> struct net_bridge_fdb_entry *fdb,
> struct net_bridge_port *source,
> @@ -1005,6 +1015,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 +1043,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)))
> @@ -1048,7 +1060,12 @@ static void __fdb_update(struct net_bridge *br,
> }
> }
>
> + /* Only from netlink (NTF_USE), with the user's flag in @flags */
This comment is useless.
> if (unlikely(test_bit(BR_FDB_ADDED_BY_USER, &flags))) {
> + /* After a roam the deletion was reported above */
> + if (!roamed && !test_bit(BR_FDB_STATIC, &fdb->flags) &&
> + !test_bit(BR_FDB_ADDED_BY_EXT_LEARN, &fdb->flags))
> + fdb_switchdev_hide(br, fdb);
> 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 +1279,10 @@ 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))
> + fdb_switchdev_hide(br, fdb);
> +
I played around with the possible bits that can result from this change and I think
I got 1 bad case:
What if a user adds a master static entry (created with BR_FDB_ADDED_BY_USER but without
ext_learn) which is later programmed and gets BR_FDB_OFFLOADED set, then a replace with
"master dynamic"?
That is,
bridge fdb add master static, bridge -> swdev driver issues add (entry is now ADDED_BY_USER | STATIC),
swdev -> bridge (entry is now with | OFFLOADED), bridge fdb replace master dynamic (ADDED_BY_USER | OFFLOADED)
but the entry has been deleted in dsa / mlxsw due to the new swdev del that is sent
> old_dst = br_fdb_dst_read(fdb);
> modified = fdb_update_dst(fdb, old_dst, dst);
>
>
> base-commit: d5b89d55a322b632e2b465b392a4c1d9d338db9c
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH net] net: bridge: withdraw the switchdev entry of an fdb entry made dynamic
2026-11-22 10:58 ` Nikolay Aleksandrov
@ 2026-11-22 19:22 ` Julius Bairaktaris
0 siblings, 0 replies; 4+ messages in thread
From: Julius Bairaktaris @ 2026-11-22 19:22 UTC (permalink / raw)
To: razor, idosch
Cc: netdev, bridge, davem, edumazet, kuba, pabeni, willemb, horms,
olteanv, vladimir.oltean, jbrandeb
On 22/11/2026 12:58, Nikolay Aleksandrov wrote:
> I think this has never worked, so this patch can go to net-next.
Agreed. v2 is for net-next:
https://lore.kernel.org/netdev/20261122192118.1204290-1-julius@bairaktaris.de/
> This helper isn't helpful. Just call br_switchdev_fdb_notify directly.
Agreed, v2 calls it directly.
> This comment is useless.
Agreed, v2 has no comments there.
> I played around with the possible bits that can result from this change and I think
> I got 1 bad case:
> What if a user adds a master static entry (created with BR_FDB_ADDED_BY_USER but without
> ext_learn) which is later programmed and gets BR_FDB_OFFLOADED set, then a replace with
> "master dynamic"?
Agreed. v2 clears BR_FDB_OFFLOADED together with the withdrawal in both
paths. Your sequence on a dsa_loop port leaves the entry without
"offload" in 3 of 3 boots; v1 kept it in 3 of 3.
pw-bot: cr
Julius
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH net] net: bridge: withdraw the switchdev entry of an fdb entry made dynamic
2026-11-21 19:16 [PATCH net] net: bridge: withdraw the switchdev entry of an fdb entry made dynamic Julius Bairaktaris
2026-11-22 10:58 ` Nikolay Aleksandrov
@ 2026-11-25 0:18 ` netdev-bot+sashiko
1 sibling, 0 replies; 4+ messages in thread
From: netdev-bot+sashiko @ 2026-11-25 0:18 UTC (permalink / raw)
To: julius
Cc: razor, idosch, netdev, bridge, davem, edumazet, kuba, pabeni,
willemb, horms, olteanv, vladimir.oltean, jbrandeb
Thank you for your contribution! Sashiko AI review found 3 potential
issue(s) to consider.
Critical: 0 · High: 1 · Medium: 2 · Low: 0
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] The patch balances only the event-driven notifications.
- [Medium] fdb_switchdev_hide() (net/bridge/br_fdb.c:1003-1007) sends
SWITCHDEV_FDB_DEL_TO_DEVICE, and the driver removes the entry from its…
- [Medium] The new withdrawal is not atomic with respect to the packet
path.
--
net: bridge: withdraw the switchdev entry of an fdb entry made dynamic
Some entries become user-added dynamic entries, which
br_switchdev_fdb_notify() no longer reports. This patch reports an FDB
deletion to switchdev just before that happens. The two paths are
fdb_add_entry() ("bridge fdb replace ... master dynamic") and the NTF_USE
branch of __fdb_update() ("... master use").
> diff --git a/net/bridge/br_fdb.c b/net/bridge/br_fdb.c
> index b601245ad9239..377ca83410294 100644
> --- a/net/bridge/br_fdb.c
> +++ b/net/bridge/br_fdb.c
> @@ -996,6 +996,16 @@ static bool __fdb_mark_active(struct net_bridge_fdb_entry *fdb)
> test_and_clear_bit(BR_FDB_NOTIFY_INACTIVE, &fdb->flags));
> }
>
> +/* Called before @fdb becomes an entry that the user added as dynamic, which
> + * br_switchdev_fdb_notify() does not report: report the deletion of the entry
> + * switchdev was told about, if it was
> + */
> +static void fdb_switchdev_hide(struct net_bridge *br,
> + const struct net_bridge_fdb_entry *fdb)
> +{
> + br_switchdev_fdb_notify(br, fdb, RTM_DELNEIGH);
> +}
[Severity: Medium]
Does this leave BR_FDB_OFFLOADED set on an entry that is no longer in
hardware?
fdb_switchdev_hide() sends SWITCHDEV_FDB_DEL_TO_DEVICE and the driver
removes the entry, but nothing clears the offloaded bit. After the hide
the entry is ADDED_BY_USER && !STATIC && !EXT_LEARN, so
br_switchdev_fdb_notify() never reports it again. No driver will then send
SWITCHDEV_FDB_OFFLOADED to correct the bit.
The SWITCHDEV_FDB_OFFLOADED senders for bridge FDB entries only report
offloaded=true, and only after an ADD. For example in DSA:
net/dsa/user.c:dsa_fdb_offload_notify() {
...
info.offloaded = true;
call_switchdev_notifiers(SWITCHDEV_FDB_OFFLOADED,
switchdev_work->orig_dev, &info.info, NULL);
}
mlxsw sends offloaded=false only on its VXLAN path. On the bridge side
the bit is only cleared in br_fdb_clear_offload() and
br_fdb_offloaded_set().
So fdb_fill_info() keeps reporting it:
if (test_bit(BR_FDB_OFFLOADED, &fdb->flags))
ndm->ndm_flags |= NTF_OFFLOADED;
After "bridge fdb replace ... master dynamic" or "... master use",
"bridge fdb show" would then print "offload" for an entry that only
exists in software.
The commit message says:
The offloaded flag of the entry stays as the drivers report it.
Drivers don't report un-offloading on DEL_TO_DEVICE, so does the flag just
go stale here? Should the hide path also clear BR_FDB_OFFLOADED?
[ ... ]
> @@ -1048,7 +1060,12 @@ static void __fdb_update(struct net_bridge *br,
> }
> }
>
> + /* Only from netlink (NTF_USE), with the user's flag in @flags */
> if (unlikely(test_bit(BR_FDB_ADDED_BY_USER, &flags))) {
> + /* After a roam the deletion was reported above */
> + if (!roamed && !test_bit(BR_FDB_STATIC, &fdb->flags) &&
> + !test_bit(BR_FDB_ADDED_BY_EXT_LEARN, &fdb->flags))
> + fdb_switchdev_hide(br, fdb);
> set_bit(BR_FDB_ADDED_BY_USER, &fdb->flags);
[Severity: Medium]
Can a concurrent roam from the packet path send an ADD between
fdb_switchdev_hide() and set_bit(BR_FDB_ADDED_BY_USER)?
The NTF_USE path runs __fdb_update() under only local_bh_disable() and
rcu_read_lock(). The packet path in br_fdb_update() updates an existing
entry without br->hash_lock:
fdb = fdb_find_rcu(&br->fdb_hash_tbl, addr, vid);
if (likely(fdb)) {
__fdb_update(br, fdb, source, dst, flags);
A possible interleaving:
CPU0 (NTF_USE) CPU1 (RX on non-sticky port B)
__fdb_update()
fdb_switchdev_hide() /* DEL */
__fdb_update()
br_switchdev_fdb_notify(DEL)
br_fdb_dst_write(fdb, B)
fdb_notify(RTM_NEWNEIGH)
br_switchdev_fdb_notify()
/* ADDED_BY_USER still clear */
SWITCHDEV_FDB_ADD_TO_DEVICE
set_bit(BR_FDB_ADDED_BY_USER)
The entry is now user-dynamic. Its later deletion is filtered in
br_switchdev_fdb_notify(), so the driver keeps the entry on port B.
fdb_add_entry() has the same window. It holds br->hash_lock, but that
doesn't exclude the packet path. There the hide runs before
fdb_update_dst() and set_bit(BR_FDB_ADDED_BY_USER).
There is a variant with the extern_learn flag. CPU0 sees
BR_FDB_ADDED_BY_EXT_LEARN set and skips the hide. Then CPU1's roam clears
that flag and sends an ADD before CPU0's set_bit().
The window is small. It needs a station roaming onto another port while
the admin command runs. When it hits, the stale entry that this patch is
meant to remove is left in the driver.
> @@ -1262,6 +1279,10 @@ 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))
> + fdb_switchdev_hide(br, fdb);
> +
[Severity: High]
This balances the event-driven notifications, but what about the replay
path? br_switchdev_fdb_replay_one() passes every entry in br->fdb_list to
the driver. It doesn't apply the filter that br_switchdev_fdb_notify()
uses:
net/bridge/br_switchdev.c:br_switchdev_fdb_replay_one() {
...
br_switchdev_fdb_populate(br, &item, fdb, ctx);
err = nb->notifier_call(nb, action, &item);
...
}
That causes two problems.
First, can an entry hidden here be installed again and then leaked? When
a DSA port joins the bridge:
dsa_port_bridge_join()
switchdev_bridge_port_offload()
nbp_switchdev_sync_objs()
br_switchdev_fdb_replay(..., true, ...)
dsa_user_switchdev_event()
switchdev_handle_fdb_event_to_device()
dsa_user_fdb_event()
dsa_port_bridge_host_fdb_add()
The replayed item has added_by_user set, so it isn't treated as
dynamically learned. DSA programs it, for example as a refcounted host
address on the CPU port for an entry on a foreign veth port.
A later "bridge fdb del" goes through
fdb_delete()->fdb_notify(RTM_DELNEIGH)->br_switchdev_fdb_notify(), which
filters it out. The entry is then gone from fdb_list, so the leave-time
replay never sees it either. The driver keeps the hardware entry and the
dsa_mac_addr allocation after the bridge has dropped the entry.
This join-time replay leak is older than this patch; it goes back to
927cdea5d209. It is still the outcome the commit message says is fixed.
Second, does this add a double DEL? Before this patch, a learned entry
that was made user-dynamic got one ADD (from learning) and one DEL (from
the leave replay). With this patch it gets the ADD, a DEL from
fdb_switchdev_hide(), and another DEL when a port leaves:
nbp_switchdev_unsync_objs()
br_switchdev_fdb_replay(br_dev, ctx, false, atomic_nb)
...
dsa_port_do_fdb_del()
On the DSA CPU port the lookup fails:
net/dsa/switch.c:dsa_port_do_fdb_del() {
...
a = dsa_mac_addr_find(&dp->fdbs, addr, vid, db);
if (!a) {
trace_dsa_fdb_del_not_found(dp, addr, vid, &db);
err = -ENOENT;
goto out;
}
...
}
dsa_user_switchdev_event_work() then logs "failed to delete ... from fdb".
Another port may have added the hidden entry again through join replay.
In that case the extra DEL drops that port's reference and deletes the
hardware entry.
Would it work better to apply the same check in both
br_switchdev_fdb_notify() and the replay path, instead of sending an extra
DEL from these two event paths?
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261121191638.1724620-1-julius%40bairaktaris.de
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-11-25 0:18 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-21 19:16 [PATCH net] net: bridge: withdraw the switchdev entry of an fdb entry made dynamic Julius Bairaktaris
2026-11-22 10:58 ` Nikolay Aleksandrov
2026-11-22 19:22 ` Julius Bairaktaris
2026-11-25 0:18 ` 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