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>,
Willem de Bruijn <willemb@google.com>,
Simon Horman <horms@kernel.org>
Subject: [PATCH net-next v5 7/7] net: dsa: motorcomm: Recompute redirect rules on bridge changes
Date: Sun, 6 Dec 2026 10:20:38 +0800 [thread overview]
Message-ID: <20261206022040.4020726-8-mmyangfl@gmail.com> (raw)
In-Reply-To: <20261206022040.4020726-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 | 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
prev parent reply other threads:[~2026-12-06 2:21 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
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 ` 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=20261206022040.4020726-8-mmyangfl@gmail.com \
--to=mmyangfl@gmail.com \
--cc=andrew@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=olteanv@gmail.com \
--cc=pabeni@redhat.com \
--cc=willemb@google.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