Skip to content

Commit e390648

Browse files
kgroenevelddavem330
authored andcommitted
net: fix race condition in several drivers when reading stats
Fix race condition in several network drivers when reading stats on 32bit UP architectures. These drivers update their stats in a BH context and therefore should use u64_stats_fetch_begin_bh/u64_stats_fetch_retry_bh instead of u64_stats_fetch_begin/u64_stats_fetch_retry when reading the stats. Signed-off-by: Kevin Groeneveld <kgroeneveld@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 0980e56 commit e390648

5 files changed

Lines changed: 14 additions & 14 deletions

File tree

‎drivers/net/dummy.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,10 @@ static struct rtnl_link_stats64 *dummy_get_stats64(struct net_device *dev,
6363

6464
dstats = per_cpu_ptr(dev->dstats, i);
6565
do {
66-
start = u64_stats_fetch_begin(&dstats->syncp);
66+
start = u64_stats_fetch_begin_bh(&dstats->syncp);
6767
tbytes = dstats->tx_bytes;
6868
tpackets = dstats->tx_packets;
69-
} while (u64_stats_fetch_retry(&dstats->syncp, start));
69+
} while (u64_stats_fetch_retry_bh(&dstats->syncp, start));
7070
stats->tx_bytes += tbytes;
7171
stats->tx_packets += tpackets;
7272
}

‎drivers/net/ethernet/neterion/vxge/vxge-main.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3131,12 +3131,12 @@ vxge_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *net_stats)
31313131
u64 packets, bytes, multicast;
31323132

31333133
do {
3134-
start = u64_stats_fetch_begin(&rxstats->syncp);
3134+
start = u64_stats_fetch_begin_bh(&rxstats->syncp);
31353135

31363136
packets = rxstats->rx_frms;
31373137
multicast = rxstats->rx_mcast;
31383138
bytes = rxstats->rx_bytes;
3139-
} while (u64_stats_fetch_retry(&rxstats->syncp, start));
3139+
} while (u64_stats_fetch_retry_bh(&rxstats->syncp, start));
31403140

31413141
net_stats->rx_packets += packets;
31423142
net_stats->rx_bytes += bytes;
@@ -3146,11 +3146,11 @@ vxge_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *net_stats)
31463146
net_stats->rx_dropped += rxstats->rx_dropped;
31473147

31483148
do {
3149-
start = u64_stats_fetch_begin(&txstats->syncp);
3149+
start = u64_stats_fetch_begin_bh(&txstats->syncp);
31503150

31513151
packets = txstats->tx_frms;
31523152
bytes = txstats->tx_bytes;
3153-
} while (u64_stats_fetch_retry(&txstats->syncp, start));
3153+
} while (u64_stats_fetch_retry_bh(&txstats->syncp, start));
31543154

31553155
net_stats->tx_packets += packets;
31563156
net_stats->tx_bytes += bytes;

‎drivers/net/loopback.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,10 @@ static struct rtnl_link_stats64 *loopback_get_stats64(struct net_device *dev,
107107

108108
lb_stats = per_cpu_ptr(dev->lstats, i);
109109
do {
110-
start = u64_stats_fetch_begin(&lb_stats->syncp);
110+
start = u64_stats_fetch_begin_bh(&lb_stats->syncp);
111111
tbytes = lb_stats->bytes;
112112
tpackets = lb_stats->packets;
113-
} while (u64_stats_fetch_retry(&lb_stats->syncp, start));
113+
} while (u64_stats_fetch_retry_bh(&lb_stats->syncp, start));
114114
bytes += tbytes;
115115
packets += tpackets;
116116
}

‎drivers/net/virtio_net.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -704,16 +704,16 @@ static struct rtnl_link_stats64 *virtnet_stats(struct net_device *dev,
704704
u64 tpackets, tbytes, rpackets, rbytes;
705705

706706
do {
707-
start = u64_stats_fetch_begin(&stats->tx_syncp);
707+
start = u64_stats_fetch_begin_bh(&stats->tx_syncp);
708708
tpackets = stats->tx_packets;
709709
tbytes = stats->tx_bytes;
710-
} while (u64_stats_fetch_retry(&stats->tx_syncp, start));
710+
} while (u64_stats_fetch_retry_bh(&stats->tx_syncp, start));
711711

712712
do {
713-
start = u64_stats_fetch_begin(&stats->rx_syncp);
713+
start = u64_stats_fetch_begin_bh(&stats->rx_syncp);
714714
rpackets = stats->rx_packets;
715715
rbytes = stats->rx_bytes;
716-
} while (u64_stats_fetch_retry(&stats->rx_syncp, start));
716+
} while (u64_stats_fetch_retry_bh(&stats->rx_syncp, start));
717717

718718
tot->rx_packets += rpackets;
719719
tot->tx_packets += tpackets;

‎net/bridge/br_device.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,9 @@ static struct rtnl_link_stats64 *br_get_stats64(struct net_device *dev,
127127
const struct br_cpu_netstats *bstats
128128
= per_cpu_ptr(br->stats, cpu);
129129
do {
130-
start = u64_stats_fetch_begin(&bstats->syncp);
130+
start = u64_stats_fetch_begin_bh(&bstats->syncp);
131131
memcpy(&tmp, bstats, sizeof(tmp));
132-
} while (u64_stats_fetch_retry(&bstats->syncp, start));
132+
} while (u64_stats_fetch_retry_bh(&bstats->syncp, start));
133133
sum.tx_bytes += tmp.tx_bytes;
134134
sum.tx_packets += tmp.tx_packets;
135135
sum.rx_bytes += tmp.rx_bytes;

0 commit comments

Comments
 (0)