ip_tunnel: adapt iptunnel_xmit_stats() to NETDEV_PCPU_STAT_DSTATS
Subsystems (3)
PATCH 1/1 ip_tunnel: adapt iptunnel_xmit_stats() to NETDEV_PCPU_STAT_DSTATS
Blamed commits forgot that vxlan/geneve use udp_tunnel[6]_xmit_skb() which call iptunnel_xmit_stats().
iptunnel_xmit_stats() was assuming tunnels were only using NETDEV_PCPU_STAT_TSTATS.
@syncp offset in pcpu_sw_netstats and pcpu_dstats is different.
32bit kernels would either have corruptions or freezes if the syncp sequence was overwritten.
This patch also moves pcpu_stat_type closer to dev->{t,d}stats to avoid a potential cache line miss since iptunnel_xmit_stats() needs to read it.
--- include/linux/netdevice.h | 3 +-- include/net/ip_tunnels.h | 30 +++++++++++++++++++++++------- 2 files changed, 24 insertions(+), 9 deletions(-)
include/linux/netdevice.h +1 -2
@@ -2155,6 +2155,7 @@ struct net_device {unsigned long state;unsigned int flags;unsigned short hard_header_len; + enum netdev_stat_type pcpu_stat_type:8;netdev_features_t features;struct inet6_dev __rcu *ip6_ptr;__cacheline_group_end (net_device_read_txrx);
@@ -2404,8 +2405,6 @@ struct net_device {void *ml_priv;enum netdev_ml_priv_type ml_priv_type; - enum netdev_stat_type pcpu_stat_type:8; -#if IS_ENABLED (CONFIG_GARP )struct garp_port __rcu *garp_port;#endif
include/net/ip_tunnels.h +23 -7
@@ -665,13 +665,29 @@ static inline int iptunnel_pull_offloads(struct sk_buff *skb)static inline void iptunnel_xmit_stats (struct net_device *dev,int pkt_len) {if (pkt_len >0 ) { -struct pcpu_sw_netstats *tstats =get_cpu_ptr (dev->tstats); - -u64_stats_update_begin (&tstats->syncp); -u64_stats_add (&tstats->tx_bytes, pkt_len); -u64_stats_inc (&tstats->tx_packets); -u64_stats_update_end (&tstats->syncp); -put_cpu_ptr (tstats); +if (dev->pcpu_stat_type ==NETDEV_PCPU_STAT_DSTATS ) { +struct pcpu_dstats *dstats =get_cpu_ptr (dev->dstats); + +u64_stats_update_begin (&dstats->syncp); +u64_stats_add (&dstats->tx_bytes, pkt_len); +u64_stats_inc (&dstats->tx_packets); +u64_stats_update_end (&dstats->syncp); +put_cpu_ptr (dstats); +return ; + } +if (dev->pcpu_stat_type ==NETDEV_PCPU_STAT_TSTATS ) { +struct pcpu_sw_netstats *tstats =get_cpu_ptr (dev->tstats); + +u64_stats_update_begin (&tstats->syncp); +u64_stats_add (&tstats->tx_bytes, pkt_len); +u64_stats_inc (&tstats->tx_packets); +u64_stats_update_end (&tstats->syncp); +put_cpu_ptr (tstats); +return ; + } +pr_err_once ("iptunnel_xmit_stats pcpu_stat_type=%d\n" , + dev->pcpu_stat_type); +WARN_ON_ONCE (1 );return ; }
Signature · 1 line
2.53.0.473.g4a7958ca14-goog
Quoted 6 lines · Eric Dumazet
Blamed commits forgot that vxlan/geneve use udp_tunnel[6]_xmit_skb() which call
iptunnel_xmit_stats().
iptunnel_xmit_stats()was assuming tunnels were only usingNETDEV_PCPU_STAT_TSTATS.
Quoted 7 lines
@syncp offset in
pcpu_sw_netstatsandpcpu_dstatsis different.32bit kernels would either have corruptions or freezes if the syncp sequence was overwritten.
This patch also moves
pcpu_stat_typecloser to dev->{t,d}stats to avoid a potential cache line miss sinceiptunnel_xmit_stats()needs to read it.
Thank!
Jakub Kicinski
maintainerQuoted 4 lines · On Wed, 11 Mar 2026 12:31:10 +0000 Eric Dumazet wrote:
@syncp offset in
pcpu_sw_netstatsandpcpu_dstatsis different.32bit kernels would either have corruptions or freezes if the syncp sequence was overwritten.
And moving syncp would be too much of a hack?
Quoted 23 lines
include/net/ip_tunnels.h +15
-7if (pkt_len >0 ) { -struct pcpu_sw_netstats *tstats =get_cpu_ptr (dev->tstats); - -u64_stats_update_begin (&tstats->syncp); -u64_stats_add (&tstats->tx_bytes, pkt_len); -u64_stats_inc (&tstats->tx_packets); -u64_stats_update_end (&tstats->syncp); -put_cpu_ptr (tstats); +if (dev->pcpu_stat_type ==NETDEV_PCPU_STAT_DSTATS ) { +struct pcpu_dstats *dstats =get_cpu_ptr (dev->dstats); + +u64_stats_update_begin (&dstats->syncp); +u64_stats_add (&dstats->tx_bytes, pkt_len); +u64_stats_inc (&dstats->tx_packets); +u64_stats_update_end (&dstats->syncp); +put_cpu_ptr (dstats); +return ; + } +if (dev->pcpu_stat_type ==NETDEV_PCPU_STAT_TSTATS ) { +struct pcpu_sw_netstats *tstats =get_cpu_ptr (dev->tstats); + +u64_stats_update_begin (&tstats->syncp); +u64_stats_add (&tstats->tx_bytes, pkt_len);
include/net/ip_tunnels.h static inline int iptunnel_pull_offloads(struct sk_buff *skb) · line 692
Quoted 10 lines
include/net/ip_tunnels.h +8
-0+u64_stats_inc (&tstats->tx_packets); +u64_stats_update_end (&tstats->syncp); +put_cpu_ptr (tstats); +return ; + } +pr_err_once ("iptunnel_xmit_stats pcpu_stat_type=%d\n" , + dev->pcpu_stat_type); +WARN_ON_ONCE (1 );return ; }
This code can run with migration enabled? Cause dev_dstats_tx_add() etc exist
Quoted 8 lines · Jakub Kicinski
Quoted 4 lines · On Wed, 11 Mar 2026 12:31:10 +0000 Eric Dumazet wrote:
@syncp offset in
pcpu_sw_netstatsandpcpu_dstatsis different.32bit kernels would either have corruptions or freezes if the syncp sequence was overwritten.
And moving syncp would be too much of a hack?
I thought about this, I prefer doing such work in net-next.
Quoted 11 lines · On Thu, 12 Mar 2026 15:53:02 +0100 Eric Dumazet wrote:
Quoted 8 lines · Jakub Kicinski
Quoted 4 lines · On Wed, 11 Mar 2026 12:31:10 +0000 Eric Dumazet wrote:
@syncp offset in
pcpu_sw_netstatsandpcpu_dstatsis different.32bit kernels would either have corruptions or freezes if the syncp sequence was overwritten.
And moving syncp would be too much of a hack?
I thought about this, I prefer doing such work in net-next.
SG
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:
Quoted 9 lines · On Wed, 11 Mar 2026 12:31:10 +0000 you wrote:
Blamed commits forgot that vxlan/geneve use udp_tunnel[6]_xmit_skb() which call
iptunnel_xmit_stats().
iptunnel_xmit_stats()was assuming tunnels were only usingNETDEV_PCPU_STAT_TSTATS.@syncp offset in
pcpu_sw_netstatsandpcpu_dstatsis different.[...]
Here is the summary with links:
- [net] ip_tunnel: adapt iptunnel_xmit_stats() to NETDEV_PCPU_STAT_DSTATS
https://git.kernel.org/netdev/net/c/8431c602f551
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html