Netdev List
 help / color / mirror / Atom feed
From: David Yang <mmyangfl@gmail.com>
To: netdev@vger.kernel.org
Cc: David Yang <mmyangfl@gmail.com>, Andrew Lunn <andrew@lunn.ch>,
	Vladimir Oltean <olteanv@gmail.com>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@kernel.org>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>
Subject: [PATCH net-next v2 4/5] net: dsa: motorcomm: Recompute redirect rules on bridge changes
Date: Sun, 29 Nov 2026 19:55:51 +0800	[thread overview]
Message-ID: <20261129115556.1669188-5-mmyangfl@gmail.com> (raw)
In-Reply-To: <20261129115556.1669188-1-mmyangfl@gmail.com>

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 become trapped.

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.

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

diff --git a/drivers/net/dsa/motorcomm/chip.c b/drivers/net/dsa/motorcomm/chip.c
index bd89823aac55..7282bc0693eb 100644
--- a/drivers/net/dsa/motorcomm/chip.c
+++ b/drivers/net/dsa/motorcomm/chip.c
@@ -1401,6 +1401,7 @@ static int
 yt921x_bridge_flags(struct yt921x_priv *priv, int port,
 		    struct switchdev_brport_flags flags)
 {
+	struct device *dev = yt921x_priv_to_device(priv);
 	struct yt921x_port *pp = &priv->ports[port];
 	bool do_flush;
 	u32 mask;
@@ -1446,6 +1447,14 @@ yt921x_bridge_flags(struct yt921x_priv *priv, int port,
 			if (res)
 				return res;
 		}
+
+		res = yt921x_acl_recompute(priv, port);
+		if (res) {
+			dev_err(dev,
+				"Failed to refresh ACL rules for port %d: %i\n",
+				port, res);
+			res = 0;
+		}
 	}
 
 	return 0;
@@ -1492,7 +1501,19 @@ yt921x_dsa_port_bridge_leave(struct dsa_switch *ds, int port,
 		return;
 
 	mutex_lock(&priv->reg_lock);
+
 	res = yt921x_bridge_leave(priv, port);
+	if (res)
+		goto end;
+
+	res = yt921x_acl_recompute(priv, port);
+	if (res) {
+		dev_err(dev, "Failed to refresh ACL rules for port %d: %i\n",
+			port, res);
+		res = 0;
+	}
+
+end:
 	mutex_unlock(&priv->reg_lock);
 
 	if (res)
@@ -1506,6 +1527,7 @@ 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 device *dev = yt921x_priv_to_device(priv);
 	struct yt921x_port *pp = &priv->ports[port];
 	struct net_device *brport_dev;
 	struct dsa_port *dp;
@@ -1522,9 +1544,21 @@ yt921x_dsa_port_bridge_join(struct dsa_switch *ds, int 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);
+	if (res)
+		goto end;
+
+	res = yt921x_acl_recompute(priv, port);
+	if (res) {
+		dev_err(dev, "Failed to refresh ACL rules for port %d: %i\n",
+			port, res);
+		res = 0;
+	}
+
+end:
 	mutex_unlock(&priv->reg_lock);
 
 	return res;
diff --git a/drivers/net/dsa/motorcomm/tc.c b/drivers/net/dsa/motorcomm/tc.c
index 20edfd53b230..146db2a37c26 100644
--- a/drivers/net/dsa/motorcomm/tc.c
+++ b/drivers/net/dsa/motorcomm/tc.c
@@ -1394,6 +1394,56 @@ yt921x_acl_commit(struct yt921x_priv *priv, unsigned int entid, u8 entsmask)
 	return 0;
 }
 
+/* Only non-skip_sw rules are refreshes; 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.
+ */
+int yt921x_acl_recompute(struct yt921x_priv *priv, int port)
+{
+	int res;
+
+	for (unsigned int blkid = 0; blkid < YT921X_ACL_BLK_NUM; blkid++) {
+		const struct yt921x_acl_blk *aclblk = priv->acl_blks[blkid];
+
+		if (!aclblk)
+			continue;
+
+		for (unsigned int i = 0; i < YT921X_ACL_ENT_PER_BLK; i++) {
+			struct yt921x_acl_rule *aclrule;
+			unsigned int entid;
+			u32 *action;
+			u32 dsts;
+			int src;
+
+			aclrule = aclblk->rules[i];
+			if (!aclrule || !aclrule->sw_assisted)
+				continue;
+
+			action = aclrule->action;
+			if (!(action[2] & YT921X_ACL_ACTc_FWD_EN) ||
+			    (action[2] & YT921X_ACL_ACTc_FWD_M) !=
+			    YT921X_ACL_ACTc_FWD_REDIR)
+				continue;
+
+			src = ffs(aclrule->entries[0].key[1] &
+				  YT921X_ACL_KEYb_SPORTS_M) - 1;
+			dsts = FIELD_GET(YT921X_ACL_ACTc_FWD_REDIR_DPORTS_M,
+					 action[2]);
+			if (src != port && !(dsts & BIT(port)))
+				continue;
+
+			aclrule->sw_assisting =
+				!!(dsts & priv->ports[src].isolation_mask);
+			entid = YT921X_ACL_ENT_PER_BLK * blkid + i;
+			res = yt921x_acl_commit(priv, entid, aclrule->mask);
+			if (res)
+				return res;
+		}
+	}
+
+	return 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..be4c258873b8 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_recompute(struct yt921x_priv *priv, int port);
 int
 yt921x_dsa_cls_flower_del(struct dsa_switch *ds, int port,
 			  struct flow_cls_offload *cls, bool ingress);
-- 
2.53.0


  parent reply	other threads:[~2026-11-29 11:57 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-29 11:55 [PATCH net-next v2 0/5] net: dsa: motorcomm: Reject isolated redirect targets David Yang
2026-11-29 11:55 ` [PATCH net-next v2 1/5] net: dsa: motorcomm: Remove local cpu_ports_mask David Yang
2026-11-29 11:55 ` [PATCH net-next v2 2/5] net: dsa: motorcomm: Cache port isolation masks David Yang
2026-11-29 11:55 ` [PATCH net-next v2 3/5] net: dsa: motorcomm: Reject isolated redirect targets David Yang
2026-11-29 11:55 ` David Yang [this message]
2026-11-29 11:55 ` [PATCH net-next v2 5/5] net: dsa: motorcomm: Reject bridge flags that break redirect rules David Yang

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=20261129115556.1669188-5-mmyangfl@gmail.com \
    --to=mmyangfl@gmail.com \
    --cc=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=kuba@kernel.org \
    --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