* [PATCH net-next v2 1/5] net: dsa: motorcomm: Remove local cpu_ports_mask
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 ` David Yang
2026-11-29 11:55 ` [PATCH net-next v2 2/5] net: dsa: motorcomm: Cache port isolation masks David Yang
` (3 subsequent siblings)
4 siblings, 0 replies; 10+ messages in thread
From: David Yang @ 2026-11-29 11:55 UTC (permalink / raw)
To: netdev
Cc: David Yang, Andrew Lunn, Vladimir Oltean, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni
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 a21d4bb5e141..49c9055c7512 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);
@@ -2377,10 +2378,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;
@@ -2417,7 +2418,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 v2 2/5] net: dsa: motorcomm: Cache port isolation masks
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 ` David Yang
2026-11-30 12:25 ` netdev-bot+sashiko
2026-11-29 11:55 ` [PATCH net-next v2 3/5] net: dsa: motorcomm: Reject isolated redirect targets David Yang
` (2 subsequent siblings)
4 siblings, 1 reply; 10+ messages in thread
From: David Yang @ 2026-11-29 11:55 UTC (permalink / raw)
To: netdev
Cc: David Yang, Andrew Lunn, Vladimir Oltean, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni
Keep a software copy of PORTn_ISOLATION values for future use.
Signed-off-by: David Yang <mmyangfl@gmail.com>
---
drivers/net/dsa/motorcomm/chip.c | 6 ++++++
drivers/net/dsa/motorcomm/chip.h | 2 ++
2 files changed, 8 insertions(+)
diff --git a/drivers/net/dsa/motorcomm/chip.c b/drivers/net/dsa/motorcomm/chip.c
index 49c9055c7512..bd89823aac55 100644
--- a/drivers/net/dsa/motorcomm/chip.c
+++ b/drivers/net/dsa/motorcomm/chip.c
@@ -1256,6 +1256,7 @@ yt921x_dsa_port_vlan_add(struct dsa_switch *ds, int port,
static int yt921x_userport_standalone(struct yt921x_priv *priv, int port)
{
+ struct yt921x_port *pp = &priv->ports[port];
struct dsa_switch *ds = &priv->ds;
u32 mask;
u32 ctrl;
@@ -1265,6 +1266,7 @@ static int yt921x_userport_standalone(struct yt921x_priv *priv, int port)
res = yt921x_reg_write(priv, YT921X_PORTn_ISOLATION(port), ctrl);
if (res)
return res;
+ pp->isolation_mask = ctrl;
/* Turn off FDB learning to prevent FDB pollution */
mask = YT921X_PORT_LEARN_DIS;
@@ -1314,6 +1316,7 @@ static int yt921x_isolate(struct yt921x_priv *priv, int port)
mask);
if (res)
return res;
+ priv->ports[i].isolation_mask |= mask;
}
return 0;
@@ -1357,6 +1360,7 @@ static int yt921x_bridge(struct yt921x_priv *priv, u16 ports_mask)
ctrl);
if (res)
return res;
+ pp->isolation_mask = ctrl;
}
return 0;
@@ -2046,6 +2050,7 @@ yt921x_dsa_phylink_get_caps(struct dsa_switch *ds, int port,
static int yt921x_port_setup(struct yt921x_priv *priv, int port)
{
+ struct yt921x_port *pp = &priv->ports[port];
struct dsa_switch *ds = &priv->ds;
u32 ctrl;
int res;
@@ -2071,6 +2076,7 @@ static int yt921x_port_setup(struct yt921x_priv *priv, int port)
ctrl);
if (res)
return res;
+ pp->isolation_mask = ctrl;
/* To simplify FDB "isolation" simulation, we also disable
* learning on the CPU port, and let software identify packets
diff --git a/drivers/net/dsa/motorcomm/chip.h b/drivers/net/dsa/motorcomm/chip.h
index d5ed580f8a78..39b7721cff40 100644
--- a/drivers/net/dsa/motorcomm/chip.h
+++ b/drivers/net/dsa/motorcomm/chip.h
@@ -464,6 +464,8 @@ struct yt921x_port {
unsigned short acl_cnt;
+ u16 isolation_mask;
+
#if IS_ENABLED(CONFIG_NET_DSA_YT921X_LEDS)
unsigned char led_duty;
unsigned short led_cycle;
--
2.53.0
^ permalink raw reply related [flat|nested] 10+ messages in thread* Re: [PATCH net-next v2 2/5] net: dsa: motorcomm: Cache port isolation masks
2026-11-29 11:55 ` [PATCH net-next v2 2/5] net: dsa: motorcomm: Cache port isolation masks David Yang
@ 2026-11-30 12:25 ` netdev-bot+sashiko
0 siblings, 0 replies; 10+ messages in thread
From: netdev-bot+sashiko @ 2026-11-30 12:25 UTC (permalink / raw)
To: mmyangfl; +Cc: netdev, andrew, olteanv, davem, edumazet, kuba, pabeni
Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] This patch adds `isolation_mask` to `struct yt921x_port`
(drivers/net/dsa/motorcomm/chip.h) and sets it in four places in…
--
net: dsa: motorcomm: Cache port isolation masks
This commit adds an isolation_mask field to struct yt921x_port. It keeps
a software copy of each port's YT921X_PORTn_ISOLATION register, updated
after each successful register write.
[ ... ]
> diff --git a/drivers/net/dsa/motorcomm/chip.h b/drivers/net/dsa/motorcomm/chip.h
> index d5ed580f8a78e..39b7721cff402 100644
> --- a/drivers/net/dsa/motorcomm/chip.h
> +++ b/drivers/net/dsa/motorcomm/chip.h
> @@ -464,6 +464,8 @@ struct yt921x_port {
>
> unsigned short acl_cnt;
>
> + u16 isolation_mask;
> +
[Severity: Low]
This isn't a bug, but nothing reads isolation_mask at this commit. Only
these functions write it:
yt921x_userport_standalone()
yt921x_isolate()
yt921x_bridge()
yt921x_port_setup()
The commit message only says:
Keep a software copy of PORTn_ISOLATION values for future use.
The code that reads it seems to come later in the series. It is in the
redirect handling in drivers/net/dsa/motorcomm/tc.c, added by "net: dsa:
motorcomm: Reject isolated redirect targets" and "net: dsa: motorcomm:
Recompute redirect rules on bridge changes".
Could the commit message say which later patches use the cache?
> #if IS_ENABLED(CONFIG_NET_DSA_YT921X_LEDS)
> unsigned char led_duty;
> unsigned short led_cycle;
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261129115556.1669188-1-mmyangfl%40gmail.com
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH net-next v2 3/5] net: dsa: motorcomm: Reject isolated redirect targets
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 ` David Yang
2026-11-30 12:25 ` netdev-bot+sashiko
2026-11-29 11:55 ` [PATCH net-next v2 4/5] net: dsa: motorcomm: Recompute redirect rules on bridge changes David Yang
2026-11-29 11:55 ` [PATCH net-next v2 5/5] net: dsa: motorcomm: Reject bridge flags that break redirect rules David Yang
4 siblings, 1 reply; 10+ messages in thread
From: David Yang @ 2026-11-29 11:55 UTC (permalink / raw)
To: netdev
Cc: David Yang, Andrew Lunn, Vladimir Oltean, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni
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/tc.c | 34 ++++++++++++++++++++++++++++++++--
drivers/net/dsa/motorcomm/tc.h | 6 +++++-
2 files changed, 37 insertions(+), 3 deletions(-)
diff --git a/drivers/net/dsa/motorcomm/tc.c b/drivers/net/dsa/motorcomm/tc.c
index e3f057ed580f..20edfd53b230 100644
--- a/drivers/net/dsa/motorcomm/tc.c
+++ b/drivers/net/dsa/motorcomm/tc.c
@@ -1030,6 +1030,7 @@ yt921x_acl_rule_ext_parse_flow_action(struct yt921x_acl_rule_ext *ruleext,
const struct flow_rule *rule = flow_cls_offload_flow_rule(cls);
const struct flow_action *flow_action = &rule->action;
struct netlink_ext_ack *extack = cls->common.extack;
+ struct yt921x_port *pp = &priv->ports[port];
const struct flow_action_entry *act;
u32 *action = ruleext->r.action;
bool seen_priority = false;
@@ -1041,6 +1042,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 +1075,20 @@ 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 (pp->isolation_mask & 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);
@@ -1301,8 +1318,20 @@ 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* Re: [PATCH net-next v2 3/5] net: dsa: motorcomm: Reject isolated redirect targets
2026-11-29 11:55 ` [PATCH net-next v2 3/5] net: dsa: motorcomm: Reject isolated redirect targets David Yang
@ 2026-11-30 12:25 ` netdev-bot+sashiko
0 siblings, 0 replies; 10+ messages in thread
From: netdev-bot+sashiko @ 2026-11-30 12:25 UTC (permalink / raw)
To: mmyangfl; +Cc: netdev, andrew, olteanv, davem, edumazet, kuba, pabeni
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.
Critical: 0 · High: 1 · Medium: 0 · Low: 0
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [High] This patch makes the REDIR-vs-TRAP decision once.
--
net: dsa: motorcomm: Reject isolated redirect targets
This patch checks the port isolation mask while parsing a flower redirect
action. If the redirect target is isolated, skip_sw rules are rejected.
Other rules are marked sw_assisting, and yt921x_acl_commit() then installs
them as TRAP instead of REDIR.
> diff --git a/drivers/net/dsa/motorcomm/tc.c b/drivers/net/dsa/motorcomm/tc.c
> index e3f057ed580f5..20edfd53b230d 100644
> --- a/drivers/net/dsa/motorcomm/tc.c
> +++ b/drivers/net/dsa/motorcomm/tc.c
[ ... ]
> @@ -1072,6 +1075,20 @@ 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 (pp->isolation_mask & 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;
> + }
> +
[Severity: High]
Can sw_assisting go stale after the rule is installed? The isolation mask
is read only once, when yt921x_acl_rule_ext_parse_flow_action() parses the
rule, and the result is cached in aclrule->sw_assisting.
At this commit, yt921x_acl_commit() is called only from yt921x_acl_add()
and yt921x_acl_del(). Nothing rechecks the REDIR vs TRAP choice after
that.
Several paths in chip.c rewrite PORTn_ISOLATION and isolation_mask but
leave installed ACL rules alone:
drivers/net/dsa/motorcomm/chip.c:yt921x_userport_standalone() {
...
ctrl = ~dsa_cpu_ports(ds);
res = yt921x_reg_write(priv, YT921X_PORTn_ISOLATION(port), ctrl);
if (res)
return res;
pp->isolation_mask = ctrl;
...
}
drivers/net/dsa/motorcomm/chip.c:yt921x_isolate() {
...
priv->ports[i].isolation_mask |= mask;
...
}
drivers/net/dsa/motorcomm/chip.c:yt921x_bridge() {
...
res = yt921x_reg_write(priv, YT921X_PORTn_ISOLATION(port),
ctrl);
if (res)
return res;
pp->isolation_mask = ctrl;
...
}
For example, say swp1 and swp2 are both in br0, and this rule is added:
tc filter add dev swp1 ingress flower [skip_sw] \
action mirred egress redirect dev swp2
BIT(2) is clear in the mask for swp1, so the rule is installed as REDIR.
Then either swp1 or swp2 leaves br0, or BR_ISOLATED or BR_HAIRPIN_MODE
changes.
Isolation now blocks port 2, but the ACL entry still redirects to it.
Would those frames be dropped in hardware without software ever seeing
them? That is the case the commit message describes. For a skip_sw rule,
tc would also still report the rule as offloaded.
The reverse case looks wrong as well. A rule installed while the ports
were isolated stays trapped to the CPU after they become bridged.
Later commits in this series fix part of this:
"Reject bridge flags that break redirect rules" rejects flag changes that
would break skip_sw rules.
"Recompute redirect rules on bridge changes" adds yt921x_acl_recompute()
for non-skip_sw rules. Its own comment says skip_sw rules are not fixed up
on bridge leave, because port_bridge_leave() cannot fail. So a skip_sw
redirect installed while bridged would still drop traffic silently once
either port leaves the bridge.
yt921x_acl_recompute() also seems to derive the source port without
FIELD_GET():
src = ffs(aclrule->entries[0].key[1] &
YT921X_ACL_KEYb_SPORTS_M) - 1;
...
if (src != port && !(dsts & BIT(port)))
continue;
aclrule->sw_assisting =
!!(dsts & priv->ports[src].isolation_mask);
YT921X_ACL_KEYb_SPORTS_M is GENMASK(20, 10), so src would be the real
port plus 10. Two things follow from that:
- The src != port check would skip rules whose source is the changing
port. For example, after swp1 leaves the bridge, its redirect to swp2
is never recomputed.
- For rules that match through dsts, src can be as large as 20, but
priv->ports[] has only YT921X_PORT_NUM (11) entries. Does that read
priv->ports[] out of bounds?
If so, this problem would still be reachable at the end of the series,
for both skip_sw and non-skip_sw rules. Could isolation changes re-commit
the affected ACL actions?
> @@ -1301,8 +1318,20 @@ 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 {
[ ... ]
> diff --git a/drivers/net/dsa/motorcomm/tc.h b/drivers/net/dsa/motorcomm/tc.h
> index cc53f148d690f..81c29a8eec5ac 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;
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261129115556.1669188-1-mmyangfl%40gmail.com
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH net-next v2 4/5] net: dsa: motorcomm: Recompute redirect rules on bridge changes
2026-11-29 11:55 [PATCH net-next v2 0/5] net: dsa: motorcomm: Reject isolated redirect targets David Yang
` (2 preceding siblings ...)
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
2026-11-30 12:25 ` netdev-bot+sashiko
2026-11-29 11:55 ` [PATCH net-next v2 5/5] net: dsa: motorcomm: Reject bridge flags that break redirect rules David Yang
4 siblings, 1 reply; 10+ messages in thread
From: David Yang @ 2026-11-29 11:55 UTC (permalink / raw)
To: netdev
Cc: David Yang, Andrew Lunn, Vladimir Oltean, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni
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
^ permalink raw reply related [flat|nested] 10+ messages in thread* Re: [PATCH net-next v2 4/5] net: dsa: motorcomm: Recompute redirect rules on bridge changes
2026-11-29 11:55 ` [PATCH net-next v2 4/5] net: dsa: motorcomm: Recompute redirect rules on bridge changes David Yang
@ 2026-11-30 12:25 ` netdev-bot+sashiko
0 siblings, 0 replies; 10+ messages in thread
From: netdev-bot+sashiko @ 2026-11-30 12:25 UTC (permalink / raw)
To: mmyangfl; +Cc: netdev, andrew, olteanv, davem, edumazet, kuba, pabeni
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.
Critical: 0 · High: 1 · Medium: 0 · Low: 1
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [High] yt921x_acl_recompute() in drivers/net/dsa/motorcomm/tc.c gets
the rule's source port wrong.
- [Low] net: dsa: motorcomm: redundant ACL commits in
yt921x_acl_recompute()
--
net: dsa: motorcomm: Recompute redirect rules on bridge changes
This adds yt921x_acl_recompute(), which re-evaluates non-skip_sw redirect
rules after bridge join, leave and flag changes rewrite the port isolation
masks. It is called from yt921x_bridge_flags(),
yt921x_dsa_port_bridge_join() and yt921x_dsa_port_bridge_leave().
> diff --git a/drivers/net/dsa/motorcomm/tc.c b/drivers/net/dsa/motorcomm/tc.c
> index 20edfd53b230d..146db2a37c268 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)
[ ... ]
> +int yt921x_acl_recompute(struct yt921x_priv *priv, int port)
> +{
[ ... ]
> + 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);
^^^^^^^^^^^^^^^^^
[Severity: High]
Can this read past the end of priv->ports[]? The source port field is not
shifted down before ffs(), and tc.h has:
#define YT921X_ACL_KEYb_SPORTS_M GENMASK(20, 10)
#define YT921X_ACL_KEYb_SPORTn(port) BIT((port) + 10)
So a rule on port p gives src = p + 10. For p >= 1 that is 11..20, but
ports[] only has YT921X_PORT_NUM (11) entries. For p == 0 it reads the
isolation_mask of port 10 instead.
The other decoders of this field, yt921x_acl_find(), yt921x_acl_add() and
yt921x_acl_del(), all use FIELD_GET(YT921X_ACL_KEYb_SPORTS_M, ...). Should
this be something like:
src = ffs(FIELD_GET(YT921X_ACL_KEYb_SPORTS_M,
aclrule->entries[0].key[1])) - 1;
The same offset also breaks the filter above. Because src != port is
almost always true, rules sourced on the port whose bridge state changed
are skipped unless they also redirect to that port.
As an example, take a non-skip_sw flower rule on port 1 that redirects to
port 2. A bridge join or leave on port 2, or a BR_ISOLATED or
BR_HAIRPIN_MODE change there, calls yt921x_acl_recompute(priv, 2). The
rule passes the dsts & BIT(2) check, and priv->ports[11] is read. That
value then decides whether yt921x_acl_commit() writes a REDIR or a TRAP
action to YT921X_ACLn_ACT.
The later patch in this series, "net: dsa: motorcomm: Reject bridge flags
that break redirect rules", does not touch yt921x_acl_recompute(), so the
problem is still there at the end of the series.
> + entid = YT921X_ACL_ENT_PER_BLK * blkid + i;
> + res = yt921x_acl_commit(priv, entid, aclrule->mask);
> + if (res)
> + return res;
> + }
> + }
> +
> + return 0;
> +}
[Severity: Low]
This calls yt921x_acl_commit() for every rule that passes the filter,
whether or not the newly computed sw_assisting value differs from the
one already programmed. Each commit rewrites the 96-bit action, the key
and mask of every entry in the rule, and the block KEEP, ENTRY and CMD
registers. All of that goes over MDIO while reg_lock is held in the
bridge join, leave and flags paths.
FLOW_ACTION_DROP rules also get past the action check here.
yt921x_acl_rule_ext_parse_flow_action() encodes them as
YT921X_ACL_ACTc_FWD_EN | YT921X_ACL_ACTc_FWD_REDIR with an empty DPORTS
field. For those rules dsts is 0, so sw_assisting always comes out false
and the commit just writes back the action that is already there. Once
src is decoded correctly, every non-skip_sw drop rule sourced on the
port would be reprogrammed on each bridge change. The same applies to
redirect rules whose destinations are not affected by the isolation
change.
Nothing breaks functionally, but would it make sense to skip rules with
dsts == 0? yt921x_acl_commit() could also be called only when
sw_assisting actually flips, for example by computing the new value into
a local, comparing it with aclrule->sw_assisting and continuing if they
match.
Or is the unconditional rewrite intended to resync the hardware after
an earlier failed commit? sw_assisting is updated before
yt921x_acl_commit() runs, so after a failure the software state and the
hardware can disagree.
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261129115556.1669188-1-mmyangfl%40gmail.com
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH net-next v2 5/5] net: dsa: motorcomm: Reject bridge flags that break redirect rules
2026-11-29 11:55 [PATCH net-next v2 0/5] net: dsa: motorcomm: Reject isolated redirect targets David Yang
` (3 preceding siblings ...)
2026-11-29 11:55 ` [PATCH net-next v2 4/5] net: dsa: motorcomm: Recompute redirect rules on bridge changes David Yang
@ 2026-11-29 11:55 ` David Yang
2026-11-30 12:25 ` netdev-bot+sashiko
4 siblings, 1 reply; 10+ messages in thread
From: David Yang @ 2026-11-29 11:55 UTC (permalink / raw)
To: netdev
Cc: David Yang, Andrew Lunn, Vladimir Oltean, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni
Bridge 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 | 35 +++++++++++++++++++++++++++++++
drivers/net/dsa/motorcomm/chip.h | 1 +
drivers/net/dsa/motorcomm/tc.c | 36 +++++++++++++++++++++++++-------
3 files changed, 64 insertions(+), 8 deletions(-)
diff --git a/drivers/net/dsa/motorcomm/chip.c b/drivers/net/dsa/motorcomm/chip.c
index 7282bc0693eb..40d0334f3d74 100644
--- a/drivers/net/dsa/motorcomm/chip.c
+++ b/drivers/net/dsa/motorcomm/chip.c
@@ -1465,9 +1465,44 @@ 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];
+
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 installed");
+ return -EINVAL;
+ }
+
+ if ((flags.mask & BR_ISOLATED) && (flags.val & BR_ISOLATED)) {
+ struct dsa_port *dp = dsa_to_port(ds, port);
+ unsigned long ports_mask;
+ struct net_device *bdev;
+ unsigned int i;
+
+ bdev = dsa_port_bridge_dev_get(dp);
+ if (!bdev)
+ return 0;
+
+ ports_mask = dsa_bridge_ports(ds, bdev);
+ for_each_set_bit(i, &ports_mask, YT921X_PORT_NUM) {
+ if (i == port || !priv->ports[i].isolated)
+ continue;
+
+ if (pp->acl_dst_cnts[i] ||
+ priv->ports[i].acl_dst_cnts[port]) {
+ NL_SET_ERR_MSG_MOD(extack,
+ "Cannot isolate port while there are redirect rules installed");
+ return -EINVAL;
+ }
+ }
+ }
+
return 0;
}
diff --git a/drivers/net/dsa/motorcomm/chip.h b/drivers/net/dsa/motorcomm/chip.h
index 39b7721cff40..c697082b5235 100644
--- a/drivers/net/dsa/motorcomm/chip.h
+++ b/drivers/net/dsa/motorcomm/chip.h
@@ -463,6 +463,7 @@ struct yt921x_port {
bool isolated:1;
unsigned short acl_cnt;
+ unsigned short acl_dst_cnts[YT921X_PORT_NUM];
u16 isolation_mask;
diff --git a/drivers/net/dsa/motorcomm/tc.c b/drivers/net/dsa/motorcomm/tc.c
index 146db2a37c26..585765aa42f3 100644
--- a/drivers/net/dsa/motorcomm/tc.c
+++ b/drivers/net/dsa/motorcomm/tc.c
@@ -1454,7 +1454,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;
@@ -1473,9 +1474,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--;
@@ -1517,6 +1526,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;
@@ -1590,8 +1601,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) {
@@ -1610,9 +1621,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* Re: [PATCH net-next v2 5/5] net: dsa: motorcomm: Reject bridge flags that break redirect rules
2026-11-29 11:55 ` [PATCH net-next v2 5/5] net: dsa: motorcomm: Reject bridge flags that break redirect rules David Yang
@ 2026-11-30 12:25 ` netdev-bot+sashiko
0 siblings, 0 replies; 10+ messages in thread
From: netdev-bot+sashiko @ 2026-11-30 12:25 UTC (permalink / raw)
To: mmyangfl; +Cc: netdev, andrew, olteanv, davem, edumazet, kuba, pabeni
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.
Critical: 0 · High: 1 · Medium: 0 · Low: 0
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [High] The patch adds a check in yt921x_dsa_port_pre_bridge_flags()
(drivers/net/dsa/motorcomm/chip.c) to reject bridge flag changes that…
--
net: dsa: motorcomm: Reject bridge flag changes that break redirect rules
This patch adds per-destination counters, acl_dst_cnts[], for hardware-only
(non sw_assisted) redirect ACL rules. yt921x_dsa_port_pre_bridge_flags()
now uses them to reject turning hairpin mode off, or isolating a port, when
the change would block an installed redirect rule.
> diff --git a/drivers/net/dsa/motorcomm/chip.c b/drivers/net/dsa/motorcomm/chip.c
> index 7282bc0693ebb..40d0334f3d74c 100644
> --- a/drivers/net/dsa/motorcomm/chip.c
> +++ b/drivers/net/dsa/motorcomm/chip.c
> @@ -1465,9 +1465,44 @@ 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];
> +
> 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 installed");
> + return -EINVAL;
> + }
> +
> + if ((flags.mask & BR_ISOLATED) && (flags.val & BR_ISOLATED)) {
> + struct dsa_port *dp = dsa_to_port(ds, port);
> + unsigned long ports_mask;
> + struct net_device *bdev;
> + unsigned int i;
> +
> + bdev = dsa_port_bridge_dev_get(dp);
> + if (!bdev)
> + return 0;
> +
> + ports_mask = dsa_bridge_ports(ds, bdev);
> + for_each_set_bit(i, &ports_mask, YT921X_PORT_NUM) {
> + if (i == port || !priv->ports[i].isolated)
> + continue;
[Severity: High]
Can this check be bypassed, because the state it reads hasn't been
committed yet?
pp->isolated, pp->hairpin and pp->isolation_mask are only updated in
yt921x_bridge_flags():
drivers/net/dsa/motorcomm/chip.c:yt921x_bridge_flags() {
...
if (flags.mask & BR_HAIRPIN_MODE) {
pp->hairpin = flags.val & BR_HAIRPIN_MODE;
...
if (flags.mask & BR_ISOLATED) {
pp->isolated = flags.val & BR_ISOLATED;
...
res = yt921x_bridge(priv, ports_mask);
...
}
br_switchdev_set_port_flag() sends PRE_BRIDGE_FLAGS synchronously. It then
queues BRIDGE_FLAGS as deferred:
net/bridge/br_switchdev.c:br_switchdev_set_port_flag() {
...
attr.id = SWITCHDEV_ATTR_ID_PORT_BRIDGE_FLAGS;
attr.flags = SWITCHDEV_F_DEFER;
err = switchdev_port_attr_set(p->dev, &attr, extack);
...
}
switchdev_deferred_process_work() takes rtnl_lock() again later, from a
workqueue. So other RTM_SETLINK or tc requests can run between this check
and the commit, and they still see the old driver state.
With A and B in the same bridge and a skip_sw redirect A->B installed
(ports[A].acl_dst_cnts[B] == 1):
bridge link set dev A isolated on
-> pre_bridge_flags(A) passes, B is not isolated yet
-> BRIDGE_FLAGS(A) queued
bridge link set dev B isolated on (e.g. next message in the same batch)
-> pre_bridge_flags(B) passes, ports[A].isolated is still false,
so the !priv->ports[i].isolated test skips A
deferred work runs both commits
-> yt921x_bridge() puts B into A's isolation_mask
The tc side has the same window. If B is already isolated,
pre_bridge_flags(A, isolated on) passes while no rules exist. A skip_sw
"mirred egress redirect dev B" on A is then checked in
yt921x_acl_rule_ext_parse_flow_action() against the old mask:
if (pp->isolation_mask & BIT(to_dp->index)) {
if (cls->common.skip_sw) {
So the rule is accepted as hardware-only, and the deferred commit then
isolates A.
The same thing can happen with hairpin. Turning hairpin off on A passes
while acl_dst_cnts[A] is 0. A skip_sw A->A redirect is then accepted
because pp->hairpin is still set, and the deferred commit clears it.
In all three cases nothing repairs the rule afterwards, because
yt921x_acl_recompute() skips non sw_assisted rules:
if (!aclrule || !aclrule->sw_assisted)
continue;
So the hardware redirect is silently blocked, which is the case the commit
message says this patch prevents.
Would it work to make the pre-check and the tc parse check use the same
committed or pending state? One option is to read the bridge port flags,
which br_setport() stores right after the pre-check succeeds. Another is to
record the pending isolated/hairpin state in the driver during
pre_bridge_flags.
> +
> + if (pp->acl_dst_cnts[i] ||
> + priv->ports[i].acl_dst_cnts[port]) {
> + NL_SET_ERR_MSG_MOD(extack,
> + "Cannot isolate port while there are redirect rules installed");
> + return -EINVAL;
> + }
> + }
> + }
> +
> return 0;
> }
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261129115556.1669188-1-mmyangfl%40gmail.com
^ permalink raw reply [flat|nested] 10+ messages in thread