Article View: linux.kernel.netdev
Article #19056Re: [PATCH net v6 7/8] net: dsa: b53: harden mirror register programming
From: netdev-bot+sashiko
Date: Thu, 19 Nov 2026 09:10
Date: Thu, 19 Nov 2026 09:10
186 lines
14905 bytes
14905 bytes
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.
Critical: 0 ยท High: 0 ยท Medium: 1 ยท Low: 1 (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).
- [Medium] This patch fixes a regression that an earlier patch in the
same series introduced.
- [Low] The series is split badly around b53_mirror_init().
Pre-existing issues:
- [Low] At this commit, on BCM5325/BCM5365, the mirror source masks and
capture-port field use the newer-chip encoding.
--
net: dsa: b53: harden mirror register programming
This commit clears and rebuilds the mirror registers during b53 and
bcm_sf2 setup. It also checks every mirror register access in
b53_mirror_add() and b53_mirror_del(), and only increments the source
reference count once programming has succeeded. Whether a destination is
occupied is now decided from the source masks instead of MIRROR_EN.
> diff --git a/drivers/net/dsa/b53/b53_common.c b/drivers/net/dsa/b53/b53_common.c
> index 98696bce368fe..deb331b3629a7 100644
> --- a/drivers/net/dsa/b53/b53_common.c
> +++ b/drivers/net/dsa/b53/b53_common.c
> @@ -1360,6 +1360,10 @@ static int b53_setup(struct dsa_switch *ds)
> return ret;
> }
>
> + ret = b53_mirror_init(ds);
> + if (ret)
> + return ret;
> +
[Severity: Low]
The commit message says this patch will "Clear capture control and both
source-control registers during b53 and bcm_sf2 setup, then rebuild the
source masks and capture destination from the mirror reference counts".
The diff, however, only adds the calls in b53_setup() and
bcm_sf2_sw_setup().
The previous patch, "net: dsa: b53: reference count shared mirror source
bits", added the body of b53_mirror_init(), its EXPORT_SYMBOL and the
prototype in b53_priv.h. That patch's message only talks about reference
counting, and the function has no callers there.
Could b53_mirror_init() move into this patch, or could the earlier commit
message describe it?
As it stands, cherry-picking this commit through its Fixes: tag without
the previous one would fail to build because b53_mirror_init() is
undefined. The "must be applied after them" note doesn't say that the
dependency is a missing function body.
[ ... ]
> @@ -2654,14 +2658,25 @@ int b53_mirror_add(struct dsa_switch *ds, int port,
> {
> struct b53_device *dev = ds->priv;
> unsigned int *mirror_count = &dev->ports[port].mirror_count[ingress];
> - u16 reg, loc, cap_ctl;
> + u16 reg, other_reg, loc, other_loc, cap_ctl;
> int ret;
>
> + loc = ingress ? B53_IG_MIR_CTL : B53_EG_MIR_CTL;
> + other_loc = ingress ? B53_EG_MIR_CTL : B53_IG_MIR_CTL;
> +
> + ret = b53_read16(dev, B53_MGMT_PAGE, loc, ®);
> + if (ret)
> + return ret;
> +
> + ret = b53_read16(dev, B53_MGMT_PAGE, other_loc, &other_reg);
> + if (ret)
> + return ret;
> +
> ret = b53_read16(dev, B53_MGMT_PAGE, B53_MIR_CAP_CTL, &cap_ctl);
> if (ret)
> return ret;
>
> - if ((cap_ctl & MIRROR_EN) &&
> + if (((reg | other_reg) & MIRROR_MASK) &&
> (cap_ctl & CAP_PORT_MASK) != mirror->to_local_port) {
[Severity: Medium]
This replaces the (cap_ctl & MIRROR_EN) check that "net: dsa: b53: reject
conflicting mirror destinations" added earlier in this series. Is that
earlier patch a regression on its own?
At that point in the series, nothing in setup clears the mirror
registers. The baseline add path always overwrote B53_MIR_CAP_CTL.
b53_switch_reset() only soft-resets some chips:
if (is539x(dev)) {
b53_write8(dev, B53_CTRL_PAGE, B53_SOFTRESET, 0x83);
b53_write8(dev, B53_CTRL_PAGE, B53_SOFTRESET, 0x00);
}
...
if (dev->chip_id == BCM58XX_DEVICE_ID ||
dev->chip_id == BCM583XX_DEVICE_ID) {
Take one of the other chips with no reset GPIO, where a bootloader or a
kexec'd kernel left MIRROR_EN set with a different capture port. The
first valid tc matchall mirror rule then fails with -EOPNOTSUPP.
If stale source bits were also left set, b53_mirror_del() never clears
MIRROR_EN. Another destination then can't be selected until a power
cycle.
The earlier patch carries Fixes: ed3af5fd08eb and a Reviewed-by, so
stable tooling can pick it up without this one. The "must be applied
after them" note only guards the other direction.
"net: dsa: b53: reference count shared mirror source bits" has a similar
problem. It increments mirror_count after unchecked writes, so a failed
first programming attempt is recorded as success. Later adds for the same
port and direction then return early instead of reprogramming. This
patch fixes that ordering too.
Would it be better to squash the b53_mirror_init() wiring and the
source-mask occupancy check into "reject conflicting mirror
destinations", and the mirror_count reordering into "reference count
shared mirror source bits"? Reordering the series so that no single
commit regresses would also work.
> NL_SET_ERR_MSG_MOD(extack,
> "Only one mirroring destination is supported");
> @@ -2673,19 +2688,17 @@ int b53_mirror_add(struct dsa_switch *ds, int port,
> return 0;
> }
>
> - if (ingress)
> - loc = B53_IG_MIR_CTL;
> - else
> - loc = B53_EG_MIR_CTL;
> -
> - b53_read16(dev, B53_MGMT_PAGE, loc, ®);
> - reg |= BIT(port);
> - b53_write16(dev, B53_MGMT_PAGE, loc, reg);
> -
> + /* Select the destination before enabling the new source. */
> cap_ctl &= ~CAP_PORT_MASK;
> cap_ctl |= mirror->to_local_port;
> cap_ctl |= MIRROR_EN;
> - b53_write16(dev, B53_MGMT_PAGE, B53_MIR_CAP_CTL, cap_ctl);
> + ret = b53_write16(dev, B53_MGMT_PAGE, B53_MIR_CAP_CTL, cap_ctl);
> + if (ret)
> + return ret;
> +
> + ret = b53_write16(dev, B53_MGMT_PAGE, loc, reg | BIT(port));
> + if (ret)
> + return ret;
>
> (*mirror_count)++;
[Severity: Low]
This is a pre-existing issue, but is the source and capture-port encoding
right here for BCM5325/BCM5365?
The source bit is written as BIT(port), so the CPU port uses bit 5 rather
than hardware bit 8. The destination is compared and written as a raw
port number under CAP_PORT_MASK, but these chips expect a port bitmap.
b53_mirror_init() uses the same encoding (cap_ctl = MIRROR_EN |
dev->mirror_port), and so does b53_mirror_del() (reg &= ~BIT(port)). The
hardware can then mirror the wrong source or destination while
mirror_count and mirror_port report the rule as installed.
The encoding goes back to ed3af5fd08eb. A later patch in this series,
"net: dsa: b53: fix mirror port encoding on BCM5325 and BCM5365", fixes
it. That patch adds b53_mirror_port_mask(), b53_mirror_capture_port(),
b53_mirror_capture_port_mask() and CAP_PORT_MASK_25, and uses them in the
init, add and del paths.
[ ... ]
--
Sashiko AI review ยท https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261116210943.1352656-1-florian.fainelli%40broadcom.com
Technical Details
Message-ID:
<179507941634.3136.10463696917464189508@kernel.org>Path:
mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-366874-linux-kernel-netdev=dewy.ruReferences:
<20261116210943.1352656-8-florian.fainelli@broadcom.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-366874-linux-kernel-netdev=dewy.ru From: netdev-bot+sashiko@kernel.org Newsgroups: linux.kernel.netdev Subject: Re: [PATCH net v6 7/8] net: dsa: b53: harden mirror register programming Date: Thu, 19 Nov 2026 09:10:16 +0000 Organization: Usenet Network Message-ID: <179507941634.3136.10463696917464189508@kernel.org> References: <20261116210943.1352656-8-florian.fainelli@broadcom.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="2835316"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:fr6vSRw6ljgRfb/cKNvPG+JQZoQ= sha256:N1LsRbALD3/xe6TGabg0IKfEd8XSakQQeCVuOlmXPjE= sha1:3ouKhENvCUmo24m/I/tmaOU1d4w= sha256:uVIAwe6NKx8RGJrI+pqVpZCLGpho9mzF3N/z5kVy6us= 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 D0756115578; Thu, 19 Nov 2026 12:10:38 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.4 X-Spam-Status: No, score=-3.4 tagged_above=-9999 required=6.31 tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, 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, URIBL_BLOCKED=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 ux2ak9wJkbC5; Thu, 19 Nov 2026 12:10:30 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-366874-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 2AAEC115574; Thu, 19 Nov 2026 12:10:22 +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 B1C9BE9B7D; Thu, 19 Nov 2026 09:10:19 +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=1795079418; b=Yu6Q7rh7g0Er5fGRaVQGL1TY0SK3Ym+gYwuI1QWURd3B3qnW7STpRlLh7dylY5xU4RQz dhRNod8RW0F2SjCZjWxrEFSn5tPm+Gyb7ZbxiFjgBphLZZJsg8Wtfqh4jh4FZ4p1SYiIV 5rOPqRJY5UPl84tzwmcMU+W9T1cdIlI4qelGuus/hAE+d3PTjodws1nRawfAEBMOMTRXc NYYEHd2TmJR48lwmD7xtJvV47LQGbBMvTnjDzzunr66Cg3mAA2O/cIr/mKQmjo38KhIh6 imQlX5MdP3eqfJwWZA9xWaCWDnhQ3bjcXvibU2Sv7s3ww2I1Q9GLkcsklg1v0oQSjuQ== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795079418; 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=QZaIpmJbdbbLJ0/+K2lgnwIVoF87UxKHw3bi+8cUMeI=; b=EqpJpQjKbuTo3iCXLBBjK/ndlf6WNkTBKf8ByvohVwjtfQ8j50dUM01/xkH0OMfN6mNJ 4M3s9UiCopg9INgWo9oe7x1Re0+Y3+v2zxQj9BDUYkgfhrHJGx6RvYMligaK2yntdfFNw XLUAlXxjtbmf3//g2B/F/h8oMS6ZXcgQyS7WEpM9T56EjUABLsg+eCHff8jdmrEqY2ild ttnok6Yo0tdVHfEY+EA732QNCaiFNl46/t06FdVHEB961hT2S74zjE6kuVzAdtM83bBYG XkVkhDr3Z06t53+zqklT/ksQkXnl5oUNxa0r9hp8ivxgoqo67078TBsFnv1WZwUQNlA== 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=n0ZG4SCx; 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 9F878606A33E; Thu, 19 Nov 2026 09:10:18 +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=n0ZG4SCx 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=1795079417; b=QvyqxJ5cVTjyNBpRc2xU6bkQOLDwhAvFQfImXEaEd2238JWSFWGff08qLXTSOS7rhj8F tXqFB+CAI+364NAB13gDOEji73oEH+A8g58LuqWemKOLXqt20kEVVa3IuUBLggIj1yGqk bHeJWCXlcYRrqxyAP2Rysf/Q1U+YgAs624USQy4TKGz7R7S+mXlaUEbtcOPHv6ijBn/Lt M8TmX/aSgoqGCWM1/+UTyyzFWZb3pYNOA1BXfFU9Km8zSnykMzJpIug6gbBw0c+T9ujjH wLhlU/ZlP6yoGvlKqlqp95u+P1iJJUvuDLtK7/hPcbveq/az3Rv9qajOwF25BMrSOlg== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795079417; 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=QZaIpmJbdbbLJ0/+K2lgnwIVoF87UxKHw3bi+8cUMeI=; b=4zP48ysYcsEyNiBQRbiAXwaPeoxz6cKuXp507kwzTymuSWwviHb2cTBHl/Pua9VczvuI Vt9O1Ok+XYaiZDIL03TuBH6trZQxx6O/G3TTYyP4PMt4HdXI0LN+IDLeI+k3cpjiIvBv5 yqY8PjuIK7H26UTUbnuBFELQ4RgLUWNwTQX0JQDRKWzcvVQo4tlpc9pHLumm0NO5fZ/E8 YHSMDYy/70fAlf23/sL9Xpud9f+88tnPso5ekgYjXx6Cl+8dCmbMxTM/EhCRW6yhmlNdh eukE1Xzz7xZp3+q9FvwwktzhJbe8WxfTaALZBw4VeuHUbsWkA/uXmWMhWU8FB0tHPBQ== 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=n0ZG4SCx; 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 C0E80606A326; Thu, 19 Nov 2026 09:10:17 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id CDB1F1F000C4; Thu, 19 Nov 2026 09:10:16 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795079417; bh=QZaIpmJbdbbLJ0/+K2lgnwIVoF87UxKHw3bi+8cUMeI=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=n0ZG4SCxH3CFGBQKpAGOjOTbSmbkbU/jbqQbT9GAJbMCquQ/Vq8wkbVUMdzVSwAkD q3HE+7GhBaWnU5dR7NALmPmOlm+jMyXM10X0sHNojf2WY5ruj//ZoAV/UUrsOTYuuc oP28MkPMPnJi0sr4usfP73DXRsjd5NhfpWIoW27xYvrWJgrpBeOQhZz6AygAaVQ11f md1roGbx61yL7zNmOzW+Jsiq0KmWLgpBzeCfniYyGcOqR3FgmmJEKK+1G4xOORKIg/ PnxVyNZGqgvyumB51dcO8noOyZ4VoY1gzoCixr59JoJXRCmvtKsTs8cfK1ZuNkGwOQ MTEq1qaBzsRgQ== X-Cc: netdev@vger.kernel.org, jonas.gorski@gmail.com, andrew@lunn.ch, olteanv@gmail.com, davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com, vivien.didelot@gmail.com, linux-kernel@vger.kernel.org X-In-Reply-To: <20261116210943.1352656-8-florian.fainelli@broadcom.com> X-sashiko-severity: Medium 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