mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: mmyangfl@gmail.com
Cc: netdev@vger.kernel.org, andrew@lunn.ch, olteanv@gmail.com,
	davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org,
	pabeni@redhat.com, linux-kernel@vger.kernel.org
Subject: Re: [PATCH net v2 2/4] net: dsa: motorcomm: Rewrite FDB entry on port migration
Date: Wed, 18 Nov 2026 16:02:48 +0000	[thread overview]
Message-ID: <179501776848.3136.5089854302333242012@kernel.org> (raw)
In-Reply-To: <20261116160107.1351198-3-mmyangfl@gmail.com>

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

Critical: 0 · High: 0 · Medium: 2 · Low: 2

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] yt921x_dsa_port_fdb_add()
  (drivers/net/dsa/motorcomm/chip.c:878-884) now builds the leave mask…
- [Medium] The YT921x hardware FDB holds both unicast FDB entries and MDB
  groups in the same table, keyed by (addr, FID).
- [Low] The commit message does not fully describe the behaviour change.
- [Low] yt921x_dsa_port_fdb_add() (chip.c:879) now calls
  dsa_bridge_ports(ds, db.bridge.dev) from the DSA ordered workqueue…

--

net: dsa: motorcomm: Rewrite FDB entry on port migration

This commit merges yt921x_fdb_join() and yt921x_fdb_leave() into one
yt921x_fdb_update() helper. For .port_fdb_add with a bridge database, the
hardware entry is rewritten with the bridge ports plus the CPU ports as the
leave mask, so ports left behind by a migration are dropped from the entry.

> Fuse FDB join/leave into one change function, and rewrite the whole
> entry on add with the bridge port mask as the leave mask, so that ports
> left behind by the migration are dropped from the entry.

[Severity: Low]
Should this say that the leave mask also includes priv->cpu_ports_mask?

yt921x_dsa_port_fdb_add() ORs the CPU ports into the leave mask. Any
bridge-scoped user port add now removes the host from the shared
(addr, vid) entry. The host delivery issue raised further down comes from
this.

> Note the commit only correctly covers single bridge usage. Multiple
> bridge scenario was broken before, but now breaks in a different way;
> that should be addressed in a following commit.

Could this describe how the multiple bridge case now breaks?

Without fdb_isolation, every bridge shares one hardware (addr, FID) entry.
They also share one CPU port refcount key, because bridge.num is forced
to 0. An add from one bridge can then remove CPU delivery that belongs to
another bridge.

None of the later patches in the series ("Read the port PVID instead of
bridge's", "Use VID 0 as the unaware PVID") seem to touch this. The final
state of the series has the same code. Since the patch carries a Fixes:
tag, it would help backporters to know about the new failure mode.

> diff --git a/drivers/net/dsa/motorcomm/chip.c b/drivers/net/dsa/motorcomm/chip.c
> index c6d0f000a1630..863ebb6c31984 100644
> --- a/drivers/net/dsa/motorcomm/chip.c
> +++ b/drivers/net/dsa/motorcomm/chip.c

[ ... ]

> @@ -877,10 +872,16 @@ yt921x_dsa_port_fdb_add(struct dsa_switch *ds, int port,
>  			const unsigned char *addr, u16 vid, struct dsa_db db)
>  {
>  	struct yt921x_priv *priv = dsa_to_yt921x_priv(ds);
> +	u32 bridge_ports_mask = 0;
>  	int res;
>  
> +	if (db.type == DSA_DB_BRIDGE) {
> +		bridge_ports_mask = dsa_bridge_ports(ds, db.bridge.dev);

[Severity: Low]
Is it safe to call dsa_bridge_ports() from this context?

.port_fdb_add is called from dsa_user_switchdev_event_work() on the DSA
ordered workqueue, which runs without rtnl_lock. This call also happens
before reg_lock is taken.

dsa_bridge_ports() walks every port through
dsa_switch_for_each_bridge_member() and ends up in
dsa_port_bridge_dev_get():

include/net/dsa.h:dsa_port_bridge_dev_get() {
	return dp->bridge ? dp->bridge->dev : NULL;
}

At the same time, under rtnl, the last port leaving a different bridge goes
through dsa_port_bridge_leave()->dsa_port_bridge_destroy():

net/dsa/port.c:dsa_port_bridge_destroy() {
    ...
	dp->bridge = NULL;

	if (!refcount_dec_and_test(&bridge->refcount))
		return;
    ...
	kfree(bridge);
}

There is no RCU grace period before the kfree(). The dsa_flush_workqueue()
in pre_bridge_leave only drains work that is already queued. FDB work for
ports in other bridges can still run in parallel, for example host adds
with assisted_learning_on_cpu_port.

If the worker loads the old dp->bridge just before the kfree(), is the
read of ->dev a use-after-free? If dp->bridge is reloaded after the NULL
check, could it also be a NULL dereference?

The value is only compared against db.bridge.dev, so the likely result is
a KASAN report or a stale leave mask.

The other dsa_bridge_ports() callers in this driver run under rtnl. The
DSA core has a similar lockless pattern in dsa_foreign_dev_check(), but
this call site is new.

> +		bridge_ports_mask |= priv->cpu_ports_mask;

[Severity: Medium]
Does putting the CPU ports into the leave mask break host delivery in the
single bridge case?

The DSA core refcounts host FDB entries on the CPU port.
dsa_port_do_fdb_add() only calls the driver for the first reference:

net/dsa/switch.c:dsa_port_do_fdb_add() {
    ...
	a = dsa_mac_addr_find(&dp->fdbs, addr, vid, db);
	if (a) {
		refcount_inc(&a->refcount);
    ...
}

Since fdb_isolation is not set, db.bridge.num is always 0. Host adds and
user port adds therefore share the same hardware (addr, vid) entry.

Consider this sequence:

  bridge fdb add X dev br0 self local
    -> host add on the CPU port, hardware entry becomes {CPU}

  bridge fdb replace X dev swp1 master static
    -> fdb_add_entry()->fdb_update_dst() sends only RTM_NEWNEIGH, with no
       DEL for the old host destination
    -> yt921x_dsa_port_fdb_add(swp1) runs with leave = bridge | CPU
    -> hardware entry becomes {swp1}, while DSA still lists X on the CPU
       port

  bridge fdb replace X dev br0 self local
    -> dsa_port_do_fdb_add() finds the stale entry and only bumps the
       refcount; the driver is not called
    -> hardware entry stays {swp1}

The bridge now treats X as local, but the switch forwards frames for X out
of swp1, so the host never receives them.

Later host deletes only decrement the inflated refcount. The static {swp1}
entry then can't be removed through DSA.

Before this patch, the same sequence left {CPU, swp1}. That entry had a
stale port, but the host still got its traffic.

Normal roaming through __fdb_update() sends RTM_DELNEIGH first and is not
affected. The bridge core's missing DEL on a host-to-port replace is part
of the cause, but evicting the CPU bit is new in this driver.

Should the CPU ports be left out of the leave mask?

> +	}
> +
>  	mutex_lock(&priv->reg_lock);
> -	res = yt921x_fdb_join(priv, addr, vid, BIT(port));
> +	res = yt921x_fdb_update(priv, addr, vid, bridge_ports_mask, BIT(port));

[Severity: Medium]
Can this rewrite overwrite MDB groups?

The hardware FDB holds both unicast FDB entries and MDB groups, keyed by
(addr, FID). yt921x_dsa_port_mdb_add() builds group membership with
yt921x_fdb_join() on those same entries.

Nothing checks is_unicast_ether_addr() before the leave mask is applied.
br_fdb_add() only rejects all-zero addresses.

Suppose the MDB already has 01:00:5e:01:01:01 with {swp0, swp1, CPU}, and
this runs:

  bridge fdb add 01:00:5e:01:01:01 dev swp2 master static vlan 1

It arrives as .port_fdb_add with DSA_DB_BRIDGE. The entry is already
static, so ctrl1 == val1, and yt921x_fdb_update() computes:

	ctrl2 = val2 & ~YT921X_FDB_IO2_EGR_PORTS(leave_ports_mask);
	...
	ctrl2 |= YT921X_FDB_IO2_EGR_PORTS(join_ports_mask);

The hardware entry becomes {swp2}. Group traffic stops reaching swp0,
swp1 and the CPU, while the bridge and DSA MDB state stays the same.

A later bridge fdb del goes through yt921x_fdb_leave(BIT(swp2)). That
finds no ports left and issues YT921X_FDB_OP_OP_DEL, which removes the MDB
group from hardware completely.

Before this patch, the add only ORed BIT(port) into the entry, so the MDB
members were kept.

Should the rewrite apply only to unicast addresses, as the commit message
describes?

>  	mutex_unlock(&priv->reg_lock);
>  
>  	return res;

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261116160107.1351198-1-mmyangfl%40gmail.com

  reply	other threads:[~2026-11-18 16:02 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-16 16:01 [PATCH net v2 0/4] net: dsa: motorcomm: FDB fixup David Yang
2026-11-16 16:01 ` [PATCH net v2 1/4] net: dsa: motorcomm: Do not inherit ports from dynamic FDB entries David Yang
2026-11-16 16:01 ` [PATCH net v2 2/4] net: dsa: motorcomm: Rewrite FDB entry on port migration David Yang
2026-11-18 16:02   ` netdev-bot+sashiko [this message]
2026-11-16 16:01 ` [PATCH net v2 3/4] net: dsa: motorcomm: Read the port PVID instead of bridge's David Yang
2026-11-18 16:02   ` netdev-bot+sashiko
2026-11-16 16:01 ` [PATCH net v2 4/4] net: dsa: motorcomm: Use VID 0 as the unaware PVID David Yang
2026-11-18 16:02   ` 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=179501776848.3136.5089854302333242012@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mmyangfl@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=olteanv@gmail.com \
    --cc=pabeni@redhat.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

all inboxes | Powered by JetHome®