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 v3 5/5] net: dsa: motorcomm: Recompute redirect rules on bridge changes
Date: Tue,  1 Dec 2026 16:14:56 +0800	[thread overview]
Message-ID: <20261201081459.2104904-6-mmyangfl@gmail.com> (raw)
In-Reply-To: <20261201081459.2104904-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 | 33 +++++++++++++
 drivers/net/dsa/motorcomm/tc.c   | 79 ++++++++++++++++++++++++++++++++
 drivers/net/dsa/motorcomm/tc.h   |  2 +
 3 files changed, 114 insertions(+)

diff --git a/drivers/net/dsa/motorcomm/chip.c b/drivers/net/dsa/motorcomm/chip.c
index 0bc5da2b80d7..a5e673a69355 100644
--- a/drivers/net/dsa/motorcomm/chip.c
+++ b/drivers/net/dsa/motorcomm/chip.c
@@ -1398,6 +1398,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);
 	u32 mask;
 	int res;
 
@@ -1431,6 +1432,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;
@@ -1531,7 +1540,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)
@@ -1545,6 +1566,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;
@@ -1564,6 +1586,17 @@ yt921x_dsa_port_bridge_join(struct dsa_switch *ds, int port,
 	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 9a19ee7d4358..210f7af3a206 100644
--- a/drivers/net/dsa/motorcomm/tc.c
+++ b/drivers/net/dsa/motorcomm/tc.c
@@ -1393,6 +1393,85 @@ yt921x_acl_commit(struct yt921x_priv *priv, unsigned int entid, u8 entsmask)
 	return 0;
 }
 
+static int
+yt921x_acl_recompute_rule(struct yt921x_priv *priv, int port,
+			  unsigned int entid)
+{
+	const struct yt921x_acl_blk *aclblk;
+	struct yt921x_acl_rule *aclrule;
+	unsigned int blkid;
+	unsigned int binid;
+	unsigned long dsts;
+	unsigned long srcs;
+	unsigned int o;
+	bool assisting;
+	int res;
+
+	blkid = entid / YT921X_ACL_ENT_PER_BLK;
+	binid = entid % YT921X_ACL_ENT_PER_BLK;
+	aclblk = priv->acl_blks[blkid];
+	aclrule = aclblk->rules[binid];
+
+	if (!(aclrule->action[2] & YT921X_ACL_ACTc_FWD_EN) ||
+	    (aclrule->action[2] & YT921X_ACL_ACTc_FWD_M) !=
+	    YT921X_ACL_ACTc_FWD_REDIR)
+		return 0;
+
+	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)))
+		return 0;
+
+	assisting = false;
+	for_each_set_bit(o, &srcs, YT921X_PORT_NUM)
+		if (dsts & priv->ports[o].isolation_mask) {
+			assisting = true;
+			break;
+		}
+
+	if (aclrule->sw_assisting != assisting) {
+		aclrule->sw_assisting = assisting;
+		res = yt921x_acl_commit(priv, entid, aclrule->mask);
+		if (res)
+			return res;
+	}
+
+	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;
+
+			aclrule = aclblk->rules[i];
+			if (!aclrule || !aclrule->sw_assisted)
+				continue;
+
+			entid = YT921X_ACL_ENT_PER_BLK * blkid + i;
+			res = yt921x_acl_recompute_rule(priv, port, entid);
+			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-12-01  8:16 UTC|newest]

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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261201081459.2104904-6-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