From: Eric Dumazet <edumazet@google.com>
Date: Thu, 7 Nov 2019 16:27:22 -0800
Subject: net: use u64_stats_t in struct pcpu_lstats
Patch-mainline: v5.5-rc1
Git-commit: fd2f4737870eb866537fbbffa2b59414b9b0c0a2
References: bsc#1154353
In order to fix the data-race found by KCSAN, we
can use the new u64_stats_t type and its accessors instead
of plain u64 fields. This will still generate optimal code
for both 32 and 64 bit platforms.
Signed-off-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Acked-by: Thomas Bogendoerfer <tbogendoerfer@suse.de>
---
drivers/net/loopback.c | 4 ++--
include/linux/netdevice.h | 8 ++++----
2 files changed, 6 insertions(+), 6 deletions(-)
--- a/drivers/net/loopback.c
+++ b/drivers/net/loopback.c
@@ -106,8 +106,8 @@ void dev_lstats_read(struct net_device *
lb_stats = per_cpu_ptr(dev->lstats, i);
do {
start = u64_stats_fetch_begin_irq(&lb_stats->syncp);
- tpackets = lb_stats->packets;
- tbytes = lb_stats->bytes;
+ tpackets = u64_stats_read(&lb_stats->packets);
+ tbytes = u64_stats_read(&lb_stats->bytes);
} while (u64_stats_fetch_retry_irq(&lb_stats->syncp, start));
*bytes += tbytes;
*packets += tpackets;
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -2397,8 +2397,8 @@ struct pcpu_sw_netstats {
} __aligned(4 * sizeof(u64));
struct pcpu_lstats {
- u64 packets;
- u64 bytes;
+ u64_stats_t packets;
+ u64_stats_t bytes;
struct u64_stats_sync syncp;
} __aligned(2 * sizeof(u64));
@@ -2409,8 +2409,8 @@ static inline void dev_lstats_add(struct
struct pcpu_lstats *lstats = this_cpu_ptr(dev->lstats);
u64_stats_update_begin(&lstats->syncp);
- lstats->bytes += len;
- lstats->packets++;
+ u64_stats_add(&lstats->bytes, len);
+ u64_stats_inc(&lstats->packets);
u64_stats_update_end(&lstats->syncp);
}