DPDK patches and discussions
 help / color / mirror / Atom feed
From: Francis Kelly <fkelly@nvidia.com>
To: <tmonjalon@nvidia.com>, Ori Kam <orika@nvidia.com>
Cc: <jamhunter@nvidia.com>, <aagbarih@nvidia.com>, <dev@dpdk.org>,
	Ady Agbarih <adypodoman@gmail.com>
Subject: [dpdk-dev] [PATCH 08/10] regex/mlx5: fix uninitialized QP destroy
Date: Fri, 22 Oct 2021 15:45:58 +0000	[thread overview]
Message-ID: <20211022154600.2180938-8-fkelly@nvidia.com> (raw)
In-Reply-To: <20211022154600.2180938-1-fkelly@nvidia.com>

From: Ady Agbarih <adypodoman@gmail.com>

The number of QPs for a device are setup during the
 configuration phase, when the user calls
 rte_regexdev_configure(). The mlx5 regex driver then
 pre-allocates QPs, however those QPs are not
 setup/ready for sending jobs. The user has to configure
 each QP using rte_regexdev_queue_pair_setup(). When
 stopping the device the driver destroys all QPs that
 were preallocated assuming that they are all setup. This
 results in an attempt to destroy an uninitialized QP,
 leading to a NULL dereference error.

In order to solve this issue we first check that the
 QP jobs array has been initialized before attempting
 to destroy the QP.

Fixes: 35f8f6c8dbee ("regex/mlx5: add cleanup code")
Cc: orika@nvidia.com

Signed-off-by: Ady Agbarih <adypodoman@gmail.com>
---
 drivers/regex/mlx5/mlx5_regex_control.c  | 3 +++
 drivers/regex/mlx5/mlx5_regex_fastpath.c | 7 ++++---
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/drivers/regex/mlx5/mlx5_regex_control.c b/drivers/regex/mlx5/mlx5_regex_control.c
index 3e0a0cdd71..52f66ecce8 100644
--- a/drivers/regex/mlx5/mlx5_regex_control.c
+++ b/drivers/regex/mlx5/mlx5_regex_control.c
@@ -283,6 +283,9 @@ mlx5_regex_clean_ctrl(struct rte_regexdev *dev)
 		return;
 	for (qp_ind = 0; qp_ind < priv->nb_queues; qp_ind++) {
 		qp = &priv->qps[qp_ind];
+		/* Check if mlx5_regex_qp_setup() was called for this QP */
+		if (!qp->jobs)
+			continue;
 		mlx5_regexdev_teardown_fastpath(priv, qp_ind);
 		mlx5_mr_btree_free(&qp->mr_ctrl.cache_bh);
 		for (i = 0; i < qp->nb_obj; i++)
diff --git a/drivers/regex/mlx5/mlx5_regex_fastpath.c b/drivers/regex/mlx5/mlx5_regex_fastpath.c
index 0833b2817e..26b4cc5c82 100644
--- a/drivers/regex/mlx5/mlx5_regex_fastpath.c
+++ b/drivers/regex/mlx5/mlx5_regex_fastpath.c
@@ -739,6 +739,7 @@ mlx5_regexdev_setup_fastpath(struct mlx5_regex_priv *priv, uint32_t qp_id)
 	err = setup_buffers(priv, qp);
 	if (err) {
 		rte_free(qp->jobs);
+		qp->jobs = NULL;
 		return err;
 	}
 
@@ -791,14 +792,14 @@ mlx5_regexdev_teardown_fastpath(struct mlx5_regex_priv *priv, uint32_t qp_id)
 	struct mlx5_regex_qp *qp = &priv->qps[qp_id];
 	uint32_t i;
 
-	if (qp) {
+	if (qp->jobs) {
 		for (i = 0; i < qp->nb_desc; i++) {
 			if (qp->jobs[i].imkey)
 				claim_zero(mlx5_devx_cmd_destroy
 							(qp->jobs[i].imkey));
 		}
 		free_buffers(qp);
-		if (qp->jobs)
-			rte_free(qp->jobs);
+		rte_free(qp->jobs);
+		qp->jobs = NULL;
 	}
 }
-- 
2.25.1


  parent reply	other threads:[~2021-10-22 15:48 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-22 15:45 [dpdk-dev] [PATCH 01/10] common/mlx5: update PRM definitions for regex availability Francis Kelly
2021-10-22 15:45 ` [dpdk-dev] [PATCH 02/10] regex/mlx5: add cleanup code Francis Kelly
2021-10-22 15:45 ` [dpdk-dev] [PATCH 03/10] common/mlx5: update regex DevX commands Francis Kelly
2021-10-24 13:39   ` Ori Kam
2021-10-22 15:45 ` [dpdk-dev] [PATCH 04/10] regex/mlx5: remove regexp register read/write Francis Kelly
2021-10-24 13:40   ` Ori Kam
2021-10-22 15:45 ` [dpdk-dev] [PATCH 05/10] regex/mlx5: move RXP to CrSpace Francis Kelly
2021-10-24 13:41   ` Ori Kam
2021-10-22 15:45 ` [dpdk-dev] [PATCH 06/10] regex/mlx5: remove start/stop engine API Francis Kelly
2021-10-22 15:45 ` [dpdk-dev] [PATCH 07/10] regex/mlx5: removed redundant rxp csr file Francis Kelly
2021-10-24 13:42   ` Ori Kam
2021-10-22 15:45 ` Francis Kelly [this message]
2021-10-24 13:42   ` [dpdk-dev] [PATCH 08/10] regex/mlx5: fix uninitialized QP destroy Ori Kam
2021-10-22 15:45 ` [dpdk-dev] [PATCH 09/10] regex/mlx5: prevent QP double setup Francis Kelly
2021-10-24 13:43   ` Ori Kam
2021-10-22 15:46 ` [dpdk-dev] [PATCH 10/10] doc: updated release notes and mlx5 file Francis Kelly
2021-10-24 13:43   ` Ori Kam
2021-11-03 22:13     ` Thomas Monjalon
2021-10-24 13:38 ` [dpdk-dev] [PATCH 01/10] common/mlx5: update PRM definitions for regex availability Ori Kam

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211022154600.2180938-8-fkelly@nvidia.com \
    --to=fkelly@nvidia.com \
    --cc=aagbarih@nvidia.com \
    --cc=adypodoman@gmail.com \
    --cc=dev@dpdk.org \
    --cc=jamhunter@nvidia.com \
    --cc=orika@nvidia.com \
    --cc=tmonjalon@nvidia.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).