Skip to content

Commit d3ed6de

Browse files
Paolo Abenikuba-moo
authored andcommitted
net: harmonize tstats and dstats
After the blamed commits below, some UDP tunnel use dstats for accounting. On the xmit path, all the UDP-base tunnels ends up using iptunnel_xmit_stats() for stats accounting, and the latter assumes the relevant (tunnel) network device uses tstats. The end result is some 'funny' stat report for the mentioned UDP tunnel, e.g. when no packet is actually dropped and a bunch of packets are transmitted: gnv2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1450 qdisc noqueue \ state UNKNOWN mode DEFAULT group default qlen 1000 link/ether ee:7d:09:87:90:ea brd ff:ff:ff:ff:ff:ff RX: bytes packets errors dropped missed mcast 14916 23 0 15 0 0 TX: bytes packets errors dropped carrier collsns 0 1566 0 0 0 0 Address the issue ensuring the same binary layout for the overlapping fields of dstats and tstats. While this solution is a bit hackish, is smaller and with no performance pitfall compared to other alternatives i.e. supporting both dstat and tstat in iptunnel_xmit_stats() or reverting the blamed commit. With time we should possibly move all the IP-based tunnel (and virtual devices) to dstats. Fixes: c77200c ("bareudp: Handle stats using NETDEV_PCPU_STAT_DSTATS.") Fixes: 6fa6de3 ("geneve: Handle stats using NETDEV_PCPU_STAT_DSTATS.") Fixes: be22635 ("vxlan: Handle stats using NETDEV_PCPU_STAT_DSTATS.") Signed-off-by: Paolo Abeni <pabeni@redhat.com> Reviewed-by: Guillaume Nault <gnault@redhat.com> Link: https://patch.msgid.link/2e1c444cf0f63ae472baff29862c4c869be17031.1738432804.git.pabeni@redhat.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 2fc9956 commit d3ed6de

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

include/linux/netdevice.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2904,9 +2904,9 @@ struct pcpu_sw_netstats {
29042904
struct pcpu_dstats {
29052905
u64_stats_t rx_packets;
29062906
u64_stats_t rx_bytes;
2907-
u64_stats_t rx_drops;
29082907
u64_stats_t tx_packets;
29092908
u64_stats_t tx_bytes;
2909+
u64_stats_t rx_drops;
29102910
u64_stats_t tx_drops;
29112911
struct u64_stats_sync syncp;
29122912
} __aligned(8 * sizeof(u64));

net/core/dev.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11286,6 +11286,20 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
1128611286
const struct net_device_ops *ops = dev->netdev_ops;
1128711287
const struct net_device_core_stats __percpu *p;
1128811288

11289+
/*
11290+
* IPv{4,6} and udp tunnels share common stat helpers and use
11291+
* different stat type (NETDEV_PCPU_STAT_TSTATS vs
11292+
* NETDEV_PCPU_STAT_DSTATS). Ensure the accounting is consistent.
11293+
*/
11294+
BUILD_BUG_ON(offsetof(struct pcpu_sw_netstats, rx_bytes) !=
11295+
offsetof(struct pcpu_dstats, rx_bytes));
11296+
BUILD_BUG_ON(offsetof(struct pcpu_sw_netstats, rx_packets) !=
11297+
offsetof(struct pcpu_dstats, rx_packets));
11298+
BUILD_BUG_ON(offsetof(struct pcpu_sw_netstats, tx_bytes) !=
11299+
offsetof(struct pcpu_dstats, tx_bytes));
11300+
BUILD_BUG_ON(offsetof(struct pcpu_sw_netstats, tx_packets) !=
11301+
offsetof(struct pcpu_dstats, tx_packets));
11302+
1128911303
if (ops->ndo_get_stats64) {
1129011304
memset(storage, 0, sizeof(*storage));
1129111305
ops->ndo_get_stats64(dev, storage);

0 commit comments

Comments
 (0)