Skip to content

Commit 9ed17db

Browse files
edumazetdavem330
authored andcommitted
net/mlx4_en: get rid of ret_stats
mlx4 uses a private struct net_device_stats in a vain attempt to avoid races. This is buggy because multiple cpus could call mlx4_en_get_stats() at the same time, so ret_stats can not guarantee stable results. To fix this, we need to switch to ndo_get_stats64() as this method provides per-thread storage. This allows to reduce mlx4_en_priv bloat. Signed-off-by: Eric Dumazet <[email protected]> Cc: Willem de Bruijn <[email protected]> Cc: Eugenia Emantayev <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 45acbac commit 9ed17db

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

drivers/net/ethernet/mellanox/mlx4/en_netdev.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1296,15 +1296,16 @@ static void mlx4_en_tx_timeout(struct net_device *dev)
12961296
}
12971297

12981298

1299-
static struct net_device_stats *mlx4_en_get_stats(struct net_device *dev)
1299+
static struct rtnl_link_stats64 *
1300+
mlx4_en_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *stats)
13001301
{
13011302
struct mlx4_en_priv *priv = netdev_priv(dev);
13021303

13031304
spin_lock_bh(&priv->stats_lock);
1304-
memcpy(&priv->ret_stats, &priv->stats, sizeof(priv->stats));
1305+
netdev_stats_to_stats64(stats, &priv->stats);
13051306
spin_unlock_bh(&priv->stats_lock);
13061307

1307-
return &priv->ret_stats;
1308+
return stats;
13081309
}
13091310

13101311
static void mlx4_en_set_default_moderation(struct mlx4_en_priv *priv)
@@ -2487,7 +2488,7 @@ static const struct net_device_ops mlx4_netdev_ops = {
24872488
.ndo_stop = mlx4_en_close,
24882489
.ndo_start_xmit = mlx4_en_xmit,
24892490
.ndo_select_queue = mlx4_en_select_queue,
2490-
.ndo_get_stats = mlx4_en_get_stats,
2491+
.ndo_get_stats64 = mlx4_en_get_stats64,
24912492
.ndo_set_rx_mode = mlx4_en_set_rx_mode,
24922493
.ndo_set_mac_address = mlx4_en_set_mac,
24932494
.ndo_validate_addr = eth_validate_addr,
@@ -2519,7 +2520,7 @@ static const struct net_device_ops mlx4_netdev_ops_master = {
25192520
.ndo_stop = mlx4_en_close,
25202521
.ndo_start_xmit = mlx4_en_xmit,
25212522
.ndo_select_queue = mlx4_en_select_queue,
2522-
.ndo_get_stats = mlx4_en_get_stats,
2523+
.ndo_get_stats64 = mlx4_en_get_stats64,
25232524
.ndo_set_rx_mode = mlx4_en_set_rx_mode,
25242525
.ndo_set_mac_address = mlx4_en_set_mac,
25252526
.ndo_validate_addr = eth_validate_addr,

drivers/net/ethernet/mellanox/mlx4/mlx4_en.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,6 @@ struct mlx4_en_priv {
484484
struct net_device *dev;
485485
unsigned long active_vlans[BITS_TO_LONGS(VLAN_N_VID)];
486486
struct net_device_stats stats;
487-
struct net_device_stats ret_stats;
488487
struct mlx4_en_port_state port_state;
489488
spinlock_t stats_lock;
490489
struct ethtool_flow_id ethtool_rules[MAX_NUM_OF_FS_RULES];

0 commit comments

Comments
 (0)