From nobody Fri Dec 19 16:01:34 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 81868C433FE for ; Sat, 22 Oct 2022 08:28:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233872AbiJVI2X (ORCPT ); Sat, 22 Oct 2022 04:28:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37776 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233857AbiJVI1c (ORCPT ); Sat, 22 Oct 2022 04:27:32 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B097627022B; Sat, 22 Oct 2022 01:01:03 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 4C4BA60B9B; Sat, 22 Oct 2022 08:00:42 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 12F27C43141; Sat, 22 Oct 2022 08:00:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666425641; bh=R9mXsIyShsVWJOH9MSgqLniCVDqACxw0AMWjzPQJhRE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gVeYf7aN9Gj1EXAJV9c0bZrQjaYCnM+mruM93I6DHSMcICuegWdPIFN/yHTNt8uB0 xk9wj2U7IPXta22QCKEti4yDW++BYkRhHGDHSSMTq8W19wOH9ibD/7BX3lj0++9mEq Fq3SQ74CFrdkKfVNMXN38FnwT8b5u4RpwHkGL21w= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Robert Hancock , Jakub Kicinski , Sasha Levin Subject: [PATCH 5.19 568/717] net: axienet: Switch to 64-bit RX/TX statistics Date: Sat, 22 Oct 2022 09:27:27 +0200 Message-Id: <20221022072523.516220122@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221022072415.034382448@linuxfoundation.org> References: <20221022072415.034382448@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Robert Hancock [ Upstream commit cb45a8bf4693965e89d115cd2c510f12bc127c37 ] The RX and TX byte/packet statistics in this driver could be overflowed relatively quickly on a 32-bit platform. Switch these stats to use the u64_stats infrastructure to avoid this. Signed-off-by: Robert Hancock Link: https://lore.kernel.org/r/20220829233901.3429419-1-robert.hancock@cal= ian.com Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- drivers/net/ethernet/xilinx/xilinx_axienet.h | 12 ++++++ .../net/ethernet/xilinx/xilinx_axienet_main.c | 37 +++++++++++++++++-- 2 files changed, 45 insertions(+), 4 deletions(-) diff --git a/drivers/net/ethernet/xilinx/xilinx_axienet.h b/drivers/net/eth= ernet/xilinx/xilinx_axienet.h index f2e2261b4b7d..8ff4333de2ad 100644 --- a/drivers/net/ethernet/xilinx/xilinx_axienet.h +++ b/drivers/net/ethernet/xilinx/xilinx_axienet.h @@ -402,6 +402,9 @@ struct axidma_bd { * @rx_bd_num: Size of RX buffer descriptor ring * @rx_bd_ci: Stores the index of the Rx buffer descriptor in the ring bei= ng * accessed currently. + * @rx_packets: RX packet count for statistics + * @rx_bytes: RX byte count for statistics + * @rx_stat_sync: Synchronization object for RX stats * @napi_tx: NAPI TX control structure * @tx_dma_cr: Nominal content of TX DMA control register * @tx_bd_v: Virtual address of the TX buffer descriptor ring @@ -411,6 +414,9 @@ struct axidma_bd { * complete. Only updated at runtime by TX NAPI poll. * @tx_bd_tail: Stores the index of the next Tx buffer descriptor in the r= ing * to be populated. + * @tx_packets: TX packet count for statistics + * @tx_bytes: TX byte count for statistics + * @tx_stat_sync: Synchronization object for TX stats * @dma_err_task: Work structure to process Axi DMA errors * @tx_irq: Axidma TX IRQ number * @rx_irq: Axidma RX IRQ number @@ -458,6 +464,9 @@ struct axienet_local { dma_addr_t rx_bd_p; u32 rx_bd_num; u32 rx_bd_ci; + u64_stats_t rx_packets; + u64_stats_t rx_bytes; + struct u64_stats_sync rx_stat_sync; =20 struct napi_struct napi_tx; u32 tx_dma_cr; @@ -466,6 +475,9 @@ struct axienet_local { u32 tx_bd_num; u32 tx_bd_ci; u32 tx_bd_tail; + u64_stats_t tx_packets; + u64_stats_t tx_bytes; + struct u64_stats_sync tx_stat_sync; =20 struct work_struct dma_err_task; =20 diff --git a/drivers/net/ethernet/xilinx/xilinx_axienet_main.c b/drivers/ne= t/ethernet/xilinx/xilinx_axienet_main.c index 1760930ec0c4..9262988d26a3 100644 --- a/drivers/net/ethernet/xilinx/xilinx_axienet_main.c +++ b/drivers/net/ethernet/xilinx/xilinx_axienet_main.c @@ -752,8 +752,10 @@ static int axienet_tx_poll(struct napi_struct *napi, i= nt budget) if (lp->tx_bd_ci >=3D lp->tx_bd_num) lp->tx_bd_ci %=3D lp->tx_bd_num; =20 - ndev->stats.tx_packets +=3D packets; - ndev->stats.tx_bytes +=3D size; + u64_stats_update_begin(&lp->tx_stat_sync); + u64_stats_add(&lp->tx_packets, packets); + u64_stats_add(&lp->tx_bytes, size); + u64_stats_update_end(&lp->tx_stat_sync); =20 /* Matches barrier in axienet_start_xmit */ smp_mb(); @@ -984,8 +986,10 @@ static int axienet_rx_poll(struct napi_struct *napi, i= nt budget) cur_p =3D &lp->rx_bd_v[lp->rx_bd_ci]; } =20 - lp->ndev->stats.rx_packets +=3D packets; - lp->ndev->stats.rx_bytes +=3D size; + u64_stats_update_begin(&lp->rx_stat_sync); + u64_stats_add(&lp->rx_packets, packets); + u64_stats_add(&lp->rx_bytes, size); + u64_stats_update_end(&lp->rx_stat_sync); =20 if (tail_p) axienet_dma_out_addr(lp, XAXIDMA_RX_TDESC_OFFSET, tail_p); @@ -1292,10 +1296,32 @@ static int axienet_ioctl(struct net_device *dev, st= ruct ifreq *rq, int cmd) return phylink_mii_ioctl(lp->phylink, rq, cmd); } =20 +static void +axienet_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *stat= s) +{ + struct axienet_local *lp =3D netdev_priv(dev); + unsigned int start; + + netdev_stats_to_stats64(stats, &dev->stats); + + do { + start =3D u64_stats_fetch_begin_irq(&lp->rx_stat_sync); + stats->rx_packets =3D u64_stats_read(&lp->rx_packets); + stats->rx_bytes =3D u64_stats_read(&lp->rx_bytes); + } while (u64_stats_fetch_retry_irq(&lp->rx_stat_sync, start)); + + do { + start =3D u64_stats_fetch_begin_irq(&lp->tx_stat_sync); + stats->tx_packets =3D u64_stats_read(&lp->tx_packets); + stats->tx_bytes =3D u64_stats_read(&lp->tx_bytes); + } while (u64_stats_fetch_retry_irq(&lp->tx_stat_sync, start)); +} + static const struct net_device_ops axienet_netdev_ops =3D { .ndo_open =3D axienet_open, .ndo_stop =3D axienet_stop, .ndo_start_xmit =3D axienet_start_xmit, + .ndo_get_stats64 =3D axienet_get_stats64, .ndo_change_mtu =3D axienet_change_mtu, .ndo_set_mac_address =3D netdev_set_mac_address, .ndo_validate_addr =3D eth_validate_addr, @@ -1850,6 +1876,9 @@ static int axienet_probe(struct platform_device *pdev) lp->rx_bd_num =3D RX_BD_NUM_DEFAULT; lp->tx_bd_num =3D TX_BD_NUM_DEFAULT; =20 + u64_stats_init(&lp->rx_stat_sync); + u64_stats_init(&lp->tx_stat_sync); + netif_napi_add(ndev, &lp->napi_rx, axienet_rx_poll, NAPI_POLL_WEIGHT); netif_napi_add(ndev, &lp->napi_tx, axienet_tx_poll, NAPI_POLL_WEIGHT); =20 --=20 2.35.1