Netdev List
 help / color / mirror / Atom feed
* [PATCH net-next v5 0/7] net: dsa: motorcomm: Reject isolated redirect targets
@ 2026-12-06  2:20 David Yang
  2026-12-06  2:20 ` [PATCH net-next v5 1/7] net: dsa: motorcomm: Remove local cpu_ports_mask David Yang
                   ` (6 more replies)
  0 siblings, 7 replies; 10+ messages in thread
From: David Yang @ 2026-12-06  2:20 UTC (permalink / raw)
  To: netdev
  Cc: David Yang, Andrew Lunn, Vladimir Oltean, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, Willem de Bruijn,
	Simon Horman

Port isolation takes after REDIR judgment, but software delivers such
frames. Reject such offloading and handle bridge changes.

Although triggered on YT9215S, target to net-next for low severity but
major refactor.

v5:
 - reject bridge join that break redirect rules
 - ensure no frames are dropped during isolation update
v4: https://lore.kernel.org/r/20261204101300.3680838-1-mmyangfl@gmail.com
 - do not block hairpins on standalone ports
 - derive port isolation masks on the fly
v3: https://lore.kernel.org/r/20261201081459.2104904-1-mmyangfl@gmail.com
 - compute the isolation masks in pre_bridge_flags
 - fix code type
v2: https://lore.kernel.org/r/20261129115556.1669188-1-mmyangfl@gmail.com
 - recompute redirect rules on bridge changes
 - reject bridge flags that break redirect rules
v1: https://lore.kernel.org/r/20261127142732.1337041-1-mmyangfl@gmail.com

David Yang (7):
  net: dsa: motorcomm: Remove local cpu_ports_mask
  net: dsa: motorcomm: Do not block hairpins on standalone ports
  net: dsa: motorcomm: Derive port isolation masks on the fly
  net: dsa: motorcomm: Reject isolated redirect targets
  net: dsa: motorcomm: Reject bridge changes that break redirect rules
  net: dsa: destroy the bridge port before the leave on join rollback
  net: dsa: motorcomm: Recompute redirect rules on bridge changes

 drivers/net/dsa/motorcomm/chip.c | 308 +++++++++++++++++++++++++------
 drivers/net/dsa/motorcomm/chip.h |  11 +-
 drivers/net/dsa/motorcomm/tc.c   | 150 ++++++++++++++-
 drivers/net/dsa/motorcomm/tc.h   |   8 +-
 net/dsa/port.c                   |  12 +-
 5 files changed, 411 insertions(+), 78 deletions(-)

-- 
2.53.0


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

* [PATCH net-next v5 1/7] net: dsa: motorcomm: Remove local cpu_ports_mask
  2026-12-06  2:20 [PATCH net-next v5 0/7] net: dsa: motorcomm: Reject isolated redirect targets David Yang
@ 2026-12-06  2:20 ` David Yang
  2026-12-06  2:20 ` [PATCH net-next v5 2/7] net: dsa: motorcomm: Do not block hairpins on standalone ports David Yang
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 10+ messages in thread
From: David Yang @ 2026-12-06  2:20 UTC (permalink / raw)
  To: netdev
  Cc: David Yang, Andrew Lunn, Vladimir Oltean, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, Willem de Bruijn,
	Simon Horman

Use dsa_cpu_ports() and dsa_is_cpu_port() instead for a clearer view of
code.

Signed-off-by: David Yang <mmyangfl@gmail.com>
---
 drivers/net/dsa/motorcomm/chip.c | 18 +++++++++---------
 drivers/net/dsa/motorcomm/chip.h |  2 --
 2 files changed, 9 insertions(+), 11 deletions(-)

diff --git a/drivers/net/dsa/motorcomm/chip.c b/drivers/net/dsa/motorcomm/chip.c
index 82f364986aeb..c96512faeca2 100644
--- a/drivers/net/dsa/motorcomm/chip.c
+++ b/drivers/net/dsa/motorcomm/chip.c
@@ -1101,7 +1101,7 @@ yt921x_vlan_add(struct yt921x_priv *priv, int port, u16 vid, bool untagged)
 	u32 ctrls[2];
 
 	masks[0] = YT921X_VLAN_CTRLa_PORTn(port) |
-		   YT921X_VLAN_CTRLa_PORTS(priv->cpu_ports_mask);
+		   YT921X_VLAN_CTRLa_PORTS(dsa_cpu_ports(&priv->ds));
 	ctrls[0] = masks[0];
 
 	masks[1] = YT921X_VLAN_CTRLb_UNTAG_PORTn(port);
@@ -1256,11 +1256,12 @@ yt921x_dsa_port_vlan_add(struct dsa_switch *ds, int port,
 
 static int yt921x_userport_standalone(struct yt921x_priv *priv, int port)
 {
+	struct dsa_switch *ds = &priv->ds;
 	u32 mask;
 	u32 ctrl;
 	int res;
 
-	ctrl = ~priv->cpu_ports_mask;
+	ctrl = ~dsa_cpu_ports(ds);
 	res = yt921x_reg_write(priv, YT921X_PORTn_ISOLATION(port), ctrl);
 	if (res)
 		return res;
@@ -1306,7 +1307,7 @@ static int yt921x_isolate(struct yt921x_priv *priv, int port)
 
 	mask = BIT(port);
 	for (int i = 0; i < YT921X_PORT_NUM; i++) {
-		if ((BIT(i) & priv->cpu_ports_mask) || i == port)
+		if (dsa_is_cpu_port(&priv->ds, i) || i == port)
 			continue;
 
 		res = yt921x_reg_set_bits(priv, YT921X_PORTn_ISOLATION(i),
@@ -1323,7 +1324,7 @@ static int yt921x_isolate(struct yt921x_priv *priv, int port)
  */
 static int yt921x_bridge(struct yt921x_priv *priv, u16 ports_mask)
 {
-	unsigned long targets_mask = ports_mask & ~priv->cpu_ports_mask;
+	unsigned long targets_mask = ports_mask & ~dsa_cpu_ports(&priv->ds);
 	u32 isolated_mask;
 	u32 ctrl;
 	int port;
@@ -1436,7 +1437,7 @@ yt921x_bridge_flags(struct yt921x_priv *priv, int port,
 			u32 ports_mask;
 
 			ports_mask = dsa_bridge_ports(ds, bdev);
-			ports_mask |= priv->cpu_ports_mask;
+			ports_mask |= dsa_cpu_ports(ds);
 			res = yt921x_bridge(priv, ports_mask);
 			if (res)
 				return res;
@@ -1511,7 +1512,7 @@ yt921x_dsa_port_bridge_join(struct dsa_switch *ds, int port,
 		return 0;
 
 	ports_mask = dsa_bridge_ports(ds, bridge.dev);
-	ports_mask |= priv->cpu_ports_mask;
+	ports_mask |= dsa_cpu_ports(ds);
 
 	dp = dsa_to_port(ds, port);
 	brport_dev = dsa_port_to_bridge_port(dp);
@@ -2382,10 +2383,10 @@ static int yt921x_chip_setup_dsa(struct yt921x_priv *priv)
 	int res;
 
 	/* Enable DSA */
-	priv->cpu_ports_mask = dsa_cpu_ports(ds);
+	cpu_ports_mask = dsa_cpu_ports(ds);
 
 	ctrl = YT921X_EXT_CPU_PORT_TAG_EN | YT921X_EXT_CPU_PORT_PORT_EN |
-	       YT921X_EXT_CPU_PORT_PORT(__ffs(priv->cpu_ports_mask));
+	       YT921X_EXT_CPU_PORT_PORT(__ffs(cpu_ports_mask));
 	res = yt921x_reg_write(priv, YT921X_EXT_CPU_PORT, ctrl);
 	if (res)
 		return res;
@@ -2422,7 +2423,6 @@ static int yt921x_chip_setup_dsa(struct yt921x_priv *priv)
 	/* Except for CPU ports, if any packets are sent via CPU ports without
 	 * tag, they should be dropped.
 	 */
-	cpu_ports_mask = priv->cpu_ports_mask;
 	for_each_set_bit(port, &cpu_ports_mask, YT921X_PORT_NUM) {
 		ctrl &= ~YT921X_ACT_UNK_ACTn_M(port);
 		ctrl |= YT921X_ACT_UNK_ACTn_DROP(port);
diff --git a/drivers/net/dsa/motorcomm/chip.h b/drivers/net/dsa/motorcomm/chip.h
index fc315f1d8f87..d5ed580f8a78 100644
--- a/drivers/net/dsa/motorcomm/chip.h
+++ b/drivers/net/dsa/motorcomm/chip.h
@@ -509,8 +509,6 @@ struct yt921x_priv {
 	const struct yt921x_info *info;
 	unsigned int meter_slot_ns;
 	unsigned int port_shape_slot_ns;
-	/* cache of dsa_cpu_ports(ds) */
-	u16 cpu_ports_mask;
 	unsigned char cycle_ns;
 
 	/* protect the access to the switch registers */
-- 
2.53.0


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

* [PATCH net-next v5 2/7] net: dsa: motorcomm: Do not block hairpins on standalone ports
  2026-12-06  2:20 [PATCH net-next v5 0/7] net: dsa: motorcomm: Reject isolated redirect targets David Yang
  2026-12-06  2:20 ` [PATCH net-next v5 1/7] net: dsa: motorcomm: Remove local cpu_ports_mask David Yang
@ 2026-12-06  2:20 ` David Yang
  2026-12-06  2:20 ` [PATCH net-next v5 3/7] net: dsa: motorcomm: Derive port isolation masks on the fly David Yang
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 10+ messages in thread
From: David Yang @ 2026-12-06  2:20 UTC (permalink / raw)
  To: netdev
  Cc: David Yang, Andrew Lunn, Vladimir Oltean, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, Willem de Bruijn,
	Simon Horman

Port isolation takes after REDIR judgment. An ACL rule redirected to
itself on a standalone port was blocked before.

Lift that block despite rare usage.

Fixes: 8eb9e7520b17 ("net: dsa: yt921x: Add ACL support")
Signed-off-by: David Yang <mmyangfl@gmail.com>
---
 drivers/net/dsa/motorcomm/chip.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/dsa/motorcomm/chip.c b/drivers/net/dsa/motorcomm/chip.c
index c96512faeca2..6e57c9262c68 100644
--- a/drivers/net/dsa/motorcomm/chip.c
+++ b/drivers/net/dsa/motorcomm/chip.c
@@ -1261,7 +1261,7 @@ static int yt921x_userport_standalone(struct yt921x_priv *priv, int port)
 	u32 ctrl;
 	int res;
 
-	ctrl = ~dsa_cpu_ports(ds);
+	ctrl = ~(dsa_cpu_ports(ds) | BIT(port));
 	res = yt921x_reg_write(priv, YT921X_PORTn_ISOLATION(port), ctrl);
 	if (res)
 		return res;
-- 
2.53.0


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

* [PATCH net-next v5 3/7] net: dsa: motorcomm: Derive port isolation masks on the fly
  2026-12-06  2:20 [PATCH net-next v5 0/7] net: dsa: motorcomm: Reject isolated redirect targets David Yang
  2026-12-06  2:20 ` [PATCH net-next v5 1/7] net: dsa: motorcomm: Remove local cpu_ports_mask David Yang
  2026-12-06  2:20 ` [PATCH net-next v5 2/7] net: dsa: motorcomm: Do not block hairpins on standalone ports David Yang
@ 2026-12-06  2:20 ` David Yang
  2026-12-06  2:20 ` [PATCH net-next v5 4/7] net: dsa: motorcomm: Reject isolated redirect targets David Yang
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 10+ messages in thread
From: David Yang @ 2026-12-06  2:20 UTC (permalink / raw)
  To: netdev
  Cc: David Yang, Andrew Lunn, Vladimir Oltean, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, Willem de Bruijn,
	Simon Horman

For a following commit, an accurate snapshot of port isolation masks is
required. However, .port_pre_bridge_flags() can only veto the changes,
and .port_bridge_flags() is deferred, thus the driver never knows the
exact time point when flags take effect.

Introduce a helper to derive such mask on the fly, and remove local
cache for port flags.

Signed-off-by: David Yang <mmyangfl@gmail.com>
---
 drivers/net/dsa/motorcomm/chip.c | 166 +++++++++++++++++++++----------
 drivers/net/dsa/motorcomm/chip.h |   4 -
 2 files changed, 113 insertions(+), 57 deletions(-)

diff --git a/drivers/net/dsa/motorcomm/chip.c b/drivers/net/dsa/motorcomm/chip.c
index 6e57c9262c68..b15c1b821087 100644
--- a/drivers/net/dsa/motorcomm/chip.c
+++ b/drivers/net/dsa/motorcomm/chip.c
@@ -1322,39 +1322,120 @@ static int yt921x_isolate(struct yt921x_priv *priv, int port)
 /* Make sure to include the CPU port in ports_mask, or your bridge will
  * not have it.
  */
-static int yt921x_bridge(struct yt921x_priv *priv, u16 ports_mask)
+static void
+yt921x_isolation_calc_bridge(struct yt921x_priv *priv, u16 ports_mask,
+			     u16 *isolation_masks)
 {
-	unsigned long targets_mask = ports_mask & ~dsa_cpu_ports(&priv->ds);
+	struct dsa_switch *ds = &priv->ds;
+	struct dsa_port *dp;
 	u32 isolated_mask;
+	u32 hairpin_mask;
 	u32 ctrl;
-	int port;
-	int res;
 
 	isolated_mask = 0;
-	for_each_set_bit(port, &targets_mask, YT921X_PORT_NUM) {
-		struct yt921x_port *pp = &priv->ports[port];
+	hairpin_mask = 0;
+	dsa_switch_for_each_user_port(dp, ds) {
+		struct net_device *brport;
+		int port = dp->index;
+
+		if (!(ports_mask & BIT(port)))
+			continue;
 
-		if (pp->isolated)
+		brport = dsa_port_to_bridge_port(dp);
+
+		if (br_port_flag_is_set(brport, BR_ISOLATED))
 			isolated_mask |= BIT(port);
+		if (br_port_flag_is_set(brport, BR_HAIRPIN_MODE))
+			hairpin_mask |= BIT(port);
 	}
 
 	/* Block from non-cpu bridge ports ... */
-	for_each_set_bit(port, &targets_mask, YT921X_PORT_NUM) {
-		struct yt921x_port *pp = &priv->ports[port];
+	dsa_switch_for_each_user_port(dp, ds) {
+		int port = dp->index;
+
+		if (!(ports_mask & BIT(port)))
+			continue;
 
 		/* to non-bridge ports */
 		ctrl = ~ports_mask;
 		/* to isolated ports when isolated */
-		if (pp->isolated)
+		if (isolated_mask & BIT(port))
 			ctrl |= isolated_mask;
 		/* to itself when non-hairpin */
-		if (!pp->hairpin)
+		if (!(hairpin_mask & BIT(port)))
 			ctrl |= BIT(port);
 		else
 			ctrl &= ~BIT(port);
 
+		isolation_masks[port] = ctrl;
+	}
+}
+
+static void
+yt921x_isolation_calc(struct yt921x_priv *priv, u16 *ports_maskp,
+		      u16 *isolation_masks)
+{
+	struct dsa_switch *ds = &priv->ds;
+	u32 ports_mask = *ports_maskp;
+	struct net_device *bdev;
+	struct dsa_port *dp;
+	u32 cpu_ports_mask;
+	u32 targets_mask;
+
+	ports_mask = dsa_user_ports(ds);
+	if (ports_maskp)
+		ports_mask &= *ports_maskp;
+	if (!ports_mask)
+		goto end;
+
+	cpu_ports_mask = dsa_cpu_ports(ds);
+	targets_mask = ports_mask;
+	dsa_switch_for_each_user_port(dp, ds) {
+		int port = dp->index;
+
+		if (!(targets_mask & BIT(port)))
+			continue;
+
+		bdev = dsa_port_bridge_dev_get(dp);
+		if (!bdev) {
+			isolation_masks[port] = ~(BIT(port) | cpu_ports_mask);
+			targets_mask &= ~BIT(port);
+		} else {
+			u32 bridge_ports_mask = dsa_bridge_ports(ds, bdev);
+
+			yt921x_isolation_calc_bridge(priv,
+						     bridge_ports_mask |
+						     cpu_ports_mask,
+						     isolation_masks);
+			targets_mask &= ~bridge_ports_mask;
+			ports_mask |= bridge_ports_mask;
+		}
+
+		if (!targets_mask)
+			break;
+	}
+
+end:
+	if (ports_maskp)
+		*ports_maskp = ports_mask;
+}
+
+static int
+yt921x_isolation_commit(struct yt921x_priv *priv, u16 ports_mask,
+			const u16 *isolation_masks)
+{
+	struct dsa_switch *ds = &priv->ds;
+	struct dsa_port *dp;
+	int res;
+
+	dsa_switch_for_each_user_port(dp, ds) {
+		int port = dp->index;
+
+		if (!(ports_mask & BIT(port)))
+			continue;
+
 		res = yt921x_reg_write(priv, YT921X_PORTn_ISOLATION(port),
-				       ctrl);
+				       isolation_masks[port]);
 		if (res)
 			return res;
 	}
@@ -1362,6 +1443,19 @@ static int yt921x_bridge(struct yt921x_priv *priv, u16 ports_mask)
 	return 0;
 }
 
+static int
+yt921x_isolation_refresh(struct yt921x_priv *priv, u16 ports_mask,
+			 bool also_bridge)
+{
+	u16 isolation_masks[YT921X_PORT_NUM];
+	u16 targets_mask = ports_mask;
+
+	yt921x_isolation_calc(priv, &targets_mask, isolation_masks);
+	return yt921x_isolation_commit(priv,
+				       also_bridge ? targets_mask : ports_mask,
+				       isolation_masks);
+}
+
 static int yt921x_bridge_leave(struct yt921x_priv *priv, int port)
 {
 	int res;
@@ -1378,7 +1472,7 @@ 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)
 {
 	int res;
 
@@ -1386,7 +1480,7 @@ yt921x_bridge_join(struct yt921x_priv *priv, int port, u16 ports_mask)
 	if (res)
 		return res;
 
-	res = yt921x_bridge(priv, ports_mask);
+	res = yt921x_isolation_refresh(priv, BIT(port), true);
 	if (res)
 		return res;
 
@@ -1397,8 +1491,6 @@ static int
 yt921x_bridge_flags(struct yt921x_priv *priv, int port,
 		    struct switchdev_brport_flags flags)
 {
-	struct yt921x_port *pp = &priv->ports[port];
-	bool do_flush;
 	u32 mask;
 	int res;
 
@@ -1418,30 +1510,10 @@ yt921x_bridge_flags(struct yt921x_priv *priv, int port,
 
 	/* BR_BCAST_FLOOD: we can filter bcast, but cannot trap them */
 
-	do_flush = false;
-	if (flags.mask & BR_HAIRPIN_MODE) {
-		pp->hairpin = flags.val & BR_HAIRPIN_MODE;
-		do_flush = true;
-	}
-	if (flags.mask & BR_ISOLATED) {
-		pp->isolated = flags.val & BR_ISOLATED;
-		do_flush = true;
-	}
-	if (do_flush) {
-		struct dsa_switch *ds = &priv->ds;
-		struct dsa_port *dp = dsa_to_port(ds, port);
-		struct net_device *bdev;
-
-		bdev = dsa_port_bridge_dev_get(dp);
-		if (bdev) {
-			u32 ports_mask;
-
-			ports_mask = dsa_bridge_ports(ds, bdev);
-			ports_mask |= dsa_cpu_ports(ds);
-			res = yt921x_bridge(priv, ports_mask);
-			if (res)
-				return res;
-		}
+	if ((flags.mask & BR_HAIRPIN_MODE) || (flags.mask & BR_ISOLATED)) {
+		res = yt921x_isolation_refresh(priv, BIT(port), true);
+		if (res)
+			return res;
 	}
 
 	return 0;
@@ -1502,25 +1574,13 @@ yt921x_dsa_port_bridge_join(struct dsa_switch *ds, int port,
 			    struct netlink_ext_ack *extack)
 {
 	struct yt921x_priv *priv = dsa_to_yt921x_priv(ds);
-	struct yt921x_port *pp = &priv->ports[port];
-	struct net_device *brport_dev;
-	struct dsa_port *dp;
-	u16 ports_mask;
 	int res;
 
 	if (dsa_is_cpu_port(ds, port))
 		return 0;
 
-	ports_mask = dsa_bridge_ports(ds, bridge.dev);
-	ports_mask |= dsa_cpu_ports(ds);
-
-	dp = dsa_to_port(ds, port);
-	brport_dev = dsa_port_to_bridge_port(dp);
-
 	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);
 	mutex_unlock(&priv->reg_lock);
 
 	return res;
diff --git a/drivers/net/dsa/motorcomm/chip.h b/drivers/net/dsa/motorcomm/chip.h
index d5ed580f8a78..22381009db51 100644
--- a/drivers/net/dsa/motorcomm/chip.h
+++ b/drivers/net/dsa/motorcomm/chip.h
@@ -457,10 +457,6 @@ struct yt921x_port {
 	bool serdes:1;
 	/* Link from in-band status (PHYLINK_PCS_NEG_INBAND) */
 	bool inband:1;
-	/* BR_HAIRPIN_MODE */
-	bool hairpin:1;
-	/* BR_ISOLATED */
-	bool isolated:1;
 
 	unsigned short acl_cnt;
 
-- 
2.53.0


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

* [PATCH net-next v5 4/7] net: dsa: motorcomm: Reject isolated redirect targets
  2026-12-06  2:20 [PATCH net-next v5 0/7] net: dsa: motorcomm: Reject isolated redirect targets David Yang
                   ` (2 preceding siblings ...)
  2026-12-06  2:20 ` [PATCH net-next v5 3/7] net: dsa: motorcomm: Derive port isolation masks on the fly David Yang
@ 2026-12-06  2:20 ` David Yang
  2026-12-06  2:20 ` [PATCH net-next v5 5/7] net: dsa: motorcomm: Reject bridge changes that break redirect rules David Yang
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 10+ messages in thread
From: David Yang @ 2026-12-06  2:20 UTC (permalink / raw)
  To: netdev
  Cc: David Yang, Andrew Lunn, Vladimir Oltean, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, Willem de Bruijn,
	Simon Horman

Port isolation takes after REDIR judgment, but software delivers such
frames. Either route such rules to the software, or reject offloading.

Fixes: 8eb9e7520b17 ("net: dsa: yt921x: Add ACL support")
Signed-off-by: David Yang <mmyangfl@gmail.com>
---
 drivers/net/dsa/motorcomm/chip.c |  9 +++++++++
 drivers/net/dsa/motorcomm/chip.h |  2 ++
 drivers/net/dsa/motorcomm/tc.c   | 34 ++++++++++++++++++++++++++++++--
 drivers/net/dsa/motorcomm/tc.h   |  6 +++++-
 4 files changed, 48 insertions(+), 3 deletions(-)

diff --git a/drivers/net/dsa/motorcomm/chip.c b/drivers/net/dsa/motorcomm/chip.c
index b15c1b821087..0fdef7d2c11d 100644
--- a/drivers/net/dsa/motorcomm/chip.c
+++ b/drivers/net/dsa/motorcomm/chip.c
@@ -1420,6 +1420,15 @@ yt921x_isolation_calc(struct yt921x_priv *priv, u16 *ports_maskp,
 		*ports_maskp = ports_mask;
 }
 
+u16 yt921x_isolation_calc_port(struct yt921x_priv *priv, int port)
+{
+	u16 isolation_masks[YT921X_PORT_NUM];
+	u16 ports_mask = BIT(port);
+
+	yt921x_isolation_calc(priv, &ports_mask, isolation_masks);
+	return isolation_masks[port];
+}
+
 static int
 yt921x_isolation_commit(struct yt921x_priv *priv, u16 ports_mask,
 			const u16 *isolation_masks)
diff --git a/drivers/net/dsa/motorcomm/chip.h b/drivers/net/dsa/motorcomm/chip.h
index 22381009db51..749fe12fa852 100644
--- a/drivers/net/dsa/motorcomm/chip.h
+++ b/drivers/net/dsa/motorcomm/chip.h
@@ -559,4 +559,6 @@ static inline u32 ethaddr_lo2_to_u32(const unsigned char *addr)
 	return (addr[4] << 8) | addr[5];
 }
 
+u16 yt921x_isolation_calc_port(struct yt921x_priv *priv, int port);
+
 #endif
diff --git a/drivers/net/dsa/motorcomm/tc.c b/drivers/net/dsa/motorcomm/tc.c
index e3f057ed580f..597a986026d5 100644
--- a/drivers/net/dsa/motorcomm/tc.c
+++ b/drivers/net/dsa/motorcomm/tc.c
@@ -1041,6 +1041,8 @@ yt921x_acl_rule_ext_parse_flow_action(struct yt921x_acl_rule_ext *ruleext,
 	int res;
 
 	memset(action, 0, 3 * sizeof(*action));
+	ruleext->r.sw_assisting = false;
+
 	flow_action_for_each(i, act, flow_action) {
 		/* The flow action entry carries no mirred control, so there
 		 * is no way to tell whether software would continue past a
@@ -1072,6 +1074,21 @@ yt921x_acl_rule_ext_parse_flow_action(struct yt921x_acl_rule_ext *ruleext,
 				goto fallback;
 			}
 
+			/* Port isolation takes after REDIR judgment, but
+			 * software delivers such frames.
+			 */
+			if (yt921x_isolation_calc_port(priv, port) &
+			    BIT(to_dp->index)) {
+				if (cls->common.skip_sw) {
+					if (to_dp->index == port)
+						reason = "Redirect to self, which is not hairpinning";
+					else
+						reason = "Redirect target isolated, or not in the same bridge";
+					goto fallback;
+				}
+				ruleext->r.sw_assisting = true;
+			}
+
 			action[2] |= YT921X_ACL_ACTc_FWD_EN |
 				     YT921X_ACL_ACTc_FWD_REDIR |
 				     YT921X_ACL_ACTc_FWD_REDIR_DPORTn(to_dp->index);
@@ -1135,6 +1152,7 @@ yt921x_acl_rule_ext_parse_flow_action(struct yt921x_acl_rule_ext *ruleext,
 				     ~YT921X_ACL_ACTc_FWD_M;
 			action[2] |= YT921X_ACL_ACTc_FWD_EN |
 				     YT921X_ACL_ACTc_FWD_TRAP;
+			ruleext->r.sw_assisting = false;
 			terminal = true;
 			break;
 		}
@@ -1301,8 +1319,19 @@ yt921x_acl_commit(struct yt921x_priv *priv, unsigned int entid, u8 entsmask)
 	aclrule = aclblk->rules[binid];
 
 	/* Write actions */
-	res = yt921x_reg96_write(priv, YT921X_ACLn_ACT(entid),
-				 aclrule ? aclrule->action : zeros);
+	if (!aclrule || !aclrule->sw_assisting) {
+		res = yt921x_reg96_write(priv, YT921X_ACLn_ACT(entid),
+					 aclrule ? aclrule->action : zeros);
+	} else {
+		u32 action[3];
+
+		memcpy(action, aclrule->action, sizeof(action));
+		action[2] &= ~YT921X_ACL_ACTc_FWD_REDIR_DPORTS_M &
+			     ~YT921X_ACL_ACTc_FWD_M;
+		action[2] |= YT921X_ACL_ACTc_FWD_EN | YT921X_ACL_ACTc_FWD_TRAP;
+
+		res = yt921x_reg96_write(priv, YT921X_ACLn_ACT(entid), action);
+	}
 	if (res)
 		return res;
 
@@ -1502,6 +1531,7 @@ yt921x_acl_add(struct yt921x_priv *priv,
 				      ~YT921X_ACL_ACTc_FWD_M;
 		aclrule->action[2] |= YT921X_ACL_ACTc_FWD_EN |
 				      YT921X_ACL_ACTc_FWD_TRAP;
+		aclrule->sw_assisting = false;
 	}
 	if (meterid < YT921X_METER_NUM)
 		aclrule->action[0] |= YT921X_ACL_ACTa_METER_ID(meterid);
diff --git a/drivers/net/dsa/motorcomm/tc.h b/drivers/net/dsa/motorcomm/tc.h
index cc53f148d690..81c29a8eec5a 100644
--- a/drivers/net/dsa/motorcomm/tc.h
+++ b/drivers/net/dsa/motorcomm/tc.h
@@ -349,7 +349,11 @@ struct yt921x_acl_rule {
 	enum tc_setup_type type;
 
 	u32 action[3];
-	bool sw_assisted;
+	bool sw_assisted:1;
+	/* not a TRAP rule, but installed as trapped as some conditions are not
+	 * met
+	 */
+	bool sw_assisting:1;
 
 	u8 mask;
 	struct yt921x_acl_entry entries[YT921X_ACL_ENT_PER_BLK];
-- 
2.53.0


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

* [PATCH net-next v5 5/7] net: dsa: motorcomm: Reject bridge changes that break redirect rules
  2026-12-06  2:20 [PATCH net-next v5 0/7] net: dsa: motorcomm: Reject isolated redirect targets David Yang
                   ` (3 preceding siblings ...)
  2026-12-06  2:20 ` [PATCH net-next v5 4/7] net: dsa: motorcomm: Reject isolated redirect targets David Yang
@ 2026-12-06  2:20 ` David Yang
  2026-12-06  2:20 ` [PATCH net-next v5 6/7] net: dsa: destroy the bridge port before the leave on join rollback David Yang
  2026-12-06  2:20 ` [PATCH net-next v5 7/7] net: dsa: motorcomm: Recompute redirect rules on bridge changes David Yang
  6 siblings, 0 replies; 10+ messages in thread
From: David Yang @ 2026-12-06  2:20 UTC (permalink / raw)
  To: netdev
  Cc: David Yang, Andrew Lunn, Vladimir Oltean, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, Willem de Bruijn,
	Simon Horman

Bridge join or flag changes rewrite the isolation masks, so a reachable
redirect rule may be blocked by port isolation.

Reject such changes based on bookkeeping counters:
.port_pre_bridge_flags() is atomic.

Fixes: 8eb9e7520b17 ("net: dsa: yt921x: Add ACL support")
Signed-off-by: David Yang <mmyangfl@gmail.com>
---
 drivers/net/dsa/motorcomm/chip.c | 62 ++++++++++++++++++++++++++++++++
 drivers/net/dsa/motorcomm/chip.h |  1 +
 drivers/net/dsa/motorcomm/tc.c   | 36 ++++++++++++++-----
 3 files changed, 91 insertions(+), 8 deletions(-)

diff --git a/drivers/net/dsa/motorcomm/chip.c b/drivers/net/dsa/motorcomm/chip.c
index 0fdef7d2c11d..0bc03ead8d36 100644
--- a/drivers/net/dsa/motorcomm/chip.c
+++ b/drivers/net/dsa/motorcomm/chip.c
@@ -1533,9 +1533,55 @@ yt921x_dsa_port_pre_bridge_flags(struct dsa_switch *ds, int port,
 				 struct switchdev_brport_flags flags,
 				 struct netlink_ext_ack *extack)
 {
+	struct yt921x_priv *priv = dsa_to_yt921x_priv(ds);
+	struct yt921x_port *pp = &priv->ports[port];
+	struct net_device *brport;
+	struct net_device *bdev;
+	struct dsa_port *dp;
+	u32 ports_mask;
+
 	if (flags.mask & ~(BR_HAIRPIN_MODE | BR_LEARNING | BR_FLOOD |
 			   BR_MCAST_FLOOD | BR_ISOLATED))
 		return -EINVAL;
+
+	if ((flags.mask & BR_HAIRPIN_MODE) && !(flags.val & BR_HAIRPIN_MODE) &&
+	    pp->acl_dst_cnts[port]) {
+		NL_SET_ERR_MSG_MOD(extack,
+				   "Cannot disable hairpin mode while there are hairpin redirect rules");
+		return -EINVAL;
+	}
+
+	dp = dsa_to_port(ds, port);
+	bdev = dsa_port_bridge_dev_get(dp);
+	if (!bdev)
+		return 0;
+	brport = dsa_port_to_bridge_port(dp);
+	ports_mask = dsa_bridge_ports(ds, bdev);
+
+	if ((flags.mask & BR_ISOLATED) && (flags.val & BR_ISOLATED)) {
+		struct dsa_port *other_dp;
+
+		dsa_switch_for_each_user_port(other_dp, ds) {
+			struct net_device *other_brport;
+			int i = other_dp->index;
+
+			if (i == port || !(ports_mask & BIT(i)))
+				continue;
+			if (!pp->acl_dst_cnts[i] &&
+			    !priv->ports[i].acl_dst_cnts[port])
+				continue;
+
+			other_brport = dsa_port_to_bridge_port(other_dp);
+			if (other_brport != brport &&
+			    !br_port_flag_is_set(other_brport, BR_ISOLATED))
+				continue;
+
+			NL_SET_ERR_MSG_MOD(extack,
+					   "Cannot isolate port while there are redirect rules");
+			return -EINVAL;
+		}
+	}
+
 	return 0;
 }
 
@@ -1583,13 +1629,29 @@ yt921x_dsa_port_bridge_join(struct dsa_switch *ds, int port,
 			    struct netlink_ext_ack *extack)
 {
 	struct yt921x_priv *priv = dsa_to_yt921x_priv(ds);
+	u16 isolation_mask;
 	int res;
 
 	if (dsa_is_cpu_port(ds, port))
 		return 0;
 
 	mutex_lock(&priv->reg_lock);
+
+	isolation_mask = yt921x_isolation_calc_port(priv, port);
+	for (int i = 0; i < YT921X_PORT_NUM; i++) {
+		if (!priv->ports[port].acl_dst_cnts[i] ||
+		    !(isolation_mask & BIT(i)))
+			continue;
+
+		NL_SET_ERR_MSG_MOD(extack,
+				   "Cannot join the bridge while there are redirect rules");
+		res = -EOPNOTSUPP;
+		goto end;
+	}
+
 	res = yt921x_bridge_join(priv, port);
+
+end:
 	mutex_unlock(&priv->reg_lock);
 
 	return res;
diff --git a/drivers/net/dsa/motorcomm/chip.h b/drivers/net/dsa/motorcomm/chip.h
index 749fe12fa852..4085a3c52f20 100644
--- a/drivers/net/dsa/motorcomm/chip.h
+++ b/drivers/net/dsa/motorcomm/chip.h
@@ -459,6 +459,7 @@ struct yt921x_port {
 	bool inband:1;
 
 	unsigned short acl_cnt;
+	unsigned short acl_dst_cnts[YT921X_PORT_NUM];
 
 #if IS_ENABLED(CONFIG_NET_DSA_YT921X_LEDS)
 	unsigned char led_duty;
diff --git a/drivers/net/dsa/motorcomm/tc.c b/drivers/net/dsa/motorcomm/tc.c
index 597a986026d5..b4c531ea9664 100644
--- a/drivers/net/dsa/motorcomm/tc.c
+++ b/drivers/net/dsa/motorcomm/tc.c
@@ -1404,7 +1404,8 @@ yt921x_acl_del(struct yt921x_priv *priv, enum tc_setup_type type,
 	unsigned int binid;
 	unsigned int blkid;
 	unsigned int entid;
-	unsigned long m;
+	unsigned long srcs;
+	unsigned long dsts;
 	unsigned int o;
 	u32 ctrl;
 	int res;
@@ -1423,9 +1424,17 @@ yt921x_acl_del(struct yt921x_priv *priv, enum tc_setup_type type,
 	ret = yt921x_acl_commit(priv, entid, aclrule->mask);
 	/* the kernel never rolls back on failure */
 
-	m = FIELD_GET(YT921X_ACL_KEYb_SPORTS_M, aclrule->entries[0].key[1]);
-	for_each_set_bit(o, &m, YT921X_PORT_NUM) {
+	srcs = FIELD_GET(YT921X_ACL_KEYb_SPORTS_M, aclrule->entries[0].key[1]);
+	dsts = FIELD_GET(YT921X_ACL_ACTc_FWD_REDIR_DPORTS_M,
+			 aclrule->action[2]);
+	for_each_set_bit(o, &srcs, YT921X_PORT_NUM) {
 		struct yt921x_port *pp = &priv->ports[o];
+		unsigned int i;
+
+		if (!aclrule->sw_assisted)
+			for_each_set_bit(i, &dsts, YT921X_PORT_NUM)
+				if (!WARN_ON(!pp->acl_dst_cnts[i]))
+					pp->acl_dst_cnts[i]--;
 
 		if (!WARN_ON(!pp->acl_cnt)) {
 			pp->acl_cnt--;
@@ -1467,6 +1476,8 @@ yt921x_acl_add(struct yt921x_priv *priv,
 	unsigned int binid;
 	unsigned int blkid;
 	unsigned int entid;
+	unsigned long srcs;
+	unsigned long dsts;
 	unsigned long m;
 	unsigned int o;
 	u32 ctrl;
@@ -1540,8 +1551,8 @@ yt921x_acl_add(struct yt921x_priv *priv,
 
 	/* Activate ACL if needed */
 	ctrl = 0;
-	m = FIELD_GET(YT921X_ACL_KEYb_SPORTS_M, ruleext->r.entries[0].key[1]);
-	for_each_set_bit(o, &m, YT921X_PORT_NUM)
+	srcs = FIELD_GET(YT921X_ACL_KEYb_SPORTS_M, aclrule->entries[0].key[1]);
+	for_each_set_bit(o, &srcs, YT921X_PORT_NUM)
 		if (!priv->ports[o].acl_cnt)
 			ctrl |= YT921X_ACL_PORT_PORTn(o);
 	if (ctrl) {
@@ -1560,9 +1571,18 @@ yt921x_acl_add(struct yt921x_priv *priv,
 	}
 
 	/* Bookkeeping */
-	m = FIELD_GET(YT921X_ACL_KEYb_SPORTS_M, ruleext->r.entries[0].key[1]);
-	for_each_set_bit(o, &m, YT921X_PORT_NUM)
-		priv->ports[o].acl_cnt++;
+	dsts = FIELD_GET(YT921X_ACL_ACTc_FWD_REDIR_DPORTS_M,
+			 aclrule->action[2]);
+	for_each_set_bit(o, &srcs, YT921X_PORT_NUM) {
+		struct yt921x_port *pp = &priv->ports[o];
+		unsigned int i;
+
+		pp->acl_cnt++;
+
+		if (!aclrule->sw_assisted)
+			for_each_set_bit(i, &dsts, YT921X_PORT_NUM)
+				pp->acl_dst_cnts[i]++;
+	}
 
 	if (meterid < YT921X_METER_NUM)
 		set_bit(meterid, priv->meters_map);
-- 
2.53.0


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

* [PATCH net-next v5 6/7] net: dsa: destroy the bridge port before the leave on join rollback
  2026-12-06  2:20 [PATCH net-next v5 0/7] net: dsa: motorcomm: Reject isolated redirect targets David Yang
                   ` (4 preceding siblings ...)
  2026-12-06  2:20 ` [PATCH net-next v5 5/7] net: dsa: motorcomm: Reject bridge changes that break redirect rules David Yang
@ 2026-12-06  2:20 ` David Yang
  2026-12-06  2:20 ` [PATCH net-next v5 7/7] net: dsa: motorcomm: Recompute redirect rules on bridge changes David Yang
  6 siblings, 0 replies; 10+ messages in thread
From: David Yang @ 2026-12-06  2:20 UTC (permalink / raw)
  To: netdev
  Cc: David Yang, Andrew Lunn, Vladimir Oltean, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, Willem de Bruijn,
	Simon Horman

The join rollback broadcasts DSA_NOTIFIER_BRIDGE_LEAVE before the bridge
port is destroyed, so drivers' port_bridge_leave() see the port still
bridged, while anywhere else (join / leave) promise the effective
configuration is applied before that method is called.

Mirror the normal leave path and destroy first.

Signed-off-by: David Yang <mmyangfl@gmail.com>
---
 net/dsa/port.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/net/dsa/port.c b/net/dsa/port.c
index 54c970984095..66dba29fade8 100644
--- a/net/dsa/port.c
+++ b/net/dsa/port.c
@@ -509,8 +509,10 @@ int dsa_port_bridge_join(struct dsa_port *dp, struct net_device *br,
 
 	info.bridge = *dp->bridge;
 	err = dsa_broadcast(DSA_NOTIFIER_BRIDGE_JOIN, &info);
-	if (err)
-		goto out_rollback;
+	if (err) {
+		dsa_port_bridge_destroy(dp, br);
+		return err;
+	}
 
 	/* Drivers which support bridge TX forwarding should set this */
 	dp->bridge->tx_fwd_offload = info.tx_fwd_offload;
@@ -534,9 +536,11 @@ int dsa_port_bridge_join(struct dsa_port *dp, struct net_device *br,
 					&dsa_user_switchdev_blocking_notifier);
 	dsa_flush_workqueue();
 out_rollback_unbridge:
-	dsa_broadcast(DSA_NOTIFIER_BRIDGE_LEAVE, &info);
-out_rollback:
+	/* Align with dsa_port_bridge_leave(), so that drivers' implementations
+	 * always see the port unbridged.
+	 */
 	dsa_port_bridge_destroy(dp, br);
+	dsa_broadcast(DSA_NOTIFIER_BRIDGE_LEAVE, &info);
 	return err;
 }
 
-- 
2.53.0


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

* [PATCH net-next v5 7/7] net: dsa: motorcomm: Recompute redirect rules on bridge changes
  2026-12-06  2:20 [PATCH net-next v5 0/7] net: dsa: motorcomm: Reject isolated redirect targets David Yang
                   ` (5 preceding siblings ...)
  2026-12-06  2:20 ` [PATCH net-next v5 6/7] net: dsa: destroy the bridge port before the leave on join rollback David Yang
@ 2026-12-06  2:20 ` David Yang
  2026-12-06 11:19   ` kernel test robot
  2026-12-06 13:51   ` kernel test robot
  6 siblings, 2 replies; 10+ messages in thread
From: David Yang @ 2026-12-06  2:20 UTC (permalink / raw)
  To: netdev
  Cc: David Yang, Andrew Lunn, Vladimir Oltean, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, Willem de Bruijn,
	Simon Horman

Bridge join, leave and flag changes rewrite the isolation masks, so a
redirect rule that was trapped because of isolation may become
reachable again, and a reachable one may need software assistant.

Reload such non-skip_sw redirect rules accordingly. skip_sw rules are
not touched at all: they cannot be degraded, port_bridge_leave() cannot
be rejected (return value is void), nor can tc be told which rule got
invalidated. Warn if any skip_sw rules are invalidated.

Fixes: 8eb9e7520b17 ("net: dsa: yt921x: Add ACL support")
Signed-off-by: David Yang <mmyangfl@gmail.com>
---
 drivers/net/dsa/motorcomm/chip.c | 75 +++++++++++++++++++++++++++---
 drivers/net/dsa/motorcomm/chip.h |  2 +
 drivers/net/dsa/motorcomm/tc.c   | 80 ++++++++++++++++++++++++++++++++
 drivers/net/dsa/motorcomm/tc.h   |  2 +
 4 files changed, 153 insertions(+), 6 deletions(-)

diff --git a/drivers/net/dsa/motorcomm/chip.c b/drivers/net/dsa/motorcomm/chip.c
index 0bc03ead8d36..dd8e06da7b2a 100644
--- a/drivers/net/dsa/motorcomm/chip.c
+++ b/drivers/net/dsa/motorcomm/chip.c
@@ -1371,7 +1371,7 @@ yt921x_isolation_calc_bridge(struct yt921x_priv *priv, u16 ports_mask,
 	}
 }
 
-static void
+void
 yt921x_isolation_calc(struct yt921x_priv *priv, u16 *ports_maskp,
 		      u16 *isolation_masks)
 {
@@ -1496,12 +1496,40 @@ yt921x_bridge_join(struct yt921x_priv *priv, int port)
 	return 0;
 }
 
+static void
+yt921x_acl_refresh_extack(struct yt921x_priv *priv, int port, int res, int res2,
+			  struct netlink_ext_ack *extack)
+{
+	struct device *dev = yt921x_priv_to_device(priv);
+
+	if (!res || (res > 0 && res2 < 0))
+		res = res2;
+
+	if (res < 0)
+		if (extack)
+			NL_SET_ERR_MSG_FMT_MOD(extack,
+					       "Failed to refresh ACL rules: %i",
+					       res);
+		else
+			dev_err(dev, "Failed to refresh ACL rules for port %d: %i\n",
+				port, res);
+	else if (res > 0)
+		if (extack)
+			NL_SET_ERR_MSG_MOD(extack,
+					   "Could not reload some redirect rules due to skip_sw, they no longer work as expected");
+		else
+			dev_warn(dev, "Could not reload some redirect rules for port %d due to skip_sw, they no longer work as expected\n",
+				 port);
+}
+
 static int
 yt921x_bridge_flags(struct yt921x_priv *priv, int port,
-		    struct switchdev_brport_flags flags)
+		    struct switchdev_brport_flags flags,
+		    struct netlink_ext_ack *extack)
 {
 	u32 mask;
 	int res;
+	int ret;
 
 	if (flags.mask & BR_LEARNING) {
 		bool learning = flags.val & BR_LEARNING;
@@ -1520,9 +1548,23 @@ yt921x_bridge_flags(struct yt921x_priv *priv, int port,
 	/* BR_BCAST_FLOOD: we can filter bcast, but cannot trap them */
 
 	if ((flags.mask & BR_HAIRPIN_MODE) || (flags.mask & BR_ISOLATED)) {
-		res = yt921x_isolation_refresh(priv, BIT(port), true);
-		if (res)
-			return res;
+		int res1;
+		int res2;
+
+		res1 = yt921x_acl_refresh(priv, port, false);
+
+		ret = yt921x_isolation_refresh(priv, BIT(port), true);
+		if (!ret) {
+			int res2 = yt921x_acl_refresh(priv, port, true);
+
+			if (!res)
+				res = res2;
+		}
+		if (ret)
+			return ret;
+
+		res2 = yt921x_acl_refresh(priv, port, true);
+		yt921x_acl_refresh_extack(priv, port, res1, res2, extack);
 	}
 
 	return 0;
@@ -1597,7 +1639,7 @@ yt921x_dsa_port_bridge_flags(struct dsa_switch *ds, int port,
 		return 0;
 
 	mutex_lock(&priv->reg_lock);
-	res = yt921x_bridge_flags(priv, port, flags);
+	res = yt921x_bridge_flags(priv, port, flags, extack);
 	mutex_unlock(&priv->reg_lock);
 
 	return res;
@@ -1609,13 +1651,25 @@ yt921x_dsa_port_bridge_leave(struct dsa_switch *ds, int port,
 {
 	struct yt921x_priv *priv = dsa_to_yt921x_priv(ds);
 	struct device *dev = yt921x_priv_to_device(priv);
+	int res1;
+	int res2;
 	int res;
 
 	if (dsa_is_cpu_port(ds, port))
 		return;
 
 	mutex_lock(&priv->reg_lock);
+
+	res1 = yt921x_acl_refresh(priv, port, false);
+
 	res = yt921x_bridge_leave(priv, port);
+	if (res)
+		goto end;
+
+	res2 = yt921x_acl_refresh(priv, port, true);
+	yt921x_acl_refresh_extack(priv, port, res1, res2, NULL);
+
+end:
 	mutex_unlock(&priv->reg_lock);
 
 	if (res)
@@ -1630,6 +1684,8 @@ yt921x_dsa_port_bridge_join(struct dsa_switch *ds, int port,
 {
 	struct yt921x_priv *priv = dsa_to_yt921x_priv(ds);
 	u16 isolation_mask;
+	int res1;
+	int res2;
 	int res;
 
 	if (dsa_is_cpu_port(ds, port))
@@ -1649,7 +1705,14 @@ yt921x_dsa_port_bridge_join(struct dsa_switch *ds, int port,
 		goto end;
 	}
 
+	res1 = yt921x_acl_refresh(priv, port, false);
+
 	res = yt921x_bridge_join(priv, port);
+	if (res)
+		goto end;
+
+	res2 = yt921x_acl_refresh(priv, port, true);
+	yt921x_acl_refresh_extack(priv, port, res1, res2, extack);
 
 end:
 	mutex_unlock(&priv->reg_lock);
diff --git a/drivers/net/dsa/motorcomm/chip.h b/drivers/net/dsa/motorcomm/chip.h
index 4085a3c52f20..55876707126e 100644
--- a/drivers/net/dsa/motorcomm/chip.h
+++ b/drivers/net/dsa/motorcomm/chip.h
@@ -560,6 +560,8 @@ static inline u32 ethaddr_lo2_to_u32(const unsigned char *addr)
 	return (addr[4] << 8) | addr[5];
 }
 
+void yt921x_isolation_calc(struct yt921x_priv *priv, u16 *ports_maskp,
+			   u16 *isolation_masks);
 u16 yt921x_isolation_calc_port(struct yt921x_priv *priv, int port);
 
 #endif
diff --git a/drivers/net/dsa/motorcomm/tc.c b/drivers/net/dsa/motorcomm/tc.c
index b4c531ea9664..00c6f5ab02b3 100644
--- a/drivers/net/dsa/motorcomm/tc.c
+++ b/drivers/net/dsa/motorcomm/tc.c
@@ -1394,6 +1394,86 @@ yt921x_acl_commit(struct yt921x_priv *priv, unsigned int entid, u8 entsmask)
 	return 0;
 }
 
+/* To ensure no frames are dropped during isolation update, two passes are
+ * required for refreshing: trap rules (redirect to software) which may be
+ * blocked by the new mask, then untrap fully offloadable ones after new mask
+ * is applied.
+ *
+ * Only non-skip_sw rules are refreshed: skip_sw rules cannot be degraded,
+ * port_bridge_leave() cannot be rejected (return value is void), nor can tc be
+ * told which rule got invalidated.
+ *
+ * Return 1 if any skip_sw rules are now invalidated.
+ */
+int yt921x_acl_refresh(struct yt921x_priv *priv, int port, bool untrap)
+{
+	u16 isolation_masks[YT921X_PORT_NUM];
+	bool inability = false;
+	int res;
+	int ret;
+
+	yt921x_isolation_calc(priv, NULL, isolation_masks);
+
+	ret = 0;
+
+	for (unsigned int blkid = 0; blkid < YT921X_ACL_BLK_NUM; blkid++) {
+		const struct yt921x_acl_blk *aclblk = priv->acl_blks[blkid];
+		unsigned long dsts;
+		unsigned long srcs;
+		unsigned int o;
+		bool assisting;
+
+		if (!aclblk)
+			continue;
+
+		for (unsigned int i = 0; i < YT921X_ACL_ENT_PER_BLK; i++) {
+			struct yt921x_acl_rule *aclrule;
+			unsigned int entid;
+
+			aclrule = aclblk->rules[i];
+			if (!aclrule)
+				continue;
+
+			if (!(aclrule->action[2] & YT921X_ACL_ACTc_FWD_EN) ||
+			    (aclrule->action[2] & YT921X_ACL_ACTc_FWD_M) !=
+			    YT921X_ACL_ACTc_FWD_REDIR)
+				continue;
+
+			srcs = FIELD_GET(YT921X_ACL_KEYb_SPORTS_M,
+					 aclrule->entries[0].key[1]);
+			dsts = FIELD_GET(YT921X_ACL_ACTc_FWD_REDIR_DPORTS_M,
+					 aclrule->action[2]);
+			if (!((srcs | dsts) & BIT(port)))
+				continue;
+
+			assisting = false;
+			for_each_set_bit(o, &srcs, YT921X_PORT_NUM)
+				if (dsts & isolation_masks[o]) {
+					assisting = true;
+					break;
+				}
+
+			if (!aclrule->sw_assisted) {
+				if (assisting)
+					inability = true;
+				continue;
+			}
+
+			entid = YT921X_ACL_ENT_PER_BLK * blkid + i;
+
+			if (aclrule->sw_assisting != assisting &&
+			    assisting != untrap) {
+				aclrule->sw_assisting = assisting;
+				res = yt921x_acl_commit(priv, entid, 0);
+				if (res && !ret)
+					ret = res;
+			}
+		}
+	}
+
+	return ret ? ret : inability ? 1 : 0;
+}
+
 static int
 yt921x_acl_del(struct yt921x_priv *priv, enum tc_setup_type type,
 	       unsigned long tag, u16 ports_mask)
diff --git a/drivers/net/dsa/motorcomm/tc.h b/drivers/net/dsa/motorcomm/tc.h
index 81c29a8eec5a..fb58beec8e13 100644
--- a/drivers/net/dsa/motorcomm/tc.h
+++ b/drivers/net/dsa/motorcomm/tc.h
@@ -371,6 +371,8 @@ yt921x_dsa_port_policer_add(struct dsa_switch *ds, int port,
 int
 yt921x_dsa_port_setup_tc(struct dsa_switch *ds, int port,
 			 enum tc_setup_type type, void *type_data);
+
+int yt921x_acl_refresh(struct yt921x_priv *priv, int port, bool untrap);
 int
 yt921x_dsa_cls_flower_del(struct dsa_switch *ds, int port,
 			  struct flow_cls_offload *cls, bool ingress);
-- 
2.53.0


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

* Re: [PATCH net-next v5 7/7] net: dsa: motorcomm: Recompute redirect rules on bridge changes
  2026-12-06  2:20 ` [PATCH net-next v5 7/7] net: dsa: motorcomm: Recompute redirect rules on bridge changes David Yang
@ 2026-12-06 11:19   ` kernel test robot
  2026-12-06 13:51   ` kernel test robot
  1 sibling, 0 replies; 10+ messages in thread
From: kernel test robot @ 2026-12-06 11:19 UTC (permalink / raw)
  To: David Yang, netdev
  Cc: oe-kbuild-all, David Yang, Andrew Lunn, Vladimir Oltean,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, Willem de Bruijn,
	Simon Horman

Hi David,

kernel test robot noticed the following build warnings:

[auto build test WARNING on net-next/main]

url:    https://github.com/intel-lab-lkp/linux/commits/David-Yang/net-dsa-motorcomm-Remove-local-cpu_ports_mask/20261206-102032
base:   net-next/main
patch link:    https://lore.kernel.org/r/20261206022040.4020726-8-mmyangfl%40gmail.com
patch subject: [PATCH net-next v5 7/7] net: dsa: motorcomm: Recompute redirect rules on bridge changes
config: parisc-randconfig-1000-20261206 (https://download.01.org/0day-ci/archive/20261206/20261206191337.dwvguvoV-lkp@intel.com/config)
compiler: hppa-linux-gcc (GCC) 12.5.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20261206/20261206191337.dwvguvoV-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/20261206191337.dwvguvoV-lkp@intel.com/

All warnings (new ones prefixed by >>):

   drivers/net/dsa/motorcomm/chip.c: In function 'yt921x_acl_refresh_extack':
>> drivers/net/dsa/motorcomm/chip.c:1516:17: warning: suggest explicit braces to avoid ambiguous 'else' [-Wdangling-else]
    1516 |         else if (res > 0)
         |                 ^


vim +/else +1516 drivers/net/dsa/motorcomm/chip.c

  1498	
  1499	static void
  1500	yt921x_acl_refresh_extack(struct yt921x_priv *priv, int port, int res, int res2,
  1501				  struct netlink_ext_ack *extack)
  1502	{
  1503		struct device *dev = yt921x_priv_to_device(priv);
  1504	
  1505		if (!res || (res > 0 && res2 < 0))
  1506			res = res2;
  1507	
  1508		if (res < 0)
  1509			if (extack)
  1510				NL_SET_ERR_MSG_FMT_MOD(extack,
  1511						       "Failed to refresh ACL rules: %i",
  1512						       res);
  1513			else
  1514				dev_err(dev, "Failed to refresh ACL rules for port %d: %i\n",
  1515					port, res);
> 1516		else if (res > 0)
  1517			if (extack)
  1518				NL_SET_ERR_MSG_MOD(extack,
  1519						   "Could not reload some redirect rules due to skip_sw, they no longer work as expected");
  1520			else
  1521				dev_warn(dev, "Could not reload some redirect rules for port %d due to skip_sw, they no longer work as expected\n",
  1522					 port);
  1523	}
  1524	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

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

* Re: [PATCH net-next v5 7/7] net: dsa: motorcomm: Recompute redirect rules on bridge changes
  2026-12-06  2:20 ` [PATCH net-next v5 7/7] net: dsa: motorcomm: Recompute redirect rules on bridge changes David Yang
  2026-12-06 11:19   ` kernel test robot
@ 2026-12-06 13:51   ` kernel test robot
  1 sibling, 0 replies; 10+ messages in thread
From: kernel test robot @ 2026-12-06 13:51 UTC (permalink / raw)
  To: David Yang, netdev
  Cc: llvm, oe-kbuild-all, David Yang, Andrew Lunn, Vladimir Oltean,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, Willem de Bruijn,
	Simon Horman

Hi David,

kernel test robot noticed the following build warnings:

[auto build test WARNING on net-next/main]

url:    https://github.com/intel-lab-lkp/linux/commits/David-Yang/net-dsa-motorcomm-Remove-local-cpu_ports_mask/20261206-102032
base:   net-next/main
patch link:    https://lore.kernel.org/r/20261206022040.4020726-8-mmyangfl%40gmail.com
patch subject: [PATCH net-next v5 7/7] net: dsa: motorcomm: Recompute redirect rules on bridge changes
config: loongarch-allmodconfig (https://download.01.org/0day-ci/archive/20261206/20261206214303.3mqK1s6q-lkp@intel.com/config)
compiler: clang version 19.1.7 (https://github.com/llvm/llvm-project cd708029e0b2869e80abe31ddb175f7c35361f90)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20261206/20261206214303.3mqK1s6q-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/20261206214303.3mqK1s6q-lkp@intel.com/

All warnings (new ones prefixed by >>):

>> drivers/net/dsa/motorcomm/chip.c:1520:3: warning: add explicit braces to avoid dangling else [-Wdangling-else]
    1520 |                 else
         |                 ^
   1 warning generated.


vim +1520 drivers/net/dsa/motorcomm/chip.c

  1498	
  1499	static void
  1500	yt921x_acl_refresh_extack(struct yt921x_priv *priv, int port, int res, int res2,
  1501				  struct netlink_ext_ack *extack)
  1502	{
  1503		struct device *dev = yt921x_priv_to_device(priv);
  1504	
  1505		if (!res || (res > 0 && res2 < 0))
  1506			res = res2;
  1507	
  1508		if (res < 0)
  1509			if (extack)
  1510				NL_SET_ERR_MSG_FMT_MOD(extack,
  1511						       "Failed to refresh ACL rules: %i",
  1512						       res);
  1513			else
  1514				dev_err(dev, "Failed to refresh ACL rules for port %d: %i\n",
  1515					port, res);
  1516		else if (res > 0)
  1517			if (extack)
  1518				NL_SET_ERR_MSG_MOD(extack,
  1519						   "Could not reload some redirect rules due to skip_sw, they no longer work as expected");
> 1520			else
  1521				dev_warn(dev, "Could not reload some redirect rules for port %d due to skip_sw, they no longer work as expected\n",
  1522					 port);
  1523	}
  1524	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

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

end of thread, other threads:[~2026-12-06 13:51 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-06  2:20 [PATCH net-next v5 0/7] net: dsa: motorcomm: Reject isolated redirect targets David Yang
2026-12-06  2:20 ` [PATCH net-next v5 1/7] net: dsa: motorcomm: Remove local cpu_ports_mask David Yang
2026-12-06  2:20 ` [PATCH net-next v5 2/7] net: dsa: motorcomm: Do not block hairpins on standalone ports David Yang
2026-12-06  2:20 ` [PATCH net-next v5 3/7] net: dsa: motorcomm: Derive port isolation masks on the fly David Yang
2026-12-06  2:20 ` [PATCH net-next v5 4/7] net: dsa: motorcomm: Reject isolated redirect targets David Yang
2026-12-06  2:20 ` [PATCH net-next v5 5/7] net: dsa: motorcomm: Reject bridge changes that break redirect rules David Yang
2026-12-06  2:20 ` [PATCH net-next v5 6/7] net: dsa: destroy the bridge port before the leave on join rollback David Yang
2026-12-06  2:20 ` [PATCH net-next v5 7/7] net: dsa: motorcomm: Recompute redirect rules on bridge changes David Yang
2026-12-06 11:19   ` kernel test robot
2026-12-06 13:51   ` kernel test robot

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