Subject: Re: [PATCH net] ip_tunnel: adapt iptunnel_xmit_stats() to NETDEV_PCPU_STAT_DSTATS

From: Jakub Kicinski <[email-masked]>
Date: Thu, 12 Mar 2026 07:46:30 -0700

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