net/bnxt: check index range in bulk get

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: Randy Schacher <stuart.schacher@broadcom.com>
Reviewed-by: Somnath Kotur <somnath.kotur@broadcom.com>
Reviewed-by: Ajit Khaparde <ajit.khaparde@broadcom.com>
This commit is contained in:
Jay Ding 2020-07-15 19:20:31 +05:30 committed by Ferruh Yigit
parent 8ee821cfae
commit 1ff85c97f4
5 changed files with 104 additions and 29 deletions

View File

@ -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.

View File

@ -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;
}

View File

@ -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;
}

View File

@ -314,6 +314,29 @@ struct tf_rm_get_inuse_count_parms {
uint16_t *count;
};
/**
* 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
*
@ -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_ */

View File

@ -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];