From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id F12CBA0C4D; Tue, 2 Nov 2021 05:06:28 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 5B3A541137; Tue, 2 Nov 2021 05:06:10 +0100 (CET) Received: from relay.smtp-ext.broadcom.com (lpdvsmtp09.broadcom.com [192.19.166.228]) by mails.dpdk.org (Postfix) with ESMTP id 09C0841122 for ; Tue, 2 Nov 2021 05:06:09 +0100 (CET) Received: from S60.dhcp.broadcom.net (unknown [10.123.66.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by relay.smtp-ext.broadcom.com (Postfix) with ESMTPS id 4E7A07A21; Mon, 1 Nov 2021 21:06:07 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 relay.smtp-ext.broadcom.com 4E7A07A21 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=broadcom.com; s=dkimrelay; t=1635825968; bh=8VWDIanUNAsAyNNQTMo0r7rejJ9Nd9W0CCcfMBpCQM8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OgRcCsWXszcUZhHkI8mG6JeRBw3vfwOMPLLmppABvoANKdEoRp4gqUNRa2VFlO35z ECmde3Is73JqU5Fe2l4RFg0Aa2LXjF1ZGBrOMXEz7z3qcipOIzqaASaCO2FdJRVaLQ X/QTmM/DHZ9QUl/0wvXr2I/5/zerCdydXTnNR0gQ= From: Venkat Duvvuru To: dev@dpdk.org Cc: Kishore Padmanabha , Venkat Duvvuru Date: Tue, 2 Nov 2021 09:35:39 +0530 Message-Id: <20211102040556.7840-4-venkatkumar.duvvuru@broadcom.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20211102040556.7840-1-venkatkumar.duvvuru@broadcom.com> References: <20211001055909.27276-1-venkatkumar.duvvuru@broadcom.com> <20211102040556.7840-1-venkatkumar.duvvuru@broadcom.com> Subject: [dpdk-dev] [PATCH v3 03/20] net/bnxt: fix the out of boundary issue in hash list X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 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: Kishore Padmanabha The number of hash bucket list calculation is fixed and added check to limit the out of boundary condition Fixes: 0001cc58d362 ("net/bnxt: support generic hash table") Signed-off-by: Kishore Padmanabha Signed-off-by: Venkat Duvvuru Reviewed-by: Michael Baucom Reviewed-by: Randy Schacher --- drivers/net/bnxt/tf_ulp/ulp_gen_hash.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/drivers/net/bnxt/tf_ulp/ulp_gen_hash.c b/drivers/net/bnxt/tf_ulp/ulp_gen_hash.c index 3c6e7fe924..84c83de35c 100644 --- a/drivers/net/bnxt/tf_ulp/ulp_gen_hash.c +++ b/drivers/net/bnxt/tf_ulp/ulp_gen_hash.c @@ -16,20 +16,21 @@ int32_t ulp_bit_alloc_list_alloc(struct bit_alloc_list *blist, { uint64_t bentry; uint32_t idx = 0, jdx = 0; + uint32_t bsize_64 = blist->bsize / ULP_64B_IN_BYTES; /* Iterate all numbers that have all 1's */ do { bentry = blist->bdata[idx++]; - } while (bentry == -1UL && idx < blist->bsize); + } while (bentry == -1UL && idx <= bsize_64); - if (idx < blist->bsize) { + if (idx <= bsize_64) { if (bentry) jdx = __builtin_clzl(~bentry); *index = ((idx - 1) * ULP_INDEX_BITMAP_SIZE) + jdx; ULP_INDEX_BITMAP_SET(blist->bdata[(idx - 1)], jdx); return 0; } - jdx = (uint32_t)(blist->bsize * ULP_INDEX_BITMAP_SIZE); + jdx = (uint32_t)(bsize_64 * ULP_INDEX_BITMAP_SIZE); BNXT_TF_DBG(ERR, "bit allocator is full reached max:%x\n", jdx); return -1; } @@ -39,9 +40,10 @@ int32_t ulp_bit_alloc_list_dealloc(struct bit_alloc_list *blist, uint32_t index) { uint32_t idx = 0, jdx; + uint32_t bsize_64 = blist->bsize / ULP_64B_IN_BYTES; idx = index / ULP_INDEX_BITMAP_SIZE; - if (idx >= blist->bsize) { + if (idx >= bsize_64) { BNXT_TF_DBG(ERR, "invalid bit index %x:%x\n", idx, blist->bsize); return -EINVAL; @@ -127,7 +129,8 @@ ulp_gen_hash_tbl_list_init(struct ulp_hash_create_params *cparams, hash_tbl->hash_mask = size - 1; /* allocate the memory for the bit allocator */ - size = (cparams->num_key_entries / sizeof(uint64_t)) + 1; + size = (cparams->num_key_entries / sizeof(uint64_t)); + size = ULP_BYTE_ROUND_OFF_8(size); hash_tbl->bit_list.bsize = size; hash_tbl->bit_list.bdata = rte_zmalloc("Generic hash bit alloc", size, ULP_BUFFER_ALIGN_64_BYTE); @@ -311,7 +314,12 @@ ulp_gen_hash_tbl_list_add(struct ulp_gen_hash_tbl *hash_tbl, BNXT_TF_DBG(ERR, "Error in bit list alloc\n"); return -ENOMEM; } - + if (key_index > hash_tbl->num_key_entries) { + BNXT_TF_DBG(ERR, "reached max size %u:%u\n", key_index, + hash_tbl->num_key_entries); + ulp_bit_alloc_list_dealloc(&hash_tbl->bit_list, key_index); + return -ENOMEM; + } /* Update the hash entry */ ULP_HASH_BUCKET_MARK_INUSE(bucket, (uint16_t)key_index); -- 2.17.1