Skip to content

Commit fd2f473

Browse files
edumazetdavem330
authored andcommitted
net: use u64_stats_t in struct pcpu_lstats
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>
1 parent 5260dd3 commit fd2f473

2 files changed

Lines changed: 6 additions & 6 deletions

File tree

‎drivers/net/loopback.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ void dev_lstats_read(struct net_device *dev, u64 *packets, u64 *bytes)
106106
lb_stats = per_cpu_ptr(dev->lstats, i);
107107
do {
108108
start = u64_stats_fetch_begin_irq(&lb_stats->syncp);
109-
tpackets = lb_stats->packets;
110-
tbytes = lb_stats->bytes;
109+
tpackets = u64_stats_read(&lb_stats->packets);
110+
tbytes = u64_stats_read(&lb_stats->bytes);
111111
} while (u64_stats_fetch_retry_irq(&lb_stats->syncp, start));
112112
*bytes += tbytes;
113113
*packets += tpackets;

‎include/linux/netdevice.h‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2396,8 +2396,8 @@ struct pcpu_sw_netstats {
23962396
} __aligned(4 * sizeof(u64));
23972397

23982398
struct pcpu_lstats {
2399-
u64 packets;
2400-
u64 bytes;
2399+
u64_stats_t packets;
2400+
u64_stats_t bytes;
24012401
struct u64_stats_sync syncp;
24022402
} __aligned(2 * sizeof(u64));
24032403

@@ -2408,8 +2408,8 @@ static inline void dev_lstats_add(struct net_device *dev, unsigned int len)
24082408
struct pcpu_lstats *lstats = this_cpu_ptr(dev->lstats);
24092409

24102410
u64_stats_update_begin(&lstats->syncp);
2411-
lstats->bytes += len;
2412-
lstats->packets++;
2411+
u64_stats_add(&lstats->bytes, len);
2412+
u64_stats_inc(&lstats->packets);
24132413
u64_stats_update_end(&lstats->syncp);
24142414
}
24152415

0 commit comments

Comments
 (0)