From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 8C1F2A0540; Mon, 13 Jul 2020 08:21:44 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id A005F1C21E; Mon, 13 Jul 2020 08:21:16 +0200 (CEST) Received: from relay.smtp.broadcom.com (unknown [192.19.211.62]) by dpdk.org (Postfix) with ESMTP id 81ECE1C0B5 for ; Mon, 13 Jul 2020 08:21:10 +0200 (CEST) Received: from dhcp-10-123-153-55.dhcp.broadcom.net (dhcp-10-123-153-55.dhcp.broadcom.net [10.123.153.55]) by relay.smtp.broadcom.com (Postfix) with ESMTP id AEC9429C647; Sun, 12 Jul 2020 23:21:09 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.10.3 relay.smtp.broadcom.com AEC9429C647 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=broadcom.com; s=dkimrelay; t=1594621269; bh=7ehpsW9rPrpGb0pAwGhwROerYlxmN3oCob1gSD/4Tq4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vDODdHI9i+Dc8/B6OUhTihs5hM0dDvYD5KaPDQ4hl0OXeiCJrmEHVKsTkbUYntzTp q6ccwOKqUPNzBQv8c6ZIOIMoTQ0PpHZaniAFsLN2uIJ6vdYxNLBXP2jerxP2tinbWk dEOfQpAsMWk9/Uuc9C/F3ShbVOmdw62MYVpqahx8= From: Somnath Kotur To: dev@dpdk.org Cc: ferruh.yigit@intel.com Date: Mon, 13 Jul 2020 11:45:53 +0530 Message-Id: <20200713061600.19456-4-somnath.kotur@broadcom.com> X-Mailer: git-send-email 2.10.1.613.g2cc2e70 In-Reply-To: <20200713061600.19456-1-somnath.kotur@broadcom.com> References: <20200713061600.19456-1-somnath.kotur@broadcom.com> Subject: [dpdk-dev] [PATCH 03/10] net/bnxt: check index range in bulk get X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" From: Jay Ding 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 Reviewed-by: Somnath Kotur Reviewed-by: Randy Schacher Reviewed-by: Ajit Kumar Khaparde Signed-off-by: Somnath Kotur --- 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