Re: [PATCH net v5 7/8] net: dsa: b53: harden mirror register programming

From: Florian Fainelli

Date: Mon Nov 16 2026 - 15:47:24 EST


On 11/16/26 11:02, netdev-bot+sashiko@xxxxxxxxxx wrote:
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?


[Medium] b53_mirror_add()/b53_mirror_del() are already wired up for every chip handled by b53_switch_ops, including BCM63xx, and they use the same three management page offsets (0x10, 0x12, 0x1C) without any per-chip variant. b53_mirror_init() touches exactly those registers and nothing else, so setup does not write to any register that the mirror callbacks would not already write. The mirror registers are at the same offsets on BCM63xx. In the BCM6368, BCM6362 and BCM63268 register documentation, the Mirror Capture Control, Ingress Mirror Control and Egress Mirror Control registers are at Management page (0x02) offsets 0x10, 0x12 and 0x1C. These are the same registers the existing port_mirror_add/del callbacks program on every b53_switch_ops chip, so zeroing them at setup does not touch an unrelated register.

[Low] Agreed on both. v6 describes the restore of active mirror rules
(bcm_sf2 runs setup again on resume) and documents the dependency on
"reject conflicting mirror destinations" and "reference count shared
mirror source bits".
--
Florian