Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp1615708pxb; Mon, 11 Oct 2021 09:32:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzVC4qPeAi0UccrGNt4z9tz9yLzp5CngDpq5Hz2Wg6q8ap98YgMvMxs4GyQ56690YXCk/0Y X-Received: by 2002:a17:90a:858e:: with SMTP id m14mr24372805pjn.1.1633969955224; Mon, 11 Oct 2021 09:32:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633969955; cv=none; d=google.com; s=arc-20160816; b=EjzGSBEHntJNxPSkyD3bPUGTm+S6sUb3CnPlMtwcyg2NPYTL/1g6Wby+t6NvtONFig 3oYQwU+oraWHksSGYKEE1gOxSw9K2AObOck9qNji4TxOm8QVMgj6jYCL+ZelPDWQ17MO Ju+hNzClMAvB8Q18d1fY6OpNGN4/dhMq2XVpwjwRzwV7MyVN/RP2mXSlhVaSWs/lR3GS 3UaWB6v/j9srJi2rUYhlOLVlrHNFA/AaoB5V0j3Mwwe/WAo+qElp1WfsaySPg1RzJXgP m70dOEMfL+Io+yxd4XJrJrQKfMBJW5KnooWwwEPby0OUN8WhHjAjXmX0m0bVuNpiD09j MIyw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=wTfqwFru7gaZTXG77BwdUo/kPZCS5TaU7cRmjdKPRJs=; b=RlLVhxx7VZVMAsPGqUQGYBZyHJ7vlDHpIddHDX25vj0TBS1FrWJR4Srk+Nd6VwMkZU glbRKyz+RLXZQi+Ny81e6PnNrbNCWXXhg0o8+1AR+oc2hsmcEDCD7EdRpT7P6LHmQ6Jq 1mMljoAVnwHvyApq8kynRdOYxfPaVNJ7hCdlGNmRtISXv0kkWitzZB3CZm+scIPeccS/ w8ji7vJ7FCNOQ0r79h27XbDGq5H3ZUiG3yThKQ/v2xP98/UbU8YQ9+USBgRFU3U2iDTJ csmGwKwh2MUqkyhGlei36jQPCVM3ZHC4IBF2eXxNT2IL3RdYd9IzOzt+G/eOjodahfCr y4Ow== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=NFM1Frf+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 125si10562523pff.12.2021.10.11.09.32.22; Mon, 11 Oct 2021 09:32:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=NFM1Frf+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236759AbhJKN7P (ORCPT + 99 others); Mon, 11 Oct 2021 09:59:15 -0400 Received: from mail.kernel.org ([198.145.29.99]:41126 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237254AbhJKN5P (ORCPT ); Mon, 11 Oct 2021 09:57:15 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 7328E611F2; Mon, 11 Oct 2021 13:54:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1633960446; bh=Jyq5ujnIrhvwj6wUcRNIXe9hjLrv2Y2WyFWQG6EYZ9o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NFM1Frf+CWBWVXPqXg7rz3aqZzKgZ8GAkWi1hSLl0xT0ujKU5ZkNTQtK8Sb5d+7wi vXUOBf5pqZnHjLTLbqgjy3k6OFK6maSZplOtNqBVRGoFrKOzkrtCeEYwwFvgeguj6G 25lN8jcjNC5Oya5IE7CePiPnq/e2gd3GqBWpKlb8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Eric Dumazet , Catherine Sullivan , Sagi Shahar , Jon Olson , Willem de Bruijn , Luigi Rizzo , Jeroen de Borst , Tao Liu , "David S. Miller" , Sasha Levin Subject: [PATCH 5.10 62/83] gve: fix gve_get_stats() Date: Mon, 11 Oct 2021 15:46:22 +0200 Message-Id: <20211011134510.527974592@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211011134508.362906295@linuxfoundation.org> References: <20211011134508.362906295@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Eric Dumazet [ Upstream commit 2f57d4975fa027eabd35fdf23a49f8222ef3abf2 ] gve_get_stats() can report wrong numbers if/when u64_stats_fetch_retry() returns true. What is needed here is to sample values in temporary variables, and only use them after each loop is ended. Fixes: f5cedc84a30d ("gve: Add transmit and receive support") Signed-off-by: Eric Dumazet Cc: Catherine Sullivan Cc: Sagi Shahar Cc: Jon Olson Cc: Willem de Bruijn Cc: Luigi Rizzo Cc: Jeroen de Borst Cc: Tao Liu Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- drivers/net/ethernet/google/gve/gve_main.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/drivers/net/ethernet/google/gve/gve_main.c b/drivers/net/ethernet/google/gve/gve_main.c index 22b2c6a8d08f..b658bf9b5399 100644 --- a/drivers/net/ethernet/google/gve/gve_main.c +++ b/drivers/net/ethernet/google/gve/gve_main.c @@ -30,6 +30,7 @@ static void gve_get_stats(struct net_device *dev, struct rtnl_link_stats64 *s) { struct gve_priv *priv = netdev_priv(dev); unsigned int start; + u64 packets, bytes; int ring; if (priv->rx) { @@ -37,10 +38,12 @@ static void gve_get_stats(struct net_device *dev, struct rtnl_link_stats64 *s) do { start = u64_stats_fetch_begin(&priv->rx[ring].statss); - s->rx_packets += priv->rx[ring].rpackets; - s->rx_bytes += priv->rx[ring].rbytes; + packets = priv->rx[ring].rpackets; + bytes = priv->rx[ring].rbytes; } while (u64_stats_fetch_retry(&priv->rx[ring].statss, start)); + s->rx_packets += packets; + s->rx_bytes += bytes; } } if (priv->tx) { @@ -48,10 +51,12 @@ static void gve_get_stats(struct net_device *dev, struct rtnl_link_stats64 *s) do { start = u64_stats_fetch_begin(&priv->tx[ring].statss); - s->tx_packets += priv->tx[ring].pkt_done; - s->tx_bytes += priv->tx[ring].bytes_done; + packets = priv->tx[ring].pkt_done; + bytes = priv->tx[ring].bytes_done; } while (u64_stats_fetch_retry(&priv->tx[ring].statss, start)); + s->tx_packets += packets; + s->tx_bytes += bytes; } } } -- 2.33.0