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
Subject: Re: [PATCH net v3 3/3] net: dsa: motorcomm: Rewrite FDB entry on port migration
Date: Mon, 23 Nov 2026 22:11:12 +0000 [thread overview]
Message-ID: <179547187297.3135.17256967241487478010@kernel.org> (raw)
In-Reply-To: <20261119221110.1123578-4-mmyangfl@gmail.com>
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.
Critical: 0 · High: 1 · Medium: 1 · 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 migration fix is incomplete when an address moves between
the host (CPU port) and a user port, even in the single-bridge setup…
- [Medium] The new dsa_bridge_ports(ds, db.bridge.dev) call in
yt921x_dsa_port_fdb_add() (chip.c:888) walks every user port of the…
--
net: dsa: motorcomm: Rewrite FDB entry on port migration
This commit merges yt921x_fdb_join() and yt921x_fdb_leave() into a new
yt921x_fdb_update() helper. On .port_fdb_add() it uses the bridge port
mask as the leave mask, so that ports left behind by a migration are
dropped from the hardware entry.
> diff --git a/drivers/net/dsa/motorcomm/chip.c b/drivers/net/dsa/motorcomm/chip.c
> index ea305159cd5e7..79e4326d5a703 100644
> --- a/drivers/net/dsa/motorcomm/chip.c
> +++ b/drivers/net/dsa/motorcomm/chip.c
[ ... ]
> @@ -888,8 +884,12 @@ yt921x_dsa_port_fdb_add(struct dsa_switch *ds, int port,
> if (is_multicast_ether_addr(addr))
> return 0;
>
> + if (db.type == DSA_DB_BRIDGE)
> + leave_ports_mask = dsa_bridge_ports(ds, db.bridge.dev);
> +
[Severity: High]
Does this leave mask handle an address that moves between the host (CPU
port) and a user port?
dsa_bridge_ports() walks dsa_switch_for_each_bridge_member(), which is
built on dsa_switch_for_each_user_port(). That means the CPU port bit is
never in leave_ports_mask.
The driver sets assisted_learning_on_cpu_port, so a host address A (on
br0, or on a foreign bridged interface) is installed through
dsa_port_do_fdb_add(cpu_dp). The hardware entry becomes static with only
the CPU port in its egress mask.
If the address is then moved with:
bridge fdb replace A dev swp2 master static
fdb_add_entry() in net/bridge/br_fdb.c only sends RTM_NEWNEIGH, so the
driver gets yt921x_dsa_port_fdb_add(swp2) with no delete first. In
yt921x_fdb_update():
ctrl2 = val2 & ~YT921X_FDB_IO2_EGR_PORTS(leave_ports_mask);
...
ctrl1 = val1;
if (join_ports_mask) {
ctrl1 &= ~YT921X_FDB_IO1_STATUS_M;
ctrl1 |= YT921X_FDB_IO1_STATUS_STATIC;
if (ctrl1 != val1)
ctrl2 &= ~YT921X_FDB_IO2_EGR_PORTS_M;
}
ctrl2 |= YT921X_FDB_IO2_EGR_PORTS(join_ports_mask);
The entry is already static, so ctrl1 == val1 and the clear-all branch is
skipped. Wouldn't the entry be written back as {CPU, swp2}, leaving the
CPU port behind?
The reverse direction looks broken too, and the driver can't see it.
Moving A back to the host goes through dsa_port_do_fdb_add(cpu_dp). There
the old record, whose refcount was never released, is found again:
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);
...
}
So .port_fdb_add() is not called for the CPU port and swp2 stays in the
entry. A later fdb del on the host side only drops the refcount.
yt921x_dsa_port_fdb_del() also only clears BIT(port).
Can this leave a static hardware entry that never ages out and keeps
forwarding unicast for A to the CPU port and/or swp2 after the software
bridge has moved it?
The commit message says single-bridge usage is covered, and this is a
single-bridge setup. The CPU port side depends on DSA's refcounting.
Can a driver-side leave mask fix that part at all?
[Severity: Medium]
Is it safe to walk every port's dp->bridge from .port_fdb_add()?
This handler can run from the deferred switchdev worker without rtnl:
dsa_user_switchdev_event_work()
dsa_port_bridge_host_fdb_add()
dsa_port_do_fdb_add(cpu_dp)
ds->ops->port_fdb_add()
yt921x_dsa_port_fdb_add()
dsa_bridge_ports()
The comment in dsa_port_bridge_host_fdb_add() says rtnl can't be
guaranteed there. Only cpu_dp->addr_lists_lock is held.
dsa_bridge_ports() reads each user port's bridge through
dsa_port_bridge_dev_get():
return dp->bridge ? dp->bridge->dev : NULL;
At the same time, another port Q can leave its bridge under rtnl. When Q
is the last member, dsa_port_bridge_destroy() does this with no RCU grace
period:
dp->bridge = NULL;
if (!refcount_dec_and_test(&bridge->refcount))
return;
...
kfree(bridge);
The dsa_flush_workqueue() in dsa_port_pre_bridge_leave() only drains work
queued before that point. Host FDB work for a port that stays bridged can
still be queued from softirq learning.
With multiple bridges on the switch, can the worker load dp->bridge for Q
and then read ->dev after that dsa_bridge has been freed?
Even without a use-after-free, the membership snapshot is not taken under
any lock that serializes bridge join/leave. Could leave_ports_mask be
stale by the time the entry is written?
Before this patch, this path only used the db that DSA passed in for the
calling port. The other dsa_bridge_ports() callers in this driver
(port_bridge_flags and bridge join) run under rtnl. DSA core already reads
dp->bridge in this worker without rtnl (for example in
dsa_foreign_dev_check()), but this patch adds a new cross-port walk.
> mutex_lock(&priv->reg_lock);
> - res = yt921x_fdb_join(priv, addr, vid, BIT(port));
> + res = yt921x_fdb_update(priv, addr, vid, leave_ports_mask,
> + BIT(port));
> mutex_unlock(&priv->reg_lock);
>
> return res;
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261119221110.1123578-1-mmyangfl%40gmail.com
prev parent reply other threads:[~2026-11-23 22:11 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-19 22:10 [PATCH net v3 0/3] net: dsa: motorcomm: FDB fixup David Yang
2026-11-19 22:10 ` [PATCH net v3 1/3] net: dsa: motorcomm: Ignore multicast addresses in FDB ops David Yang
2026-11-23 22:11 ` netdev-bot+sashiko
2026-11-19 22:10 ` [PATCH net v3 2/3] net: dsa: motorcomm: Do not inherit ports from dynamic FDB entries David Yang
2026-11-23 22:11 ` netdev-bot+sashiko
2026-11-19 22:10 ` [PATCH net v3 3/3] net: dsa: motorcomm: Rewrite FDB entry on port migration David Yang
2026-11-23 22:11 ` netdev-bot+sashiko [this message]
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=179547187297.3135.17256967241487478010@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=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