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 v4 6/6] net: dsa: motorcomm: Recompute redirect rules on bridge changes
Date: Fri, 4 Dec 2026 18:12:57 +0800 [thread overview]
Message-ID: <20261204101300.3680838-7-mmyangfl@gmail.com> (raw)
In-Reply-To: <20261204101300.3680838-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 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 | 53 ++++++++++++++++++++---
drivers/net/dsa/motorcomm/chip.h | 2 +
drivers/net/dsa/motorcomm/tc.c | 74 ++++++++++++++++++++++++++++++++
drivers/net/dsa/motorcomm/tc.h | 2 +
4 files changed, 125 insertions(+), 6 deletions(-)
diff --git a/drivers/net/dsa/motorcomm/chip.c b/drivers/net/dsa/motorcomm/chip.c
index 323c1705f613..dc64ec1e310d 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_ports(struct yt921x_priv *priv, u16 *ports_maskp,
u16 *isolation_masks)
{
@@ -1488,12 +1488,25 @@ yt921x_bridge_join(struct yt921x_priv *priv, int port)
return 0;
}
+static void yt921x_acl_refresh_extack(int res, struct netlink_ext_ack *extack)
+{
+ if (res < 0)
+ NL_SET_ERR_MSG_FMT_MOD(extack,
+ "Failed to refresh ACL rules: %i\n",
+ res);
+ else if (res > 0)
+ NL_SET_ERR_MSG_MOD(extack,
+ "Could not reload some redirect rules due to skip_sw, they no longer work as expected\n");
+}
+
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;
@@ -1512,9 +1525,17 @@ 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;
+ /* Trap the rules first, so no frame is dropped in between */
+ res = yt921x_acl_refresh(priv, port);
+ /* Refresh failure is not considered fatal, though the hardware
+ * is likely desynced
+ */
+
+ ret = yt921x_isolation_refresh(priv, BIT(port), true);
+ if (ret)
+ return ret;
+
+ yt921x_acl_refresh_extack(res, extack);
}
return 0;
@@ -1586,7 +1607,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;
@@ -1604,7 +1625,17 @@ yt921x_dsa_port_bridge_leave(struct dsa_switch *ds, int port,
return;
mutex_lock(&priv->reg_lock);
+
+ res = yt921x_acl_refresh(priv, port);
+ if (res < 0)
+ dev_err(dev, "Failed to refresh ACL rules for port %d: %i\n",
+ port, res);
+ else if (res > 0)
+ dev_warn(dev, "Could not reload some redirect rules for port %d due to skip_sw, they no longer work as expected\n",
+ port);
+
res = yt921x_bridge_leave(priv, port);
+
mutex_unlock(&priv->reg_lock);
if (res)
@@ -1625,6 +1656,16 @@ yt921x_dsa_port_bridge_join(struct dsa_switch *ds, int port,
mutex_lock(&priv->reg_lock);
res = yt921x_bridge_join(priv, port);
+ if (res)
+ goto end;
+
+ res = yt921x_acl_refresh(priv, port);
+ if (res) {
+ yt921x_acl_refresh_extack(res, extack);
+ res = 0;
+ }
+
+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 4085a3c52f20..0484d1bb2e44 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_ports(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 7691da95d76f..00c632447b3c 100644
--- a/drivers/net/dsa/motorcomm/tc.c
+++ b/drivers/net/dsa/motorcomm/tc.c
@@ -1393,6 +1393,80 @@ 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.
+ *
+ * Return 1 if any skip_sw rules are now invalidated.
+ */
+int yt921x_acl_refresh(struct yt921x_priv *priv, int port)
+{
+ u16 isolation_masks[YT921X_PORT_NUM];
+ bool inability = false;
+ u16 ports_maskp = ~0;
+ int res;
+ int ret;
+
+ yt921x_isolation_calc_ports(priv, &ports_maskp, 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) {
+ inability = true;
+ continue;
+ }
+
+ entid = YT921X_ACL_ENT_PER_BLK * blkid + i;
+ if (aclrule->sw_assisting != assisting) {
+ aclrule->sw_assisting = assisting;
+ res = yt921x_acl_commit(priv, entid,
+ aclrule->mask);
+ 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..8712a4f3af2d 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);
int
yt921x_dsa_cls_flower_del(struct dsa_switch *ds, int port,
struct flow_cls_offload *cls, bool ingress);
--
2.53.0
prev parent reply other threads:[~2026-12-04 10:13 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-04 10:12 [PATCH net-next v4 0/6] net: dsa: motorcomm: Reject isolated redirect targets David Yang
2026-12-04 10:12 ` [PATCH net-next v4 1/6] net: dsa: motorcomm: Remove local cpu_ports_mask David Yang
2026-12-04 10:12 ` [PATCH net-next v4 2/6] net: dsa: motorcomm: Do not block hairpins on standalone ports David Yang
2026-12-04 10:12 ` [PATCH net-next v4 3/6] net: dsa: motorcomm: Derive port isolation masks on the fly David Yang
2026-12-04 10:12 ` [PATCH net-next v4 4/6] net: dsa: motorcomm: Reject isolated redirect targets David Yang
2026-12-04 10:12 ` [PATCH net-next v4 5/6] net: dsa: motorcomm: Reject bridge flags that break redirect rules David Yang
2026-12-04 10:12 ` 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=20261204101300.3680838-7-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