Re: [PATCH v5 net-next 3/3] net: mscc: ocelot: use bulk reads for stats

From: Vladimir Oltean
Date: Tue Feb 08 2022 - 10:34:57 EST


On Tue, Feb 08, 2022 at 05:03:03PM +0200, Vladimir Oltean wrote:
> > for (i = 0; i < ocelot->num_phys_ports; i++) {
> > + unsigned int idx = 0;
> > +
>
> This is a bug which causes ocelot->stats to be overwritten with the
> statistics of port 0, for all ports. Either move the variable
> declaration and initialization with 0 in the larger scope (outside the
> "for" loop), or initialize idx with i * ocelot->num_stats.

My analysis was slightly incorrect. Somehow I managed to fool myself
into thinking that you had tested this in a limited scenario, hence the
reason you didn't notice it's not working. But apparently you didn't
test with traffic at all.

So ocelot->stats isn't overwritten with the stats of port 0 for all
ports. But rather, all ports write into the ocelot->stats space
dedicated for port 0, effectively overwriting the stats of port 0 with
the stats of the last port. And no one populates the ocelot->stats space
for ports [1 .. last]. So no port has good statistics, I don't see a
circumstance where testing could have misled you.