public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH net] ip_tunnel: adapt iptunnel_xmit_stats() to NETDEV_PCPU_STAT_DSTATS
@ 2026-03-11 12:31 Eric Dumazet
  2026-03-12 10:33 ` Guillaume Nault
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Eric Dumazet @ 2026-03-11 12:31 UTC (permalink / raw)
  To: David S . Miller, Jakub Kicinski, Paolo Abeni
  Cc: Simon Horman, netdev, eric.dumazet, Eric Dumazet, Guillaume Nault

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.

Fixes: 6fa6de302246 ("geneve: Handle stats using NETDEV_PCPU_STAT_DSTATS.")
Fixes: be226352e8dc ("vxlan: Handle stats using NETDEV_PCPU_STAT_DSTATS.")
Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Guillaume Nault <gnault@redhat.com>
---
 include/linux/netdevice.h |  3 +--
 include/net/ip_tunnels.h  | 30 +++++++++++++++++++++++-------
 2 files changed, 24 insertions(+), 9 deletions(-)

diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index ae269a2e7f4dd22e4679db7f88b0f6dfedb36115..d7aac6f185bcab8a93a204c349272fc7c1b15ee7 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -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
diff --git a/include/net/ip_tunnels.h b/include/net/ip_tunnels.h
index 80662f81208039feb4fc1d3feae401633af2a5c2..1f577a4f8ce9b1ae4223d9cfd903bec8d7d78c04 100644
--- a/include/net/ip_tunnels.h
+++ b/include/net/ip_tunnels.h
@@ -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;
 	}
 
-- 
2.53.0.473.g4a7958ca14-goog


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH net] ip_tunnel: adapt iptunnel_xmit_stats() to NETDEV_PCPU_STAT_DSTATS
  2026-03-11 12:31 [PATCH net] ip_tunnel: adapt iptunnel_xmit_stats() to NETDEV_PCPU_STAT_DSTATS Eric Dumazet
@ 2026-03-12 10:33 ` Guillaume Nault
  2026-03-12 14:46 ` Jakub Kicinski
  2026-03-13  2:50 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 6+ messages in thread
From: Guillaume Nault @ 2026-03-12 10:33 UTC (permalink / raw)
  To: Eric Dumazet
  Cc: David S . Miller, Jakub Kicinski, Paolo Abeni, Simon Horman,
	netdev, eric.dumazet

On Wed, Mar 11, 2026 at 12:31:10PM +0000, Eric Dumazet 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 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.

Reviewed-by: Guillaume Nault <gnault@redhat.com>

Thank!


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH net] ip_tunnel: adapt iptunnel_xmit_stats() to NETDEV_PCPU_STAT_DSTATS
  2026-03-11 12:31 [PATCH net] ip_tunnel: adapt iptunnel_xmit_stats() to NETDEV_PCPU_STAT_DSTATS Eric Dumazet
  2026-03-12 10:33 ` Guillaume Nault
@ 2026-03-12 14:46 ` Jakub Kicinski
  2026-03-12 14:53   ` Eric Dumazet
  2026-03-13  2:50 ` patchwork-bot+netdevbpf
  2 siblings, 1 reply; 6+ messages in thread
From: Jakub Kicinski @ 2026-03-12 14:46 UTC (permalink / raw)
  To: Eric Dumazet
  Cc: David S . Miller, Paolo Abeni, Simon Horman, netdev, eric.dumazet,
	Guillaume Nault

On Wed, 11 Mar 2026 12:31:10 +0000 Eric Dumazet wrote:
> @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.

And moving syncp would be too much of a hack? 

>  	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;
>  	}

This code can run with migration enabled? Cause dev_dstats_tx_add() etc
exist

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH net] ip_tunnel: adapt iptunnel_xmit_stats() to NETDEV_PCPU_STAT_DSTATS
  2026-03-12 14:46 ` Jakub Kicinski
@ 2026-03-12 14:53   ` Eric Dumazet
  2026-03-12 15:12     ` Jakub Kicinski
  0 siblings, 1 reply; 6+ messages in thread
From: Eric Dumazet @ 2026-03-12 14:53 UTC (permalink / raw)
  To: Jakub Kicinski
  Cc: David S . Miller, Paolo Abeni, Simon Horman, netdev, eric.dumazet,
	Guillaume Nault

On Thu, Mar 12, 2026 at 3:46 PM Jakub Kicinski <kuba@kernel.org> wrote:
>
> On Wed, 11 Mar 2026 12:31:10 +0000 Eric Dumazet wrote:
> > @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.
>
> And moving syncp would be too much of a hack?

I thought about this, I prefer doing such work in net-next.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH net] ip_tunnel: adapt iptunnel_xmit_stats() to NETDEV_PCPU_STAT_DSTATS
  2026-03-12 14:53   ` Eric Dumazet
@ 2026-03-12 15:12     ` Jakub Kicinski
  0 siblings, 0 replies; 6+ messages in thread
From: Jakub Kicinski @ 2026-03-12 15:12 UTC (permalink / raw)
  To: Eric Dumazet
  Cc: David S . Miller, Paolo Abeni, Simon Horman, netdev, eric.dumazet,
	Guillaume Nault

On Thu, 12 Mar 2026 15:53:02 +0100 Eric Dumazet wrote:
> On Thu, Mar 12, 2026 at 3:46 PM Jakub Kicinski <kuba@kernel.org> wrote:
> >
> > On Wed, 11 Mar 2026 12:31:10 +0000 Eric Dumazet wrote:  
> > > @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.  
> >
> > And moving syncp would be too much of a hack?  
> 
> I thought about this, I prefer doing such work in net-next.

SG

Acked-by: Jakub Kicinski <kuba@kernel.org>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH net] ip_tunnel: adapt iptunnel_xmit_stats() to NETDEV_PCPU_STAT_DSTATS
  2026-03-11 12:31 [PATCH net] ip_tunnel: adapt iptunnel_xmit_stats() to NETDEV_PCPU_STAT_DSTATS Eric Dumazet
  2026-03-12 10:33 ` Guillaume Nault
  2026-03-12 14:46 ` Jakub Kicinski
@ 2026-03-13  2:50 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 6+ messages in thread
From: patchwork-bot+netdevbpf @ 2026-03-13  2:50 UTC (permalink / raw)
  To: Eric Dumazet; +Cc: davem, kuba, pabeni, horms, netdev, eric.dumazet, gnault

Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <kuba@kernel.org>:

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 using
> NETDEV_PCPU_STAT_TSTATS.
> 
> @syncp offset in pcpu_sw_netstats and pcpu_dstats is 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!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-03-13  2:50 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-11 12:31 [PATCH net] ip_tunnel: adapt iptunnel_xmit_stats() to NETDEV_PCPU_STAT_DSTATS Eric Dumazet
2026-03-12 10:33 ` Guillaume Nault
2026-03-12 14:46 ` Jakub Kicinski
2026-03-12 14:53   ` Eric Dumazet
2026-03-12 15:12     ` Jakub Kicinski
2026-03-13  2:50 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox