* [PATCH net-next v4 1/6] net: dsa: motorcomm: Remove local cpu_ports_mask
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 ` 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
` (4 subsequent siblings)
5 siblings, 0 replies; 10+ messages in thread
From: David Yang @ 2026-12-04 10:12 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 82f364986aeb..c96512faeca2 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);
@@ -2382,10 +2383,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;
@@ -2422,7 +2423,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 v4 2/6] net: dsa: motorcomm: Do not block hairpins on standalone ports
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 ` David Yang
2026-12-05 11:00 ` netdev-bot+sashiko
2026-12-04 10:12 ` [PATCH net-next v4 3/6] net: dsa: motorcomm: Derive port isolation masks on the fly David Yang
` (3 subsequent siblings)
5 siblings, 1 reply; 10+ messages in thread
From: David Yang @ 2026-12-04 10:12 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. An ACL rule redirected to
itself on a standalone port was blocked before.
Lift that block despite rare usage.
Fixes: 8eb9e7520b17 ("net: dsa: yt921x: Add ACL support")
Signed-off-by: David Yang <mmyangfl@gmail.com>
---
drivers/net/dsa/motorcomm/chip.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/net/dsa/motorcomm/chip.c b/drivers/net/dsa/motorcomm/chip.c
index c96512faeca2..6e57c9262c68 100644
--- a/drivers/net/dsa/motorcomm/chip.c
+++ b/drivers/net/dsa/motorcomm/chip.c
@@ -1261,7 +1261,7 @@ static int yt921x_userport_standalone(struct yt921x_priv *priv, int port)
u32 ctrl;
int res;
- ctrl = ~dsa_cpu_ports(ds);
+ ctrl = ~(dsa_cpu_ports(ds) | BIT(port));
res = yt921x_reg_write(priv, YT921X_PORTn_ISOLATION(port), ctrl);
if (res)
return res;
--
2.53.0
^ permalink raw reply related [flat|nested] 10+ messages in thread* Re: [PATCH net-next v4 2/6] net: dsa: motorcomm: Do not block hairpins on standalone ports
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-05 11:00 ` netdev-bot+sashiko
0 siblings, 0 replies; 10+ messages in thread
From: netdev-bot+sashiko @ 2026-12-05 11:00 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: 0 · Medium: 1 · 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).
- [Medium] In drivers/net/dsa/motorcomm/chip.c,
yt921x_userport_standalone() now writes YT921X_PORTn_ISOLATION(port) =…
--
net: dsa: motorcomm: Do not block hairpins on standalone ports
The patch clears the port's own bit in YT921X_PORTn_ISOLATION(port) for
standalone user ports. The goal is to allow ACL rules that redirect a
frame back to its ingress port. The commit message says port isolation
is applied after the REDIR decision, so these rules were blocked before.
> diff --git a/drivers/net/dsa/motorcomm/chip.c b/drivers/net/dsa/motorcomm/chip.c
> index c96512faeca25..6e57c9262c681 100644
> --- a/drivers/net/dsa/motorcomm/chip.c
> +++ b/drivers/net/dsa/motorcomm/chip.c
> @@ -1261,7 +1261,7 @@ static int yt921x_userport_standalone(struct yt921x_priv *priv, int port)
> u32 ctrl;
> int res;
>
> - ctrl = ~dsa_cpu_ports(ds);
> + ctrl = ~(dsa_cpu_ports(ds) | BIT(port));
> res = yt921x_reg_write(priv, YT921X_PORTn_ISOLATION(port), ctrl);
[Severity: Medium]
Does this change turn on hairpin for all hardware-forwarded traffic on
standalone ports, and not only for ACL redirect-to-self?
The driver already uses this same bit as its general hairpin control in
yt921x_bridge():
/* to itself when non-hairpin */
if (!pp->hairpin)
ctrl |= BIT(port);
else
ctrl &= ~BIT(port);
Broadcasts don't seem to be trapped on this switch. yt921x_chip_setup_dsa()
programs YT921X_ACT_UNK_ACTn_TRAP only for unknown unicast and unknown
multicast. YT921X_FILTER_BCAST is never written, and yt921x_bridge_flags()
notes:
/* BR_BCAST_FLOOD: we can filter bcast, but cannot trap them */
This means the comment further down in yt921x_userport_standalone()
doesn't hold for broadcasts:
/* Unrelated since learning is off and all packets are trapped;
* set it anyway
*/
So a broadcast arriving on a standalone port is flooded in hardware,
limited only by the isolation register. Before this patch it could only
reach the CPU port. With the self bit cleared, could the switch also
send ARP or DHCP broadcasts back out of the port they arrived on?
If that happens, an upstream switch would see the sender's MAC arrive
from the yt921x link and could move its FDB entry there, which would
blackhole that host. Two such ports in a loop could also cause a
broadcast storm.
This path runs at port setup and on every yt921x_bridge_leave(). Also,
yt921x_isolate() only sets this port's bit in other ports' registers,
never in the port's own register.
All of this depends on how the hardware floods. The reflection only
happens if the switch has no separate source-port suppression for
flooded frames. The BR_HAIRPIN_MODE offload in yt921x_bridge() seems to
assume there is none.
Later patches in the series keep the same behaviour. The new helper
yt921x_isolation_calc_ports() also computes the standalone mask as:
isolation_masks[port] = ~(BIT(port) | cpu_ports_mask);
Could the self bit stay set for normal forwarding, and redirect-to-self
be handled another way? One option is trapping it to the CPU, as the
later commit "net: dsa: motorcomm: Reject isolated redirect targets"
does for other isolated targets.
> if (res)
> return res;
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261204101300.3680838-1-mmyangfl%40gmail.com
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH net-next v4 3/6] net: dsa: motorcomm: Derive port isolation masks on the fly
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 ` David Yang
2026-12-04 10:12 ` [PATCH net-next v4 4/6] net: dsa: motorcomm: Reject isolated redirect targets David Yang
` (2 subsequent siblings)
5 siblings, 0 replies; 10+ messages in thread
From: David Yang @ 2026-12-04 10:12 UTC (permalink / raw)
To: netdev
Cc: David Yang, Andrew Lunn, Vladimir Oltean, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni
For a following commit, an accurate snapshot of port isolation masks is
required. However, .port_pre_bridge_flags() can only veto the changes,
and .port_bridge_flags() is deferred, thus the driver never knows the
exact time point when flags take effect.
Introduce a helper to derive such mask on the fly, and remove local
cache for port flags.
Signed-off-by: David Yang <mmyangfl@gmail.com>
---
drivers/net/dsa/motorcomm/chip.c | 158 ++++++++++++++++++++-----------
drivers/net/dsa/motorcomm/chip.h | 4 -
2 files changed, 105 insertions(+), 57 deletions(-)
diff --git a/drivers/net/dsa/motorcomm/chip.c b/drivers/net/dsa/motorcomm/chip.c
index 6e57c9262c68..567ce8716acd 100644
--- a/drivers/net/dsa/motorcomm/chip.c
+++ b/drivers/net/dsa/motorcomm/chip.c
@@ -1322,39 +1322,112 @@ static int yt921x_isolate(struct yt921x_priv *priv, int port)
/* Make sure to include the CPU port in ports_mask, or your bridge will
* not have it.
*/
-static int yt921x_bridge(struct yt921x_priv *priv, u16 ports_mask)
+static void
+yt921x_isolation_calc_bridge(struct yt921x_priv *priv, u16 ports_mask,
+ u16 *isolation_masks)
{
- unsigned long targets_mask = ports_mask & ~dsa_cpu_ports(&priv->ds);
+ struct dsa_switch *ds = &priv->ds;
+ struct net_device *brport;
+ struct dsa_port *dp;
u32 isolated_mask;
+ u32 hairpin_mask;
u32 ctrl;
- int port;
- int res;
isolated_mask = 0;
- for_each_set_bit(port, &targets_mask, YT921X_PORT_NUM) {
- struct yt921x_port *pp = &priv->ports[port];
+ hairpin_mask = 0;
+ dsa_switch_for_each_user_port(dp, ds) {
+ int port = dp->index;
+
+ if (!(ports_mask & BIT(port)))
+ continue;
- if (pp->isolated)
+ brport = dsa_port_to_bridge_port(dp);
+
+ if (br_port_flag_is_set(brport, BR_ISOLATED))
isolated_mask |= BIT(port);
+ if (br_port_flag_is_set(brport, BR_HAIRPIN_MODE))
+ hairpin_mask |= BIT(port);
}
/* Block from non-cpu bridge ports ... */
- for_each_set_bit(port, &targets_mask, YT921X_PORT_NUM) {
- struct yt921x_port *pp = &priv->ports[port];
+ dsa_switch_for_each_user_port(dp, ds) {
+ int port = dp->index;
+
+ if (!(ports_mask & BIT(port)))
+ continue;
/* to non-bridge ports */
ctrl = ~ports_mask;
/* to isolated ports when isolated */
- if (pp->isolated)
+ if (isolated_mask & BIT(port))
ctrl |= isolated_mask;
/* to itself when non-hairpin */
- if (!pp->hairpin)
+ if (!(hairpin_mask & BIT(port)))
ctrl |= BIT(port);
else
ctrl &= ~BIT(port);
+ isolation_masks[port] = ctrl;
+ }
+}
+
+static void
+yt921x_isolation_calc_ports(struct yt921x_priv *priv, u16 *ports_maskp,
+ u16 *isolation_masks)
+{
+ struct dsa_switch *ds = &priv->ds;
+ struct net_device *bdev;
+ struct dsa_port *dp;
+ u32 cpu_ports_mask;
+ u32 targets_mask;
+
+ cpu_ports_mask = dsa_cpu_ports(ds);
+ targets_mask = *ports_maskp & ~cpu_ports_mask;
+ if (!targets_mask)
+ return;
+
+ dsa_switch_for_each_user_port(dp, ds) {
+ u32 bridge_ports_mask;
+ int port = dp->index;
+
+ if (!(targets_mask & BIT(port)))
+ continue;
+
+ bdev = dsa_port_bridge_dev_get(dp);
+ if (!bdev) {
+ isolation_masks[port] = ~(BIT(port) | cpu_ports_mask);
+ targets_mask &= ~BIT(port);
+ } else {
+ bridge_ports_mask = dsa_bridge_ports(ds, bdev);
+ yt921x_isolation_calc_bridge(priv,
+ bridge_ports_mask |
+ cpu_ports_mask,
+ isolation_masks);
+ targets_mask &= ~bridge_ports_mask;
+ *ports_maskp |= bridge_ports_mask;
+ }
+
+ if (!targets_mask)
+ break;
+ }
+}
+
+static int
+yt921x_isolation_commit(struct yt921x_priv *priv, u16 ports_mask,
+ const u16 *isolation_masks)
+{
+ struct dsa_switch *ds = &priv->ds;
+ struct dsa_port *dp;
+ int res;
+
+ dsa_switch_for_each_user_port(dp, ds) {
+ int port = dp->index;
+
+ if (!(ports_mask & BIT(port)))
+ continue;
+
res = yt921x_reg_write(priv, YT921X_PORTn_ISOLATION(port),
- ctrl);
+ isolation_masks[port]);
if (res)
return res;
}
@@ -1362,6 +1435,19 @@ static int yt921x_bridge(struct yt921x_priv *priv, u16 ports_mask)
return 0;
}
+static int
+yt921x_isolation_refresh(struct yt921x_priv *priv, u16 ports_mask,
+ bool also_bridge)
+{
+ u16 isolation_masks[YT921X_PORT_NUM];
+ u16 targets_mask = ports_mask;
+
+ yt921x_isolation_calc_ports(priv, &targets_mask, isolation_masks);
+ return yt921x_isolation_commit(priv,
+ also_bridge ? targets_mask : ports_mask,
+ isolation_masks);
+}
+
static int yt921x_bridge_leave(struct yt921x_priv *priv, int port)
{
int res;
@@ -1378,7 +1464,7 @@ static int yt921x_bridge_leave(struct yt921x_priv *priv, int port)
}
static int
-yt921x_bridge_join(struct yt921x_priv *priv, int port, u16 ports_mask)
+yt921x_bridge_join(struct yt921x_priv *priv, int port)
{
int res;
@@ -1386,7 +1472,7 @@ yt921x_bridge_join(struct yt921x_priv *priv, int port, u16 ports_mask)
if (res)
return res;
- res = yt921x_bridge(priv, ports_mask);
+ res = yt921x_isolation_refresh(priv, BIT(port), true);
if (res)
return res;
@@ -1397,8 +1483,6 @@ static int
yt921x_bridge_flags(struct yt921x_priv *priv, int port,
struct switchdev_brport_flags flags)
{
- struct yt921x_port *pp = &priv->ports[port];
- bool do_flush;
u32 mask;
int res;
@@ -1418,30 +1502,10 @@ yt921x_bridge_flags(struct yt921x_priv *priv, int port,
/* BR_BCAST_FLOOD: we can filter bcast, but cannot trap them */
- do_flush = false;
- if (flags.mask & BR_HAIRPIN_MODE) {
- pp->hairpin = flags.val & BR_HAIRPIN_MODE;
- do_flush = true;
- }
- if (flags.mask & BR_ISOLATED) {
- pp->isolated = flags.val & BR_ISOLATED;
- do_flush = true;
- }
- if (do_flush) {
- struct dsa_switch *ds = &priv->ds;
- struct dsa_port *dp = dsa_to_port(ds, port);
- struct net_device *bdev;
-
- bdev = dsa_port_bridge_dev_get(dp);
- if (bdev) {
- u32 ports_mask;
-
- ports_mask = dsa_bridge_ports(ds, bdev);
- ports_mask |= dsa_cpu_ports(ds);
- res = yt921x_bridge(priv, ports_mask);
- if (res)
- return res;
- }
+ if ((flags.mask & BR_HAIRPIN_MODE) || (flags.mask & BR_ISOLATED)) {
+ res = yt921x_isolation_refresh(priv, BIT(port), true);
+ if (res)
+ return res;
}
return 0;
@@ -1502,25 +1566,13 @@ 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 yt921x_port *pp = &priv->ports[port];
- struct net_device *brport_dev;
- struct dsa_port *dp;
- u16 ports_mask;
int res;
if (dsa_is_cpu_port(ds, port))
return 0;
- ports_mask = dsa_bridge_ports(ds, bridge.dev);
- ports_mask |= dsa_cpu_ports(ds);
-
- dp = dsa_to_port(ds, 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);
+ res = yt921x_bridge_join(priv, port);
mutex_unlock(&priv->reg_lock);
return res;
diff --git a/drivers/net/dsa/motorcomm/chip.h b/drivers/net/dsa/motorcomm/chip.h
index d5ed580f8a78..22381009db51 100644
--- a/drivers/net/dsa/motorcomm/chip.h
+++ b/drivers/net/dsa/motorcomm/chip.h
@@ -457,10 +457,6 @@ struct yt921x_port {
bool serdes:1;
/* Link from in-band status (PHYLINK_PCS_NEG_INBAND) */
bool inband:1;
- /* BR_HAIRPIN_MODE */
- bool hairpin:1;
- /* BR_ISOLATED */
- bool isolated:1;
unsigned short acl_cnt;
--
2.53.0
^ permalink raw reply related [flat|nested] 10+ messages in thread* [PATCH net-next v4 4/6] net: dsa: motorcomm: Reject isolated redirect targets
2026-12-04 10:12 [PATCH net-next v4 0/6] net: dsa: motorcomm: Reject isolated redirect targets David Yang
` (2 preceding siblings ...)
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 ` 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 ` [PATCH net-next v4 6/6] net: dsa: motorcomm: Recompute redirect rules on bridge changes David Yang
5 siblings, 0 replies; 10+ messages in thread
From: David Yang @ 2026-12-04 10:12 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/chip.c | 9 +++++++++
drivers/net/dsa/motorcomm/chip.h | 2 ++
drivers/net/dsa/motorcomm/tc.c | 33 ++++++++++++++++++++++++++++++--
drivers/net/dsa/motorcomm/tc.h | 6 +++++-
4 files changed, 47 insertions(+), 3 deletions(-)
diff --git a/drivers/net/dsa/motorcomm/chip.c b/drivers/net/dsa/motorcomm/chip.c
index 567ce8716acd..a71a8dd5dc63 100644
--- a/drivers/net/dsa/motorcomm/chip.c
+++ b/drivers/net/dsa/motorcomm/chip.c
@@ -1412,6 +1412,15 @@ yt921x_isolation_calc_ports(struct yt921x_priv *priv, u16 *ports_maskp,
}
}
+u16 yt921x_isolation_calc_port(struct yt921x_priv *priv, int port)
+{
+ u16 isolation_masks[YT921X_PORT_NUM];
+ u16 ports_mask = BIT(port);
+
+ yt921x_isolation_calc_ports(priv, &ports_mask, isolation_masks);
+ return isolation_masks[port];
+}
+
static int
yt921x_isolation_commit(struct yt921x_priv *priv, u16 ports_mask,
const u16 *isolation_masks)
diff --git a/drivers/net/dsa/motorcomm/chip.h b/drivers/net/dsa/motorcomm/chip.h
index 22381009db51..749fe12fa852 100644
--- a/drivers/net/dsa/motorcomm/chip.h
+++ b/drivers/net/dsa/motorcomm/chip.h
@@ -559,4 +559,6 @@ static inline u32 ethaddr_lo2_to_u32(const unsigned char *addr)
return (addr[4] << 8) | addr[5];
}
+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 e3f057ed580f..e65baccda99e 100644
--- a/drivers/net/dsa/motorcomm/tc.c
+++ b/drivers/net/dsa/motorcomm/tc.c
@@ -1041,6 +1041,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 +1074,21 @@ 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 (yt921x_isolation_calc_port(priv, port) &
+ 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,19 @@ 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 +1530,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* [PATCH net-next v4 5/6] net: dsa: motorcomm: Reject bridge flags that break redirect rules
2026-12-04 10:12 [PATCH net-next v4 0/6] net: dsa: motorcomm: Reject isolated redirect targets David Yang
` (3 preceding siblings ...)
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 ` David Yang
2026-12-05 11:00 ` netdev-bot+sashiko
2026-12-04 10:12 ` [PATCH net-next v4 6/6] net: dsa: motorcomm: Recompute redirect rules on bridge changes David Yang
5 siblings, 1 reply; 10+ messages in thread
From: David Yang @ 2026-12-04 10:12 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 | 43 ++++++++++++++++++++++++++++++++
drivers/net/dsa/motorcomm/chip.h | 1 +
drivers/net/dsa/motorcomm/tc.c | 36 ++++++++++++++++++++------
3 files changed, 72 insertions(+), 8 deletions(-)
diff --git a/drivers/net/dsa/motorcomm/chip.c b/drivers/net/dsa/motorcomm/chip.c
index a71a8dd5dc63..323c1705f613 100644
--- a/drivers/net/dsa/motorcomm/chip.c
+++ b/drivers/net/dsa/motorcomm/chip.c
@@ -1525,9 +1525,52 @@ 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];
+ struct net_device *bdev;
+ struct dsa_port *dp;
+ u32 ports_mask;
+
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");
+ return -EINVAL;
+ }
+
+ dp = dsa_to_port(ds, port);
+ bdev = dsa_port_bridge_dev_get(dp);
+ if (!bdev)
+ return 0;
+ ports_mask = dsa_bridge_ports(ds, bdev);
+
+ if ((flags.mask & BR_ISOLATED) && (flags.val & BR_ISOLATED)) {
+ struct dsa_port *other_dp;
+
+ dsa_switch_for_each_user_port(other_dp, ds) {
+ struct net_device *other_brport;
+ int i = other_dp->index;
+
+ if (i == port || !(ports_mask & BIT(i)))
+ continue;
+ if (!pp->acl_dst_cnts[i] &&
+ !priv->ports[i].acl_dst_cnts[port])
+ continue;
+
+ other_brport = dsa_port_to_bridge_port(other_dp);
+ if (!br_port_flag_is_set(other_brport, BR_ISOLATED))
+ continue;
+
+ NL_SET_ERR_MSG_MOD(extack,
+ "Cannot isolate port while there are redirect rules");
+ return -EINVAL;
+ }
+ }
+
return 0;
}
diff --git a/drivers/net/dsa/motorcomm/chip.h b/drivers/net/dsa/motorcomm/chip.h
index 749fe12fa852..4085a3c52f20 100644
--- a/drivers/net/dsa/motorcomm/chip.h
+++ b/drivers/net/dsa/motorcomm/chip.h
@@ -459,6 +459,7 @@ struct yt921x_port {
bool inband:1;
unsigned short acl_cnt;
+ unsigned short acl_dst_cnts[YT921X_PORT_NUM];
#if IS_ENABLED(CONFIG_NET_DSA_YT921X_LEDS)
unsigned char led_duty;
diff --git a/drivers/net/dsa/motorcomm/tc.c b/drivers/net/dsa/motorcomm/tc.c
index e65baccda99e..7691da95d76f 100644
--- a/drivers/net/dsa/motorcomm/tc.c
+++ b/drivers/net/dsa/motorcomm/tc.c
@@ -1403,7 +1403,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;
@@ -1422,9 +1423,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--;
@@ -1466,6 +1475,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;
@@ -1539,8 +1550,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) {
@@ -1559,9 +1570,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 v4 5/6] net: dsa: motorcomm: Reject bridge flags that break redirect rules
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-05 11:00 ` netdev-bot+sashiko
0 siblings, 0 replies; 10+ messages in thread
From: netdev-bot+sashiko @ 2026-12-05 11:00 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: 0 · Medium: 1 · 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).
- [Medium] yt921x_dsa_port_pre_bridge_flags()
(drivers/net/dsa/motorcomm/chip.c) does not veto BR_ISOLATED when the…
--
net: dsa: motorcomm: Reject bridge flags that break redirect rules
This commit adds per-port acl_dst_cnts bookkeeping in yt921x_acl_add() and
yt921x_acl_del() for redirect rules that are not sw_assisted. It then uses
those counters in yt921x_dsa_port_pre_bridge_flags() to reject turning off
hairpin mode, or turning on BR_ISOLATED, when the change would block such a
rule.
> diff --git a/drivers/net/dsa/motorcomm/chip.c b/drivers/net/dsa/motorcomm/chip.c
> index a71a8dd5dc63c..323c1705f613c 100644
> --- a/drivers/net/dsa/motorcomm/chip.c
> +++ b/drivers/net/dsa/motorcomm/chip.c
> @@ -1525,9 +1525,52 @@ yt921x_dsa_port_pre_bridge_flags(struct dsa_switch *ds, int port,
[ ... ]
> + if ((flags.mask & BR_ISOLATED) && (flags.val & BR_ISOLATED)) {
> + struct dsa_port *other_dp;
> +
> + dsa_switch_for_each_user_port(other_dp, ds) {
> + struct net_device *other_brport;
> + int i = other_dp->index;
> +
> + if (i == port || !(ports_mask & BIT(i)))
> + continue;
> + if (!pp->acl_dst_cnts[i] &&
> + !priv->ports[i].acl_dst_cnts[port])
> + continue;
> +
> + other_brport = dsa_port_to_bridge_port(other_dp);
> + if (!br_port_flag_is_set(other_brport, BR_ISOLATED))
> + continue;
[Severity: Medium]
Can this check be bypassed when both ends of a skip_sw redirect rule are
members of the same offloaded LAG?
The port being changed gets its new isolation state from flags.val. The
peer's state is read back from the bridge. For LAG members,
dsa_port_to_bridge_port() returns the shared LAG netdev:
include/net/dsa.h:dsa_port_to_bridge_port() {
...
if (dp->lag)
return dp->lag->dev;
...
}
The bridge sends PRE_BRIDGE_FLAGS before it writes the new value into
p->flags. This happens on both the netlink path and the sysfs path:
net/bridge/br_netlink.c:br_setport() {
...
err = br_switchdev_set_port_flag(p, flags, changed_mask, extack);
...
} while (!try_cmpxchg(&p->flags, &old_flags, flags));
...
}
net/bridge/br_sysfs_if.c:store_flag() {
...
err = br_switchdev_set_port_flag(p, flags, BIT(bitnr), &extack);
...
assign_bit(bitnr, &p->flags, v);
...
}
So when the LAG bridge port itself is being isolated, each member sees its
LAG peer as not yet isolated and hits the continue above.
Here is an example. Ports P and Q are in one offloaded LAG, bond0, and bond0
is a bridge port:
skip_sw flower redirect rule from P to Q
-> P's acl_dst_cnts[Q] is incremented
bridge link set dev bond0 isolated on
-> pre_bridge_flags(P) and pre_bridge_flags(Q) both return 0
-> .port_bridge_flags
-> yt921x_isolation_refresh()
-> yt921x_isolation_calc_bridge()
When yt921x_isolation_calc_bridge() runs, bond0 now reads as isolated:
if (br_port_flag_is_set(brport, BR_ISOLATED))
isolated_mask |= BIT(port);
That gives isolated_mask = BIT(P) | BIT(Q). Q's bit then lands in P's
isolation mask, and the hardware drops the P->Q redirect even though the
rule was accepted as skip_sw.
Isn't this the case the commit message says should be rejected?
The later patch in the series ("net: dsa: motorcomm: Recompute redirect
rules on bridge changes") does not change yt921x_dsa_port_pre_bridge_flags(),
so this still seems to apply at the end of the series.
The new warning that patch adds in yt921x_bridge_flags() would not reach
the user here either, because the deferred switchdev attr path passes a
NULL extack.
> +
> + NL_SET_ERR_MSG_MOD(extack,
> + "Cannot isolate port while there are redirect rules");
> + return -EINVAL;
> + }
> + }
> +
> return 0;
> }
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261204101300.3680838-1-mmyangfl%40gmail.com
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH net-next v4 6/6] net: dsa: motorcomm: Recompute redirect rules on bridge changes
2026-12-04 10:12 [PATCH net-next v4 0/6] net: dsa: motorcomm: Reject isolated redirect targets David Yang
` (4 preceding siblings ...)
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
2026-12-05 11:00 ` netdev-bot+sashiko
5 siblings, 1 reply; 10+ messages in thread
From: David Yang @ 2026-12-04 10:12 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 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
^ permalink raw reply related [flat|nested] 10+ messages in thread* Re: [PATCH net-next v4 6/6] net: dsa: motorcomm: Recompute redirect rules on bridge changes
2026-12-04 10:12 ` [PATCH net-next v4 6/6] net: dsa: motorcomm: Recompute redirect rules on bridge changes David Yang
@ 2026-12-05 11:00 ` netdev-bot+sashiko
0 siblings, 0 replies; 10+ messages in thread
From: netdev-bot+sashiko @ 2026-12-05 11:00 UTC (permalink / raw)
To: mmyangfl; +Cc: netdev, andrew, olteanv, davem, edumazet, kuba, pabeni
Thank you for your contribution! Sashiko AI review found 6 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 2 · Low: 4
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).
- [Medium] yt921x_acl_refresh() in drivers/net/dsa/motorcomm/tc.c sets
`inability = true` for every skip_sw rule (`!aclrule->sw_assisted`)…
- [Medium] net: dsa: motorcomm: bridge join breaks skip_sw hairpin
redirect rules
- [Low] The order of the ACL refresh relative to the isolation register
update is fixed per call site.
- [Low] Both strings built by the new yt921x_acl_refresh_extack() helper
end with '\n': "Failed to refresh ACL rules: %i\n"…
- [Low] In yt921x_bridge_flags(), the result of yt921x_acl_refresh() is
reported only through extack via yt921x_acl_refresh_extack(res,…
- [Low] yt921x_acl_refresh() updates the driver's record
(`aclrule->sw_assisting = assisting;`) before calling…
--
net: dsa: motorcomm: Recompute redirect rules on bridge changes
On bridge join, bridge leave, and hairpin/isolated flag changes, this
commit re-evaluates the non-skip_sw redirect ACL rules. Each one is
trapped or untrapped to match the new isolation masks. skip_sw rules
are left as they are, and a warning is meant to be emitted if any of
them are invalidated.
> diff --git a/drivers/net/dsa/motorcomm/chip.c b/drivers/net/dsa/motorcomm/chip.c
> index 323c1705f613c..dc64ec1e310dd 100644
> --- a/drivers/net/dsa/motorcomm/chip.c
> +++ b/drivers/net/dsa/motorcomm/chip.c
[ ... ]
> @@ -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");
> +}
[Severity: Low]
This isn't a bug, but both extack strings in yt921x_acl_refresh_extack()
end with a trailing \n. The other extack messages in the driver don't
have one.
> +
> 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)
> {
[ ... ]
> @@ -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;
[Severity: Low]
Does this ordering still hold when isolation is being relaxed? In a
single pass, yt921x_acl_refresh() computes the post-change masks and
commits both trap and untrap transitions.
Clearing BR_ISOLATED or enabling BR_HAIRPIN_MODE turns trapped rules
back into plain REDIR. That happens while the old, stricter
PORTn_ISOLATION is still programmed. The existing comment in
yt921x_acl_rule_ext_parse_flow_action() says:
/* Port isolation takes after REDIR judgment, but
* software delivers such frames.
*/
So until yt921x_isolation_refresh() runs, would matching frames be
dropped in hardware? That would contradict "no frame is dropped in
between".
yt921x_dsa_port_bridge_leave() uses the same order. For example, a
sw_assisted P->P rule on a non-hairpin bridged port is untrapped before
yt921x_bridge_leave() relaxes isolation.
yt921x_dsa_port_bridge_join() uses the opposite order:
res = yt921x_bridge_join(priv, port);
if (res)
goto end;
res = yt921x_acl_refresh(priv, port);
There, a sw_assisted P->P rule that was a live REDIR while the port was
standalone gets blocked by the new non-hairpin isolation before it is
trapped.
If yt921x_isolation_refresh() fails here, the ACL also stays programmed
for an isolation state that was never applied.
Would trap first, then isolation update, then untrap avoid the window
in all three paths?
> +
> + yt921x_acl_refresh_extack(res, extack);
> }
>
> return 0;
[Severity: Medium]
Should yt921x_dsa_port_bridge_join() refuse the join here instead of
downgrading the result to a warning?
A standalone port has isolation_masks[port] = ~(BIT(port) | cpu), so
yt921x_acl_rule_ext_parse_flow_action() lets a skip_sw P->P redirect
be offloaded on it. yt921x_acl_add() then bumps
priv->ports[port].acl_dst_cnts[port].
When that port is enslaved, new_nbp() creates the bridge port without
BR_HAIRPIN_MODE, so yt921x_bridge_join() programs self-isolation for
the port. The skip_sw rule stays a plain REDIR. Port isolation is
applied after the REDIR decision, so matching frames are dropped in
hardware. tc still reports the rule as offloaded, and because it is
skip_sw, software will not deliver those frames either.
yt921x_acl_refresh() returns 1 in this case. The join path only
passes that to yt921x_acl_refresh_extack() and then clears res, so
the join succeeds and the rule is silently broken.
yt921x_dsa_port_pre_bridge_flags() already refuses to clear
BR_HAIRPIN_MODE while pp->acl_dst_cnts[port] is non-zero, precisely
so that skip_sw hairpin rules are not broken behind tc's back.
port_bridge_join() can return an error, unlike port_bridge_leave().
Could the same check be done here, before yt921x_bridge_join() touches
the hardware, so that the join fails with an error and an extack
message?
[Severity: Low]
Can extack be non-NULL when this branch runs? br_switchdev_set_port_flag()
sends SWITCHDEV_ATTR_ID_PORT_BRIDGE_FLAGS with SWITCHDEV_F_DEFER, and the
deferred path does:
net/switchdev/switchdev.c:switchdev_port_attr_set_deferred() {
...
err = switchdev_port_attr_set_now(dev, attr, NULL);
...
}
dsa_port_inherit_brport_flags() and dsa_port_clear_brport_flags() call
in directly, but they only use BR_LEARNING, BR_FLOOD, BR_MCAST_FLOOD,
BR_BCAST_FLOOD and BR_PORT_LOCKED. They never reach the hairpin/isolated
branch.
So if yt921x_acl_commit() fails during a hairpin or isolated change, the
error seems to go unreported, and yt921x_bridge_flags() returns 0.
yt921x_dsa_port_bridge_leave() reports the same result with dev_err()
and dev_warn(). Should this path do that too?
[ ... ]
> diff --git a/drivers/net/dsa/motorcomm/tc.c b/drivers/net/dsa/motorcomm/tc.c
> index 7691da95d76f3..00c632447b3c5 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)
> +{
[ ... ]
> + 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;
> + }
[Severity: Medium]
Should this check assisting before setting inability? As written, any
skip_sw redirect rule that touches the port makes yt921x_acl_refresh()
return 1. It does not matter whether the new isolation masks block the
rule or not.
The function comment says "Return 1 if any skip_sw rules are now
invalidated", and the commit message says "Warn if any skip_sw rules are
invalidated". For skip_sw rules, though, the assisting value computed
just above is never used.
Drop rules are caught as well. yt921x_acl_rule_ext_parse_flow_action()
encodes a drop as:
case FLOW_ACTION_DROP:
action[2] |= YT921X_ACL_ACTc_FWD_EN |
YT921X_ACL_ACTc_FWD_REDIR;
The DPORTS field is left empty, so the rule passes the REDIR filter
above and srcs & BIT(port) is true. With dsts == 0, isolation can't
affect the rule. Even so, any port with a skip_sw drop rule would get
"they no longer work as expected" on every bridge leave (dev_warn() in
yt921x_dsa_port_bridge_leave()) and on every bridge join (extack in
yt921x_dsa_port_bridge_join()).
A skip_sw P->P rule on a hairpin-enabled bridged port is another
example. It stays valid after the port leaves, because the standalone
mask ~(BIT(P) | cpu) allows self-redirect, but it would still be
reported.
On the bridge_flags path, yt921x_dsa_port_pre_bridge_flags() already
rejects changes that would invalidate skip_sw hairpin redirects:
if ((flags.mask & BR_HAIRPIN_MODE) && !(flags.val & BR_HAIRPIN_MODE) &&
pp->acl_dst_cnts[port]) {
So any skip_sw warning from that path looks spurious.
The warning is right in one case. On join, a skip_sw P->P rule from a
standalone port really is invalidated, because the port joins as
non-hairpin.
Would something like this match the intent?
if (!aclrule->sw_assisted) {
if (assisting)
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;
> + }
[Severity: Low]
What happens to aclrule->sw_assisting if yt921x_acl_commit() fails? It
is updated before the commit and never restored. The hardware can keep
the old action, or a half-written block, while the driver records the
new state.
Later refreshes compare aclrule->sw_assisting != assisting, find the
two equal, and never rewrite the entry. The mismatch would last until
the rule is deleted.
yt921x_bridge_flags() also ignores the refresh error and still writes
the new isolation masks. A failed REDIR->TRAP transition would then
leave the hardware redirecting into a port that is now isolated, so
those frames would be dropped.
Should sw_assisting be updated only after the commit succeeds, or be
restored when it fails?
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261204101300.3680838-1-mmyangfl%40gmail.com
^ permalink raw reply [flat|nested] 10+ messages in thread