Skip to content

Commit

Permalink
net: use u64_stats_t in struct pcpu_lstats
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Eric Dumazet authored and David S. Miller committed Nov 8, 2019
1 parent 5260dd3 commit fd2f473
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions drivers/net/loopback.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ void dev_lstats_read(struct net_device *dev, u64 *packets, u64 *bytes)
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;
Expand Down
8 changes: 4 additions & 4 deletions include/linux/netdevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -2396,8 +2396,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));

Expand All @@ -2408,8 +2408,8 @@ static inline void dev_lstats_add(struct net_device *dev, unsigned int len)
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);
}

Expand Down

0 comments on commit fd2f473

Please sign in to comment.