lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID:
 <DM3PR11MB87364054C23D4B64069F4639EC28A@DM3PR11MB8736.namprd11.prod.outlook.com>
Date: Mon, 11 Aug 2025 20:47:59 +0000
From: <Tristram.Ha@...rochip.com>
To: <marek.vasut@...lbox.org>
CC: <andrew@...n.ch>, <Arun.Ramadoss@...rochip.com>, <edumazet@...gle.com>,
	<kuba@...nel.org>, <pabeni@...hat.com>, <UNGLinuxDriver@...rochip.com>,
	<olteanv@...il.com>, <Woojung.Huh@...rochip.com>, <netdev@...r.kernel.org>
Subject: RE: [net-next,PATCH] net: dsa: microchip: Do not count RX/TX Bytes
 and discards on KSZ87xx

> Unlike KSZ94xx, the KSZ87xx is missing the last four MIB counters at
> address 0x20..0x23, namely rx_total, tx_total, rx_discards, tx_discards.
> 
> Using values from rx_total / tx_total in rx_bytes / tx_bytes calculation
> results in an underflow, because rx_total / tx_total returns values 0,
> and the "raw->rx_total - stats->rx_packets * ETH_FCS_LEN;" calculation
> undeflows if rx_packets / tx_packets is > 0 .
> 
> Stop using the missing MIB counters on KSZ87xx .
> 
> Fixes: c6101dd7ffb8 ("net: dsa: ksz9477: move get_stats64 to ksz_common.c")
> Signed-off-by: Marek Vasut <marek.vasut@...lbox.org>
> ---
> Cc: Andrew Lunn <andrew@...n.ch>
> Cc: Arun Ramadoss <arun.ramadoss@...rochip.com>
> Cc: Eric Dumazet <edumazet@...gle.com>
> Cc: Jakub Kicinski <kuba@...nel.org>
> Cc: Paolo Abeni <pabeni@...hat.com>
> Cc: Tristram Ha <tristram.ha@...rochip.com>
> Cc: UNGLinuxDriver@...rochip.com
> Cc: Vladimir Oltean <olteanv@...il.com>
> Cc: Woojung Huh <woojung.huh@...rochip.com>
> Cc: netdev@...r.kernel.org
> ---
>  drivers/net/dsa/microchip/ksz_common.c | 13 ++++++++-----
>  1 file changed, 8 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/net/dsa/microchip/ksz_common.c
> b/drivers/net/dsa/microchip/ksz_common.c
> index 7292bfe2f7cac..9c01526779a6d 100644
> --- a/drivers/net/dsa/microchip/ksz_common.c
> +++ b/drivers/net/dsa/microchip/ksz_common.c
> @@ -2239,20 +2239,23 @@ void ksz_r_mib_stats64(struct ksz_device *dev, int port)
>         /* HW counters are counting bytes + FCS which is not acceptable
>          * for rtnl_link_stats64 interface
>          */
> -       stats->rx_bytes = raw->rx_total - stats->rx_packets * ETH_FCS_LEN;
> -       stats->tx_bytes = raw->tx_total - stats->tx_packets * ETH_FCS_LEN;
> -
> +       if (!ksz_is_ksz87xx(dev)) {
> +               stats->rx_bytes = raw->rx_total - stats->rx_packets * ETH_FCS_LEN;
> +               stats->tx_bytes = raw->tx_total - stats->tx_packets * ETH_FCS_LEN;
> +       }
>         stats->rx_length_errors = raw->rx_undersize + raw->rx_fragments +
>                 raw->rx_oversize;
> 
>         stats->rx_crc_errors = raw->rx_crc_err;
>         stats->rx_frame_errors = raw->rx_align_err;
> -       stats->rx_dropped = raw->rx_discards;
> +       if (!ksz_is_ksz87xx(dev))
> +               stats->rx_dropped = raw->rx_discards;
>         stats->rx_errors = stats->rx_length_errors + stats->rx_crc_errors +
>                 stats->rx_frame_errors  + stats->rx_dropped;
> 
>         stats->tx_window_errors = raw->tx_late_col;
> -       stats->tx_fifo_errors = raw->tx_discards;
> +       if (!ksz_is_ksz87xx(dev))
> +               stats->tx_fifo_errors = raw->tx_discards;
>         stats->tx_aborted_errors = raw->tx_exc_col;
>         stats->tx_errors = stats->tx_window_errors + stats->tx_fifo_errors +
>                 stats->tx_aborted_errors;

I am not sure why you have that problem.  In my KSZ8795 board running in
kernel 6.16 those counters are working.  Using "ethtool -S lan3" or
"ethtool -S eth0" shows rx_total and tx_total.  The "rx_discards" and
"tx_discards" are hard to get.  In KSZ8863 the "tx_discards" counter is
incremented when the port does not have link and a packet is sent to that
port.  In newer switches that behavior was changed.  Occasionally you may
get 1 or 2 at the beginning when the tail tagging function is not enabled
yet but the MAC sends out packets.  The "rx_discards" count typically
seldom happens, but somehow in my first bootup there are many from my
KSZ8795 board.

Actually that many rx_discards may be a problem I need to find out.

I think you are confused about how those MIB counters are read from
KSZ8795.  They are not using the code in ksz9477.c but in ksz8.c.


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ