Netdev List
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: julius@bairaktaris.de
Cc: razor@blackwall.org, idosch@nvidia.com, andrew+netdev@lunn.ch,
	olteanv@gmail.com, netdev@vger.kernel.org,
	bridge@lists.linux.dev, davem@davemloft.net, edumazet@kernel.org,
	kuba@kernel.org, pabeni@redhat.com, horms@kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH net-next v2 1/2] net: bridge: switchdev: add br_switchdev_fdb_find_port()
Date: Mon, 16 Nov 2026 04:43:31 +0000	[thread overview]
Message-ID: <179480421183.3136.1759261843920553958@kernel.org> (raw)
In-Reply-To: <ce6ea6a96b66c70b882832a07c36caf12193c6c2.1794696609.git.julius@bairaktaris.de>

Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 · Low: 1

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).

- [Medium] br_switchdev_fdb_find_port() (net/bridge/br_switchdev.c)
  decides that an entry "was learned by a switchdev driver, whose…
- [Low] br_switchdev_fdb_find_port() reads f->flags several times with
  separate test_bit() calls, under RCU only.

--

net: bridge: switchdev: add br_switchdev_fdb_find_port()

This adds an exported RCU lookup, br_switchdev_fdb_find_port(). It
returns the device that br_switchdev_fdb_notify() reports an FDB entry
on, or NULL for entries whose addition is not reported to switchdev. The
existing notify filter moves into a shared helper,
br_switchdev_fdb_notifies(), and the next patch uses the lookup from DSA.

> diff --git a/net/bridge/br_switchdev.c b/net/bridge/br_switchdev.c
> index 10f3aea6a1f82..f832657c0c22e 100644
> --- a/net/bridge/br_switchdev.c
> +++ b/net/bridge/br_switchdev.c

[ ... ]

> @@ -156,9 +152,67 @@ br_switchdev_fdb_notify(struct net_bridge *br,
>  	 * Drivers don't know how to deal with these, so don't notify them to
>  	 * avoid confusing them.
>  	 */
> -	if (test_bit(BR_FDB_ADDED_BY_USER, &fdb->flags) &&
> -	    !test_bit(BR_FDB_STATIC, &fdb->flags) &&
> -	    !test_bit(BR_FDB_ADDED_BY_EXT_LEARN, &fdb->flags))
> +	return !test_bit(BR_FDB_ADDED_BY_USER, &fdb->flags) ||
> +	       test_bit(BR_FDB_STATIC, &fdb->flags) ||
> +	       test_bit(BR_FDB_ADDED_BY_EXT_LEARN, &fdb->flags);
> +}
> +
> +/**
> + * br_switchdev_fdb_find_port - find the device a switchdev entry is reported on

[ ... ]

> + * Return: the device that br_switchdev_fdb_notify() reports the entry for
> + * @addr and @vid on: its port, or @br_dev for a local entry. NULL if there is
> + * no such entry, or if it is locked, was added with "master dynamic", or was
> + * learned by a switchdev driver, whose addition br_switchdev_fdb_notify()
> + * does not report.
> + */
> +struct net_device *br_switchdev_fdb_find_port(struct net_device *br_dev,
> +					      const unsigned char *addr,
> +					      u16 vid, bool *added_by_user)
> +{

[ ... ]

> +	f = br_fdb_find_rcu(netdev_priv(br_dev), addr, vid);
> +	if (!f || !br_switchdev_fdb_notifies(f))
> +		return NULL;
> +
> +	by_user = test_bit(BR_FDB_ADDED_BY_USER, &f->flags);
> +	if (!by_user && test_bit(BR_FDB_ADDED_BY_EXT_LEARN, &f->flags))
> +		return NULL;

[Severity: Medium]
Can this check hide entries whose ADD was already reported to switchdev?
The flags don't record whether an ADD was actually sent.

Take an entry that the software bridge learns first on port P:

br_fdb_update()
  fdb_create()                      /* USER and EXT_LEARN clear */
  fdb_notify(br, fdb, RTM_NEWNEIGH, true)
    br_switchdev_fdb_notify()       /* FDB_ADD_TO_DEVICE sent on P */

Then the switchdev driver of P learns the same MAC in hardware and sends
SWITCHDEV_FDB_ADD_TO_BRIDGE:

br_switchdev_event()
  br_fdb_external_learn_add(br, p, addr, vid, locked, false)

br_fdb_external_learn_add() takes the existing-entry branch:

		if (test_and_set_bit(BR_FDB_ADDED_BY_EXT_LEARN, &fdb->flags)) {
		...
		if (swdev_notify)
			set_bit(BR_FDB_ADDED_BY_USER, &fdb->flags);

After this the entry has EXT_LEARN set and USER clear, and no switchdev
event goes out.

>From then on, br_switchdev_fdb_find_port() returns NULL for this entry.
br_switchdev_fdb_notifies() still accepts it, though, because USER is
clear. So the DEL is still reported on P, either from fdb_delete(br, f,
true) in the user delete and port flush paths, or from the roaming
branch of __fdb_update():

		if (source != old_port) {
			br_switchdev_fdb_notify(br, fdb, RTM_DELNEIGH);

Doesn't this contradict the kernel-doc ("the device that
br_switchdev_fdb_notify() reports the entry ... on") and the commit
message ("does not find the entries whose addition the bridge does not
notify to switchdev")?

The next patch in the series uses this helper from
dsa_user_bridge_host_fdb_wanted(). Consider an assisted-learning DSA
switch bridged with a foreign port that learns in hardware.

If the queued host_addr ADD work runs after the hardware learn, the
helper returns NULL and the host address is never installed. If the work
ran before it, the address is installed. Before the series the address
was always installed.

Is this timing-dependent result intended? When the address is missing,
traffic from DSA user ports to that MAC is flooded instead of being
forwarded to the CPU.

> +
> +	if (added_by_user)
> +		*added_by_user = by_user;

[Severity: Low]
Can by_user disagree with the decision br_switchdev_fdb_notifies() just
made?

The flags are read several times with separate test_bit() calls, under
RCU only. Some writers change these bits without hash_lock. One is the
NTF_USE path of __fdb_update(), reached from br_fdb_update() under
rcu_read_lock():

	if (unlikely(test_bit(BR_FDB_ADDED_BY_USER, &flags))) {
		set_bit(BR_FDB_ADDED_BY_USER, &fdb->flags);

The roaming branch of __fdb_update() also clears
BR_FDB_ADDED_BY_EXT_LEARN and BR_FDB_LOCKED.

For a dynamically learned entry:

CPU0                                 CPU1
br_switchdev_fdb_notifies()
  sees USER == 0, passes
                                     __fdb_update() with NTF_USE
                                       set_bit(BR_FDB_ADDED_BY_USER)
by_user = test_bit(...) == 1
returns port, *added_by_user = true

With USER clear the answer would be (port, false). With USER set the
entry is "master dynamic" and the answer would be NULL. The pair (port,
true) matches neither state.

Would reading f->flags once with READ_ONCE() and testing the local copy
avoid this?

> +
> +	if (test_bit(BR_FDB_LOCAL, &f->flags))
> +		return br_dev;

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/cover.1794696608.git.julius%40bairaktaris.de

  reply	other threads:[~2026-11-16  4:43 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-14 22:53 [PATCH net-next v2 0/2] net: dsa: fix host fdb refcount when an entry roams Julius Bairaktaris
2026-11-14 22:53 ` [PATCH net-next v2 1/2] net: bridge: switchdev: add br_switchdev_fdb_find_port() Julius Bairaktaris
2026-11-16  4:43   ` netdev-bot+sashiko [this message]
2026-11-14 22:53 ` [PATCH net-next v2 2/2] net: dsa: fix host fdb refcount when a bridge fdb entry roams Julius Bairaktaris
2026-11-16  4:43   ` netdev-bot+sashiko
2026-11-15 20:06 ` [PATCH net-next v2 0/2] net: dsa: fix host fdb refcount when an " netdev-bot+sinfo

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=179480421183.3136.1759261843920553958@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=andrew+netdev@lunn.ch \
    --cc=bridge@lists.linux.dev \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=horms@kernel.org \
    --cc=idosch@nvidia.com \
    --cc=julius@bairaktaris.de \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=olteanv@gmail.com \
    --cc=pabeni@redhat.com \
    --cc=razor@blackwall.org \
    /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