DPDK patches and discussions
 help / color / mirror / Atom feed
From: Somnath Kotur <somnath.kotur@broadcom.com>
To: dev@dpdk.org
Cc: ferruh.yigit@intel.com
Subject: [dpdk-dev] [PATCH 03/10] net/bnxt: check index range in bulk get
Date: Mon, 13 Jul 2020 11:45:53 +0530	[thread overview]
Message-ID: <20200713061600.19456-4-somnath.kotur@broadcom.com> (raw)
In-Reply-To: <20200713061600.19456-1-somnath.kotur@broadcom.com>

From: Jay Ding <jay.ding@broadcom.com>

In tf_tbl_bulk_get, check if the indexes are in the range
of reserved tbl id instead of checking the allocation of each id.

Signed-off-by: Jay Ding <jay.ding@broadcom.com>
Reviewed-by: Somnath Kotur <somnath.kotur@broadcom.com>
Reviewed-by: Randy Schacher <stuart.schacher@broadcom.com>
Reviewed-by: Ajit Kumar Khaparde <ajit.khaparde@broadcom.com>
Signed-off-by: Somnath Kotur <somnath.kotur@broadcom.com>
---
 drivers/net/bnxt/tf_core/tf_core.h |  8 ++++---
 drivers/net/bnxt/tf_core/tf_msg.c  |  3 ++-
 drivers/net/bnxt/tf_core/tf_rm.c   | 45 ++++++++++++++++++++++++++++++++++++--
 drivers/net/bnxt/tf_core/tf_rm.h   | 37 +++++++++++++++++++++++++++++++
 drivers/net/bnxt/tf_core/tf_tbl.c  | 40 ++++++++++++++-------------------
 5 files changed, 104 insertions(+), 29 deletions(-)

diff --git a/drivers/net/bnxt/tf_core/tf_core.h b/drivers/net/bnxt/tf_core/tf_core.h
index 9a5e816..758685e 100644
--- a/drivers/net/bnxt/tf_core/tf_core.h
+++ b/drivers/net/bnxt/tf_core/tf_core.h
@@ -1426,10 +1426,12 @@ struct tf_bulk_get_tbl_entry_parms {
 /**
  * Bulk get index table entry
  *
- * Used to retrieve a previous set index table entry.
+ * Used to retrieve a set of index table entries.
  *
- * Reads and compares with the shadow table copy (if enabled) (only
- * for internal objects).
+ * Entries within the range may not have been allocated using
+ * tf_alloc_tbl_entry() at the time of access. But the range must
+ * be within the bounds determined from tf_open_session() for the
+ * given table type.  Currently, this is only used for collecting statistics.
  *
  * Returns success or failure code. Failure will be returned if the
  * provided data buffer is too small for the data type requested.
diff --git a/drivers/net/bnxt/tf_core/tf_msg.c b/drivers/net/bnxt/tf_core/tf_msg.c
index 1e14d92..53515ad 100644
--- a/drivers/net/bnxt/tf_core/tf_msg.c
+++ b/drivers/net/bnxt/tf_core/tf_msg.c
@@ -143,7 +143,8 @@ tf_msg_session_open(struct tf *tfp,
 		return rc;
 
 	*fw_session_id = (uint8_t)tfp_le_to_cpu_32(resp.fw_session_id);
-	*fw_session_client_id = (uint8_t)tfp_le_to_cpu_32(resp.fw_session_id);
+	*fw_session_client_id =
+		(uint8_t)tfp_le_to_cpu_32(resp.fw_session_client_id);
 
 	return rc;
 }
diff --git a/drivers/net/bnxt/tf_core/tf_rm.c b/drivers/net/bnxt/tf_core/tf_rm.c
index 78bc231..9aec954 100644
--- a/drivers/net/bnxt/tf_core/tf_rm.c
+++ b/drivers/net/bnxt/tf_core/tf_rm.c
@@ -755,7 +755,8 @@ tf_rm_allocate(struct tf_rm_allocate_parms *parms)
 	}
 
 	*parms->index = index;
-	*parms->base_index = id;
+	if (parms->base_index)
+		*parms->base_index = id;
 
 	return rc;
 }
@@ -842,7 +843,8 @@ tf_rm_is_allocated(struct tf_rm_is_allocated_parms *parms)
 	if (rc)
 		return rc;
 
-	*parms->base_index = adj_index;
+	if (parms->base_index)
+		*parms->base_index = adj_index;
 	*parms->allocated = ba_inuse(rm_db->db[parms->db_index].pool,
 				     adj_index);
 
@@ -922,3 +924,42 @@ tf_rm_get_inuse_count(struct tf_rm_get_inuse_count_parms *parms)
 	return rc;
 
 }
+
+int
+tf_rm_check_indexes_in_range(struct tf_rm_check_indexes_in_range_parms *parms)
+{
+	struct tf_rm_new_db *rm_db;
+	enum tf_rm_elem_cfg_type cfg_type;
+	uint32_t base_index;
+	uint32_t stride;
+	int rc = 0;
+
+	TF_CHECK_PARMS2(parms, parms->rm_db);
+
+	rm_db = (struct tf_rm_new_db *)parms->rm_db;
+	cfg_type = rm_db->db[parms->db_index].cfg_type;
+
+	/* Bail out if not controlled by RM */
+	if (cfg_type != TF_RM_ELEM_CFG_HCAPI_BA)
+		return -ENOTSUP;
+
+	/* Bail out if the pool is not valid, should never happen */
+	if (rm_db->db[parms->db_index].pool == NULL) {
+		rc = -ENOTSUP;
+		TFP_DRV_LOG(ERR,
+			    "%s: Invalid pool for this type:%d, rc:%s\n",
+			    tf_dir_2_str(rm_db->dir),
+			    parms->db_index,
+			    strerror(-rc));
+		return rc;
+	}
+
+	base_index = rm_db->db[parms->db_index].alloc.entry.start;
+	stride = rm_db->db[parms->db_index].alloc.entry.stride;
+
+	if (parms->starting_index < base_index ||
+	    parms->starting_index + parms->num_entries > base_index + stride)
+		return -EINVAL;
+
+	return rc;
+}
diff --git a/drivers/net/bnxt/tf_core/tf_rm.h b/drivers/net/bnxt/tf_core/tf_rm.h
index 971120a..97692db 100644
--- a/drivers/net/bnxt/tf_core/tf_rm.h
+++ b/drivers/net/bnxt/tf_core/tf_rm.h
@@ -315,6 +315,29 @@ struct tf_rm_get_inuse_count_parms {
 };
 
 /**
+ * Check if the indexes are in the range of reserved resource
+ */
+struct tf_rm_check_indexes_in_range_parms {
+	/**
+	 * [in] RM DB Handle
+	 */
+	void *rm_db;
+	/**
+	 * [in] DB Index, indicates which DB entry to perform the
+	 * action on.
+	 */
+	uint16_t db_index;
+	/**
+	 * [in] Starting index
+	 */
+	uint16_t starting_index;
+	/**
+	 * [in] number of entries
+	 */
+	uint16_t num_entries;
+};
+
+/**
  * @page rm Resource Manager
  *
  * @ref tf_rm_create_db
@@ -462,4 +485,18 @@ int tf_rm_get_hcapi_type(struct tf_rm_get_hcapi_parms *parms);
  */
 int tf_rm_get_inuse_count(struct tf_rm_get_inuse_count_parms *parms);
 
+/**
+ * Check if the requested indexes are in the range of reserved resource.
+ *
+ * [in] parms
+ *   Pointer to get inuse parameters
+ *
+ * Returns
+ *   - (0) if successful.
+ *   - (-EINVAL) on failure.
+ */
+int
+tf_rm_check_indexes_in_range(struct tf_rm_check_indexes_in_range_parms *parms);
+
+
 #endif /* TF_RM_NEW_H_ */
diff --git a/drivers/net/bnxt/tf_core/tf_tbl.c b/drivers/net/bnxt/tf_core/tf_tbl.c
index 2b4a7c5..9ebaa34 100644
--- a/drivers/net/bnxt/tf_core/tf_tbl.c
+++ b/drivers/net/bnxt/tf_core/tf_tbl.c
@@ -350,12 +350,9 @@ tf_tbl_bulk_get(struct tf *tfp,
 		struct tf_tbl_get_bulk_parms *parms)
 {
 	int rc;
-	int i;
 	uint16_t hcapi_type;
-	uint32_t idx;
-	int allocated = 0;
-	struct tf_rm_is_allocated_parms aparms = { 0 };
 	struct tf_rm_get_hcapi_parms hparms = { 0 };
+	struct tf_rm_check_indexes_in_range_parms cparms = { 0 };
 
 	TF_CHECK_PARMS2(tfp, parms);
 
@@ -366,26 +363,23 @@ tf_tbl_bulk_get(struct tf *tfp,
 
 		return -EINVAL;
 	}
-	/* Verify that the entries has been previously allocated */
-	aparms.rm_db = tbl_db[parms->dir];
-	aparms.db_index = parms->type;
-	aparms.allocated = &allocated;
-	idx = parms->starting_idx;
-	for (i = 0; i < parms->num_entries; i++) {
-		aparms.index = idx;
-		rc = tf_rm_is_allocated(&aparms);
-		if (rc)
-			return rc;
 
-		if (allocated != TF_RM_ALLOCATED_ENTRY_IN_USE) {
-			TFP_DRV_LOG(ERR,
-				    "%s, Invalid or not allocated index, type:%d, idx:%d\n",
-				    tf_dir_2_str(parms->dir),
-				    parms->type,
-				    idx);
-			return -EINVAL;
-		}
-		idx++;
+	/* Verify that the entries are in the range of reserved resources. */
+	cparms.rm_db = tbl_db[parms->dir];
+	cparms.db_index = parms->type;
+	cparms.starting_index = parms->starting_idx;
+	cparms.num_entries = parms->num_entries;
+
+	rc = tf_rm_check_indexes_in_range(&cparms);
+	if (rc) {
+		TFP_DRV_LOG(ERR,
+			    "%s, Invalid or %d index starting from %d"
+			    " not in range, type:%d",
+			    tf_dir_2_str(parms->dir),
+			    parms->starting_idx,
+			    parms->num_entries,
+			    parms->type);
+		return rc;
 	}
 
 	hparms.rm_db = tbl_db[parms->dir];
-- 
2.7.4


  parent reply	other threads:[~2020-07-13  6:21 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-13  6:15 [dpdk-dev] [PATCH 00/10] bnxt patches Somnath Kotur
2020-07-13  6:15 ` [dpdk-dev] [PATCH 01/10] net/bnxt: add option to delay EEM sysmem mapping Somnath Kotur
2020-07-13  6:15 ` [dpdk-dev] [PATCH 02/10] net/bnxt: implement TF Identifier search Somnath Kotur
2020-07-13  6:15 ` Somnath Kotur [this message]
2020-07-13  6:15 ` [dpdk-dev] [PATCH 04/10] net/bnxt: add changes to support 2 table scopes Somnath Kotur
2020-07-13  6:15 ` [dpdk-dev] [PATCH 05/10] net/bnxt: add support to extract data from the ulp blob Somnath Kotur
2020-07-13  6:15 ` [dpdk-dev] [PATCH 06/10] net/bnxt: ignore ipv4 tos mask Somnath Kotur
2020-07-13  6:15 ` [dpdk-dev] [PATCH 07/10] net/bnxt: add support for identifier search and ref count Somnath Kotur
2020-07-13  6:15 ` [dpdk-dev] [PATCH 08/10] net/bnxt: consider vlan fields for the template match criteria Somnath Kotur
2020-07-13  6:15 ` [dpdk-dev] [PATCH 09/10] net/bnxt: increase the number of egress flow entries Somnath Kotur
2020-07-13  6:16 ` [dpdk-dev] [PATCH 10/10] net/bnxt: add support for decrement ttl action Somnath Kotur
2020-07-13  9:42 ` [dpdk-dev] [PATCH v3 00/10] bnxt patches Somnath Kotur
2020-07-13  9:42   ` [dpdk-dev] [PATCH 01/10] net/bnxt: add option to delay EEM sysmem mapping Somnath Kotur
2020-07-13  9:42   ` [dpdk-dev] [PATCH 02/10] net/bnxt: implement TF Identifier search Somnath Kotur
2020-07-13  9:42   ` [dpdk-dev] [PATCH 03/10] net/bnxt: check index range in bulk get Somnath Kotur
2020-07-13  9:42   ` [dpdk-dev] [PATCH 04/10] net/bnxt: add changes to support 2 table scopes Somnath Kotur
2020-07-13  9:42   ` [dpdk-dev] [PATCH 05/10] net/bnxt: add support to extract data from the ulp blob Somnath Kotur
2020-07-13  9:42   ` [dpdk-dev] [PATCH 06/10] net/bnxt: ignore ipv4 TOS mask Somnath Kotur
2020-07-13  9:42   ` [dpdk-dev] [PATCH 07/10] net/bnxt: add support for identifier search and ref count Somnath Kotur
2020-07-13  9:42   ` [dpdk-dev] [PATCH 08/10] net/bnxt: consider VLAN fields for template match criteria Somnath Kotur
2020-07-13  9:42   ` [dpdk-dev] [PATCH 09/10] net/bnxt: increase the number of egress flow entries Somnath Kotur
2020-07-13  9:42   ` [dpdk-dev] [PATCH 10/10] net/bnxt: add support for decrement TTL action Somnath Kotur
2020-07-14 22:36   ` [dpdk-dev] [PATCH v3 00/10] bnxt patches Ajit Khaparde
2020-07-15 12:50     ` Ferruh Yigit
2020-07-15 13:50 ` [dpdk-dev] [PATCH v4 " Somnath Kotur
2020-07-15 13:50   ` [dpdk-dev] [PATCH 01/10] net/bnxt: add option to delay EEM sysmem mapping Somnath Kotur
2020-07-15 13:50   ` [dpdk-dev] [PATCH 02/10] net/bnxt: implement TF Identifier search Somnath Kotur
2020-07-15 13:50   ` [dpdk-dev] [PATCH 03/10] net/bnxt: check index range in bulk get Somnath Kotur
2020-07-15 13:50   ` [dpdk-dev] [PATCH 04/10] net/bnxt: add changes to support 2 table scopes Somnath Kotur
2020-07-15 13:50   ` [dpdk-dev] [PATCH 05/10] net/bnxt: add support to extract data from the ulp blob Somnath Kotur
2020-07-15 13:50   ` [dpdk-dev] [PATCH 06/10] net/bnxt: ignore ipv4 TOS mask Somnath Kotur
2020-07-15 13:50   ` [dpdk-dev] [PATCH 07/10] net/bnxt: add support for identifier search and ref count Somnath Kotur
2020-07-15 13:50   ` [dpdk-dev] [PATCH 08/10] net/bnxt: consider VLAN fields for template match criteria Somnath Kotur
2020-07-15 13:50   ` [dpdk-dev] [PATCH 09/10] net/bnxt: increase the number of egress flow entries Somnath Kotur
2020-07-15 13:50   ` [dpdk-dev] [PATCH 10/10] net/bnxt: add support for decrement TTL action Somnath Kotur
2020-07-16 23:04   ` [dpdk-dev] [PATCH v4 00/10] bnxt patches Ajit Khaparde
2020-07-13  6:28 [dpdk-dev] [v2 PATCH " Somnath Kotur
2020-07-13  6:28 ` [dpdk-dev] [PATCH 03/10] net/bnxt: check index range in bulk get Somnath Kotur

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=20200713061600.19456-4-somnath.kotur@broadcom.com \
    --to=somnath.kotur@broadcom.com \
    --cc=dev@dpdk.org \
    --cc=ferruh.yigit@intel.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).