Commit f5f37fc9 authored by Jakub Kicinski's avatar Jakub Kicinski
Browse files

Merge branch 'net-adopt-u64_stats_t-type'

Eric Dumazet says:

====================
net: adopt u64_stats_t type

While KCSAN has not raised any reports yet, we should address the
potential load/store tearing problem happening with per cpu stats.

This series is not exhaustive, but hopefully a step in the right
direction.
====================

Link: https://lore.kernel.org/r/20220608154640.1235958-1-eric.dumazet@gmail.com


Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parents d62607c3 9ec321ab
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -47,11 +47,11 @@ typedef enum {
} ipvl_hdr_type;

struct ipvl_pcpu_stats {
	u64			rx_pkts;
	u64			rx_bytes;
	u64			rx_mcast;
	u64			tx_pkts;
	u64			tx_bytes;
	u64_stats_t		rx_pkts;
	u64_stats_t		rx_bytes;
	u64_stats_t		rx_mcast;
	u64_stats_t		tx_pkts;
	u64_stats_t		tx_bytes;
	struct u64_stats_sync	syncp;
	u32			rx_errs;
	u32			tx_drps;
+3 −3
Original line number Diff line number Diff line
@@ -19,10 +19,10 @@ void ipvlan_count_rx(const struct ipvl_dev *ipvlan,

		pcptr = this_cpu_ptr(ipvlan->pcpu_stats);
		u64_stats_update_begin(&pcptr->syncp);
		pcptr->rx_pkts++;
		pcptr->rx_bytes += len;
		u64_stats_inc(&pcptr->rx_pkts);
		u64_stats_add(&pcptr->rx_bytes, len);
		if (mcast)
			pcptr->rx_mcast++;
			u64_stats_inc(&pcptr->rx_mcast);
		u64_stats_update_end(&pcptr->syncp);
	} else {
		this_cpu_inc(ipvlan->pcpu_stats->rx_errs);
+9 −9
Original line number Diff line number Diff line
@@ -224,8 +224,8 @@ static netdev_tx_t ipvlan_start_xmit(struct sk_buff *skb,
		pcptr = this_cpu_ptr(ipvlan->pcpu_stats);

		u64_stats_update_begin(&pcptr->syncp);
		pcptr->tx_pkts++;
		pcptr->tx_bytes += skblen;
		u64_stats_inc(&pcptr->tx_pkts);
		u64_stats_add(&pcptr->tx_bytes, skblen);
		u64_stats_update_end(&pcptr->syncp);
	} else {
		this_cpu_inc(ipvlan->pcpu_stats->tx_drps);
@@ -300,11 +300,11 @@ static void ipvlan_get_stats64(struct net_device *dev,
			pcptr = per_cpu_ptr(ipvlan->pcpu_stats, idx);
			do {
				strt= u64_stats_fetch_begin_irq(&pcptr->syncp);
				rx_pkts = pcptr->rx_pkts;
				rx_bytes = pcptr->rx_bytes;
				rx_mcast = pcptr->rx_mcast;
				tx_pkts = pcptr->tx_pkts;
				tx_bytes = pcptr->tx_bytes;
				rx_pkts = u64_stats_read(&pcptr->rx_pkts);
				rx_bytes = u64_stats_read(&pcptr->rx_bytes);
				rx_mcast = u64_stats_read(&pcptr->rx_mcast);
				tx_pkts = u64_stats_read(&pcptr->tx_pkts);
				tx_bytes = u64_stats_read(&pcptr->tx_bytes);
			} while (u64_stats_fetch_retry_irq(&pcptr->syncp,
							   strt));

@@ -315,8 +315,8 @@ static void ipvlan_get_stats64(struct net_device *dev,
			s->tx_bytes += tx_bytes;

			/* u32 values are updated without syncp protection. */
			rx_errs += pcptr->rx_errs;
			tx_drps += pcptr->tx_drps;
			rx_errs += READ_ONCE(pcptr->rx_errs);
			tx_drps += READ_ONCE(pcptr->tx_drps);
		}
		s->rx_errors = rx_errs;
		s->rx_dropped = rx_errs;
+4 −4
Original line number Diff line number Diff line
@@ -523,8 +523,8 @@ static void count_tx(struct net_device *dev, int ret, int len)
		struct pcpu_sw_netstats *stats = this_cpu_ptr(dev->tstats);

		u64_stats_update_begin(&stats->syncp);
		stats->tx_packets++;
		stats->tx_bytes += len;
		u64_stats_inc(&stats->tx_packets);
		u64_stats_add(&stats->tx_bytes, len);
		u64_stats_update_end(&stats->syncp);
	}
}
@@ -825,8 +825,8 @@ static void count_rx(struct net_device *dev, int len)
	struct pcpu_sw_netstats *stats = this_cpu_ptr(dev->tstats);

	u64_stats_update_begin(&stats->syncp);
	stats->rx_packets++;
	stats->rx_bytes += len;
	u64_stats_inc(&stats->rx_packets);
	u64_stats_add(&stats->rx_bytes, len);
	u64_stats_update_end(&stats->syncp);
}

+9 −9
Original line number Diff line number Diff line
@@ -575,8 +575,8 @@ static netdev_tx_t macvlan_start_xmit(struct sk_buff *skb,

		pcpu_stats = this_cpu_ptr(vlan->pcpu_stats);
		u64_stats_update_begin(&pcpu_stats->syncp);
		pcpu_stats->tx_packets++;
		pcpu_stats->tx_bytes += len;
		u64_stats_inc(&pcpu_stats->tx_packets);
		u64_stats_add(&pcpu_stats->tx_bytes, len);
		u64_stats_update_end(&pcpu_stats->syncp);
	} else {
		this_cpu_inc(vlan->pcpu_stats->tx_dropped);
@@ -949,11 +949,11 @@ static void macvlan_dev_get_stats64(struct net_device *dev,
			p = per_cpu_ptr(vlan->pcpu_stats, i);
			do {
				start = u64_stats_fetch_begin_irq(&p->syncp);
				rx_packets	= p->rx_packets;
				rx_bytes	= p->rx_bytes;
				rx_multicast	= p->rx_multicast;
				tx_packets	= p->tx_packets;
				tx_bytes	= p->tx_bytes;
				rx_packets	= u64_stats_read(&p->rx_packets);
				rx_bytes	= u64_stats_read(&p->rx_bytes);
				rx_multicast	= u64_stats_read(&p->rx_multicast);
				tx_packets	= u64_stats_read(&p->tx_packets);
				tx_bytes	= u64_stats_read(&p->tx_bytes);
			} while (u64_stats_fetch_retry_irq(&p->syncp, start));

			stats->rx_packets	+= rx_packets;
@@ -964,8 +964,8 @@ static void macvlan_dev_get_stats64(struct net_device *dev,
			/* rx_errors & tx_dropped are u32, updated
			 * without syncp protection.
			 */
			rx_errors	+= p->rx_errors;
			tx_dropped	+= p->tx_dropped;
			rx_errors	+= READ_ONCE(p->rx_errors);
			tx_dropped	+= READ_ONCE(p->tx_dropped);
		}
		stats->rx_errors	= rx_errors;
		stats->rx_dropped	= rx_errors;
Loading