patches for DPDK stable branches
 help / color / mirror / Atom feed
From: Venkat Duvvuru <venkatkumar.duvvuru@broadcom.com>
To: dev@dpdk.org
Cc: Kishore Padmanabha <kishore.padmanabha@broadcom.com>,
	stable@dpdk.org,
	Venkat Duvvuru <venkatkumar.duvvuru@broadcom.com>
Subject: [dpdk-stable] [PATCH 3/9] net/bnxt: fix the out of boundary issue in hash list
Date: Fri,  1 Oct 2021 11:29:03 +0530	[thread overview]
Message-ID: <20211001055909.27276-4-venkatkumar.duvvuru@broadcom.com> (raw)
In-Reply-To: <20211001055909.27276-1-venkatkumar.duvvuru@broadcom.com>

From: Kishore Padmanabha <kishore.padmanabha@broadcom.com>

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")
Cc: stable@dpdk.org

Signed-off-by: Kishore Padmanabha <kishore.padmanabha@broadcom.com>
Signed-off-by: Venkat Duvvuru <venkatkumar.duvvuru@broadcom.com>
Reviewed-by: Michael Baucom <michael.baucom@broadcom.com>
Reviewed-by: Randy Schacher <stuart.schacher@broadcom.com>
---
 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


           reply	other threads:[~2021-10-01  5:59 UTC|newest]

Thread overview: expand[flat|nested]  mbox.gz  Atom feed
 [parent not found: <20211001055909.27276-1-venkatkumar.duvvuru@broadcom.com>]

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=20211001055909.27276-4-venkatkumar.duvvuru@broadcom.com \
    --to=venkatkumar.duvvuru@broadcom.com \
    --cc=dev@dpdk.org \
    --cc=kishore.padmanabha@broadcom.com \
    --cc=stable@dpdk.org \
    /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).