Netdev List
 help / color / mirror / Atom feed
From: Nikolay Aleksandrov <razor@blackwall.org>
To: Julius Bairaktaris <julius@bairaktaris.de>,
	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>,
	Willem de Bruijn <willemb@google.com>,
	Simon Horman <horms@kernel.org>,
	Vladimir Oltean <olteanv@gmail.com>,
	Vladimir Oltean <vladimir.oltean@nxp.com>,
	Jesse Brandeburg <jbrandeb@kernel.org>
Subject: Re: [PATCH net] net: bridge: withdraw the switchdev entry of an fdb entry made dynamic
Date: Sun, 22 Nov 2026 12:58:04 +0200	[thread overview]
Message-ID: <4937f07a-6238-4136-94ca-a98b2f4b8db5@blackwall.org> (raw)
In-Reply-To: <20261121191638.1724620-1-julius@bairaktaris.de>

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


  reply	other threads:[~2026-11-22 10:58 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2026-11-22 19:22   ` Julius Bairaktaris
2026-11-25  0:18 ` 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=4937f07a-6238-4136-94ca-a98b2f4b8db5@blackwall.org \
    --to=razor@blackwall.org \
    --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=julius@bairaktaris.de \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=olteanv@gmail.com \
    --cc=pabeni@redhat.com \
    --cc=vladimir.oltean@nxp.com \
    --cc=willemb@google.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