patches for DPDK stable branches
 help / color / mirror / Atom feed
From: Gavin Li <gavinl@nvidia.com>
To: <matan@nvidia.com>, <viacheslavo@nvidia.com>, <orika@nvidia.com>,
	<thomas@monjalon.net>, Dariusz Sosnowski <dsosnowski@nvidia.com>,
	Bing Zhao <bingz@nvidia.com>, Suanming Mou <suanmingm@nvidia.com>,
	Alexander Kozyrev <akozyrev@nvidia.com>
Cc: <dev@dpdk.org>, <rasland@nvidia.com>,
	"Minggang Li (Gavin)" <gavinl@nvidia.com>, <stable@dpdk.org>
Subject: [PATCH V1 1/3] net/mlx5: set rte errno if malloc failed
Date: Tue, 10 Sep 2024 10:58:51 +0300	[thread overview]
Message-ID: <20240910075853.292823-2-gavinl@nvidia.com> (raw)
In-Reply-To: <20240910075853.292823-1-gavinl@nvidia.com>

From: "Minggang Li (Gavin)" <gavinl@nvidia.com>

rte_errno should be set if anything wrong happened in under layer so that
user can figure out what's going on.

There were some cases that did not set it when ipool allocation failed. To
fix the issue, set rte_errno to ENOMEM if mlx5_ipool_malloc failed to
allocate ID.

Fixes: c40c061a02 ("net/mlx5: add basic flow queue operation")
Fixes: 48fbb0e93d ("net/mlx5: support flow meter mark indirect action with HWS")
cc: stable@dpdk.org
Signed-off-by: Gavin Li <gavinl@nvidia.com>
Acked-by: Bing Zhao <bingz@nvidia.com>
---
 drivers/net/mlx5/mlx5_flow_hw.c | 31 ++++++++++++++++++++++++-------
 1 file changed, 24 insertions(+), 7 deletions(-)

diff --git a/drivers/net/mlx5/mlx5_flow_hw.c b/drivers/net/mlx5/mlx5_flow_hw.c
index 50888944a5..509de2a6a4 100644
--- a/drivers/net/mlx5/mlx5_flow_hw.c
+++ b/drivers/net/mlx5/mlx5_flow_hw.c
@@ -1897,7 +1897,7 @@ flow_hw_meter_mark_alloc(struct rte_eth_dev *dev, uint32_t queue,
 	const struct rte_flow_action_meter_mark *meter_mark = action->conf;
 	struct mlx5_aso_mtr *aso_mtr;
 	struct mlx5_flow_meter_info *fm;
-	uint32_t mtr_id;
+	uint32_t mtr_id = 0;
 	uintptr_t handle = (uintptr_t)MLX5_INDIRECT_ACTION_TYPE_METER_MARK <<
 					MLX5_INDIRECT_ACTION_TYPE_OFFSET;
 
@@ -1909,8 +1909,15 @@ flow_hw_meter_mark_alloc(struct rte_eth_dev *dev, uint32_t queue,
 	if (meter_mark->profile == NULL)
 		return NULL;
 	aso_mtr = mlx5_ipool_malloc(pool->idx_pool, &mtr_id);
-	if (!aso_mtr)
+	if (!aso_mtr) {
+		rte_flow_error_set(error, ENOMEM,
+				   RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+				   NULL,
+				   "failed to allocate aso meter entry");
+		if (mtr_id)
+			mlx5_ipool_free(pool->idx_pool, mtr_id);
 		return NULL;
+	}
 	/* Fill the flow meter parameters. */
 	aso_mtr->type = ASO_METER_INDIRECT;
 	fm = &aso_mtr->fm;
@@ -3918,8 +3925,10 @@ flow_hw_async_flow_create(struct rte_eth_dev *dev,
 			return NULL;
 	}
 	flow = mlx5_ipool_malloc(table->flow, &flow_idx);
-	if (!flow)
+	if (!flow) {
+		rte_errno = ENOMEM;
 		goto error;
+	}
 	rule_acts = flow_hw_get_dr_action_buffer(priv, table, action_template_index, queue);
 	/*
 	 * Set the table here in order to know the destination table
@@ -3930,8 +3939,10 @@ flow_hw_async_flow_create(struct rte_eth_dev *dev,
 	flow->idx = flow_idx;
 	if (table->resource) {
 		mlx5_ipool_malloc(table->resource, &res_idx);
-		if (!res_idx)
+		if (!res_idx) {
+			rte_errno = ENOMEM;
 			goto error;
+		}
 		flow->res_idx = res_idx;
 	} else {
 		flow->res_idx = flow_idx;
@@ -4062,8 +4073,10 @@ flow_hw_async_flow_create_by_index(struct rte_eth_dev *dev,
 			return NULL;
 	}
 	flow = mlx5_ipool_malloc(table->flow, &flow_idx);
-	if (!flow)
+	if (!flow) {
+		rte_errno = ENOMEM;
 		goto error;
+	}
 	rule_acts = flow_hw_get_dr_action_buffer(priv, table, action_template_index, queue);
 	/*
 	 * Set the table here in order to know the destination table
@@ -4074,8 +4087,10 @@ flow_hw_async_flow_create_by_index(struct rte_eth_dev *dev,
 	flow->idx = flow_idx;
 	if (table->resource) {
 		mlx5_ipool_malloc(table->resource, &res_idx);
-		if (!res_idx)
+		if (!res_idx) {
+			rte_errno = ENOMEM;
 			goto error;
+		}
 		flow->res_idx = res_idx;
 	} else {
 		flow->res_idx = flow_idx;
@@ -4210,8 +4225,10 @@ flow_hw_async_flow_update(struct rte_eth_dev *dev,
 	nf->idx = of->idx;
 	if (table->resource) {
 		mlx5_ipool_malloc(table->resource, &res_idx);
-		if (!res_idx)
+		if (!res_idx) {
+			rte_errno = ENOMEM;
 			goto error;
+		}
 		nf->res_idx = res_idx;
 	} else {
 		nf->res_idx = of->res_idx;
-- 
2.34.1


           reply	other threads:[~2024-09-10  7:59 UTC|newest]

Thread overview: expand[flat|nested]  mbox.gz  Atom feed
 [parent not found: <20240910075853.292823-1-gavinl@nvidia.com>]

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=20240910075853.292823-2-gavinl@nvidia.com \
    --to=gavinl@nvidia.com \
    --cc=akozyrev@nvidia.com \
    --cc=bingz@nvidia.com \
    --cc=dev@dpdk.org \
    --cc=dsosnowski@nvidia.com \
    --cc=matan@nvidia.com \
    --cc=orika@nvidia.com \
    --cc=rasland@nvidia.com \
    --cc=stable@dpdk.org \
    --cc=suanmingm@nvidia.com \
    --cc=thomas@monjalon.net \
    --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).