diff options
author | Bodong Wang <bodong@mellanox.com> | 2019-09-13 16:24:19 -0500 |
---|---|---|
committer | Saeed Mahameed <saeedm@mellanox.com> | 2020-03-13 16:26:01 -0700 |
commit | 14c844cbf3503076de6e2e48d575216f1600b19f (patch) | |
tree | 74888c193fc458bf5309f2bdb15abd1b9f7fc5e5 /drivers | |
parent | 86f9453c5fca845ca592777ef8960ff827fc7cc9 (diff) | |
download | linux-14c844cbf3503076de6e2e48d575216f1600b19f.tar.bz2 |
net/mlx5: E-Switch, Hold mutex when querying drop counter in legacy mode
Consider scenario below, CPU 1 is at risk to query already destroyed
drop counters. Need to apply the same state mutex when disabling vport.
+-------------------------------+-------------------------------------+
| CPU 0 | CPU 1 |
+-------------------------------+-------------------------------------+
| mlx5_device_disable_sriov | mlx5e_get_vf_stats |
| mlx5_eswitch_disable | mlx5_eswitch_get_vport_stats |
| esw_disable_vport | mlx5_eswitch_query_vport_drop_stats |
| mlx5_fc_destroy(drop_counter) | mlx5_fc_query(drop_counter) |
+-------------------------------+-------------------------------------+
Fixes: b8a0dbe3a90b ("net/mlx5e: E-switch, Add steering drop counters")
Signed-off-by: Bodong Wang <bodong@mellanox.com>
Reviewed-by: Parav Pandit <parav@mellanox.com>
Signed-off-by: Saeed Mahameed <saeedm@mellanox.com>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/net/ethernet/mellanox/mlx5/core/eswitch.c | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c b/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c index b123089866e2..b4b93d2322a9 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c @@ -2620,9 +2620,13 @@ static int mlx5_eswitch_query_vport_drop_stats(struct mlx5_core_dev *dev, u64 bytes = 0; int err = 0; - if (!vport->enabled || esw->mode != MLX5_ESWITCH_LEGACY) + if (esw->mode != MLX5_ESWITCH_LEGACY) return 0; + mutex_lock(&esw->state_lock); + if (!vport->enabled) + goto unlock; + if (vport->egress.legacy.drop_counter) mlx5_fc_query(dev, vport->egress.legacy.drop_counter, &stats->rx_dropped, &bytes); @@ -2633,20 +2637,22 @@ static int mlx5_eswitch_query_vport_drop_stats(struct mlx5_core_dev *dev, if (!MLX5_CAP_GEN(dev, receive_discard_vport_down) && !MLX5_CAP_GEN(dev, transmit_discard_vport_down)) - return 0; + goto unlock; err = mlx5_query_vport_down_stats(dev, vport->vport, 1, &rx_discard_vport_down, &tx_discard_vport_down); if (err) - return err; + goto unlock; if (MLX5_CAP_GEN(dev, receive_discard_vport_down)) stats->rx_dropped += rx_discard_vport_down; if (MLX5_CAP_GEN(dev, transmit_discard_vport_down)) stats->tx_dropped += tx_discard_vport_down; - return 0; +unlock: + mutex_unlock(&esw->state_lock); + return err; } int mlx5_eswitch_get_vport_stats(struct mlx5_eswitch *esw, |