Article View: linux.kernel.netdev
Article #26296Re: [PATCH net-next v3 2/5] net: dsa: motorcomm: Cache port isolation masks
From: netdev-bot+sashiko
Date: Thu, 03 Dec 2026 11:15
Date: Thu, 03 Dec 2026 11:15
242 lines
16657 bytes
16657 bytes
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
Technical Details
Message-ID:
<179629654064.3146.1517097756165636642@kernel.org>Path:
mbox-mo1.pugleaf.net!news-can.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-376509-linux-kernel-netdev=dewy.ruReferences:
<20261201081459.2104904-3-mmyangfl@gmail.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-can.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-376509-linux-kernel-netdev=dewy.ru From: netdev-bot+sashiko@kernel.org Newsgroups: linux.kernel.netdev Subject: Re: [PATCH net-next v3 2/5] net: dsa: motorcomm: Cache port isolation masks Date: Thu, 03 Dec 2026 11:15:40 +0000 Organization: Usenet Network Message-ID: <179629654064.3146.1517097756165636642@kernel.org> References: <20261201081459.2104904-3-mmyangfl@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="2470086"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:Cg4118U7F3e7ktCfVp3Ckj4diS0= sha256:rfwuFTSPKCsTIGDbtK+xGw5P7AoqsvXEZQtN9zkfNkQ= sha1:JHlJYR46gRDmbzKmfr/DAsSqbH4= sha256:hChgdEPnu2+anFGlBfhKFvqMFdqAHnYk7khC0hxqKeQ= List-ID: <netdev.vger.kernel.org> X-Mailpost-Empty-Hdrs: X-Spam-Level X-Received: from localhost (localhost [127.0.0.1]) by mail.dewy.ru (Postfix) with ESMTP id 712E41178E4; Thu, 3 Dec 2026 14:16:08 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.64 X-Spam-Status: No, score=-3.64 tagged_above=-9999 required=6.31 tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.24, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001] autolearn=ham autolearn_force=no X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key) header.d=kernel.org X-Received: from mail.dewy.ru ([127.0.0.1]) by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id xTLnpRbn-eR0; Thu, 3 Dec 2026 14:16:05 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-376509-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10]) by mail.dewy.ru (Postfix) with ESMTPS id 024001178E6; Thu, 3 Dec 2026 14:15:54 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sea.lore.kernel.org (Postfix) with ESMTP id E3E252AA36; Thu, 3 Dec 2026 11:15:44 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796296542; b=XD8Y3hnisKYFavDi4XJEyUET0IIFh8c0tq9Dj5qiaNimyemVj4j1HzzDJggKkZoJDEAR IEpKtHydM1JD9ShAbo0aX9eRljXKw3mS6Oj8x8pYDsHcdBQonCTWNq/79nLor/Qnk97kv 1adydtWxUyWyJvT3rjNZosJUHc65Ufl8sEbB2DQHxItZN6QnCHccL0/MCNda2vbqmmNWE Ya60YuzEa6K4g+snZS/PhW7Mn5HiFQ9kFtVmN+S1wF9VslZ2YIvRZ4zpn7M1aEgd+Rwzk AIwaVM79W8c6HlwnXt31YMwKoJg7nBoXJnxsEbO2+asrAniwvX/WcWYO2fafqKLgqyQ== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796296542; h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc: Date:Message-ID:In-Reply-To:References:X-sashiko-severity: Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id: List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner: Precedence:MIME-Version; bh=AiaJHI2PL9xkL+ugHLsQAEW2LuMz5F7ajV1T6KigNaE=; b=tFFa0bCQByNfOiHiSrUhgVkiYK4lF+YJLINBGHyYMraS4qrGQNF11fZIu7goZLZiAGQ1 vZn+drUwvRZYg26xoxvFa33jxoehtmo7VX7GwfCHPEFbK23tR/hin23dG4aBXWpkMuDc6 OB88MpB0xTbiHbOm1AkDeyDof5GlnbacwcnznGE7PPt/7DKC8sXvYCDWvaUjrUI2RNDuv tkp5MuWlAg8jKKSKdzcG7iqOTSxVvrQBHLtJh4aOk6Qu2Ayf9Ill+lFtqKPbPk1dbo9A2 alo+SQUzvGNScktf43398HTJoCbR8ppY3sV1yKBUKQy2PXhT4p7SCCxV0A6VtooMoow== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=KdJOtaXg; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 91568606A691; Thu, 3 Dec 2026 11:15:42 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=KdJOtaXg X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796296541; b=EeEPOrjRE63wSg09NWRuSS9pm+4gO8IJyzh4CO0p0+0RrfpuTfBg7AP9fCycbvdt8mZp Aw6q8tQZKGZtF9axX4DrPu+60yQ8oeNq5BPIuz3P/XYsfdPcSj4TbvRcBZU11HWcSG+Ce Dq6WicNCwa3W/xwiTpJAkzDwEsWXJXAv7cUplUpxyLQZPeCfhm6LIqfMX/lpF6cdhlnUO YTcAjgboJEmYonRQ1DryokobD7ojtcguAbFD+JJTJe817MKqBYaQcz0FUd4rVFcjrnWKK Vi83v2/dDIMrqntxSqzM0vuvGjIVpWkyvKU6JZUXkGMPxXd9j7KjH0pxaCcdrsW9C/g== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796296541; h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID: In-Reply-To:References:X-sashiko-severity:Content-Type: Content-Transfer-Encoding:MIME-Version; bh=AiaJHI2PL9xkL+ugHLsQAEW2LuMz5F7ajV1T6KigNaE=; b=pODnpxGTMGhe/S4KVU7kyH9IyB9ShGl5qaCyLYvyK2/tG+3/yd+axpq0hVQC2+GIzqQf JrY4zcarmVCBAyj6nzLODZSY6KJNG9llZIlF69VIVdZ1CRtytcY0pdmjDUqxhEAFQI/pR dsHnKpXYIczVEwasKEWUdlTaIkeTJ617VPpXvboiW5GZ9TY6ALdTu5dv5614BbdGR3Gnk jjZPlmh5ijIH9Eh7q01kN332waTJFWpBumN/J11w0B6tdRVwEOrtTG1DQwpVP0EA3J/jN KPgXJecY+WbeBejwFGT0/2esk2v3vCSgAucze62KaP/tlVDkjhqXjqX03FU/alwR6ow== X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=KdJOtaXg; arc=none smtp.remote-ip=100.103.45.18 X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B3179606A685 for <netdev@vger.kernel.org>; Thu, 3 Dec 2026 11:15:41 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 23DB31F00893; Thu, 3 Dec 2026 11:15:41 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796296541; bh=AiaJHI2PL9xkL+ugHLsQAEW2LuMz5F7ajV1T6KigNaE=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=KdJOtaXgvuS+YCTck4sW7GlTzvbVQeDCi4LPzxQFYxtzSvR9MY66hF398JUuiCLOn WbKVMjT94Ks4aV5EHBl1RD/V/rDLa21XT3ZcMs2QHd9Z9kDVv1FArOawna1khB8wYY 6UejDndJRmADBidgexmEGxVb6wSVepF4m3arD0NkxhSO8MJrhYrob4S0ba+XtP1neO 6AawRd5Q05WFHmd+WupD9XaFQwMa+mF5e/2UKhLBIdRDFQsZzg/LsPQqF46+7m1iSK YGNA01Z/awGtcOlr0p4QFxGjKfRkrlaRkG31EJ0ptBXs+eqrVnzNk69BwAeumVvXHy aH4rjKbK4LRiw== X-Cc: netdev@vger.kernel.org, andrew@lunn.ch, olteanv@gmail.com, davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com X-In-Reply-To: <20261201081459.2104904-3-mmyangfl@gmail.com> X-sashiko-severity: High X-Mailing-List: netdev@vger.kernel.org X-List-Post: <mailto:netdev@vger.kernel.org> X-List-Help: <mailto:netdev+help@vger.kernel.org> X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org> X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org> X-List-Owner: <mailto:netdev+owner@vger.kernel.org> X-Precedence: list