Skip to content

Commit 6dee402

Browse files
Guillaume Naultdavem330
authored andcommitted
vxlan: Fix racy device stats updates.
VXLAN devices update their stats locklessly. Therefore these counters should either be stored in per-cpu data structures or the updates should be done using atomic increments. Since the net_device_core_stats infrastructure is already used in vxlan_rcv(), use it for the other rx_dropped and tx_dropped counter updates. Update the other counters atomically using DEV_STATS_INC(). Fixes: d342894 ("vxlan: virtual extensible lan") Signed-off-by: Guillaume Nault <gnault@redhat.com> Reviewed-by: Eric Dumazet <edumazet@google.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent b867247 commit 6dee402

1 file changed

Lines changed: 14 additions & 14 deletions

File tree

drivers/net/vxlan/vxlan_core.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1766,8 +1766,8 @@ static int vxlan_rcv(struct sock *sk, struct sk_buff *skb)
17661766
skb_reset_network_header(skb);
17671767

17681768
if (!vxlan_ecn_decapsulate(vs, oiph, skb)) {
1769-
++vxlan->dev->stats.rx_frame_errors;
1770-
++vxlan->dev->stats.rx_errors;
1769+
DEV_STATS_INC(vxlan->dev, rx_frame_errors);
1770+
DEV_STATS_INC(vxlan->dev, rx_errors);
17711771
vxlan_vnifilter_count(vxlan, vni, vninode,
17721772
VXLAN_VNI_STATS_RX_ERRORS, 0);
17731773
goto drop;
@@ -1837,7 +1837,7 @@ static int arp_reduce(struct net_device *dev, struct sk_buff *skb, __be32 vni)
18371837
goto out;
18381838

18391839
if (!pskb_may_pull(skb, arp_hdr_len(dev))) {
1840-
dev->stats.tx_dropped++;
1840+
dev_core_stats_tx_dropped_inc(dev);
18411841
goto out;
18421842
}
18431843
parp = arp_hdr(skb);
@@ -1893,7 +1893,7 @@ static int arp_reduce(struct net_device *dev, struct sk_buff *skb, __be32 vni)
18931893
reply->pkt_type = PACKET_HOST;
18941894

18951895
if (netif_rx(reply) == NET_RX_DROP) {
1896-
dev->stats.rx_dropped++;
1896+
dev_core_stats_rx_dropped_inc(dev);
18971897
vxlan_vnifilter_count(vxlan, vni, NULL,
18981898
VXLAN_VNI_STATS_RX_DROPS, 0);
18991899
}
@@ -2052,7 +2052,7 @@ static int neigh_reduce(struct net_device *dev, struct sk_buff *skb, __be32 vni)
20522052
goto out;
20532053

20542054
if (netif_rx(reply) == NET_RX_DROP) {
2055-
dev->stats.rx_dropped++;
2055+
dev_core_stats_rx_dropped_inc(dev);
20562056
vxlan_vnifilter_count(vxlan, vni, NULL,
20572057
VXLAN_VNI_STATS_RX_DROPS, 0);
20582058
}
@@ -2263,7 +2263,7 @@ static void vxlan_encap_bypass(struct sk_buff *skb, struct vxlan_dev *src_vxlan,
22632263
len);
22642264
} else {
22652265
drop:
2266-
dev->stats.rx_dropped++;
2266+
dev_core_stats_rx_dropped_inc(dev);
22672267
vxlan_vnifilter_count(dst_vxlan, vni, NULL,
22682268
VXLAN_VNI_STATS_RX_DROPS, 0);
22692269
}
@@ -2295,7 +2295,7 @@ static int encap_bypass_if_local(struct sk_buff *skb, struct net_device *dev,
22952295
addr_family, dst_port,
22962296
vxlan->cfg.flags);
22972297
if (!dst_vxlan) {
2298-
dev->stats.tx_errors++;
2298+
DEV_STATS_INC(dev, tx_errors);
22992299
vxlan_vnifilter_count(vxlan, vni, NULL,
23002300
VXLAN_VNI_STATS_TX_ERRORS, 0);
23012301
kfree_skb(skb);
@@ -2559,19 +2559,19 @@ void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev,
25592559
return;
25602560

25612561
drop:
2562-
dev->stats.tx_dropped++;
2562+
dev_core_stats_tx_dropped_inc(dev);
25632563
vxlan_vnifilter_count(vxlan, vni, NULL, VXLAN_VNI_STATS_TX_DROPS, 0);
25642564
dev_kfree_skb(skb);
25652565
return;
25662566

25672567
tx_error:
25682568
rcu_read_unlock();
25692569
if (err == -ELOOP)
2570-
dev->stats.collisions++;
2570+
DEV_STATS_INC(dev, collisions);
25712571
else if (err == -ENETUNREACH)
2572-
dev->stats.tx_carrier_errors++;
2572+
DEV_STATS_INC(dev, tx_carrier_errors);
25732573
dst_release(ndst);
2574-
dev->stats.tx_errors++;
2574+
DEV_STATS_INC(dev, tx_errors);
25752575
vxlan_vnifilter_count(vxlan, vni, NULL, VXLAN_VNI_STATS_TX_ERRORS, 0);
25762576
kfree_skb(skb);
25772577
}
@@ -2604,7 +2604,7 @@ static void vxlan_xmit_nh(struct sk_buff *skb, struct net_device *dev,
26042604
return;
26052605

26062606
drop:
2607-
dev->stats.tx_dropped++;
2607+
dev_core_stats_tx_dropped_inc(dev);
26082608
vxlan_vnifilter_count(netdev_priv(dev), vni, NULL,
26092609
VXLAN_VNI_STATS_TX_DROPS, 0);
26102610
dev_kfree_skb(skb);
@@ -2642,7 +2642,7 @@ static netdev_tx_t vxlan_xmit_nhid(struct sk_buff *skb, struct net_device *dev,
26422642
return NETDEV_TX_OK;
26432643

26442644
drop:
2645-
dev->stats.tx_dropped++;
2645+
dev_core_stats_tx_dropped_inc(dev);
26462646
vxlan_vnifilter_count(netdev_priv(dev), vni, NULL,
26472647
VXLAN_VNI_STATS_TX_DROPS, 0);
26482648
dev_kfree_skb(skb);
@@ -2739,7 +2739,7 @@ static netdev_tx_t vxlan_xmit(struct sk_buff *skb, struct net_device *dev)
27392739
!is_multicast_ether_addr(eth->h_dest))
27402740
vxlan_fdb_miss(vxlan, eth->h_dest);
27412741

2742-
dev->stats.tx_dropped++;
2742+
dev_core_stats_tx_dropped_inc(dev);
27432743
vxlan_vnifilter_count(vxlan, vni, NULL,
27442744
VXLAN_VNI_STATS_TX_DROPS, 0);
27452745
kfree_skb(skb);

0 commit comments

Comments
 (0)