Netdev List
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: mmyangfl@gmail.com
Cc: netdev@vger.kernel.org, andrew@lunn.ch, olteanv@gmail.com,
	davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org,
	pabeni@redhat.com
Subject: Re: [PATCH net-next v3 2/5] net: dsa: motorcomm: Cache port isolation masks
Date: Thu, 03 Dec 2026 11:15:40 +0000	[thread overview]
Message-ID: <179629654064.3146.1517097756165636642@kernel.org> (raw)
In-Reply-To: <20261201081459.2104904-3-mmyangfl@gmail.com>

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

  reply	other threads:[~2026-12-03 11:15 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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-03 11:15   ` netdev-bot+sashiko [this message]
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
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
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=179629654064.3146.1517097756165636642@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=kuba@kernel.org \
    --cc=mmyangfl@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=olteanv@gmail.com \
    --cc=pabeni@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox