Netdev List
 help / color / mirror / Atom feed
* [PATCH net v2 0/4] net: dsa: motorcomm: FDB fixup
@ 2026-11-16 16:01 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
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: David Yang @ 2026-11-16 16:01 UTC (permalink / raw)
  To: netdev
  Cc: David Yang, Andrew Lunn, Vladimir Oltean, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, linux-kernel

Various FDB defects. Assisted and verified on the hardware by LLM.

There are more gotchas about multi-bridge setup, but I'd leave that for
net-next since multi-bridge has always been tricky among DSA drivers.

v2:
 - include the CPU port when rewriting FDB entry
 - read the port PVID instead of bridge's
 - fix PVID when port joining/leaving bridge
v1: https://lore.kernel.org/r/20261111234110.1449602-1-mmyangfl@gmail.com

David Yang (4):
  net: dsa: motorcomm: Do not inherit ports from dynamic FDB entries
  net: dsa: motorcomm: Rewrite FDB entry on port migration
  net: dsa: motorcomm: Read the port PVID instead of bridge's
  net: dsa: motorcomm: Use VID 0 as the unaware PVID

 drivers/net/dsa/motorcomm/chip.c | 160 +++++++++++++++++--------------
 1 file changed, 86 insertions(+), 74 deletions(-)

-- 
2.53.0


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH net v2 1/4] net: dsa: motorcomm: Do not inherit ports from dynamic FDB entries
  2026-11-16 16:01 [PATCH net v2 0/4] net: dsa: motorcomm: FDB fixup David Yang
@ 2026-11-16 16:01 ` David Yang
  2026-11-16 16:01 ` [PATCH net v2 2/4] net: dsa: motorcomm: Rewrite FDB entry on port migration David Yang
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 8+ messages in thread
From: David Yang @ 2026-11-16 16:01 UTC (permalink / raw)
  To: netdev
  Cc: David Yang, Andrew Lunn, Vladimir Oltean, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, linux-kernel

When adding an fdb/mdb entry whose (address, VID) key already exists in
hardware, the existing egress ports were silently merged into the new
static entry. Ports learned by hardware are untracked by DSA and can
never be deleted. Replace the port mask instead of merging when the
existing entry is not static.

Fixes: 186623f4aa72 ("net: dsa: yt921x: Add support for Motorcomm YT921x")
Signed-off-by: David Yang <mmyangfl@gmail.com>
---
 drivers/net/dsa/motorcomm/chip.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/net/dsa/motorcomm/chip.c b/drivers/net/dsa/motorcomm/chip.c
index c753c746490a..c6d0f000a163 100644
--- a/drivers/net/dsa/motorcomm/chip.c
+++ b/drivers/net/dsa/motorcomm/chip.c
@@ -799,7 +799,10 @@ yt921x_fdb_join(struct yt921x_priv *priv, const unsigned char *addr, u16 vid,
 
 	ctrl1 = val1 & ~YT921X_FDB_IO1_STATUS_M;
 	ctrl1 |= YT921X_FDB_IO1_STATUS_STATIC;
-	ctrl2 = val2 | YT921X_FDB_IO2_EGR_PORTS(ports_mask);
+	ctrl2 = val2;
+	if (ctrl1 != val1)
+		ctrl2 &= ~YT921X_FDB_IO2_EGR_PORTS_M;
+	ctrl2 |= YT921X_FDB_IO2_EGR_PORTS(ports_mask);
 	if (ctrl1 == val1 && ctrl2 == val2)
 		return 0;
 
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH net v2 2/4] net: dsa: motorcomm: Rewrite FDB entry on port migration
  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 ` David Yang
  2026-11-18 16:02   ` netdev-bot+sashiko
  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-16 16:01 ` [PATCH net v2 4/4] net: dsa: motorcomm: Use VID 0 as the unaware PVID David Yang
  3 siblings, 1 reply; 8+ messages in thread
From: David Yang @ 2026-11-16 16:01 UTC (permalink / raw)
  To: netdev
  Cc: David Yang, Andrew Lunn, Vladimir Oltean, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, linux-kernel

When unicast addresses move between ports, DSA calls .port_fdb_add()
without a prior .port_fdb_del() call, making the new port directly OR
into the existing entries. The old port mask then loses track in DSA and
can never be deleted.

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.

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.

Fixes: 186623f4aa72 ("net: dsa: yt921x: Add support for Motorcomm YT921x")
Signed-off-by: David Yang <mmyangfl@gmail.com>
---
 drivers/net/dsa/motorcomm/chip.c | 95 ++++++++++++++++----------------
 1 file changed, 48 insertions(+), 47 deletions(-)

diff --git a/drivers/net/dsa/motorcomm/chip.c b/drivers/net/dsa/motorcomm/chip.c
index c6d0f000a163..863ebb6c3198 100644
--- a/drivers/net/dsa/motorcomm/chip.c
+++ b/drivers/net/dsa/motorcomm/chip.c
@@ -729,13 +729,14 @@ yt921x_fdb_add(struct yt921x_priv *priv, const unsigned char *addr, u16 vid,
 }
 
 static int
-yt921x_fdb_leave(struct yt921x_priv *priv, const unsigned char *addr,
-		 u16 vid, u16 ports_mask)
+yt921x_fdb_update(struct yt921x_priv *priv, const unsigned char *addr,
+		  u16 vid, u16 leave_ports_mask, u16 join_ports_mask)
 {
 	u16 index;
 	u32 ctrl1;
 	u32 ctrl2;
 	u32 ctrl;
+	u32 val1;
 	u32 val2;
 	u32 val;
 	int res;
@@ -744,69 +745,63 @@ yt921x_fdb_leave(struct yt921x_priv *priv, const unsigned char *addr,
 	res = yt921x_fdb_has(priv, addr, vid, &index);
 	if (res)
 		return res;
-	if (index >= YT921X_FDB_NUM)
-		return 0;
+	if (index >= YT921X_FDB_NUM) {
+		if (!join_ports_mask)
+			return 0;
+
+		return yt921x_fdb_add(priv, addr, vid, join_ports_mask);
+	}
 
 	/* Check if action required */
 	res = yt921x_reg_read(priv, YT921X_FDB_OUT2, &val2);
 	if (res)
 		return res;
 
-	ctrl2 = val2 & ~YT921X_FDB_IO2_EGR_PORTS(ports_mask);
-	if (ctrl2 == val2)
-		return 0;
-	if (!(ctrl2 & YT921X_FDB_IO2_EGR_PORTS_M)) {
-		ctrl = YT921X_FDB_OP_OP_DEL | YT921X_FDB_OP_START;
-		res = yt921x_reg_write(priv, YT921X_FDB_OP, ctrl);
-		if (res)
-			return res;
+	ctrl2 = val2 & ~YT921X_FDB_IO2_EGR_PORTS(leave_ports_mask);
+	if (!join_ports_mask) {
+		if (ctrl2 == val2)
+			return 0;
+
+		if (!(ctrl2 & YT921X_FDB_IO2_EGR_PORTS_M)) {
+			ctrl = YT921X_FDB_OP_OP_DEL | YT921X_FDB_OP_START;
+			res = yt921x_reg_write(priv, YT921X_FDB_OP, ctrl);
+			if (res)
+				return res;
 
-		return yt921x_fdb_wait(priv, &val);
+			return yt921x_fdb_wait(priv, &val);
+		}
 	}
 
-	res = yt921x_reg_read(priv, YT921X_FDB_OUT1, &ctrl1);
+	res = yt921x_reg_read(priv, YT921X_FDB_OUT1, &val1);
 	if (res)
 		return res;
 
+	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);
+	if (ctrl1 == val1 && ctrl2 == val2)
+		return 0;
+
 	return yt921x_fdb_add_index_in12(priv, index, ctrl1, ctrl2);
 }
 
+static int
+yt921x_fdb_leave(struct yt921x_priv *priv, const unsigned char *addr,
+		 u16 vid, u16 ports_mask)
+{
+	return yt921x_fdb_update(priv, addr, vid, ports_mask, 0);
+}
+
 static int
 yt921x_fdb_join(struct yt921x_priv *priv, const unsigned char *addr, u16 vid,
 		u16 ports_mask)
 {
-	u16 index;
-	u32 ctrl1;
-	u32 ctrl2;
-	u32 val1;
-	u32 val2;
-	int res;
-
-	/* Check for presence */
-	res = yt921x_fdb_has(priv, addr, vid, &index);
-	if (res)
-		return res;
-	if (index >= YT921X_FDB_NUM)
-		return yt921x_fdb_add(priv, addr, vid, ports_mask);
-
-	/* Check if action required */
-	res = yt921x_reg_read(priv, YT921X_FDB_OUT1, &val1);
-	if (res)
-		return res;
-	res = yt921x_reg_read(priv, YT921X_FDB_OUT2, &val2);
-	if (res)
-		return res;
-
-	ctrl1 = val1 & ~YT921X_FDB_IO1_STATUS_M;
-	ctrl1 |= YT921X_FDB_IO1_STATUS_STATIC;
-	ctrl2 = val2;
-	if (ctrl1 != val1)
-		ctrl2 &= ~YT921X_FDB_IO2_EGR_PORTS_M;
-	ctrl2 |= YT921X_FDB_IO2_EGR_PORTS(ports_mask);
-	if (ctrl1 == val1 && ctrl2 == val2)
-		return 0;
-
-	return yt921x_fdb_add_index_in12(priv, index, ctrl1, ctrl2);
+	return yt921x_fdb_update(priv, addr, vid, 0, ports_mask);
 }
 
 static int
@@ -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);
+		bridge_ports_mask |= priv->cpu_ports_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));
 	mutex_unlock(&priv->reg_lock);
 
 	return res;
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH net v2 3/4] net: dsa: motorcomm: Read the port PVID instead of bridge's
  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-16 16:01 ` 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
  3 siblings, 1 reply; 8+ messages in thread
From: David Yang @ 2026-11-16 16:01 UTC (permalink / raw)
  To: netdev
  Cc: David Yang, Andrew Lunn, Vladimir Oltean, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, linux-kernel

The driver passed the bridge master to br_vlan_get_pvid(), returning the
bridge's own PVID (VID 1 by default) instead of the configured port's.
Query the PVID from dsa_port_to_bridge_port() instead.

Fixes: 186623f4aa72 ("net: dsa: yt921x: Add support for Motorcomm YT921x")
Signed-off-by: David Yang <mmyangfl@gmail.com>
---
 drivers/net/dsa/motorcomm/chip.c | 26 +++++++++++++-------------
 1 file changed, 13 insertions(+), 13 deletions(-)

diff --git a/drivers/net/dsa/motorcomm/chip.c b/drivers/net/dsa/motorcomm/chip.c
index 863ebb6c3198..d84d863080ce 100644
--- a/drivers/net/dsa/motorcomm/chip.c
+++ b/drivers/net/dsa/motorcomm/chip.c
@@ -952,18 +952,18 @@ static int
 yt921x_vlan_filtering(struct yt921x_priv *priv, int port, bool vlan_filtering)
 {
 	struct dsa_port *dp = dsa_to_port(&priv->ds, port);
-	struct net_device *bdev;
+	struct net_device *brport;
 	u16 pvid;
 	u32 mask;
 	u32 ctrl;
 	int res;
 
-	bdev = dsa_port_bridge_dev_get(dp);
+	brport = dsa_port_to_bridge_port(dp);
 
-	if (!bdev || !vlan_filtering)
+	if (!brport || !vlan_filtering)
 		pvid = YT921X_VID_UNWARE;
 	else
-		br_vlan_get_pvid(bdev, &pvid);
+		br_vlan_get_pvid(brport, &pvid);
 	res = yt921x_port_set_pvid(priv, port, pvid);
 	if (res)
 		return res;
@@ -1102,16 +1102,16 @@ yt921x_dsa_port_vlan_del(struct dsa_switch *ds, int port,
 	mutex_lock(&priv->reg_lock);
 	do {
 		struct dsa_port *dp = dsa_to_port(ds, port);
-		struct net_device *bdev;
+		struct net_device *brport;
 
 		res = yt921x_vlan_del(priv, port, vid);
 		if (res)
 			break;
 
-		bdev = dsa_port_bridge_dev_get(dp);
-		if (bdev) {
-			br_vlan_get_pvid(bdev, &pvid);
-			if (pvid == vid)
+		brport = dsa_port_to_bridge_port(dp);
+		if (brport) {
+			br_vlan_get_pvid(brport, &pvid);
+			if (!pvid)
 				res = yt921x_pvid_clear(priv, port);
 		}
 	} while (0);
@@ -1139,19 +1139,19 @@ yt921x_dsa_port_vlan_add(struct dsa_switch *ds, int port,
 	mutex_lock(&priv->reg_lock);
 	do {
 		struct dsa_port *dp = dsa_to_port(ds, port);
-		struct net_device *bdev;
+		struct net_device *brport;
 
 		res = yt921x_vlan_add(priv, port, vid,
 				      vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED);
 		if (res)
 			break;
 
-		bdev = dsa_port_bridge_dev_get(dp);
-		if (bdev) {
+		brport = dsa_port_to_bridge_port(dp);
+		if (brport) {
 			if (vlan->flags & BRIDGE_VLAN_INFO_PVID) {
 				res = yt921x_pvid_set(priv, port, vid);
 			} else {
-				br_vlan_get_pvid(bdev, &pvid);
+				br_vlan_get_pvid(brport, &pvid);
 				if (pvid == vid)
 					res = yt921x_pvid_clear(priv, port);
 			}
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH net v2 4/4] net: dsa: motorcomm: Use VID 0 as the unaware PVID
  2026-11-16 16:01 [PATCH net v2 0/4] net: dsa: motorcomm: FDB fixup David Yang
                   ` (2 preceding siblings ...)
  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-16 16:01 ` David Yang
  2026-11-18 16:02   ` netdev-bot+sashiko
  3 siblings, 1 reply; 8+ messages in thread
From: David Yang @ 2026-11-16 16:01 UTC (permalink / raw)
  To: netdev
  Cc: David Yang, Andrew Lunn, Vladimir Oltean, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, linux-kernel

The hardware classifies untagged and priority-tagged frames to the
port's PVID before the VLAN table lookup, and the FDB lookup key equals
the classified VID (measured on YT9215S).

The driver assigned PVID 4095 to the VLAN-unaware ports, while switchdev
reports the bridge's FDB entries with VID 0. These entries were then
installed under FID 0 and could never be hit by the hardware lookups.
Dynamic entries learnt under VID 4095, if any, took effect instead.

Lift the restriction on VLAN 0. Keep VLAN 0 out of the generic VLAN
add/delete paths, otherwise 8021q's automatic VLAN 0 filtering would
leave a stray CPU port bit behind.

Use VLAN 0 as the PVID of the VLAN-unaware ports. Program the PVID when
a port joins a VLAN-unaware bridge since DSA does not necessarily call
.port_vlan_filtering().

The standalone default of 4095 stays, so mislearnt entries, if any,
would not pollute the bridge FDB.

Fixes: 186623f4aa72 ("net: dsa: yt921x: Add support for Motorcomm YT921x")
Signed-off-by: David Yang <mmyangfl@gmail.com>
---
 drivers/net/dsa/motorcomm/chip.c | 44 +++++++++++++++++++-------------
 1 file changed, 26 insertions(+), 18 deletions(-)

diff --git a/drivers/net/dsa/motorcomm/chip.c b/drivers/net/dsa/motorcomm/chip.c
index d84d863080ce..aa4d6a0c930c 100644
--- a/drivers/net/dsa/motorcomm/chip.c
+++ b/drivers/net/dsa/motorcomm/chip.c
@@ -79,7 +79,7 @@ static const struct yt921x_info yt921x_infos[] = {
 	{}
 };
 
-#define YT921X_VID_UNWARE	4095
+#define YT921X_VID_STANDALONE	4095
 
 struct yt921x_reg_mdio {
 	struct mii_bus *bus;
@@ -960,8 +960,10 @@ yt921x_vlan_filtering(struct yt921x_priv *priv, int port, bool vlan_filtering)
 
 	brport = dsa_port_to_bridge_port(dp);
 
-	if (!brport || !vlan_filtering)
-		pvid = YT921X_VID_UNWARE;
+	if (!brport)
+		pvid = YT921X_VID_STANDALONE;
+	else if (!vlan_filtering)
+		pvid = 0;
 	else
 		br_vlan_get_pvid(brport, &pvid);
 	res = yt921x_port_set_pvid(priv, port, pvid);
@@ -1029,8 +1031,7 @@ yt921x_pvid_clear(struct yt921x_priv *priv, int port)
 
 	vlan_filtering = dsa_port_is_vlan_filtering(dp);
 
-	res = yt921x_port_set_pvid(priv, port,
-				   vlan_filtering ? 0 : YT921X_VID_UNWARE);
+	res = yt921x_port_set_pvid(priv, port, 0);
 	if (res)
 		return res;
 
@@ -1098,6 +1099,8 @@ yt921x_dsa_port_vlan_del(struct dsa_switch *ds, int port,
 
 	if (dsa_is_cpu_port(ds, port))
 		return 0;
+	if (!vid)
+		return 0;
 
 	mutex_lock(&priv->reg_lock);
 	do {
@@ -1135,6 +1138,11 @@ yt921x_dsa_port_vlan_add(struct dsa_switch *ds, int port,
 	 */
 	if (dsa_is_cpu_port(ds, port))
 		return 0;
+	/* VID 0 is the VLAN-unaware bridges' FDB domain; nothing to program,
+	 * keep the entry at reset defaults
+	 */
+	if (!vid)
+		return 0;
 
 	mutex_lock(&priv->reg_lock);
 	do {
@@ -1187,7 +1195,7 @@ static int yt921x_userport_standalone(struct yt921x_priv *priv, int port)
 	/* Unrelated since learning is off and all packets are trapped;
 	 * set it anyway
 	 */
-	res = yt921x_port_set_pvid(priv, port, YT921X_VID_UNWARE);
+	res = yt921x_port_set_pvid(priv, port, YT921X_VID_STANDALONE);
 	if (res)
 		return res;
 
@@ -1285,7 +1293,8 @@ static int yt921x_bridge_leave(struct yt921x_priv *priv, int port)
 }
 
 static int
-yt921x_bridge_join(struct yt921x_priv *priv, int port, u16 ports_mask)
+yt921x_bridge_join(struct yt921x_priv *priv, int port, u16 ports_mask,
+		   bool vlan_filtering)
 {
 	int res;
 
@@ -1297,6 +1306,14 @@ yt921x_bridge_join(struct yt921x_priv *priv, int port, u16 ports_mask)
 	if (res)
 		return res;
 
+	if (!vlan_filtering) {
+		/* DSA may shortcut .port_vlan_filtering(), leaving stale PVID
+		 */
+		res = yt921x_port_set_pvid(priv, port, 0);
+		if (res)
+			return res;
+	}
+
 	return 0;
 }
 
@@ -1427,7 +1444,8 @@ yt921x_dsa_port_bridge_join(struct dsa_switch *ds, int port,
 	mutex_lock(&priv->reg_lock);
 	pp->isolated = br_port_flag_is_set(brport_dev, BR_ISOLATED);
 	pp->hairpin = br_port_flag_is_set(brport_dev, BR_HAIRPIN_MODE);
-	res = yt921x_bridge_join(priv, port, ports_mask);
+	res = yt921x_bridge_join(priv, port, ports_mask,
+				 br_vlan_enabled(bridge.dev));
 	mutex_unlock(&priv->reg_lock);
 
 	return res;
@@ -2277,7 +2295,6 @@ static int yt921x_chip_setup_dsa(struct yt921x_priv *priv)
 {
 	struct dsa_switch *ds = &priv->ds;
 	unsigned long cpu_ports_mask;
-	u32 ctrls[2];
 	u32 ctrl;
 	int port;
 	int res;
@@ -2335,15 +2352,6 @@ static int yt921x_chip_setup_dsa(struct yt921x_priv *priv)
 	if (res)
 		return res;
 
-	/* Tagged VID 0 should be treated as untagged, which confuses the
-	 * hardware a lot
-	 */
-	ctrls[0] = YT921X_VLAN_CTRLa_LEARN_DIS | YT921X_VLAN_CTRLa_PORTS_M;
-	ctrls[1] = 0;
-	res = yt921x_reg64_write(priv, YT921X_VLANn_CTRL(0), ctrls);
-	if (res)
-		return res;
-
 	return 0;
 }
 
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH net v2 2/4] net: dsa: motorcomm: Rewrite FDB entry on port migration
  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
  0 siblings, 0 replies; 8+ messages in thread
From: netdev-bot+sashiko @ 2026-11-18 16:02 UTC (permalink / raw)
  To: mmyangfl
  Cc: netdev, andrew, olteanv, davem, edumazet, kuba, pabeni,
	linux-kernel

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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH net v2 3/4] net: dsa: motorcomm: Read the port PVID instead of bridge's
  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
  0 siblings, 0 replies; 8+ messages in thread
From: netdev-bot+sashiko @ 2026-11-18 16:02 UTC (permalink / raw)
  To: mmyangfl
  Cc: netdev, andrew, olteanv, davem, edumazet, kuba, pabeni,
	linux-kernel

Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] Besides swapping the bridge master (dsa_port_bridge_dev_get())
  for the bridge port (dsa_port_to_bridge_port()), the patch also…

--

net: dsa: motorcomm: Read the port PVID instead of bridge's

This patch changes the yt921x driver so br_vlan_get_pvid() is called on
the bridge port returned by dsa_port_to_bridge_port(). Before, it was
called on the bridge master, which returned the bridge's own PVID. The
change covers yt921x_vlan_filtering(), yt921x_dsa_port_vlan_add() and
yt921x_dsa_port_vlan_del().

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

[ ... ]

> @@ -1102,16 +1102,16 @@ yt921x_dsa_port_vlan_del(struct dsa_switch *ds, int port,
>  	mutex_lock(&priv->reg_lock);
>  	do {
>  		struct dsa_port *dp = dsa_to_port(ds, port);
> -		struct net_device *bdev;
> +		struct net_device *brport;
>  
>  		res = yt921x_vlan_del(priv, port, vid);
>  		if (res)
>  			break;
>  
> -		bdev = dsa_port_bridge_dev_get(dp);
> -		if (bdev) {
> -			br_vlan_get_pvid(bdev, &pvid);
> -			if (pvid == vid)
> +		brport = dsa_port_to_bridge_port(dp);
> +		if (brport) {
> +			br_vlan_get_pvid(brport, &pvid);
> +			if (!pvid)

[Severity: Low]
Besides the switch to dsa_port_to_bridge_port(), this hunk also changes
the condition in yt921x_dsa_port_vlan_del() from "pvid == vid" to
"!pvid". The commit message only says:

  "Query the PVID from dsa_port_to_bridge_port() instead."

Could the changelog mention this condition change too?

The del path now checks whether the port has no PVID at all. Before, it
checked whether the deleted VID was the PVID. The new check works
because the bridge clears vg->pvid before it sends the switchdev delete
notification:

net/bridge/br_vlan.c:nbp_vlan_delete()
    __vlan_unpublish(vg, v);
    synchronize_net();
    ...
    __vlan_del(vg, v);

__vlan_flush() also clears vg->pvid before it deletes each VLAN.

yt921x_dsa_port_vlan_add() still uses "pvid == vid". That is correct,
because in nbp_vlan_add() the switchdev add notification is sent before
__vlan_flags_commit(), so the driver still sees the old PVID. The two
handlers now use different checks, though, and nothing explains why.

Since the patch carries a Fixes: tag and may be backported, would it be
worth saying in the changelog why the two checks differ, and that the
del path depends on this ordering in the bridge?

The changelog also leaves out the user-visible effects being fixed.
Deleting the bridge's own PVID VID from a port cleared that port's real
hardware PVID. Toggling vlan_filtering programmed the bridge's PVID into
every port. Could these be described too?

>  				res = yt921x_pvid_clear(priv, port);
>  		}
>  	} while (0);

[ ... ]

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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH net v2 4/4] net: dsa: motorcomm: Use VID 0 as the unaware PVID
  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
  0 siblings, 0 replies; 8+ messages in thread
From: netdev-bot+sashiko @ 2026-11-18 16:02 UTC (permalink / raw)
  To: mmyangfl
  Cc: netdev, andrew, olteanv, davem, edumazet, kuba, pabeni,
	linux-kernel

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

Critical: 0 · High: 0 · Medium: 1 · Low: 2 (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] This patch turns VID 0 into the shared FDB domain of VLAN-
  unaware bridges and removes the YT921X_VLAN_CTRLa_LEARN_DIS that used…
- [Low] After this patch, nothing in the driver ever programs VLAN table
  entry 0.
- [Low] The concern: VID 0 is now the forwarding domain of VLAN-unaware
  bridges, but its VLAN entry is never programmed.

Pre-existing issues:
- [Low] yt921x_bridge_join() first clears YT921X_PORT_LEARN_DIS through
  yt921x_userport_bridge() (line 1301), then writes the isolation…

--

net: dsa: motorcomm: Use VID 0 as the unaware PVID

This patch changes the PVID of ports in VLAN-unaware bridges from 4095 to
0, so the hardware lookups can hit bridge FDB entries that switchdev
reports with VID 0. It also skips VID 0 in the VLAN add/del paths and
programs PVID 0 when a port joins a VLAN-unaware bridge. Finally, it
removes the setup-time write of VLAN table entry 0.

> diff --git a/drivers/net/dsa/motorcomm/chip.c b/drivers/net/dsa/motorcomm/chip.c
> index d84d863080ce0..aa4d6a0c930ce 100644
> --- a/drivers/net/dsa/motorcomm/chip.c
> +++ b/drivers/net/dsa/motorcomm/chip.c

[ ... ]

> @@ -1029,8 +1031,7 @@ yt921x_pvid_clear(struct yt921x_priv *priv, int port)
>  
>  	vlan_filtering = dsa_port_is_vlan_filtering(dp);
>  
> -	res = yt921x_port_set_pvid(priv, port,
> -				   vlan_filtering ? 0 : YT921X_VID_UNWARE);
> +	res = yt921x_port_set_pvid(priv, port, 0);
>  	if (res)
>  		return res;

[Severity: Medium]
Ports in a VLAN-aware bridge that have no bridge PVID get hardware PVID 0.
That happens here, and also in yt921x_vlan_filtering() when
br_vlan_get_pvid() returns 0. On those ports, the only extra protection is
YT921X_PORT_VLAN_CTRL1_CVLAN_DROP_UNTAGGED.

This patch also makes VID 0 the shared FDB domain of the VLAN-unaware
bridges. It removes YT921X_VLAN_CTRLa_LEARN_DIS from VLAN entry 0 in
yt921x_chip_setup_dsa().

Suppose a VLAN-aware bridge and a VLAN-unaware bridge are on the same
switch. A priority-tagged frame arrives on a VLAN-aware port that has no
PVID. The commit message says such frames are classified to the port
PVID, so this one would be classified to VID 0.

If CVLAN_DROP_UNTAGGED does not drop priority-tagged frames, and the reset
member mask of VLAN 0 lets the frame through VLAN_IGR_FILTER, could its
source MAC be learnt into the FDB that the VLAN-unaware bridges use?

The comment in yt921x_chip_setup_dsa() says port isolation is applied
after the FDB lookup. A unicast frame from the VLAN-unaware bridge to that
MAC would hit an entry pointing at a port in the other bridge. It would be
dropped instead of trapped to the CPU until the entry ages out. The
software bridge would have dropped the original priority-tagged frame,
because the port has no PVID.

Before this patch, LEARN_DIS on VLAN 0 prevented this learning. Could
VLAN-filtering ports without a PVID use a VID other than 0, for example an
unused VID with learning disabled, so their traffic stays out of the
unaware domain?

[ ... ]

> @@ -1135,6 +1138,11 @@ yt921x_dsa_port_vlan_add(struct dsa_switch *ds, int port,
>  	 */
>  	if (dsa_is_cpu_port(ds, port))
>  		return 0;
> +	/* VID 0 is the VLAN-unaware bridges' FDB domain; nothing to program,
> +	 * keep the entry at reset defaults
> +	 */
> +	if (!vid)
> +		return 0;

[Severity: Low]
The comment just above says the CPU port is supposed to be a member of
every VLAN. With this early return, VID 0 never reaches yt921x_vlan_add(),
which is the only place that sets the CPU port bits:

yt921x_vlan_add() {
    ...
	masks[0] = YT921X_VLAN_CTRLa_PORTn(port) |
		   YT921X_VLAN_CTRLa_PORTS(priv->cpu_ports_mask);
    ...
}

VID 0 is now the forwarding domain of the VLAN-unaware bridges, yet entry
0 keeps its reset values for member ports, UNTAG_PORTS, FID and STP_ID.

This is probably fine in practice. The old unaware PVID 4095 was never
programmed either. VLAN_IGR_FILTER is only enabled on VLAN-filtering user
ports, and YT921X_VLAN_EGR_FILTER is never written.

Should the CPU port comment mention the VID 0 exception, though?

[ ... ]

> @@ -1297,6 +1306,14 @@ yt921x_bridge_join(struct yt921x_priv *priv, int port, u16 ports_mask)
>  	if (res)
>  		return res;
>  
> +	if (!vlan_filtering) {
> +		/* DSA may shortcut .port_vlan_filtering(), leaving stale PVID
> +		 */
> +		res = yt921x_port_set_pvid(priv, port, 0);
> +		if (res)
> +			return res;
> +	}
> +
>  	return 0;
>  }

[Severity: Low]
This isn't a bug introduced by this patch, but there is a short window
where frames are learnt under the standalone VID 4095.
yt921x_bridge_join() clears YT921X_PORT_LEARN_DIS in
yt921x_userport_bridge(), then writes the isolation registers in
yt921x_bridge(). Only after that is the PVID moved off 4095 here.

For VLAN-aware bridges, the PVID stays at 4095 even longer. It changes
only when dsa_port_switchdev_sync_attrs() calls dsa_port_vlan_filtering(),
which happens after DSA_NOTIFIER_BRIDGE_JOIN has been handled.

Port isolation is applied after the FDB lookup. Could a standalone port
sending to a MAC learnt in this window have its frame dropped instead of
trapped, until the entry ages out?

This patch makes the unaware window much shorter than before. Would
writing the PVID before clearing LEARN_DIS close what remains?

[ ... ]

> @@ -2335,15 +2352,6 @@ static int yt921x_chip_setup_dsa(struct yt921x_priv *priv)
>  	if (res)
>  		return res;
>  
> -	/* Tagged VID 0 should be treated as untagged, which confuses the
> -	 * hardware a lot
> -	 */
> -	ctrls[0] = YT921X_VLAN_CTRLa_LEARN_DIS | YT921X_VLAN_CTRLa_PORTS_M;
> -	ctrls[1] = 0;
> -	res = yt921x_reg64_write(priv, YT921X_VLANn_CTRL(0), ctrls);
> -	if (res)
> -		return res;
> -
>  	return 0;
>  }

[Severity: Low]
After this removal, does anything in the driver still program VLAN table
entry 0?

yt921x_dsa_port_vlan_add() and yt921x_dsa_port_vlan_del() now return early
for vid 0, and yt921x_dsa_vlan_msti_set() rejects vid 0 with -EINVAL.
Learning and membership in the VID 0 domain therefore depend entirely on
the chip's reset value for entry 0.

The commit message says:

    Lift the restriction on VLAN 0.

The new comment in yt921x_dsa_port_vlan_add() says "keep the entry at
reset defaults". Neither one gives the reset values. Neither says that
the all-ports membership (YT921X_VLAN_CTRLa_PORTS_M) is also dropped.
Neither explains why the workaround in the removed comment is no longer
needed.

The commit message mentions a measurement on YT9215S only. Could it
document which reset value of entry 0 is relied on, and whether that value
is the same on the other supported variants?

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

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2026-11-18 16:02 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox