Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3934158pxj; Mon, 21 Jun 2021 09:41:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw2zkQiilRqx+YHYR2UJFk5xTRF2Xpd2BWW7ra72HvwCWco7MJicy/H7wrQBHI5nXwz9L4J X-Received: by 2002:a02:2384:: with SMTP id u126mr18705712jau.143.1624293681899; Mon, 21 Jun 2021 09:41:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624293681; cv=none; d=google.com; s=arc-20160816; b=A56AJzVUyZO9RSA2IoC/vMvj8pJFmRy/b3INxpH9Z8Z3iXTbMOeF8EakSc4ZomfJpw k/nZpHrjXw2aAQearQdCx4kv44lsQtl2I2Gy2Y80FnkZGV2pl7EUcwPTj2jjagwX4inn 1f+IGKnqgqd8uNWrabR3FBuDV5lCXg4i6rQNkfdLZfgRjOukx6BQTQs2TKorpddCI66V PjSmr6JWH/fNgWzyre8BfCnzcY74nLFFzZL+NFwhx6RwAVRWDzs5Dx7+2mGdYpRE+fXj r0lFgPqkt6ZAqRnmPVnn2B9JpbGJxpoI0QDOo2Wy436qhSxfi1zI9XUzSEF8eX+lypff jWLQ== 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=qJB9nV/p0eOtwcpCmfqWBM+0ZQsvHl3nsWgehIjL3L4=; b=IF4I0AJqSULwJcCd+zfgXJKqnuKq7MVN62XTmOpGMs3LGwSqp2PX6WNQeLQgSe2E3W FfSArm4DDvHQxEvnP/TF4oS5h6WllJVXaw+HA+NXREU/imNBB4gWbKQZtVp+ApypcuNO 5LZN6xMOBd17/wLDSxbP63BGH2oboVTzm78XXXVP4UGXodBKEE7ylD4G+kqH6hvbYOr5 ZJOSDIvGJxVUfKgRDABx9DjdODkswWfGek2nFPsF6HwxSVKxGRXDthtEOxrb8wLInZJZ vJ003DHQWaO9G4g4Q3b0WJJN2GkNFB/gV8P24XBs/xAX4lK5KXSct4u0JdWK6ZZGSrId WNgg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=hplWNz87; 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 n3si21371929jaj.18.2021.06.21.09.41.09; Mon, 21 Jun 2021 09:41:21 -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=hplWNz87; 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 S232589AbhFUQmp (ORCPT + 99 others); Mon, 21 Jun 2021 12:42:45 -0400 Received: from mail.kernel.org ([198.145.29.99]:33868 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233090AbhFUQjS (ORCPT ); Mon, 21 Jun 2021 12:39:18 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 52CCE6142C; Mon, 21 Jun 2021 16:29:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1624292986; bh=hSTdOlQt8ax+4Aja3rCVbTqTIvD2N8XmRgqSRxE6WKs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hplWNz87ce6v5tEIMcryJeT7vfyJi1rUlVURmRw2v1pXc+s4oePS+QYT3uV5rdCLc TDFg3Yd7GsLM7MafPpi6dxdA8SAFba/j9u81hH7lx7phaHeHokv17jTpTcNiALZDYR 3Ux9dP6T2+eijoGt7pNKip7bgiF/fQrmJdvRL9O4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Alex Elder , "David S. Miller" , Sasha Levin Subject: [PATCH 5.12 055/178] net: qualcomm: rmnet: dont over-count statistics Date: Mon, 21 Jun 2021 18:14:29 +0200 Message-Id: <20210621154924.300920608@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210621154921.212599475@linuxfoundation.org> References: <20210621154921.212599475@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: Alex Elder [ Upstream commit 994c393bb6886d6d94d628475b274a8cb3fc67a4 ] The purpose of the loop using u64_stats_fetch_*_irq() is to ensure statistics on a given CPU are collected atomically. If one of the statistics values gets updated within the begin/retry window, the loop will run again. Currently the statistics totals are updated inside that window. This means that if the loop ever retries, the statistics for the CPU will be counted more than once. Fix this by taking a snapshot of a CPU's statistics inside the protected window, and then updating the counters with the snapshot values after exiting the loop. (Also add a newline at the end of this file...) Fixes: 192c4b5d48f2a ("net: qualcomm: rmnet: Add support for 64 bit stats") Signed-off-by: Alex Elder Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- .../net/ethernet/qualcomm/rmnet/rmnet_vnd.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/drivers/net/ethernet/qualcomm/rmnet/rmnet_vnd.c b/drivers/net/ethernet/qualcomm/rmnet/rmnet_vnd.c index 41fbd2ceeede..ab1e0fcccabb 100644 --- a/drivers/net/ethernet/qualcomm/rmnet/rmnet_vnd.c +++ b/drivers/net/ethernet/qualcomm/rmnet/rmnet_vnd.c @@ -126,24 +126,24 @@ static void rmnet_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *s) { struct rmnet_priv *priv = netdev_priv(dev); - struct rmnet_vnd_stats total_stats; + struct rmnet_vnd_stats total_stats = { }; struct rmnet_pcpu_stats *pcpu_ptr; + struct rmnet_vnd_stats snapshot; unsigned int cpu, start; - memset(&total_stats, 0, sizeof(struct rmnet_vnd_stats)); - for_each_possible_cpu(cpu) { pcpu_ptr = per_cpu_ptr(priv->pcpu_stats, cpu); do { start = u64_stats_fetch_begin_irq(&pcpu_ptr->syncp); - total_stats.rx_pkts += pcpu_ptr->stats.rx_pkts; - total_stats.rx_bytes += pcpu_ptr->stats.rx_bytes; - total_stats.tx_pkts += pcpu_ptr->stats.tx_pkts; - total_stats.tx_bytes += pcpu_ptr->stats.tx_bytes; + snapshot = pcpu_ptr->stats; /* struct assignment */ } while (u64_stats_fetch_retry_irq(&pcpu_ptr->syncp, start)); - total_stats.tx_drops += pcpu_ptr->stats.tx_drops; + total_stats.rx_pkts += snapshot.rx_pkts; + total_stats.rx_bytes += snapshot.rx_bytes; + total_stats.tx_pkts += snapshot.tx_pkts; + total_stats.tx_bytes += snapshot.tx_bytes; + total_stats.tx_drops += snapshot.tx_drops; } s->rx_packets = total_stats.rx_pkts; @@ -354,4 +354,4 @@ int rmnet_vnd_update_dev_mtu(struct rmnet_port *port, } return 0; -} \ No newline at end of file +} -- 2.30.2