History

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.

Eric Dumazet committed 7 years ago

Commit fd2f4731 parent 5260dd32 files · +6 −6Browse files

Unified · Split

2 files
  1. drivers/net/loopback.c +2 −2
  2. include/linux/netdevice.h +4 −4
drivers/net/loopback.c+2−2
@@ -106,8 +106,8 @@ void dev_lstats_read(struct net_device *dev, u64 *packets, u64 *bytes) · 105 unmodified lines
106 lb_stats = per_cpu_ptr(dev->lstats, i);106 lb_stats = per_cpu_ptr(dev->lstats, i);
107 do {107 do {
108 start = u64_stats_fetch_begin_irq(&lb_stats->syncp);108 start = u64_stats_fetch_begin_irq(&lb_stats->syncp);
109 tpackets = lb_stats->packets;109 tpackets = u64_stats_read(&lb_stats->packets);
110 tbytes = lb_stats->bytes;110 tbytes = u64_stats_read(&lb_stats->bytes);
111 } while (u64_stats_fetch_retry_irq(&lb_stats->syncp, start));111 } while (u64_stats_fetch_retry_irq(&lb_stats->syncp, start));
112 *bytes += tbytes;112 *bytes += tbytes;
113 *packets += tpackets;113 *packets += tpackets;
include/linux/netdevice.h+4−4
@@ -2396,8 +2396,8 @@ struct pcpu_sw_netstats { · 2395 unmodified lines
2396} __aligned(4 * sizeof(u64));2396} __aligned(4 * sizeof(u64));
2397 2397
2398struct pcpu_lstats {2398struct pcpu_lstats {
2399 u64 packets;2399 u64_stats_t packets;
2400 u64 bytes;2400 u64_stats_t bytes;
2401 struct u64_stats_sync syncp;2401 struct u64_stats_sync syncp;
2402} __aligned(2 * sizeof(u64));2402} __aligned(2 * sizeof(u64));
2403 2403
@@ -2408,8 +2408,8 @@ static inline void dev_lstats_add(struct net_device *dev, unsigned int len) · 4 unmodified lines
2408 struct pcpu_lstats *lstats = this_cpu_ptr(dev->lstats);2408 struct pcpu_lstats *lstats = this_cpu_ptr(dev->lstats);
2409 2409
2410 u64_stats_update_begin(&lstats->syncp);2410 u64_stats_update_begin(&lstats->syncp);
2411 lstats->bytes += len;2411 u64_stats_add(&lstats->bytes, len);
2412 lstats->packets++;2412 u64_stats_inc(&lstats->packets);
2413 u64_stats_update_end(&lstats->syncp);2413 u64_stats_update_end(&lstats->syncp);
2414}2414}
2415 2415

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t