[dpdk-dev] [PATCH 03/10] net/bnxt: check index range in bulk get

Somnath Kotur somnath.kotur at broadcom.com
Wed Jul 15 15:50:31 CEST 2020


From: Jay Ding <jay.ding at 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 at broadcom.com>
Reviewed-by: Somnath Kotur <somnath.kotur at broadcom.com>
Reviewed-by: Randy Schacher <stuart.schacher at broadcom.com>
Reviewed-by: Ajit Kumar Khaparde <ajit.khaparde at broadcom.com>
Signed-off-by: Somnath Kotur <somnath.kotur at 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



More information about the dev mailing list