mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: florian.fainelli@broadcom.com
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
Subject: Re: [PATCH net v5 7/8] net: dsa: b53: harden mirror register programming
Date: Mon, 16 Nov 2026 19:02:22 +0000	[thread overview]
Message-ID: <179485574238.3136.7987059479392278091@kernel.org> (raw)
In-Reply-To: <20261112180202.324504-8-florian.fainelli@broadcom.com>

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] Speculative; needs datasheet confirmation.
- [Low] This patch fixes a regression that an earlier patch in the same
  series introduced, but its message says nothing about that or about…
- [Low] The commit message says the patch will "Clear capture control and
  both source-control registers during b53 and bcm_sf2 setup".

--

net: dsa: b53: harden mirror register programming

This commit calls b53_mirror_init() from b53_setup() and
bcm_sf2_sw_setup() to reset the mirror registers at setup. It checks
every mirror register read and write in b53_mirror_add() and
b53_mirror_del(), and only increments the source reference count after
programming succeeds. It also uses the ingress/egress source masks,
instead of MIRROR_EN, to decide whether the capture destination is in use.

> The mirror destination check can reject a first rule when a bootloader or
> previous kernel left mirroring enabled. Not all supported switches receive
> a hardware reset during setup. Unchecked register accesses can also
> corrupt mirror state or report an unsuccessful rule installation as
> successful. Reference counting must not record a first source reference
> until hardware programming has succeeded.

[ ... ]

> Fixes: ed3af5fd08eb ("net: dsa: b53: Add support for port mirroring")

[Severity: Low]
Is ed3af5fd08eb the right commit for the first problem described here?

Before this series, b53_mirror_add() overwrote B53_MIR_CAP_CTL and never
rejected a rule. The check that can reject a first rule because of stale
firmware state was added earlier in this series, by "net: dsa: b53: reject
conflicting mirror destinations":

	if ((cap_ctl & MIRROR_EN) &&
	    (cap_ctl & CAP_PORT_MASK) != mirror->to_local_port) {
		...
		return -EOPNOTSUPP;
	}

That patch does not clear the capture state at setup.

The same is true of the reference count increment that runs after
unchecked register accesses. It comes from "net: dsa: b53: reference count
shared mirror source bits". That patch also defined and exported
b53_mirror_init() but never called it, so this patch cannot build without
it.

All three patches carry the same Fixes: ed3af5fd08eb tag, and none of them
says what order they need to go in.

Suppose "reject conflicting mirror destinations" is picked up for stable
on its own. On a switch where the bootloader or a previous kernel left
MIRROR_EN set with a different capture port, would the first tc matchall
mirred rule then fail with -EOPNOTSUPP?

Could these fixes be folded into the patches that introduced the problems?
If not, could the commit message name those patches and the required
ordering?

> 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: Medium]
Are the mirror register offsets the same on every chip family that goes
through b53_setup()?

With this call, b53_mirror_init() writes zero to Management page offsets
0x10 (B53_MIR_CAP_CTL), 0x12 (B53_IG_MIR_CTL) and 0x1C (B53_EG_MIR_CTL) at
every setup, on every chip_id:

	ret = b53_write16(dev, B53_MGMT_PAGE, B53_MIR_CAP_CTL, 0);
	...
	ret = b53_write16(dev, B53_MGMT_PAGE, B53_IG_MIR_CTL, 0);
	...
	ret = b53_write16(dev, B53_MGMT_PAGE, B53_EG_MIR_CTL, 0);

Before this patch, these offsets were only written when a user installed a
matchall mirror rule.

The driver already treats the BCM63xx Management page layout as different
in at least one place:

	#define B53_AGING_TIME_CONTROL		0x06
	#define B53_AGING_TIME_CONTROL_63XX	0x08

The mirror registers have no 63xx variant, though. Nothing in the tree
confirms these offsets for BCM63xx either way, so this may be fine.

If BCM63xx, or another supported family, has a different register at 0x10,
0x12 or 0x1C, would that register now be silently zeroed on every boot?
A write to the wrong register would still return success here.

[ ... ]

> diff --git a/drivers/net/dsa/bcm_sf2.c b/drivers/net/dsa/bcm_sf2.c
> index 98a4a62ca73a2..85ea32fb501db 100644
> --- a/drivers/net/dsa/bcm_sf2.c
> +++ b/drivers/net/dsa/bcm_sf2.c
> @@ -1063,6 +1063,10 @@ static int bcm_sf2_sw_setup(struct dsa_switch *ds)
>  	unsigned int port;
>  	int ret;
>  
> +	ret = b53_mirror_init(ds);
> +	if (ret)
> +		return ret;
> +

[Severity: Low]
The commit message says:

  Clear capture control and both source-control registers during b53 and
  bcm_sf2 setup, propagating initialization failures.

b53_mirror_init() does more than clear these registers. After writing zero
to them, it rebuilds the source masks from dev->ports[].mirror_count[] and
writes the capture port back:

	cap_ctl = MIRROR_EN | dev->mirror_port;

On bcm_sf2 this also runs on every resume:

bcm_sf2_sw_resume()
  ds->ops->setup()
    bcm_sf2_sw_setup()
      b53_mirror_init()

So with this patch, active tc mirror rules are restored from software state
after each resume. A failed mirror register access also makes resume fail.

No patch in the series describes this restore behaviour. Could the commit
message mention it, so that readers don't expect resume to wipe active
mirror rules?

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261112180202.324504-1-florian.fainelli%40broadcom.com

  reply	other threads:[~2026-11-16 19:02 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-12 18:01 [PATCH net v5 0/8] net: dsa: b53: Preliminary fixes Florian Fainelli
2026-11-12 18:01 ` [PATCH net v5 1/8] net: dsa: b53: initialize the jumbo frame size register offset Florian Fainelli
2026-11-12 18:01 ` [PATCH net v5 2/8] net: dsa: b53: fix the SRAB grant timeout check Florian Fainelli
2026-11-12 18:01 ` [PATCH net v5 3/8] net: dsa: b53: clear stale state when creating an ARL entry Florian Fainelli
2026-11-16 19:02   ` netdev-bot+sashiko
2026-11-16 20:37     ` Florian Fainelli
2026-11-12 18:01 ` [PATCH net v5 4/8] net: dsa: b53: reject conflicting mirror destinations Florian Fainelli
2026-11-16 19:02   ` netdev-bot+sashiko
2026-11-16 20:38     ` Florian Fainelli
2026-11-12 18:01 ` [PATCH net v5 5/8] net: dsa: b53: use the correct override register 2 Gbps bit Florian Fainelli
2026-11-16 19:02   ` netdev-bot+sashiko
2026-11-16 20:41     ` Florian Fainelli
2026-11-12 18:02 ` [PATCH net v5 6/8] net: dsa: b53: reference count shared mirror source bits Florian Fainelli
2026-11-16 19:02   ` netdev-bot+sashiko
2026-11-16 20:42     ` Florian Fainelli
2026-11-12 18:02 ` [PATCH net v5 7/8] net: dsa: b53: harden mirror register programming Florian Fainelli
2026-11-16 19:02   ` netdev-bot+sashiko [this message]
2026-11-16 20:47     ` Florian Fainelli
2026-11-12 18:02 ` [PATCH net v5 8/8] net: dsa: b53: fix mirror port encoding on BCM5325 and BCM5365 Florian Fainelli

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=179485574238.3136.7987059479392278091@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=florian.fainelli@broadcom.com \
    --cc=jonas.gorski@gmail.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=olteanv@gmail.com \
    --cc=pabeni@redhat.com \
    --cc=vivien.didelot@gmail.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

all inboxes | Powered by JetHome®