veth: fix 64bit stats on 32bit arches
Using 64bit stats on 32bit arches must use a synchronization or readers
can get transient values.
Fixes bug introduced in commit 6311cc44a2
(veth: convert to 64 bit
statistics)
Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
219eb47e6f
commit
cf05c700cf
1 changed files with 36 additions and 17 deletions
|
@ -12,6 +12,7 @@
|
||||||
#include <linux/slab.h>
|
#include <linux/slab.h>
|
||||||
#include <linux/ethtool.h>
|
#include <linux/ethtool.h>
|
||||||
#include <linux/etherdevice.h>
|
#include <linux/etherdevice.h>
|
||||||
|
#include <linux/u64_stats_sync.h>
|
||||||
|
|
||||||
#include <net/dst.h>
|
#include <net/dst.h>
|
||||||
#include <net/xfrm.h>
|
#include <net/xfrm.h>
|
||||||
|
@ -24,12 +25,13 @@
|
||||||
#define MAX_MTU 65535 /* Max L3 MTU (arbitrary) */
|
#define MAX_MTU 65535 /* Max L3 MTU (arbitrary) */
|
||||||
|
|
||||||
struct veth_net_stats {
|
struct veth_net_stats {
|
||||||
u64 rx_packets;
|
u64 rx_packets;
|
||||||
u64 tx_packets;
|
u64 tx_packets;
|
||||||
u64 rx_bytes;
|
u64 rx_bytes;
|
||||||
u64 tx_bytes;
|
u64 tx_bytes;
|
||||||
u64 tx_dropped;
|
u64 rx_dropped;
|
||||||
u64 rx_dropped;
|
u64 tx_dropped;
|
||||||
|
struct u64_stats_sync syncp;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct veth_priv {
|
struct veth_priv {
|
||||||
|
@ -137,21 +139,29 @@ static netdev_tx_t veth_xmit(struct sk_buff *skb, struct net_device *dev)
|
||||||
if (dev_forward_skb(rcv, skb) != NET_RX_SUCCESS)
|
if (dev_forward_skb(rcv, skb) != NET_RX_SUCCESS)
|
||||||
goto rx_drop;
|
goto rx_drop;
|
||||||
|
|
||||||
|
u64_stats_update_begin(&stats->syncp);
|
||||||
stats->tx_bytes += length;
|
stats->tx_bytes += length;
|
||||||
stats->tx_packets++;
|
stats->tx_packets++;
|
||||||
|
u64_stats_update_end(&stats->syncp);
|
||||||
|
|
||||||
|
u64_stats_update_begin(&rcv_stats->syncp);
|
||||||
rcv_stats->rx_bytes += length;
|
rcv_stats->rx_bytes += length;
|
||||||
rcv_stats->rx_packets++;
|
rcv_stats->rx_packets++;
|
||||||
|
u64_stats_update_end(&rcv_stats->syncp);
|
||||||
|
|
||||||
return NETDEV_TX_OK;
|
return NETDEV_TX_OK;
|
||||||
|
|
||||||
tx_drop:
|
tx_drop:
|
||||||
kfree_skb(skb);
|
kfree_skb(skb);
|
||||||
|
u64_stats_update_begin(&stats->syncp);
|
||||||
stats->tx_dropped++;
|
stats->tx_dropped++;
|
||||||
|
u64_stats_update_end(&stats->syncp);
|
||||||
return NETDEV_TX_OK;
|
return NETDEV_TX_OK;
|
||||||
|
|
||||||
rx_drop:
|
rx_drop:
|
||||||
|
u64_stats_update_begin(&rcv_stats->syncp);
|
||||||
rcv_stats->rx_dropped++;
|
rcv_stats->rx_dropped++;
|
||||||
|
u64_stats_update_end(&rcv_stats->syncp);
|
||||||
return NETDEV_TX_OK;
|
return NETDEV_TX_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -162,21 +172,30 @@ rx_drop:
|
||||||
static struct rtnl_link_stats64 *veth_get_stats64(struct net_device *dev,
|
static struct rtnl_link_stats64 *veth_get_stats64(struct net_device *dev,
|
||||||
struct rtnl_link_stats64 *tot)
|
struct rtnl_link_stats64 *tot)
|
||||||
{
|
{
|
||||||
struct veth_priv *priv;
|
struct veth_priv *priv = netdev_priv(dev);
|
||||||
int cpu;
|
int cpu;
|
||||||
struct veth_net_stats *stats;
|
|
||||||
|
|
||||||
priv = netdev_priv(dev);
|
|
||||||
|
|
||||||
for_each_possible_cpu(cpu) {
|
for_each_possible_cpu(cpu) {
|
||||||
stats = per_cpu_ptr(priv->stats, cpu);
|
struct veth_net_stats *stats = per_cpu_ptr(priv->stats, cpu);
|
||||||
|
u64 rx_packets, rx_bytes, rx_dropped;
|
||||||
|
u64 tx_packets, tx_bytes, tx_dropped;
|
||||||
|
unsigned int start;
|
||||||
|
|
||||||
tot->rx_packets += stats->rx_packets;
|
do {
|
||||||
tot->tx_packets += stats->tx_packets;
|
start = u64_stats_fetch_begin_bh(&stats->syncp);
|
||||||
tot->rx_bytes += stats->rx_bytes;
|
rx_packets = stats->rx_packets;
|
||||||
tot->tx_bytes += stats->tx_bytes;
|
tx_packets = stats->tx_packets;
|
||||||
tot->tx_dropped += stats->tx_dropped;
|
rx_bytes = stats->rx_bytes;
|
||||||
tot->rx_dropped += stats->rx_dropped;
|
tx_bytes = stats->tx_bytes;
|
||||||
|
rx_dropped = stats->rx_dropped;
|
||||||
|
tx_dropped = stats->tx_dropped;
|
||||||
|
} while (u64_stats_fetch_retry_bh(&stats->syncp, start));
|
||||||
|
tot->rx_packets += rx_packets;
|
||||||
|
tot->tx_packets += tx_packets;
|
||||||
|
tot->rx_bytes += rx_bytes;
|
||||||
|
tot->tx_bytes += tx_bytes;
|
||||||
|
tot->rx_dropped += rx_dropped;
|
||||||
|
tot->tx_dropped += tx_dropped;
|
||||||
}
|
}
|
||||||
|
|
||||||
return tot;
|
return tot;
|
||||||
|
|
Loading…
Add table
Reference in a new issue