patches for DPDK stable branches
 help / color / mirror / Atom feed
* [dpdk-stable] [PATCH 18.11] net/mlx5: fix crash on hash Rx queue handling for drop
@ 2019-12-17  7:26 Xiaoyu Min
  2019-12-17 14:09 ` Kevin Traynor
  0 siblings, 1 reply; 2+ messages in thread
From: Xiaoyu Min @ 2019-12-17  7:26 UTC (permalink / raw)
  To: stable, Matan Azrad, Shahaf Shuler, Viacheslav Ovsiienko; +Cc: Zengmo Gao

[ upstream commit 8e2f25cf3c14a9d4c4ee7cf5c6971e9fd5ad64c4 ]

When to create hrxq for the drop, it could fail on creating qp and goto
the error handle which will release created ind_table by calling drop
release function, which takes rte_ethdev as the only parameter and uses
the priv->drop_queue.hrxq as input to release.

Unfortunately, at this point, the hrxq is not allocated and
priv->drop_queue.hrxq is still NULL, which leads to a segfault.

This patch fixes the above by allocating the hrxq at first place and
when the error happens, hrxq is released as the last one.

This patch also release other allocated resources by the correct order,
which is missing previously.

Fixes: 78be885295b8 ("net/mlx5: handle drop queues as regular queues")

Reported-by: Zengmo Gao <gaozengmo@jd.com>
Signed-off-by: Xiaoyu Min <jackmin@mellanox.com>
Acked-by: Viacheslav Ovsiienko <viacheslavo@mellanox.com>
---
 drivers/net/mlx5/mlx5_rxq.c | 34 ++++++++++++++++++++--------------
 1 file changed, 20 insertions(+), 14 deletions(-)

diff --git a/drivers/net/mlx5/mlx5_rxq.c b/drivers/net/mlx5/mlx5_rxq.c
index f6edb10fed..566fb64fad 100644
--- a/drivers/net/mlx5/mlx5_rxq.c
+++ b/drivers/net/mlx5/mlx5_rxq.c
@@ -2140,17 +2140,27 @@ struct mlx5_hrxq *
 mlx5_hrxq_drop_new(struct rte_eth_dev *dev)
 {
 	struct mlx5_priv *priv = dev->data->dev_private;
-	struct mlx5_ind_table_ibv *ind_tbl;
-	struct ibv_qp *qp;
-	struct mlx5_hrxq *hrxq;
+	struct mlx5_ind_table_ibv *ind_tbl = NULL;
+	struct ibv_qp *qp = NULL;
+	struct mlx5_hrxq *hrxq = NULL;
 
 	if (priv->drop_queue.hrxq) {
 		rte_atomic32_inc(&priv->drop_queue.hrxq->refcnt);
 		return priv->drop_queue.hrxq;
 	}
+	hrxq = rte_calloc(__func__, 1, sizeof(*hrxq), 0);
+	if (!hrxq) {
+		DRV_LOG(WARNING,
+			"port %u cannot allocate memory for drop queue",
+			dev->data->port_id);
+		rte_errno = ENOMEM;
+		goto error;
+	}
+	priv->drop_queue.hrxq = hrxq;
 	ind_tbl = mlx5_ind_table_ibv_drop_new(dev);
 	if (!ind_tbl)
-		return NULL;
+		goto error;
+	hrxq->ind_table = ind_tbl;
 	qp = mlx5_glue->create_qp_ex(priv->ctx,
 		 &(struct ibv_qp_init_attr_ex){
 			.qp_type = IBV_QPT_RAW_PACKET,
@@ -2174,22 +2184,18 @@ mlx5_hrxq_drop_new(struct rte_eth_dev *dev)
 		rte_errno = errno;
 		goto error;
 	}
-	hrxq = rte_calloc(__func__, 1, sizeof(*hrxq), 0);
-	if (!hrxq) {
-		DRV_LOG(WARNING,
-			"port %u cannot allocate memory for drop queue",
-			dev->data->port_id);
-		rte_errno = ENOMEM;
-		goto error;
-	}
-	hrxq->ind_table = ind_tbl;
 	hrxq->qp = qp;
-	priv->drop_queue.hrxq = hrxq;
 	rte_atomic32_set(&hrxq->refcnt, 1);
 	return hrxq;
 error:
+	if (qp)
+		claim_zero(mlx5_glue->destroy_qp(hrxq->qp));
 	if (ind_tbl)
 		mlx5_ind_table_ibv_drop_release(dev);
+	if (hrxq) {
+		priv->drop_queue.hrxq = NULL;
+		rte_free(hrxq);
+	}
 	return NULL;
 }
 
-- 
2.24.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [dpdk-stable] [PATCH 18.11] net/mlx5: fix crash on hash Rx queue handling for drop
  2019-12-17  7:26 [dpdk-stable] [PATCH 18.11] net/mlx5: fix crash on hash Rx queue handling for drop Xiaoyu Min
@ 2019-12-17 14:09 ` Kevin Traynor
  0 siblings, 0 replies; 2+ messages in thread
From: Kevin Traynor @ 2019-12-17 14:09 UTC (permalink / raw)
  To: Xiaoyu Min, stable, Matan Azrad, Shahaf Shuler, Viacheslav Ovsiienko
  Cc: Zengmo Gao

On 17/12/2019 07:26, Xiaoyu Min wrote:
> [ upstream commit 8e2f25cf3c14a9d4c4ee7cf5c6971e9fd5ad64c4 ]
> 
> When to create hrxq for the drop, it could fail on creating qp and goto
> the error handle which will release created ind_table by calling drop
> release function, which takes rte_ethdev as the only parameter and uses
> the priv->drop_queue.hrxq as input to release.
> 
> Unfortunately, at this point, the hrxq is not allocated and
> priv->drop_queue.hrxq is still NULL, which leads to a segfault.
> 
> This patch fixes the above by allocating the hrxq at first place and
> when the error happens, hrxq is released as the last one.
> 
> This patch also release other allocated resources by the correct order,
> which is missing previously.
> 
> Fixes: 78be885295b8 ("net/mlx5: handle drop queues as regular queues")
> 
> Reported-by: Zengmo Gao <gaozengmo@jd.com>
> Signed-off-by: Xiaoyu Min <jackmin@mellanox.com>
> Acked-by: Viacheslav Ovsiienko <viacheslavo@mellanox.com>

Thanks, applied to 18.11 branch.


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-12-17 14:09 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-17  7:26 [dpdk-stable] [PATCH 18.11] net/mlx5: fix crash on hash Rx queue handling for drop Xiaoyu Min
2019-12-17 14:09 ` Kevin Traynor

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).