net/mlx5: fix counter query fail during port closing

Message ID 1589533003-322710-1-git-send-email-suanmingm@mellanox.com (mailing list archive)
State Superseded, archived
Delegated to: Raslan Darawsheh
Headers
Series net/mlx5: fix counter query fail during port closing |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation fail apply issues

Commit Message

Suanming Mou May 15, 2020, 8:56 a.m. UTC
  Currently, the DevX counter query works asynchronously with Devx
interrupt handler return the query result. When port closes, the
interrupt handler will be uninstalled and the Devx comp obj will
also be destroyed. Meanwhile the query is still not cancelled.
In this case, counter query may use the invalid Devx comp which
has been destroyed, and query failure with invalid FD will be
reported.

Move the query alarm cancel before Devx interrupt uninstall to
avoid query failure with invalid FD issue.

Fixes: f15db67df09c ("net/mlx5: accelerate DV flow counter query")
Cc: stable@dpdk.org

Signed-off-by: Suanming Mou <suanmingm@mellanox.com>
Acked-by: Viacheslav Ovsiienko <viacheslavo@mellanox.com>
---
Please apply the patch after the patch below:
https://patches.dpdk.org/patch/70310/
---
 drivers/net/mlx5/mlx5.c | 25 +++++++++++++++++--------
 1 file changed, 17 insertions(+), 8 deletions(-)
  

Patch

diff --git a/drivers/net/mlx5/mlx5.c b/drivers/net/mlx5/mlx5.c
index be16841..579da76 100644
--- a/drivers/net/mlx5/mlx5.c
+++ b/drivers/net/mlx5/mlx5.c
@@ -506,15 +506,7 @@  struct mlx5_flow_id_pool *
 	struct mlx5_counter_stats_mem_mng *mng;
 	int i;
 	int j;
-	int retries = 1024;
 
-	rte_errno = 0;
-	while (--retries) {
-		rte_eal_alarm_cancel(mlx5_flow_query_alarm, sh);
-		if (rte_errno != EINPROGRESS)
-			break;
-		rte_pause();
-	}
 	for (i = 0; i < MLX5_CCONT_TYPE_MAX; ++i) {
 		struct mlx5_flow_counter_pool *pool;
 		uint32_t batch = !!(i > 1);
@@ -1427,6 +1419,23 @@  struct mlx5_flow_id_pool *
 		dev->data->port_id,
 		((priv->sh && priv->sh->ctx) ?
 		priv->sh->ctx->device->name : ""));
+	/*
+	 * The devx->comp is going to be destroyed in
+	 * mlx5_dev_interrupt_handler_devx_uninstall(), stop the asynchronous
+	 * counter query in advanced in case the devx->comp destroyed during
+	 * query causes invalid fd used.
+	 */
+	if (priv->sh) {
+		int retries = 1024;
+
+		rte_errno = 0;
+		while (--retries) {
+			rte_eal_alarm_cancel(mlx5_flow_query_alarm, priv->sh);
+			if (rte_errno != EINPROGRESS)
+				break;
+			rte_pause();
+		}
+	}
 	/* In case mlx5_dev_stop() has not been called. */
 	mlx5_dev_interrupt_handler_uninstall(dev);
 	mlx5_dev_interrupt_handler_devx_uninstall(dev);