* [PATCH net-next v3 1/5] net: dsa: motorcomm: Remove local cpu_ports_mask
2026-12-01 8:14 [PATCH net-next v3 0/5] net: dsa: motorcomm: Reject isolated redirect targets David Yang
@ 2026-12-01 8:14 ` David Yang
2026-12-01 8:14 ` [PATCH net-next v3 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-12-01 8:14 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 v3 2/5] net: dsa: motorcomm: Cache port isolation masks
2026-12-01 8:14 [PATCH net-next v3 0/5] net: dsa: motorcomm: Reject isolated redirect targets David Yang
2026-12-01 8:14 ` [PATCH net-next v3 1/5] net: dsa: motorcomm: Remove local cpu_ports_mask David Yang
@ 2026-12-01 8:14 ` David Yang
2026-12-03 11:15 ` netdev-bot+sashiko
2026-12-01 8:14 ` [PATCH net-next v3 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-12-01 8:14 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, the bridge core invokes .port_pre_bridge_flags()
synchronously in an atomic context, and userspace already sees such
changes applied before .port_bridge_flags() is called, causing the stale
snapshot to be used before the deferred call.
Calculate first, so that part can be made atomic, then apply later.
Signed-off-by: David Yang <mmyangfl@gmail.com>
---
drivers/net/dsa/motorcomm/chip.c | 90 ++++++++++++++++++--------------
drivers/net/dsa/motorcomm/chip.h | 4 ++
2 files changed, 56 insertions(+), 38 deletions(-)
diff --git a/drivers/net/dsa/motorcomm/chip.c b/drivers/net/dsa/motorcomm/chip.c
index 49c9055c7512..6c6a87207bd5 100644
--- a/drivers/net/dsa/motorcomm/chip.c
+++ b/drivers/net/dsa/motorcomm/chip.c
@@ -1256,12 +1256,14 @@ 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;
int res;
ctrl = ~dsa_cpu_ports(ds);
+ pp->isolation_mask = ctrl;
res = yt921x_reg_write(priv, YT921X_PORTn_ISOLATION(port), ctrl);
if (res)
return res;
@@ -1300,35 +1302,22 @@ static int yt921x_userport_bridge(struct yt921x_priv *priv, int port)
return 0;
}
-static int yt921x_isolate(struct yt921x_priv *priv, int port)
+static void yt921x_isolation_calc_standalone(struct yt921x_priv *priv, int port)
{
- u32 mask;
- int res;
-
- mask = BIT(port);
- for (int i = 0; i < YT921X_PORT_NUM; i++) {
- if (dsa_is_cpu_port(&priv->ds, i) || i == port)
- continue;
-
- res = yt921x_reg_set_bits(priv, YT921X_PORTn_ISOLATION(i),
- mask);
- if (res)
- return res;
- }
-
- return 0;
+ for (int i = 0; i < YT921X_PORT_NUM; i++)
+ priv->ports[i].isolation_mask |= BIT(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)
{
unsigned long targets_mask = ports_mask & ~dsa_cpu_ports(&priv->ds);
u32 isolated_mask;
u32 ctrl;
int port;
- int res;
isolated_mask = 0;
for_each_set_bit(port, &targets_mask, YT921X_PORT_NUM) {
@@ -1353,11 +1342,21 @@ static int yt921x_bridge(struct yt921x_priv *priv, u16 ports_mask)
else
ctrl &= ~BIT(port);
- res = yt921x_reg_write(priv, YT921X_PORTn_ISOLATION(port),
- ctrl);
- if (res)
- return res;
+ pp->isolation_mask = ctrl;
}
+}
+
+static int yt921x_isolation_commit(struct yt921x_priv *priv, u16 ports_mask)
+{
+ int res;
+
+ for (int i = 0; i < YT921X_PORT_NUM; i++)
+ if (BIT(i) & ports_mask) {
+ res = yt921x_reg_write(priv, YT921X_PORTn_ISOLATION(i),
+ priv->ports[i].isolation_mask);
+ if (res)
+ return res;
+ }
return 0;
}
@@ -1370,7 +1369,8 @@ static int yt921x_bridge_leave(struct yt921x_priv *priv, int port)
if (res)
return res;
- res = yt921x_isolate(priv, port);
+ yt921x_isolation_calc_standalone(priv, port);
+ res = yt921x_isolation_commit(priv, ~0);
if (res)
return res;
@@ -1386,7 +1386,8 @@ yt921x_bridge_join(struct yt921x_priv *priv, int port, u16 ports_mask)
if (res)
return res;
- res = yt921x_bridge(priv, ports_mask);
+ yt921x_isolation_calc_bridge(priv, ports_mask);
+ res = yt921x_isolation_commit(priv, ports_mask);
if (res)
return res;
@@ -1397,8 +1398,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,16 +1417,7 @@ 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) {
+ if ((flags.mask & BR_HAIRPIN_MODE) || (flags.mask & BR_ISOLATED)) {
struct dsa_switch *ds = &priv->ds;
struct dsa_port *dp = dsa_to_port(ds, port);
struct net_device *bdev;
@@ -1437,8 +1427,7 @@ yt921x_bridge_flags(struct yt921x_priv *priv, int port,
u32 ports_mask;
ports_mask = dsa_bridge_ports(ds, bdev);
- ports_mask |= dsa_cpu_ports(ds);
- res = yt921x_bridge(priv, ports_mask);
+ res = yt921x_isolation_commit(priv, ports_mask);
if (res)
return res;
}
@@ -1452,9 +1441,32 @@ 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.mask & BR_ISOLATED)) {
+ struct dsa_port *dp = dsa_to_port(ds, port);
+ struct net_device *bdev;
+
+ if (flags.mask & BR_HAIRPIN_MODE)
+ pp->hairpin = flags.val & BR_HAIRPIN_MODE;
+ if (flags.mask & BR_ISOLATED)
+ pp->isolated = flags.val & BR_ISOLATED;
+
+ 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);
+ yt921x_isolation_calc_bridge(priv, ports_mask);
+ }
+ }
+
return 0;
}
@@ -2046,6 +2058,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;
@@ -2067,6 +2080,7 @@ static int yt921x_port_setup(struct yt921x_priv *priv, int port)
* without tag).
*/
ctrl = ~(u32)0;
+ pp->isolation_mask = ctrl;
res = yt921x_reg_write(priv, YT921X_PORTn_ISOLATION(port),
ctrl);
if (res)
diff --git a/drivers/net/dsa/motorcomm/chip.h b/drivers/net/dsa/motorcomm/chip.h
index d5ed580f8a78..203371888c45 100644
--- a/drivers/net/dsa/motorcomm/chip.h
+++ b/drivers/net/dsa/motorcomm/chip.h
@@ -457,11 +457,15 @@ struct yt921x_port {
bool serdes:1;
/* Link from in-band status (PHYLINK_PCS_NEG_INBAND) */
bool inband:1;
+ bool:0;
+
/* BR_HAIRPIN_MODE */
bool hairpin:1;
/* BR_ISOLATED */
bool isolated:1;
+ u16 isolation_mask;
+
unsigned short acl_cnt;
#if IS_ENABLED(CONFIG_NET_DSA_YT921X_LEDS)
--
2.53.0
^ permalink raw reply related [flat|nested] 10+ messages in thread* Re: [PATCH net-next v3 2/5] net: dsa: motorcomm: Cache port isolation masks
2026-12-01 8:14 ` [PATCH net-next v3 2/5] net: dsa: motorcomm: Cache port isolation masks David Yang
@ 2026-12-03 11:15 ` netdev-bot+sashiko
0 siblings, 0 replies; 10+ messages in thread
From: netdev-bot+sashiko @ 2026-12-03 11:15 UTC (permalink / raw)
To: mmyangfl; +Cc: netdev, andrew, olteanv, davem, edumazet, kuba, pabeni
Thank you for your contribution! Sashiko AI review found 3 potential
issue(s) to consider.
Critical: 0 · High: 1 · Medium: 1 · 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_dsa_port_pre_bridge_flags()
(drivers/net/dsa/motorcomm/chip.c) used to only validate.
- [Medium] yt921x_bridge_join()
(drivers/net/dsa/motorcomm/chip.c:1389-1392) calls…
- [Low] The new cache field struct yt921x_port::isolation_mask is u16
(drivers/net/dsa/motorcomm/chip.h:467), but it stores u32 register…
--
net: dsa: motorcomm: Cache port isolation masks
This commit adds a per-port isolation_mask cache to the yt921x driver. It
splits the isolation logic into calculation helpers and a single
yt921x_isolation_commit() helper. The hairpin/isolated flags and bridge
isolation masks are now computed in .port_pre_bridge_flags(), and
.port_bridge_flags() only writes the cached masks to hardware.
> diff --git a/drivers/net/dsa/motorcomm/chip.c b/drivers/net/dsa/motorcomm/chip.c
> index 49c9055c75126..6c6a87207bd5c 100644
> --- a/drivers/net/dsa/motorcomm/chip.c
> +++ b/drivers/net/dsa/motorcomm/chip.c
[ ... ]
> @@ -1386,7 +1386,8 @@ yt921x_bridge_join(struct yt921x_priv *priv, int port, u16 ports_mask)
> if (res)
> return res;
>
> - res = yt921x_bridge(priv, ports_mask);
> + yt921x_isolation_calc_bridge(priv, ports_mask);
> + res = yt921x_isolation_commit(priv, ports_mask);
> if (res)
> return res;
[Severity: Medium]
What happens to the cache if yt921x_isolation_commit() fails partway
through here?
By this point yt921x_isolation_calc_bridge() has already set the joining
port's cached isolation_mask to its bridged value. It has also cleared
BIT(port) in every other member's cache. yt921x_isolation_commit() returns
on the first yt921x_reg_write() error, and nothing restores the cache.
DSA doesn't clean this up either:
net/dsa/port.c:dsa_port_bridge_join() {
...
err = dsa_broadcast(DSA_NOTIFIER_BRIDGE_JOIN, &info);
if (err)
goto out_rollback;
...
out_rollback:
dsa_port_bridge_destroy(dp, br);
return err;
}
.port_bridge_leave is never called for this port, so the driver cache
stays in the joined state while DSA treats the port as standalone.
Later, when any other port leaves a bridge, yt921x_bridge_leave() calls
yt921x_isolation_commit(priv, ~0). That writes the stale joined masks to
all ISOLATION registers, including the ones the failed join never reached.
Could this let the standalone port and the would-be bridge members forward
to each other in hardware? Before this patch, a failed join left only
partial hardware state, and that state was never replayed.
[ ... ]
> @@ -1452,9 +1441,32 @@ 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.mask & BR_ISOLATED)) {
> + struct dsa_port *dp = dsa_to_port(ds, port);
> + struct net_device *bdev;
> +
> + if (flags.mask & BR_HAIRPIN_MODE)
> + pp->hairpin = flags.val & BR_HAIRPIN_MODE;
> + if (flags.mask & BR_ISOLATED)
> + pp->isolated = flags.val & BR_ISOLATED;
> +
> + 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);
> + yt921x_isolation_calc_bridge(priv, ports_mask);
> + }
> + }
> +
> return 0;
> }
[Severity: High]
Is it safe to change driver state in the PRE_BRIDGE_FLAGS phase?
This callback now sets pp->hairpin and pp->isolated, and it rewrites the
cached isolation_mask of every bridge member. Nothing undoes those changes
if the bridge abandons the transaction after this callback returned 0.
One way that can happen is in br_switchdev_set_port_flag():
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);
if (err) {
...
return err;
}
...
}
switchdev_deferred_enqueue() allocates with GFP_ATOMIC and can return
-ENOMEM. br_setport() and store_flag() then return the error without
updating p->flags, and .port_bridge_flags is never called.
A bridged LAG is another way. __switchdev_handle_port_attr_set() calls the
PRE callback on each lower port in turn and returns on the first hard
error. Lower ports that already ran keep their modified cache.
Later in the series, "net: dsa: motorcomm: Reject bridge flags that break
redirect rules" adds -EINVAL vetoes to this callback. One example is
refusing to disable hairpin while pp->acl_dst_cnts[port] is non-zero.
With that change, setting hairpin off on a LAG whose second lower port has
a hairpin redirect rule would hit this path every time.
In both cases the hardware still matches the bridge, but the cache holds
the rejected configuration. These later paths write that cache to
hardware:
yt921x_bridge_leave() of any port
yt921x_isolation_commit(priv, ~0) rewrites all registers from the cache
yt921x_bridge_flags() for another port's hairpin/isolated change
commits all bridge members, and its PRE reruns
yt921x_isolation_calc_bridge() with the stale pp->hairpin/pp->isolated
yt921x_bridge_join() of another port
reruns yt921x_isolation_calc_bridge(), but existing members keep their
stale pp->hairpin/pp->isolated values
Take a failed attempt to clear BR_ISOLATED. Could it reach hardware later
and let isolated ports forward to each other, while the bridge still
reports them as isolated? A failed attempt to set it, or to turn hairpin
off, could likewise cut forwarding that the bridge still reports as
enabled.
The stale flags also feed the redirect veto checks and
yt921x_acl_recompute() added later in the series.
The commit message says:
"Calculate first, so that part can be made atomic, then apply later."
It doesn't mention that the validation phase now has side effects with no
rollback. Could PRE compute the masks without publishing them into
priv->ports[]? Alternatively, .port_bridge_flags() could recompute them
from flags.val. The same code is still in pre_bridge_flags at the end of
the series.
[ ... ]
> diff --git a/drivers/net/dsa/motorcomm/chip.h b/drivers/net/dsa/motorcomm/chip.h
> index d5ed580f8a78e..203371888c450 100644
> --- a/drivers/net/dsa/motorcomm/chip.h
> +++ b/drivers/net/dsa/motorcomm/chip.h
> @@ -457,11 +457,15 @@ struct yt921x_port {
> bool serdes:1;
> /* Link from in-band status (PHYLINK_PCS_NEG_INBAND) */
> bool inband:1;
> + bool:0;
> +
> /* BR_HAIRPIN_MODE */
> bool hairpin:1;
> /* BR_ISOLATED */
> bool isolated:1;
>
> + u16 isolation_mask;
> +
[Severity: Low]
Should this be a u32? PORTn_ISOLATION is a 32-bit register, and the values
cached here are built with bitwise NOT on u32:
yt921x_port_setup():
ctrl = ~(u32)0;
pp->isolation_mask = ctrl;
res = yt921x_reg_write(priv, YT921X_PORTn_ISOLATION(port),
ctrl);
yt921x_userport_standalone():
ctrl = ~dsa_cpu_ports(ds);
pp->isolation_mask = ctrl;
res = yt921x_reg_write(priv, YT921X_PORTn_ISOLATION(port), ctrl);
yt921x_isolation_calc_bridge() also stores ~ports_mask here.
The direct writes put the full 32-bit value into the register.
yt921x_isolation_commit() writes the zero-extended u16 cache instead. So
the same register ends up as 0xFFFFFFFF or 0x0000FFFF depending on which
path wrote it last.
The set of registers written also changes in ways the commit message
doesn't mention:
- yt921x_bridge_join() now commits ports_mask, which includes the CPU
ports. Every join rewrites the CPU ports' registers from 0xFFFFFFFF to
0x0000FFFF. The old yt921x_bridge() wrote only non-CPU bridge members.
- yt921x_bridge_leave() now overwrites all 11 ISOLATION registers. The old
yt921x_isolate() did a read-modify-write on non-CPU ports only.
chip.h defines only bits 0-10, via YT921X_PORT_ISOLATION_BLOCKn(), so
isolation behavior is probably unchanged. Even so, is this cache the
"accurate snapshot of port isolation masks" the commit message describes?
The field is still u16 at the end of the series.
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261201081459.2104904-1-mmyangfl%40gmail.com
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH net-next v3 3/5] net: dsa: motorcomm: Reject isolated redirect targets
2026-12-01 8:14 [PATCH net-next v3 0/5] net: dsa: motorcomm: Reject isolated redirect targets David Yang
2026-12-01 8:14 ` [PATCH net-next v3 1/5] net: dsa: motorcomm: Remove local cpu_ports_mask David Yang
2026-12-01 8:14 ` [PATCH net-next v3 2/5] net: dsa: motorcomm: Cache port isolation masks David Yang
@ 2026-12-01 8:14 ` David Yang
2026-12-03 11:15 ` netdev-bot+sashiko
2026-12-01 8:14 ` [PATCH net-next v3 4/5] net: dsa: motorcomm: Reject bridge flags that break redirect rules David Yang
2026-12-01 8:14 ` [PATCH net-next v3 5/5] net: dsa: motorcomm: Recompute redirect rules on bridge changes David Yang
4 siblings, 1 reply; 10+ messages in thread
From: David Yang @ 2026-12-01 8:14 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 | 33 +++++++++++++++++++++++++++++++--
drivers/net/dsa/motorcomm/tc.h | 6 +++++-
2 files changed, 36 insertions(+), 3 deletions(-)
diff --git a/drivers/net/dsa/motorcomm/tc.c b/drivers/net/dsa/motorcomm/tc.c
index e3f057ed580f..b7fe867da088 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,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* Re: [PATCH net-next v3 3/5] net: dsa: motorcomm: Reject isolated redirect targets
2026-12-01 8:14 ` [PATCH net-next v3 3/5] net: dsa: motorcomm: Reject isolated redirect targets David Yang
@ 2026-12-03 11:15 ` netdev-bot+sashiko
0 siblings, 0 replies; 10+ messages in thread
From: netdev-bot+sashiko @ 2026-12-03 11:15 UTC (permalink / raw)
To: mmyangfl; +Cc: netdev, andrew, olteanv, davem, edumazet, kuba, pabeni
Thank you for your contribution! Sashiko AI review found 3 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 2
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] This patch decides once, when a filter is added, whether a
redirect is programmed as hardware REDIR, downgraded to TRAP, or (for…
- [Low] This patch carries `Fixes: 8eb9e7520b17 ("net: dsa: yt921x: Add
ACL support")` and will be picked as a stable candidate.
- [Low] The new check `pp->isolation_mask & BIT(to_dp->index)` in
yt921x_acl_rule_ext_parse_flow_action() fires for more than…
--
net: dsa: motorcomm: Reject isolated redirect targets
When parsing a tc redirect action, this patch checks the ingress port's
isolation mask. If the target is isolated, skip_sw rules are rejected.
Other rules get a new sw_assisting flag, and yt921x_acl_commit() uses it
to program the action as a CPU trap.
> diff --git a/drivers/net/dsa/motorcomm/tc.c b/drivers/net/dsa/motorcomm/tc.c
> index e3f057ed580f5..b7fe867da0882 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];
[Severity: Low]
This patch has a Fixes: tag for 8eb9e7520b17 ("net: dsa: yt921x: Add ACL
support"), so it is likely to be picked up for stable.
It reads yt921x_port::isolation_mask. That field does not exist before the
previous commit, "net: dsa: motorcomm: Cache port isolation masks". That
commit has no Fixes: tag and no stable dependency note.
Would a backport of this fix build without that prerequisite? Could the
dependency be annotated so both commits get picked up together?
[ ... ]
> @@ -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: Medium]
This check runs only once, when the filter is added. The result is stored
in sw_assisting, or for skip_sw it decides whether the rule is accepted.
yt921x_acl_commit() turns sw_assisting into the YT921X_ACLn_ACT value, and
it only runs on rule add and delete.
What happens if isolation changes after the rule is installed? In this
patch nothing re-checks the decision on bridge join, bridge leave, or a
BR_ISOLATED / BR_HAIRPIN_MODE change. A REDIR into a port that becomes
isolated later would still be dropped by hardware.
Two later commits in the series cover most of this:
"Reject bridge flags that break redirect rules" refuses BR_ISOLATED and
hairpin-off changes while skip_sw rules depend on them.
"Recompute redirect rules on bridge changes" re-checks non-skip_sw rules
on join, leave and flag changes.
Even at the end of the series, skip_sw redirects still don't seem to be
handled on bridge leave. yt921x_acl_recompute() skips them:
aclrule = aclblk->rules[i];
if (!aclrule || !aclrule->sw_assisted)
continue;
Meanwhile yt921x_dsa_port_bridge_leave()->yt921x_bridge_leave() rewrites
the isolation masks:
yt921x_userport_standalone() sets the leaving port's own mask to
~dsa_cpu_ports(ds).
yt921x_isolation_calc_standalone() sets the leaving port's bit in every
port's mask.
For example, with lan1 and lan2 both in br0:
tc filter add dev lan1 ingress flower skip_sw ... \
action mirred egress redirect dev lan2
ip link set lan2 nomaster
The REDIR action stays in YT921X_ACLn_ACT while lan1 now isolates lan2.
Matching frames are silently dropped, and tc still reports the filter as
in_hw. The same thing happens with lan1 nomaster or ip link del br0.
This patch refuses exactly that setup at add time, with "Redirect target
isolated, or not in the same bridge". A skip_sw self-redirect on a hairpin
port that leaves the bridge looks like it would behave the same way.
The comment above yt921x_acl_recompute() documents this as a limitation,
because port_bridge_leave() returns void. Would it be worth at least
printing a warning when a skip_sw redirect is invalidated this way, so the
drop isn't completely silent?
[Severity: Low]
This isn't a bug, but the isolation_mask test matches more than BR_ISOLATED
ports. It also matches targets outside the ingress port's bridge, including
two plain standalone ports. yt921x_userport_standalone() sets
isolation_mask = ~dsa_cpu_ports(ds), and yt921x_isolation_calc_standalone()
sets each standalone port's bit in every mask.
So standalone-to-standalone and cross-bridge redirects are now rejected
with skip_sw, and trapped to the CPU without it. Given the hardware
behaviour the commit message describes, hardware was already dropping these
redirects before this patch, so the new behaviour looks correct.
The commit message only mentions "Port isolation". Could it also say that
bridge membership now decides whether a redirect is offloaded? The extack
string does mention "not in the same bridge".
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261201081459.2104904-1-mmyangfl%40gmail.com
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH net-next v3 4/5] net: dsa: motorcomm: Reject bridge flags that break redirect rules
2026-12-01 8:14 [PATCH net-next v3 0/5] net: dsa: motorcomm: Reject isolated redirect targets David Yang
` (2 preceding siblings ...)
2026-12-01 8:14 ` [PATCH net-next v3 3/5] net: dsa: motorcomm: Reject isolated redirect targets David Yang
@ 2026-12-01 8:14 ` David Yang
2026-12-03 11:15 ` netdev-bot+sashiko
2026-12-01 8:14 ` [PATCH net-next v3 5/5] net: dsa: motorcomm: Recompute redirect rules on bridge changes David Yang
4 siblings, 1 reply; 10+ messages in thread
From: David Yang @ 2026-12-01 8:14 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. The masks are rewritten only from
the deferred handler, so judge a rule and a flag change against the flags
as configured, not against what the switch was last programmed with.
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 | 31 +++++++++++++++++++++++++++
drivers/net/dsa/motorcomm/chip.h | 1 +
drivers/net/dsa/motorcomm/tc.c | 36 +++++++++++++++++++++++++-------
3 files changed, 60 insertions(+), 8 deletions(-)
diff --git a/drivers/net/dsa/motorcomm/chip.c b/drivers/net/dsa/motorcomm/chip.c
index 6c6a87207bd5..0bc5da2b80d7 100644
--- a/drivers/net/dsa/motorcomm/chip.c
+++ b/drivers/net/dsa/motorcomm/chip.c
@@ -1448,6 +1448,37 @@ yt921x_dsa_port_pre_bridge_flags(struct dsa_switch *ds, int port,
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;
+ }
+ }
+ }
+
if ((flags.mask & BR_HAIRPIN_MODE) || (flags.mask & BR_ISOLATED)) {
struct dsa_port *dp = dsa_to_port(ds, port);
struct net_device *bdev;
diff --git a/drivers/net/dsa/motorcomm/chip.h b/drivers/net/dsa/motorcomm/chip.h
index 203371888c45..b87329dac609 100644
--- a/drivers/net/dsa/motorcomm/chip.h
+++ b/drivers/net/dsa/motorcomm/chip.h
@@ -467,6 +467,7 @@ struct yt921x_port {
u16 isolation_mask;
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 b7fe867da088..9a19ee7d4358 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 v3 4/5] net: dsa: motorcomm: Reject bridge flags that break redirect rules
2026-12-01 8:14 ` [PATCH net-next v3 4/5] net: dsa: motorcomm: Reject bridge flags that break redirect rules David Yang
@ 2026-12-03 11:15 ` netdev-bot+sashiko
0 siblings, 0 replies; 10+ messages in thread
From: netdev-bot+sashiko @ 2026-12-03 11:15 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 yt921x_dsa_port_pre_bridge_flags()
(drivers/net/dsa/motorcomm/chip.c), the new per-port vetoes run before…
--
net: dsa: motorcomm: Reject bridge flags that break redirect rules
This commit adds a per-port acl_dst_cnts[] counter. yt921x_acl_add() and
yt921x_acl_del() update it for redirect rules that are not sw_assisted.
yt921x_dsa_port_pre_bridge_flags() then uses the counters to reject turning
off hairpin mode or turning on isolation when such rules would be blocked.
> diff --git a/drivers/net/dsa/motorcomm/chip.c b/drivers/net/dsa/motorcomm/chip.c
> index 6c6a87207bd5c..0bc5da2b80d7a 100644
> --- a/drivers/net/dsa/motorcomm/chip.c
> +++ b/drivers/net/dsa/motorcomm/chip.c
> @@ -1448,6 +1448,37 @@ yt921x_dsa_port_pre_bridge_flags(struct dsa_switch *ds, int port,
> 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)) {
[ ... ]
> + 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;
> + }
> + }
> + }
> +
> if ((flags.mask & BR_HAIRPIN_MODE) || (flags.mask & BR_ISOLATED)) {
> struct dsa_port *dp = dsa_to_port(ds, port);
> struct net_device *bdev;
[Severity: Medium]
Can these new per-port checks leave driver state half updated when the
bridge port is an offloaded LAG?
Right after these checks, the prepare phase already changes driver state:
if (flags.mask & BR_HAIRPIN_MODE)
pp->hairpin = flags.val & BR_HAIRPIN_MODE;
if (flags.mask & BR_ISOLATED)
pp->isolated = flags.val & BR_ISOLATED;
...
yt921x_isolation_calc_bridge(priv, ports_mask);
Take bond0 with lowers swpA and swpB on this switch. The bridge sends one
PRE_BRIDGE_FLAGS notification, and switchdev calls the driver once per
lower:
br_setport()
br_switchdev_set_port_flag()
__switchdev_handle_port_attr_set() /* loops over lowers */
dsa_user_port_attr_set()
dsa_port_pre_bridge_flags()
yt921x_dsa_port_pre_bridge_flags()
__switchdev_handle_port_attr_set() returns on the first hard error. It does
not undo the lowers that already succeeded.
Suppose swpA has no conflicting rules. Its call passes, sets pp->hairpin or
pp->isolated, and rewrites isolation_mask for every bridge member through
yt921x_isolation_calc_bridge().
Then suppose swpB fails one of the new acl_dst_cnts[] checks. br_setport()
returns the error, the bridge keeps its old flags, and the deferred
PORT_BRIDGE_FLAGS is never sent.
Nothing appears to roll back swpA's hairpin/isolated state or the cached
isolation_mask values. The next yt921x_isolation_commit() would write those
stale masks to hardware. That happens on a later successful hairpin or
isolated change, or on a bridge_join. Frames would then be dropped even
though the bridge configuration allows them.
The stale masks are also used by the tc parse path and by
yt921x_acl_recompute_rule(). The isolation check above also reads the stale
priv->ports[i].isolated, so isolation changes on other ports could be
rejected wrongly.
Retrying the same flag change would not fix it. The bridge sees no change in
its flags, so it never calls the driver.
Before this patch, the only failure in this function was the unsupported-flag
mask check. That check gives the same result for every lower, so it failed
on the first lower before any state changed.
The later patch in this series, "net: dsa: motorcomm: Recompute redirect
rules on bridge changes", does not touch pre_bridge_flags. Does this problem
still exist at the end of the series?
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261201081459.2104904-1-mmyangfl%40gmail.com
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH net-next v3 5/5] net: dsa: motorcomm: Recompute redirect rules on bridge changes
2026-12-01 8:14 [PATCH net-next v3 0/5] net: dsa: motorcomm: Reject isolated redirect targets David Yang
` (3 preceding siblings ...)
2026-12-01 8:14 ` [PATCH net-next v3 4/5] net: dsa: motorcomm: Reject bridge flags that break redirect rules David Yang
@ 2026-12-01 8:14 ` David Yang
2026-12-03 11:15 ` netdev-bot+sashiko
4 siblings, 1 reply; 10+ messages in thread
From: David Yang @ 2026-12-01 8:14 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 | 33 +++++++++++++
drivers/net/dsa/motorcomm/tc.c | 79 ++++++++++++++++++++++++++++++++
drivers/net/dsa/motorcomm/tc.h | 2 +
3 files changed, 114 insertions(+)
diff --git a/drivers/net/dsa/motorcomm/chip.c b/drivers/net/dsa/motorcomm/chip.c
index 0bc5da2b80d7..a5e673a69355 100644
--- a/drivers/net/dsa/motorcomm/chip.c
+++ b/drivers/net/dsa/motorcomm/chip.c
@@ -1398,6 +1398,7 @@ static int
yt921x_bridge_flags(struct yt921x_priv *priv, int port,
struct switchdev_brport_flags flags)
{
+ struct device *dev = yt921x_priv_to_device(priv);
u32 mask;
int res;
@@ -1431,6 +1432,14 @@ yt921x_bridge_flags(struct yt921x_priv *priv, int port,
if (res)
return res;
}
+
+ res = yt921x_acl_recompute(priv, port);
+ if (res) {
+ dev_err(dev,
+ "Failed to refresh ACL rules for port %d: %i\n",
+ port, res);
+ res = 0;
+ }
}
return 0;
@@ -1531,7 +1540,19 @@ yt921x_dsa_port_bridge_leave(struct dsa_switch *ds, int port,
return;
mutex_lock(&priv->reg_lock);
+
res = yt921x_bridge_leave(priv, port);
+ if (res)
+ goto end;
+
+ res = yt921x_acl_recompute(priv, port);
+ if (res) {
+ dev_err(dev, "Failed to refresh ACL rules for port %d: %i\n",
+ port, res);
+ res = 0;
+ }
+
+end:
mutex_unlock(&priv->reg_lock);
if (res)
@@ -1545,6 +1566,7 @@ yt921x_dsa_port_bridge_join(struct dsa_switch *ds, int port,
struct netlink_ext_ack *extack)
{
struct yt921x_priv *priv = dsa_to_yt921x_priv(ds);
+ struct device *dev = yt921x_priv_to_device(priv);
struct yt921x_port *pp = &priv->ports[port];
struct net_device *brport_dev;
struct dsa_port *dp;
@@ -1564,6 +1586,17 @@ yt921x_dsa_port_bridge_join(struct dsa_switch *ds, int port,
pp->isolated = br_port_flag_is_set(brport_dev, BR_ISOLATED);
pp->hairpin = br_port_flag_is_set(brport_dev, BR_HAIRPIN_MODE);
res = yt921x_bridge_join(priv, port, ports_mask);
+ if (res)
+ goto end;
+
+ res = yt921x_acl_recompute(priv, port);
+ if (res) {
+ dev_err(dev, "Failed to refresh ACL rules for port %d: %i\n",
+ port, res);
+ res = 0;
+ }
+
+end:
mutex_unlock(&priv->reg_lock);
return res;
diff --git a/drivers/net/dsa/motorcomm/tc.c b/drivers/net/dsa/motorcomm/tc.c
index 9a19ee7d4358..210f7af3a206 100644
--- a/drivers/net/dsa/motorcomm/tc.c
+++ b/drivers/net/dsa/motorcomm/tc.c
@@ -1393,6 +1393,85 @@ yt921x_acl_commit(struct yt921x_priv *priv, unsigned int entid, u8 entsmask)
return 0;
}
+static int
+yt921x_acl_recompute_rule(struct yt921x_priv *priv, int port,
+ unsigned int entid)
+{
+ const struct yt921x_acl_blk *aclblk;
+ struct yt921x_acl_rule *aclrule;
+ unsigned int blkid;
+ unsigned int binid;
+ unsigned long dsts;
+ unsigned long srcs;
+ unsigned int o;
+ bool assisting;
+ int res;
+
+ blkid = entid / YT921X_ACL_ENT_PER_BLK;
+ binid = entid % YT921X_ACL_ENT_PER_BLK;
+ aclblk = priv->acl_blks[blkid];
+ aclrule = aclblk->rules[binid];
+
+ if (!(aclrule->action[2] & YT921X_ACL_ACTc_FWD_EN) ||
+ (aclrule->action[2] & YT921X_ACL_ACTc_FWD_M) !=
+ YT921X_ACL_ACTc_FWD_REDIR)
+ return 0;
+
+ srcs = FIELD_GET(YT921X_ACL_KEYb_SPORTS_M, aclrule->entries[0].key[1]);
+ dsts = FIELD_GET(YT921X_ACL_ACTc_FWD_REDIR_DPORTS_M,
+ aclrule->action[2]);
+ if (!((srcs | dsts) & BIT(port)))
+ return 0;
+
+ assisting = false;
+ for_each_set_bit(o, &srcs, YT921X_PORT_NUM)
+ if (dsts & priv->ports[o].isolation_mask) {
+ assisting = true;
+ break;
+ }
+
+ if (aclrule->sw_assisting != assisting) {
+ aclrule->sw_assisting = assisting;
+ res = yt921x_acl_commit(priv, entid, aclrule->mask);
+ if (res)
+ return res;
+ }
+
+ return 0;
+}
+
+/* Only non-skip_sw rules are refreshes; skip_sw rules cannot be degraded,
+ * port_bridge_leave() cannot be rejected (return value is void), nor can tc be
+ * told which rule got invalidated.
+ */
+int yt921x_acl_recompute(struct yt921x_priv *priv, int port)
+{
+ int res;
+
+ for (unsigned int blkid = 0; blkid < YT921X_ACL_BLK_NUM; blkid++) {
+ const struct yt921x_acl_blk *aclblk = priv->acl_blks[blkid];
+
+ if (!aclblk)
+ continue;
+
+ for (unsigned int i = 0; i < YT921X_ACL_ENT_PER_BLK; i++) {
+ struct yt921x_acl_rule *aclrule;
+ unsigned int entid;
+
+ aclrule = aclblk->rules[i];
+ if (!aclrule || !aclrule->sw_assisted)
+ continue;
+
+ entid = YT921X_ACL_ENT_PER_BLK * blkid + i;
+ res = yt921x_acl_recompute_rule(priv, port, entid);
+ if (res)
+ return res;
+ }
+ }
+
+ return 0;
+}
+
static int
yt921x_acl_del(struct yt921x_priv *priv, enum tc_setup_type type,
unsigned long tag, u16 ports_mask)
diff --git a/drivers/net/dsa/motorcomm/tc.h b/drivers/net/dsa/motorcomm/tc.h
index 81c29a8eec5a..be4c258873b8 100644
--- a/drivers/net/dsa/motorcomm/tc.h
+++ b/drivers/net/dsa/motorcomm/tc.h
@@ -371,6 +371,8 @@ yt921x_dsa_port_policer_add(struct dsa_switch *ds, int port,
int
yt921x_dsa_port_setup_tc(struct dsa_switch *ds, int port,
enum tc_setup_type type, void *type_data);
+
+int yt921x_acl_recompute(struct yt921x_priv *priv, int port);
int
yt921x_dsa_cls_flower_del(struct dsa_switch *ds, int port,
struct flow_cls_offload *cls, bool ingress);
--
2.53.0
^ permalink raw reply related [flat|nested] 10+ messages in thread* Re: [PATCH net-next v3 5/5] net: dsa: motorcomm: Recompute redirect rules on bridge changes
2026-12-01 8:14 ` [PATCH net-next v3 5/5] net: dsa: motorcomm: Recompute redirect rules on bridge changes David Yang
@ 2026-12-03 11:15 ` netdev-bot+sashiko
0 siblings, 0 replies; 10+ messages in thread
From: netdev-bot+sashiko @ 2026-12-03 11:15 UTC (permalink / raw)
To: mmyangfl; +Cc: netdev, andrew, olteanv, davem, edumazet, kuba, pabeni
Thank you for your contribution! Sashiko AI review found 3 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 2
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 yt921x_acl_recompute_rule()
(drivers/net/dsa/motorcomm/tc.c), the cached flag…
- [Low] When the isolation step fails part-way,
yt921x_dsa_port_bridge_leave(), yt921x_dsa_port_bridge_join() and…
- [Low] When isolation is tightened, the new PORTn_ISOLATION registers
are written first and the affected non-skip_sw redirect rules are…
--
net: dsa: motorcomm: Recompute redirect rules on bridge changes
This commit makes bridge join, bridge leave and BR_ISOLATED or
BR_HAIRPIN_MODE flag changes in the yt921x driver recompute the non-skip_sw
tc redirect rules. Each rule is switched between REDIR and TRAP depending
on whether the new isolation masks still allow the redirect. skip_sw rules
are not changed.
> diff --git a/drivers/net/dsa/motorcomm/chip.c b/drivers/net/dsa/motorcomm/chip.c
> index 0bc5da2b80d7a..a5e673a693555 100644
> --- a/drivers/net/dsa/motorcomm/chip.c
> +++ b/drivers/net/dsa/motorcomm/chip.c
[ ... ]
> @@ -1431,6 +1432,14 @@ yt921x_bridge_flags(struct yt921x_priv *priv, int port,
> if (res)
> return res;
> }
> +
> + res = yt921x_acl_recompute(priv, port);
> + if (res) {
> + dev_err(dev,
> + "Failed to refresh ACL rules for port %d: %i\n",
> + port, res);
> + res = 0;
> + }
> }
[Severity: Low]
Is the order of these two steps right when isolation is being tightened?
When BR_ISOLATED is set or BR_HAIRPIN_MODE is cleared,
yt921x_isolation_commit() writes the tighter PORTn_ISOLATION registers for
every bridge port first. Only then does yt921x_acl_recompute() switch the
affected redirect rules from REDIR to TRAP.
The comment at the FLOW_ACTION_REDIRECT case in tc.c says port isolation
is applied after the REDIR decision. So while these SMI/MDIO writes are in
progress, would frames matching a non-skip_sw redirect rule be redirected
into a port that isolation now blocks, and be dropped instead of trapped to
the CPU?
yt921x_dsa_port_bridge_leave() has the same ordering. It writes the
isolation registers in yt921x_userport_standalone() and in
yt921x_isolation_commit(priv, ~0), and recomputes the ACLs afterwards.
The join path looks fine, because it loosens isolation first and un-traps
afterwards.
On the tightening paths, could the rules be trapped first, using the
software isolation_mask values that are already computed, and the
isolation registers committed after that?
[ ... ]
> @@ -1531,7 +1540,19 @@ yt921x_dsa_port_bridge_leave(struct dsa_switch *ds, int port,
> return;
>
> mutex_lock(&priv->reg_lock);
> +
> res = yt921x_bridge_leave(priv, port);
> + if (res)
> + goto end;
[Severity: Low]
If yt921x_bridge_leave() fails part-way, the ACL refresh is skipped. But
yt921x_userport_standalone() may already have tightened isolation in both
software and hardware before a later write fails:
drivers/net/dsa/motorcomm/chip.c:yt921x_userport_standalone() {
...
ctrl = ~dsa_cpu_ports(ds);
pp->isolation_mask = ctrl;
res = yt921x_reg_write(priv, YT921X_PORTn_ISOLATION(port), ctrl);
...
res = yt921x_reg_set_bits(priv, YT921X_PORTn_LEARN(port), mask);
if (res)
return res;
...
}
port_bridge_leave() returns void, so DSA and the bridge treat the port as
gone either way.
Take a non-skip_sw rule whose source is the leaving port and whose
destination is a former bridge peer. Would that rule keep sw_assisting ==
false and keep redirecting into a port that isolation now blocks?
yt921x_bridge_flags() has the same pattern. pre_bridge_flags has already
recalculated isolation_mask, but a failure in yt921x_isolation_commit()
returns before yt921x_acl_recompute() runs.
yt921x_dsa_port_bridge_join() is similar. It does goto end after
yt921x_isolation_calc_bridge() has already changed the software masks.
yt921x_acl_recompute() only reads the software isolation_mask. Could it
still be called on these failure paths, so the rules match the intended
isolation state?
> +
> + 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);
[ ... ]
> diff --git a/drivers/net/dsa/motorcomm/tc.c b/drivers/net/dsa/motorcomm/tc.c
> index 9a19ee7d4358a..210f7af3a206a 100644
> --- a/drivers/net/dsa/motorcomm/tc.c
> +++ b/drivers/net/dsa/motorcomm/tc.c
[ ... ]
> +static int
> +yt921x_acl_recompute_rule(struct yt921x_priv *priv, int port,
> + unsigned int entid)
> +{
[ ... ]
> + assisting = false;
> + for_each_set_bit(o, &srcs, YT921X_PORT_NUM)
> + if (dsts & priv->ports[o].isolation_mask) {
> + assisting = true;
> + break;
> + }
> +
> + if (aclrule->sw_assisting != assisting) {
> + aclrule->sw_assisting = assisting;
> + res = yt921x_acl_commit(priv, entid, aclrule->mask);
> + if (res)
> + return res;
> + }
[Severity: Medium]
What happens if yt921x_acl_commit() fails here? sw_assisting has already
been updated, but the hardware ACT entry has not.
Wouldn't every later recompute then see sw_assisting == assisting and skip
the commit? The hardware would stay out of sync until the rule is deleted
or the isolation state flips twice.
In the REDIR to TRAP direction, the rule would keep redirecting into a port
that is now isolated, so its frames are dropped.
Two other things make this harder to recover from. The walk in
yt921x_acl_recompute() stops at the first failing rule:
> + res = yt921x_acl_recompute_rule(priv, port, entid);
> + if (res)
> + return res;
so the remaining redirect rules for this port are never refreshed. Also,
yt921x_bridge_flags(), yt921x_dsa_port_bridge_leave() and
yt921x_dsa_port_bridge_join() all log the error, set res = 0 and carry on,
so nothing retries.
Could sw_assisting be set only after the commit succeeds, or be restored on
failure? And could yt921x_acl_recompute() keep going through the remaining
rules and return the first error at the end?
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261201081459.2104904-1-mmyangfl%40gmail.com
^ permalink raw reply [flat|nested] 10+ messages in thread