DPDK patches and discussions
 help / color / mirror / Atom feed
From: Gregory Etelson <getelson@nvidia.com>
To: <dev@dpdk.org>
Cc: <getelson@nvidia.com>, <mkashani@nvidia.com>,
	<rasland@nvidia.com>, Dariusz Sosnowski <dsosnowski@nvidia.com>,
	Viacheslav Ovsiienko <viacheslavo@nvidia.com>,
	Bing Zhao <bingz@nvidia.com>, Ori Kam <orika@nvidia.com>,
	Suanming Mou <suanmingm@nvidia.com>,
	Matan Azrad <matan@nvidia.com>
Subject: [PATCH] net/mlx5: fix indexed pool resize
Date: Sun, 7 Jul 2024 12:48:28 +0300	[thread overview]
Message-ID: <20240707094829.44604-1-getelson@nvidia.com> (raw)

On success, indexed pool resize sets maximal pool entries number to
the `num_entries` parameter value.

The patch fixes maximal pool entries assignment.

The patch also adds `error` parameter to log error types.

Fixes: 89578504edd9 ("net/mlx5: add ipool resize function")

Signed-off-by: Gregory Etelson <getelson@nvidia.com>
Acked-by: Dariusz Sosnowski <dsosnowski@nvidia.com>
---
 drivers/net/mlx5/mlx5_flow_hw.c |  6 ++---
 drivers/net/mlx5/mlx5_utils.c   | 39 ++++++++++++++-------------------
 drivers/net/mlx5/mlx5_utils.h   |  3 ++-
 3 files changed, 21 insertions(+), 27 deletions(-)

diff --git a/drivers/net/mlx5/mlx5_flow_hw.c b/drivers/net/mlx5/mlx5_flow_hw.c
index ad8d73a089..45dab32f80 100644
--- a/drivers/net/mlx5/mlx5_flow_hw.c
+++ b/drivers/net/mlx5/mlx5_flow_hw.c
@@ -14747,11 +14747,9 @@ flow_hw_table_resize(struct rte_eth_dev *dev,
 		return rte_flow_error_set(error, EINVAL,
 					  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
 					  table, "shrinking table is not supported");
-	ret = mlx5_ipool_resize(table->flow, nb_flows);
+	ret = mlx5_ipool_resize(table->flow, nb_flows, error);
 	if (ret)
-		return rte_flow_error_set(error, EINVAL,
-					  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
-					  table, "cannot resize flows pool");
+		return ret;
 	/*
 	 * A resizable matcher doesn't support rule update. In this case, the ipool
 	 * for the resource is not created and there is no need to resize it.
diff --git a/drivers/net/mlx5/mlx5_utils.c b/drivers/net/mlx5/mlx5_utils.c
index d52119f0be..d882af6047 100644
--- a/drivers/net/mlx5/mlx5_utils.c
+++ b/drivers/net/mlx5/mlx5_utils.c
@@ -811,30 +811,25 @@ mlx5_ipool_get_next(struct mlx5_indexed_pool *pool, uint32_t *pos)
 }
 
 int
-mlx5_ipool_resize(struct mlx5_indexed_pool *pool, uint32_t num_entries)
+mlx5_ipool_resize(struct mlx5_indexed_pool *pool, uint32_t num_entries,
+	struct rte_flow_error *error)
 {
-	uint32_t cur_max_idx;
-	uint32_t max_index = mlx5_trunk_idx_offset_get(pool, TRUNK_MAX_IDX + 1);
-
-	if (num_entries % pool->cfg.trunk_size) {
-		DRV_LOG(ERR, "num_entries param should be trunk_size(=%u) multiplication\n",
-			pool->cfg.trunk_size);
-		return -EINVAL;
-	}
-
+	if (num_entries == pool->cfg.max_idx)
+		return 0;
+	else if (num_entries < pool->cfg.max_idx)
+		return rte_flow_error_set(error, EINVAL,
+					  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+					  NULL, "cannot decrease pool size");
+	if (num_entries % pool->cfg.trunk_size)
+		return rte_flow_error_set(error, EINVAL,
+					  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+					  NULL, "number of entries in pool must be trunk size multiplication");
+	if (num_entries >= mlx5_trunk_idx_offset_get(pool, TRUNK_MAX_IDX + 1))
+		return rte_flow_error_set(error, EINVAL,
+					  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+					  NULL, "requested number of entries exceeds pool limit");
 	mlx5_ipool_lock(pool);
-	cur_max_idx = pool->cfg.max_idx + num_entries;
-	/* If the ipool max idx is above maximum or uint overflow occurred. */
-	if (cur_max_idx > max_index || cur_max_idx < num_entries) {
-		DRV_LOG(ERR, "Ipool resize failed\n");
-		DRV_LOG(ERR, "Adding %u entries to existing %u entries, will cross max limit(=%u)\n",
-		num_entries, cur_max_idx, max_index);
-		mlx5_ipool_unlock(pool);
-		return -EINVAL;
-	}
-
-	/* Update maximum entries number. */
-	pool->cfg.max_idx = cur_max_idx;
+	pool->cfg.max_idx = num_entries;
 	mlx5_ipool_unlock(pool);
 	return 0;
 }
diff --git a/drivers/net/mlx5/mlx5_utils.h b/drivers/net/mlx5/mlx5_utils.h
index c44a9d88be..f933daf03c 100644
--- a/drivers/net/mlx5/mlx5_utils.h
+++ b/drivers/net/mlx5/mlx5_utils.h
@@ -438,7 +438,8 @@ void *mlx5_ipool_get_next(struct mlx5_indexed_pool *pool, uint32_t *pos);
  *   - 0 on success.
  *
  */
-int mlx5_ipool_resize(struct mlx5_indexed_pool *pool, uint32_t num_entries);
+int mlx5_ipool_resize(struct mlx5_indexed_pool *pool, uint32_t num_entries,
+		      struct rte_flow_error *error);
 
 /**
  * This function allocates new empty Three-level table.
-- 
2.43.0


             reply	other threads:[~2024-07-07  9:49 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-07  9:48 Gregory Etelson [this message]
2024-07-18  7:23 ` Raslan Darawsheh

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=20240707094829.44604-1-getelson@nvidia.com \
    --to=getelson@nvidia.com \
    --cc=bingz@nvidia.com \
    --cc=dev@dpdk.org \
    --cc=dsosnowski@nvidia.com \
    --cc=matan@nvidia.com \
    --cc=mkashani@nvidia.com \
    --cc=orika@nvidia.com \
    --cc=rasland@nvidia.com \
    --cc=suanmingm@nvidia.com \
    --cc=viacheslavo@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).