Received: by 2002:ab2:6816:0:b0:1f9:5764:f03e with SMTP id t22csp2770781lqo; Mon, 20 May 2024 16:59:19 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVih9iHCswQ5eM4f6c1StgMJwJnftxiaQv+U2y7Y2LCdc+0B41rUOLYJN2IiLmWphrw14DuqVkue6Q6XKsTYraVRzEFPvobR5BvAFUAzQ== X-Google-Smtp-Source: AGHT+IGU+PeNJ9DrWqnXlBP5ZiV5eqaU0UhEslXLUoOY5UxYNCU4egRE4kKKd69RUSGGwLvyl6Ez X-Received: by 2002:a17:906:ef01:b0:a5a:3da6:7712 with SMTP id a640c23a62f3a-a5a3da67767mr2171074866b.71.1716249559389; Mon, 20 May 2024 16:59:19 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716249559; cv=pass; d=google.com; s=arc-20160816; b=RuZ1HWU8deX3xNiUfSXI2N1TK7T1lIwWvZ3/MfdmxGxSVaYPnt7goTxZp3aRTIrsPA o6w449wmh/iN3Ooe6GHoakEnIHQzz2xZicdeW+B6FpQOzY2n/+zQUF80i5EAP+4gXFU7 V9+JXhWoyCuDv389q9ctoPvo67cRfdoryF7JCxY9x69PqahdwMvI6ciL61AC2eq6B3na ck7iHHfGkNR4ZlTwB0iskWFBLuzBZBkHaUxvuEEOCe10QW2ye6k1hCJnrx8+SCXVEaoc q/HFBgvBuTJLBSr96rb5J0RKp1aAzhASfe9fVH7LtmSS0QRXnFclZlgXx3Lwjo9DhyuQ kedQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=4MSMZDcDirakrNTBU0fNIxBAtvPtCqIO/PWdx7abHpI=; fh=RB3CqmaSWdNym0sNqOlzn+xRjChIlTdt19FAn1Ooih8=; b=xB1hGK3OiZ0/7C7/4aZHVsonhPf4NQK7qWOt6625Rs2ssqhtEtL/LiCxENZhqJHCbV b+sn4l+cQzx8IAD7FiXnHSBMOIC8WibAxETVO934UsBQ41MUXJIT+XxCU11CeuPcqv8k 1csTS9RnL07Lv/A1iuErwgSJLM+QzNSq7l46vfKcGIfP/JNU3DNEmZD4BHMj9SLqw6sZ pMbua3QkNZS+bVrpSjq/rvQRnc9ucNRSXsCEw8NjcHtBQ9Pe1uNX7iC+m3pJO5fz0WzI PUzblW9OCjVzE1HfsXBfy4WVHRCj+CKdl9cAMtLnkiyVU7sdnab4LaCfyEdhOuRWliEs tGow==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@fastly.com header.s=google header.b=gkMkTpuo; arc=pass (i=1 spf=pass spfdomain=fastly.com dkim=pass dkdomain=fastly.com dmarc=pass fromdomain=fastly.com); spf=pass (google.com: domain of linux-kernel+bounces-184312-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-184312-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=fastly.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id a640c23a62f3a-a5a17c2c4b1si1306574266b.1007.2024.05.20.16.59.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 May 2024 16:59:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-184312-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@fastly.com header.s=google header.b=gkMkTpuo; arc=pass (i=1 spf=pass spfdomain=fastly.com dkim=pass dkdomain=fastly.com dmarc=pass fromdomain=fastly.com); spf=pass (google.com: domain of linux-kernel+bounces-184312-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-184312-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=fastly.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id EF32B1F21772 for ; Mon, 20 May 2024 23:59:18 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2E78013956B; Mon, 20 May 2024 23:59:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=fastly.com header.i=@fastly.com header.b="gkMkTpuo" Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CAC5813849C for ; Mon, 20 May 2024 23:59:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.181 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716249550; cv=none; b=WGQAYr/ZYABRQwG2XHEOJD+A7n1jiZqmXyZ2wUdxfZ5IbSMx9MnVYZUrh/j0hNgCvu5xYN5uY83hunPjv1zz3Y8qgO/Aj8kPcHMACvR8JtcpXTdRSZu7Q3SrZNvTFMeZWNEMc7cNZgOrxJ9o8JuxHExTZJlq94QoBOdnNw675lA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716249550; c=relaxed/simple; bh=xiGzFz5+hu1xpjpEUf4HSER5PouTUhVlGDQbTva3RGc=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=h6M3sBvnnbBVK/1e6Jlg41WQNNIY+VbUpB2IIyUyI1uqFPkNxBoTwZMSDpeIv6JDKciicaETsy996utQtIxdKR02wjMBAHlopMhoL+6Kx3lZA2XlSzHKUl2oJPtGz5NzHhg9zyyr78c6iPyYXQ+C/AqhI3s50oVUWPtbYKBkPzg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=fastly.com; spf=pass smtp.mailfrom=fastly.com; dkim=pass (1024-bit key) header.d=fastly.com header.i=@fastly.com header.b=gkMkTpuo; arc=none smtp.client-ip=209.85.214.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=fastly.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=fastly.com Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-1edf506b216so88179525ad.2 for ; Mon, 20 May 2024 16:59:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fastly.com; s=google; t=1716249548; x=1716854348; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=4MSMZDcDirakrNTBU0fNIxBAtvPtCqIO/PWdx7abHpI=; b=gkMkTpuodemqcggQX+QS8j0l5j69KRlVLl/ZYmtwb+jylUbVhpJAYPDwzBAiMbv0kK M1mBQHqmg5/XNBvKwFVPPwvw2omyLT0NWme67XFACTm1V7P9WWOJJ4bim4M4I4APfk7m 25q97hqUuUqKSWtajbFFdBUFkM56qr7ObCE6M= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716249548; x=1716854348; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=4MSMZDcDirakrNTBU0fNIxBAtvPtCqIO/PWdx7abHpI=; b=vDl0TwsHL4DzuQ1IfxOtENHmTgTjoFzCkJ/atP4SBoo/kmZFwDJyEcKWp8CTQ4dc2S lxawIrvrWESip46/djiCCcMaYtKQS6aYQ+Ry20leBzmcLhm5XKUnLkQ+37tx3drpDRyW O7qSM2jm0Ap+FbuM74T/z0nu8IajmlRpzBNEADJsXcMsTbxYSd01gLOMTdR8yIotIXtQ ZfbeX8cTLbgWHGxuhfRplGdaEHsWZJg+jxJCHkptZt5fYZf+uXT6FiyN/N/PTfXuwk+x 3LlhCb4DG6AwWL66a/ElS3/QlU4rfa7/9A1QHP1XSHSopdSU4FkNrtj7kEFOM6tBIU3q Sl2g== X-Gm-Message-State: AOJu0YzzBOaOD9zj4InFv2tgHOU96u7RnO7ClNtHOeQZq16YU1GEWZ7j tnqFHA3lzQB1aMUjMskiu9wS7fLbiEK6Pvp2bKi9csx6aLKreBn7N//l54TkjShcsTlcCl4QxT5 i/3c/N7Sw5IVe85o6spiK7/lVw6jATqpCkseJnud96IaH2NC1v5VYg6qJbMzlx56hwoPQ9H7PKz WzdgXcoSvyUKZdhPUQk7ayQRtFM7DXAUYgDu/MiJiQn/0= X-Received: by 2002:a05:6a20:96d2:b0:1af:d07a:37c8 with SMTP id adf61e73a8af0-1afde128be9mr28414750637.37.1716249547566; Mon, 20 May 2024 16:59:07 -0700 (PDT) Received: from localhost.localdomain ([2620:11a:c019:0:65e:3115:2f58:c5fd]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-6f66e4a24f4sm11111009b3a.0.2024.05.20.16.59.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 May 2024 16:59:07 -0700 (PDT) From: Joe Damato To: linux-kernel@vger.kernel.org, netdev@vger.kernel.org Cc: nalramli@fastly.com, Joe Damato , Shuah Khan , Jakub Kicinski , "David S. Miller" , linux-kselftest@vger.kernel.org (open list:KERNEL SELFTEST FRAMEWORK) Subject: [PATCH net] testing: net-drv: use stats64 for testing Date: Mon, 20 May 2024 23:58:43 +0000 Message-Id: <20240520235850.190041-1-jdamato@fastly.com> X-Mailer: git-send-email 2.25.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Testing a network device that has large numbers of bytes/packets may overflow. Using stats64 when comparing fixes this problem. I tripped on this while iterating on a qstats patch for mlx5. See below for confirmation without my added code that this is a bug. Before this patch (with added debugging output): $ NETIF=eth0 tools/testing/selftests/drivers/net/stats.py KTAP version 1 1..4 ok 1 stats.check_pause ok 2 stats.check_fec rstat: 481708634 qstat: 666201639514 key: tx-bytes not ok 3 stats.pkt_byte_sum ok 4 stats.qstat_by_ifindex Note the huge delta above ^^^ in the rtnl vs qstats. After this patch: $ NETIF=eth0 tools/testing/selftests/drivers/net/stats.py KTAP version 1 1..4 ok 1 stats.check_pause ok 2 stats.check_fec ok 3 stats.pkt_byte_sum ok 4 stats.qstat_by_ifindex It looks like rtnl_fill_stats in net/core/rtnetlink.c will attempt to copy the 64bit stats into a 32bit structure which is probably why this behavior is occurring. To show this is happening, you can get the underlying stats that the stats.py test uses like this: $ ./cli.py --spec ../../../Documentation/netlink/specs/rt_link.yaml \ --do getlink --json '{"ifi-index": 7}' And examine the output (heavily snipped to show relevant fields): 'stats': { 'multicast': 3739197, 'rx-bytes': 1201525399, 'rx-packets': 56807158, 'tx-bytes': 492404458, 'tx-packets': 1200285371, 'stats64': { 'multicast': 3739197, 'rx-bytes': 35561263767, 'rx-packets': 56807158, 'tx-bytes': 666212335338, 'tx-packets': 1200285371, The stats.py test prior to this patch was using the 'stats' structure above, which matches the failure output on my system. Comparing side by side, rx-bytes and tx-bytes, and getting ethtool -S output: rx-bytes stats: 1201525399 rx-bytes stats64: 35561263767 rx-bytes ethtool: 36203402638 tx-bytes stats: 492404458 tx-bytes stats64: 666212335338 tx-bytes ethtool: 666215360113 Note that the above was taken from a system with an mlx5 NIC, which only exposes ndo_get_stats64. Based on the ethtool output and qstat output, it appears that stats.py should be updated to use the 'stats64' structure for accurate comparisons when packet/byte counters get very large. To confirm that this was not related to the qstats code I was iterating on, I booted a kernel without my driver changes and re-ran the test which shows the qstats are skipped (as they don't exist for mlx5): NETIF=eth0 tools/testing/selftests/drivers/net/stats.py KTAP version 1 1..4 ok 1 stats.check_pause ok 2 stats.check_fec ok 3 stats.pkt_byte_sum # SKIP qstats not supported by the device ok 4 stats.qstat_by_ifindex # SKIP No ifindex supports qstats But, fetching the stats using the CLI $ ./cli.py --spec ../../../Documentation/netlink/specs/rt_link.yaml \ --do getlink --json '{"ifi-index": 7}' Shows the same issue (heavily snipped for relevant fields only): 'stats': { 'multicast': 105489, 'rx-bytes': 530879526, 'rx-packets': 751415, 'tx-bytes': 2510191396, 'tx-packets': 27700323, 'stats64': { 'multicast': 105489, 'rx-bytes': 530879526, 'rx-packets': 751415, 'tx-bytes': 15395093284, 'tx-packets': 27700323, Comparing side by side with ethtool -S on the unmodified mlx5 driver: tx-bytes stats: 2510191396 tx-bytes stats64: 15395093284 tx-bytes ethtool: 17718435810 Fixes: f0e6c86e4bab ("testing: net-drv: add a driver test for stats reporting") Signed-off-by: Joe Damato --- tools/testing/selftests/drivers/net/stats.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/testing/selftests/drivers/net/stats.py b/tools/testing/selftests/drivers/net/stats.py index 7a7b16b180e2..820b8e0a22c6 100755 --- a/tools/testing/selftests/drivers/net/stats.py +++ b/tools/testing/selftests/drivers/net/stats.py @@ -69,7 +69,7 @@ def pkt_byte_sum(cfg) -> None: return 0 for _ in range(10): - rtstat = rtnl.getlink({"ifi-index": cfg.ifindex})['stats'] + rtstat = rtnl.getlink({"ifi-index": cfg.ifindex})['stats64'] if stat_cmp(rtstat, qstat) < 0: raise Exception("RTNL stats are lower, fetched later") qstat = get_qstat(cfg) -- 2.25.1