Skip to content

Commit 1510d72

Browse files
iamkafaidavem330
authored andcommitted
net/mlx5e: Fix race in mlx5e_sw_stats and mlx5e_vport_stats
We have observed a sudden spike in rx/tx_packets and rx/tx_bytes reported under /proc/net/dev. There is a race in mlx5e_update_stats() and some of the get-stats functions (the one that we hit is the mlx5e_get_stats() which is called by ndo_get_stats64()). In particular, the very first thing mlx5e_update_sw_counters() does is 'memset(s, 0, sizeof(*s))'. For example, if mlx5e_get_stats() is unlucky at one point, rx_bytes and rx_packets could be 0. One second later, a normal (and much bigger than 0) value will be reported. This patch is to use a 'struct mlx5e_sw_stats temp' to avoid a direct memset zero on priv->stats.sw. mlx5e_update_vport_counters() has a similar race. Hence, addressed together. However, memset zero is removed instead because it is not needed. I am lucky enough to catch this 0-reset in rx multicast: eth0: 41457665 76804 70 0 0 70 0 47085 15586634 87502 3 0 0 0 3 0 eth0: 41459860 76815 70 0 0 70 0 47094 15588376 87516 3 0 0 0 3 0 eth0: 41460577 76822 70 0 0 70 0 0 15589083 87521 3 0 0 0 3 0 eth0: 41463293 76838 70 0 0 70 0 47108 15595872 87538 3 0 0 0 3 0 eth0: 41463379 76839 70 0 0 70 0 47116 15596138 87539 3 0 0 0 3 0 v2: Remove memset zero from mlx5e_update_vport_counters() v1: Use temp and memcpy Fixes: 9218b44 ("net/mlx5e: Statistics handling refactoring") Suggested-by: Eric Dumazet <[email protected]> Suggested-by: Saeed Mahameed <[email protected]> Signed-off-by: Martin KaFai Lau <[email protected]> Acked-by: Saeed Mahameed <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 94836ec commit 1510d72

File tree

1 file changed

+2
-2
lines changed
  • drivers/net/ethernet/mellanox/mlx5/core

1 file changed

+2
-2
lines changed

drivers/net/ethernet/mellanox/mlx5/core/en_main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ static void mlx5e_tx_timeout_work(struct work_struct *work)
174174

175175
static void mlx5e_update_sw_counters(struct mlx5e_priv *priv)
176176
{
177-
struct mlx5e_sw_stats *s = &priv->stats.sw;
177+
struct mlx5e_sw_stats temp, *s = &temp;
178178
struct mlx5e_rq_stats *rq_stats;
179179
struct mlx5e_sq_stats *sq_stats;
180180
u64 tx_offload_none = 0;
@@ -229,6 +229,7 @@ static void mlx5e_update_sw_counters(struct mlx5e_priv *priv)
229229
s->link_down_events_phy = MLX5_GET(ppcnt_reg,
230230
priv->stats.pport.phy_counters,
231231
counter_set.phys_layer_cntrs.link_down_events);
232+
memcpy(&priv->stats.sw, s, sizeof(*s));
232233
}
233234

234235
static void mlx5e_update_vport_counters(struct mlx5e_priv *priv)
@@ -243,7 +244,6 @@ static void mlx5e_update_vport_counters(struct mlx5e_priv *priv)
243244
MLX5_SET(query_vport_counter_in, in, op_mod, 0);
244245
MLX5_SET(query_vport_counter_in, in, other_vport, 0);
245246

246-
memset(out, 0, outlen);
247247
mlx5_cmd_exec(mdev, in, sizeof(in), out, outlen);
248248
}
249249

0 commit comments

Comments
 (0)