DPDK patches and discussions
 help / color / mirror / Atom feed
From: Yuval Avnery <yuvalav@nvidia.com>
To: Ori Kam <orika@mellanox.com>
Cc: thomas@monjalon.net, dev@dpdk.org, yuvalav@mellanox.com
Subject: [dpdk-dev] [PATCH v2] regex/mlx5: add teardown flow to fastpath buffers
Date: Wed,  2 Sep 2020 11:38:22 +0000	[thread overview]
Message-ID: <1599046703-69676-1-git-send-email-yuvalav@nvidia.com> (raw)

From: Yuval Avnery <yuvalav@mellanox.com>

Added missing code to free Input/Output buffers and memory
registration.
Also added calls to this code in case of error in the qp setup
procedure.
The rollback code itself did not handle rollback properly
and did not check return value from the fastpath setup.

Signed-off-by: Yuval Avnery <yuvalav@mellanox.com>
Acked-by: Ori Kam <orika@mellanox.com>
---
 drivers/regex/mlx5/mlx5_regex.h          |  2 ++
 drivers/regex/mlx5/mlx5_regex_control.c  | 20 ++++++++++++-------
 drivers/regex/mlx5/mlx5_regex_fastpath.c | 33 +++++++++++++++++++++++++++++++-
 3 files changed, 47 insertions(+), 8 deletions(-)

diff --git a/drivers/regex/mlx5/mlx5_regex.h b/drivers/regex/mlx5/mlx5_regex.h
index 6098fb1..fc0f362 100644
--- a/drivers/regex/mlx5/mlx5_regex.h
+++ b/drivers/regex/mlx5/mlx5_regex.h
@@ -109,6 +109,8 @@ int mlx5_regex_qp_setup(struct rte_regexdev *dev, uint16_t qp_ind,
 
 /* mlx5_regex_fastpath.c */
 int mlx5_regexdev_setup_fastpath(struct mlx5_regex_priv *priv, uint32_t qp_id);
+void mlx5_regexdev_teardown_fastpath(struct mlx5_regex_priv *priv,
+				     uint32_t qp_id);
 uint16_t mlx5_regexdev_enqueue(struct rte_regexdev *dev, uint16_t qp_id,
 		       struct rte_regex_ops **ops, uint16_t nb_ops);
 uint16_t mlx5_regexdev_dequeue(struct rte_regexdev *dev, uint16_t qp_id,
diff --git a/drivers/regex/mlx5/mlx5_regex_control.c b/drivers/regex/mlx5/mlx5_regex_control.c
index faafb76..187c3de 100644
--- a/drivers/regex/mlx5/mlx5_regex_control.c
+++ b/drivers/regex/mlx5/mlx5_regex_control.c
@@ -357,23 +357,29 @@
 	ret = regex_ctrl_create_cq(priv, &qp->cq);
 	if (ret) {
 		DRV_LOG(ERR, "Can't create cq.");
-		goto error;
+		goto err_cq;
 	}
 	for (i = 0; i < qp->nb_obj; i++) {
 		ret = regex_ctrl_create_sq(priv, qp, i, log_desc);
 		if (ret) {
 			DRV_LOG(ERR, "Can't create sq.");
-			goto error;
+			goto err_sq;
 		}
 	}
 
-	mlx5_regexdev_setup_fastpath(priv, qp_ind);
+	ret = mlx5_regexdev_setup_fastpath(priv, qp_ind);
+	if (ret) {
+		DRV_LOG(ERR, "Fail to setup fastpath.");
+		goto err_fp;
+	}
 	return 0;
 
-error:
-	regex_ctrl_destroy_cq(priv, &qp->cq);
+err_fp:
 	for (i = 0; i < qp->nb_obj; i++)
 		ret = regex_ctrl_destroy_sq(priv, qp, i);
-	return -rte_errno;
-
+err_sq:
+	regex_ctrl_destroy_cq(priv, &qp->cq);
+err_cq:
+	rte_free(qp->sqs);
+	return ret;
 }
diff --git a/drivers/regex/mlx5/mlx5_regex_fastpath.c b/drivers/regex/mlx5/mlx5_regex_fastpath.c
index 2c6c9e1..6fafcff 100644
--- a/drivers/regex/mlx5/mlx5_regex_fastpath.c
+++ b/drivers/regex/mlx5/mlx5_regex_fastpath.c
@@ -407,8 +407,39 @@ struct mlx5_regex_job {
 	if (!qp->jobs)
 		return -ENOMEM;
 	err = setup_buffers(qp, priv->pd);
-	if (err)
+	if (err) {
+		rte_free(qp->jobs);
 		return err;
+	}
 	setup_sqs(qp);
 	return 0;
 }
+
+static void
+free_buffers(struct mlx5_regex_qp *qp)
+{
+	if (qp->metadata) {
+		mlx5_glue->dereg_mr(qp->metadata);
+		rte_free(qp->metadata->addr);
+	}
+	if (qp->inputs) {
+		mlx5_glue->dereg_mr(qp->inputs);
+		rte_free(qp->inputs->addr);
+	}
+	if (qp->outputs) {
+		mlx5_glue->dereg_mr(qp->outputs);
+		rte_free(qp->outputs->addr);
+	}
+}
+
+void
+mlx5_regexdev_teardown_fastpath(struct mlx5_regex_priv *priv, uint32_t qp_id)
+{
+	struct mlx5_regex_qp *qp = &priv->qps[qp_id];
+
+	if (qp) {
+		free_buffers(qp);
+		if (qp->jobs)
+			rte_free(qp->jobs);
+	}
+}
-- 
1.8.3.1


             reply	other threads:[~2020-09-02 11:38 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-02 11:38 Yuval Avnery [this message]
2020-09-08 22:29 ` Thomas Monjalon

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=1599046703-69676-1-git-send-email-yuvalav@nvidia.com \
    --to=yuvalav@nvidia.com \
    --cc=dev@dpdk.org \
    --cc=orika@mellanox.com \
    --cc=thomas@monjalon.net \
    --cc=yuvalav@mellanox.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).