mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Florian Fainelli <florian.fainelli@broadcom.com>
To: netdev-bot+sashiko@kernel.org
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 v6 7/8] net: dsa: b53: harden mirror register programming
Date: Thu, 19 Nov 2026 10:17:38 -0800	[thread overview]
Message-ID: <89b39817-2e4c-4aee-953d-b84cc075bb14@broadcom.com> (raw)
In-Reply-To: <179507941634.3136.10463696917464189508@kernel.org>

On 11/19/26 01:10, netdev-bot+sashiko@kernel.org wrote:
> 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, &reg);
>> +	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);
>> -	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.
> 
> [ ... ]
> 

Agreed. The conflicting-destination check can reject the first rule 
because of stale mirror state, and the reference-counting change can
retain a reference after failed register writes.

I will combine the destination check, mirror initialization, reference
counting and register error handling so these intermediate states are
not introduced. This will also keep b53_mirror_init() and its callers
together.

The BCM5325/BCM5365 encoding issue is addressed by patch #8; I will
move that fix before the combined change.

pw-bot: cr
-- 
Florian

  reply	other threads:[~2026-11-19 18:17 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-16 21:09 [PATCH net v6 0/8] net: dsa: b53: Preliminary fixes Florian Fainelli
2026-11-16 21:09 ` [PATCH net v6 1/8] net: dsa: b53: initialize the jumbo frame size register offset Florian Fainelli
2026-11-16 21:09 ` [PATCH net v6 2/8] net: dsa: b53: fix the SRAB grant timeout check Florian Fainelli
2026-11-16 21:09 ` [PATCH net v6 3/8] net: dsa: b53: clear stale state when creating an ARL entry Florian Fainelli
2026-11-16 21:09 ` [PATCH net v6 4/8] net: dsa: b53: reject conflicting mirror destinations Florian Fainelli
2026-11-16 21:09 ` [PATCH net v6 5/8] net: dsa: b53: use the correct override register 2 Gbps bit Florian Fainelli
2026-11-16 21:09 ` [PATCH net v6 6/8] net: dsa: b53: reference count shared mirror source bits Florian Fainelli
2026-11-16 21:09 ` [PATCH net v6 7/8] net: dsa: b53: harden mirror register programming Florian Fainelli
2026-11-19  9:10   ` netdev-bot+sashiko
2026-11-19 18:17     ` Florian Fainelli [this message]
2026-11-16 21:09 ` [PATCH net v6 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=89b39817-2e4c-4aee-953d-b84cc075bb14@broadcom.com \
    --to=florian.fainelli@broadcom.com \
    --cc=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=jonas.gorski@gmail.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev-bot+sashiko@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®