Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp1613727pxb; Mon, 11 Oct 2021 09:30:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxlBHuQ5tx83YOxRzIuoRnPKwLwa6TQLoaJGDIoN5Gq3osUEYDtU+blj6G19ha9HwU92Eaz X-Received: by 2002:a17:90b:33c3:: with SMTP id lk3mr4962412pjb.237.1633969824664; Mon, 11 Oct 2021 09:30:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633969824; cv=none; d=google.com; s=arc-20160816; b=ZCGXyfRzJwJRa6VExFU8sC7dUl8wQoscIejerqnw2znUwsbC26rBFo2rUk/YcZoC2s 2Df4JaJr7VJsc3jNFpx+5ue0t7CW7G89jdCN5gwpG4rqZBeF61prUmMiJJg5DJzuxmD8 vJQtTgEYBwctE0Ke5wZh/gvnTjfiYsYPY73LgDDfRflPDrLtGPeBUZ7FupcFJxceHqsz Pn55IjpFpVg6iRFzyywcmxfpGw2TsOwccxn06Sub0C25HAHKThecQYywD5LknyV2YtGR tgusp+QjomhO1Cn/7dcNM4CyxlfFAe12UuNfdjT0InAuWWL70fSqGfqb/2avuA18ncBW yzOw== 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=bKC6tZIPIgUf6we/q3NHayLimBTXRM3vWl1F2fLV6N4=; b=ll2NW/oPY6tVE+d7/wqD1ktx4v2BW45g//NXKpZlpaVX7nvcuNdlM/yJnRNXQ7fatK eXtcrTsaaFmUc4QRYQXDH1gFz6092RAnyZOLEBSrp6iPz7sr3zcyzT5pwHZL/nrii9y7 pxzk+RQVMYnuW5600gRJTJtHOFG+mBo6V732LTFsLLzVuQiS0QbShGBZqcqOtYQhMmBS TrHqMJFfd1NNNYBBBTKPney5RdEBmXt7eO5IzLeoAQBBPmL3aI/Ln66/ocbd8/RpEEju fDfcbHnOnAJN09UPN1ScJJGbj6CscI+rQn51S5tNvoDllv8m+65n9w+xFfXyQOcHUig4 eRrg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=xnZK0D8f; 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 s4si11133196plq.25.2021.10.11.09.30.12; Mon, 11 Oct 2021 09:30:24 -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=xnZK0D8f; 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 S235251AbhJKNwl (ORCPT + 99 others); Mon, 11 Oct 2021 09:52:41 -0400 Received: from mail.kernel.org ([198.145.29.99]:39898 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237312AbhJKNv3 (ORCPT ); Mon, 11 Oct 2021 09:51:29 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id D2E9F60F6E; Mon, 11 Oct 2021 13:49:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1633960169; bh=keNjjvzLQJSgEUpmj8FQWPXJPc1fSunGgn1xTTnt5Pg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xnZK0D8fQ9bN8/XXA5mYwaLPH/kAGwkgOVTPWf3ZIrBPrCwCq9zQ1fseA8x8ZFaSI emheSCl9xE6T9rpYSv0kxU1GFZqTnERT3u8kDD7t+p0mxf9marTe/0qcsFsTypfMbK Hw8qlmBbQkI9SZ8qNoKt/r4PUUTPnU/+sVjwkf80= 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.4 42/52] gve: fix gve_get_stats() Date: Mon, 11 Oct 2021 15:46:11 +0200 Message-Id: <20211011134505.163433262@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211011134503.715740503@linuxfoundation.org> References: <20211011134503.715740503@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 f8dfa7501f65..5b450c6100ad 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