patches for DPDK stable branches
 help / color / mirror / Atom feed
* [dpdk-stable] [PATCH 1/2] hash: fix bugs in 'free key with position'
       [not found] <20190508165121.20471-1-dharmik.thakkar@arm.com>
@ 2019-05-08 16:51 ` Dharmik Thakkar
       [not found] ` <20190508225924.21200-1-dharmik.thakkar@arm.com>
  1 sibling, 0 replies; 17+ messages in thread
From: Dharmik Thakkar @ 2019-05-08 16:51 UTC (permalink / raw)
  To: Yipeng Wang, Sameh Gobriel, Bruce Richardson, Pablo de Lara
  Cc: dev, honnappa.nagarahalli, zhongdahulinfan, Dharmik Thakkar, stable

This patch fixes 2 bugs-
1] Incorrect position returned to the free slots.
2] Incorrect computation of total_entries

Bugzilla ID: 261
Fixes: 9d033dac7d7c ("hash: support no free on delete")
Cc: honnappa.nagarahalli@arm.com
Cc: stable@dpdk.org

Reported-by: Linfan <zhongdahulinfan@163.com>
Suggested-by: Linfan <zhongdahulinfan@163.com>
Signed-off-by: Dharmik Thakkar <dharmik.thakkar@arm.com>
---
 lib/librte_hash/rte_cuckoo_hash.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/lib/librte_hash/rte_cuckoo_hash.c b/lib/librte_hash/rte_cuckoo_hash.c
index 261267b7fd3d..590895d72062 100644
--- a/lib/librte_hash/rte_cuckoo_hash.c
+++ b/lib/librte_hash/rte_cuckoo_hash.c
@@ -1587,14 +1587,18 @@ int __rte_experimental
 rte_hash_free_key_with_position(const struct rte_hash *h,
 				const int32_t position)
 {
-	RETURN_IF_TRUE(((h == NULL) || (position == EMPTY_SLOT)), -EINVAL);
+	/*  Key index where key is stored, adding the first dummy index*/
+	uint32_t key_idx = position + 1;
+
+	RETURN_IF_TRUE(((h == NULL) || (key_idx == EMPTY_SLOT)), -EINVAL);
 
 	unsigned int lcore_id, n_slots;
 	struct lcore_cache *cached_free_slots;
-	const int32_t total_entries = h->num_buckets * RTE_HASH_BUCKET_ENTRIES;
+	const uint32_t total_entries = h->use_local_cache ?
+		h->entries + (RTE_MAX_LCORE - 1) * (LCORE_CACHE_SIZE - 1) + 1 : h->entries + 1;
 
 	/* Out of bounds */
-	if (position >= total_entries)
+	if (key_idx >= total_entries)
 		return -EINVAL;
 	if (h->ext_table_support && h->readwrite_concur_lf_support) {
 		uint32_t index = h->ext_bkt_to_free[position];
@@ -1619,11 +1623,11 @@ rte_hash_free_key_with_position(const struct rte_hash *h,
 		}
 		/* Put index of new free slot in cache. */
 		cached_free_slots->objs[cached_free_slots->len] =
-					(void *)((uintptr_t)position);
+					(void *)((uintptr_t)key_idx);
 		cached_free_slots->len++;
 	} else {
 		rte_ring_sp_enqueue(h->free_slots,
-				(void *)((uintptr_t)position));
+				(void *)((uintptr_t)key_idx));
 	}
 
 	return 0;
-- 
2.17.1


^ permalink raw reply	[flat|nested] 17+ messages in thread

* [dpdk-stable] [PATCH v2 1/2] hash: fix bugs in 'free key with position'
       [not found] ` <20190508225924.21200-1-dharmik.thakkar@arm.com>
@ 2019-05-08 22:59   ` Dharmik Thakkar
  2019-05-09  8:29     ` Thomas Monjalon
       [not found]   ` <20190509133924.7153-1-dharmik.thakkar@arm.com>
  1 sibling, 1 reply; 17+ messages in thread
From: Dharmik Thakkar @ 2019-05-08 22:59 UTC (permalink / raw)
  To: Yipeng Wang, Sameh Gobriel, Bruce Richardson, Pablo de Lara
  Cc: dev, honnappa.nagarahalli, zhongdahulinfan, Dharmik Thakkar, stable

This patch fixes 2 bugs-
1] Incorrect position returned to the free slots.
2] Incorrect computation of total_entries

Bugzilla ID: 261
Fixes: 9d033dac7d7c ("hash: support no free on delete")
Cc: honnappa.nagarahalli@arm.com
Cc: stable@dpdk.org

Reported-by: Linfan <zhongdahulinfan@163.com>
Suggested-by: Linfan <zhongdahulinfan@163.com>
Signed-off-by: Dharmik Thakkar <dharmik.thakkar@arm.com>
---
 lib/librte_hash/rte_cuckoo_hash.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/lib/librte_hash/rte_cuckoo_hash.c b/lib/librte_hash/rte_cuckoo_hash.c
index 261267b7fd3d..ed2e96b6f178 100644
--- a/lib/librte_hash/rte_cuckoo_hash.c
+++ b/lib/librte_hash/rte_cuckoo_hash.c
@@ -1587,14 +1587,19 @@ int __rte_experimental
 rte_hash_free_key_with_position(const struct rte_hash *h,
 				const int32_t position)
 {
-	RETURN_IF_TRUE(((h == NULL) || (position == EMPTY_SLOT)), -EINVAL);
+	/*  Key index where key is stored, adding the first dummy index*/
+	uint32_t key_idx = position + 1;
+
+	RETURN_IF_TRUE(((h == NULL) || (key_idx == EMPTY_SLOT)), -EINVAL);
 
 	unsigned int lcore_id, n_slots;
 	struct lcore_cache *cached_free_slots;
-	const int32_t total_entries = h->num_buckets * RTE_HASH_BUCKET_ENTRIES;
+	const uint32_t total_entries = h->use_local_cache ?
+		h->entries + (RTE_MAX_LCORE - 1) * (LCORE_CACHE_SIZE - 1) + 1
+							: h->entries + 1;
 
 	/* Out of bounds */
-	if (position >= total_entries)
+	if (key_idx >= total_entries)
 		return -EINVAL;
 	if (h->ext_table_support && h->readwrite_concur_lf_support) {
 		uint32_t index = h->ext_bkt_to_free[position];
@@ -1619,11 +1624,11 @@ rte_hash_free_key_with_position(const struct rte_hash *h,
 		}
 		/* Put index of new free slot in cache. */
 		cached_free_slots->objs[cached_free_slots->len] =
-					(void *)((uintptr_t)position);
+					(void *)((uintptr_t)key_idx);
 		cached_free_slots->len++;
 	} else {
 		rte_ring_sp_enqueue(h->free_slots,
-				(void *)((uintptr_t)position));
+				(void *)((uintptr_t)key_idx));
 	}
 
 	return 0;
-- 
2.17.1


^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [dpdk-stable] [PATCH v2 1/2] hash: fix bugs in 'free key with position'
  2019-05-08 22:59   ` [dpdk-stable] [PATCH v2 " Dharmik Thakkar
@ 2019-05-09  8:29     ` Thomas Monjalon
  2019-05-09 10:40       ` 胡林帆
  0 siblings, 1 reply; 17+ messages in thread
From: Thomas Monjalon @ 2019-05-09  8:29 UTC (permalink / raw)
  To: Dharmik Thakkar
  Cc: stable, Yipeng Wang, Sameh Gobriel, Bruce Richardson,
	Pablo de Lara, dev, honnappa.nagarahalli, zhongdahulinfan

09/05/2019 00:59, Dharmik Thakkar:
> This patch fixes 2 bugs-
> 1] Incorrect position returned to the free slots.
> 2] Incorrect computation of total_entries

Is it possible to split in 2 patches?

How critical is this bug? It looks old.
I'm afraid it will miss 19.05.




^ permalink raw reply	[flat|nested] 17+ messages in thread

* [dpdk-stable] [PATCH v2 1/2] hash: fix bugs in 'free key with position'
  2019-05-09  8:29     ` Thomas Monjalon
@ 2019-05-09 10:40       ` 胡林帆
  2019-05-09 11:25         ` Thomas Monjalon
  0 siblings, 1 reply; 17+ messages in thread
From: 胡林帆 @ 2019-05-09 10:40 UTC (permalink / raw)
  To: Thomas Monjalon
  Cc: Dharmik Thakkar, stable, Yipeng Wang, Sameh Gobriel,
	Bruce Richardson, Pablo de Lara, dev, honnappa.nagarahalli



This bug makes 'lock free reader/writer concurrency hash' unusable.
There are two reasons:
1] memory leak because we cannot free keys which indexes greater than the number of total entries

2] the ring of free_slots may have unexpected key conflict with in use one


The patch fixes these 2 issues, both of which are in the same API:


int __rte_experimental
rte_hash_free_key_with_position(const struct rte_hash *h,
    const int32_t position)


I don't think it is necessarily to split in 2 patches.


Thanks,
Linfan

At 2019-05-09 16:29:56, "Thomas Monjalon" <thomas@monjalon.net> wrote:
>09/05/2019 00:59, Dharmik Thakkar:
>> This patch fixes 2 bugs-
>> 1] Incorrect position returned to the free slots.
>> 2] Incorrect computation of total_entries
>
>Is it possible to split in 2 patches?
>
>How critical is this bug? It looks old.
>I'm afraid it will miss 19.05.
>
>

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [dpdk-stable] [PATCH v2 1/2] hash: fix bugs in 'free key with position'
  2019-05-09 10:40       ` 胡林帆
@ 2019-05-09 11:25         ` Thomas Monjalon
  2019-05-09 12:38           ` Dharmik Thakkar
  0 siblings, 1 reply; 17+ messages in thread
From: Thomas Monjalon @ 2019-05-09 11:25 UTC (permalink / raw)
  To: 胡林帆
  Cc: Dharmik Thakkar, stable, Yipeng Wang, Sameh Gobriel,
	Bruce Richardson, Pablo de Lara, dev, honnappa.nagarahalli

09/05/2019 12:40, 胡林帆:
> This bug makes 'lock free reader/writer concurrency hash' unusable.
> There are two reasons:
> 1] memory leak because we cannot free keys which indexes greater than the number of total entries
> 
> 2] the ring of free_slots may have unexpected key conflict with in use one
> 
> The patch fixes these 2 issues, both of which are in the same API:
> 
> int __rte_experimental
> rte_hash_free_key_with_position(const struct rte_hash *h,
>     const int32_t position)
> 
> I don't think it is necessarily to split in 2 patches.

Sorry for insisting, I think it is necessary to split in 2 patches
with better explanations in the commit logs.
Then we'll need approval from the maintainers.

PS1: Please provide your full name in english alphabet
PS2: Please do not top-post


> At 2019-05-09 16:29:56, "Thomas Monjalon" <thomas@monjalon.net> wrote:
> >09/05/2019 00:59, Dharmik Thakkar:
> >> This patch fixes 2 bugs-
> >> 1] Incorrect position returned to the free slots.
> >> 2] Incorrect computation of total_entries
> >
> >Is it possible to split in 2 patches?
> >
> >How critical is this bug? It looks old.
> >I'm afraid it will miss 19.05.




^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [dpdk-stable] [PATCH v2 1/2] hash: fix bugs in 'free key with position'
  2019-05-09 11:25         ` Thomas Monjalon
@ 2019-05-09 12:38           ` Dharmik Thakkar
  0 siblings, 0 replies; 17+ messages in thread
From: Dharmik Thakkar @ 2019-05-09 12:38 UTC (permalink / raw)
  To: thomas
  Cc: 胡林帆,
	stable, Yipeng Wang, Sameh Gobriel, Bruce Richardson,
	Pablo de Lara, dev, Honnappa Nagarahalli



> On May 9, 2019, at 6:25 AM, Thomas Monjalon <thomas@monjalon.net> wrote:
>
> 09/05/2019 12:40, 胡林帆:
>> This bug makes 'lock free reader/writer concurrency hash' unusable.
>> There are two reasons:
>> 1] memory leak because we cannot free keys which indexes greater than the number of total entries
>>
>> 2] the ring of free_slots may have unexpected key conflict with in use one
>>
>> The patch fixes these 2 issues, both of which are in the same API:
>>
>> int __rte_experimental
>> rte_hash_free_key_with_position(const struct rte_hash *h,
>>    const int32_t position)
>>
>> I don't think it is necessarily to split in 2 patches.
>
> Sorry for insisting, I think it is necessary to split in 2 patches
> with better explanations in the commit logs.
I will update the patch. Thanks!
> Then we'll need approval from the maintainers.
>
> PS1: Please provide your full name in english alphabet
> PS2: Please do not top-post
>
>
>> At 2019-05-09 16:29:56, "Thomas Monjalon" <thomas@monjalon.net> wrote:
>>> 09/05/2019 00:59, Dharmik Thakkar:
>>>> This patch fixes 2 bugs-
>>>> 1] Incorrect position returned to the free slots.
>>>> 2] Incorrect computation of total_entries
>>>
>>> Is it possible to split in 2 patches?
>>>
>>> How critical is this bug? It looks old.
>>> I'm afraid it will miss 19.05.
>
>
>

IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [dpdk-stable] [PATCH v3 1/3] hash: fix position bug in 'free key with position'
       [not found]   ` <20190509133924.7153-1-dharmik.thakkar@arm.com>
@ 2019-05-09 13:39     ` Dharmik Thakkar
  2019-05-09 15:48       ` Wang, Yipeng1
  2019-05-09 13:39     ` [dpdk-stable] [PATCH v3 2/3] hash: fix total entries in free key with position Dharmik Thakkar
       [not found]     ` <20190509171907.14693-1-dharmik.thakkar@arm.com>
  2 siblings, 1 reply; 17+ messages in thread
From: Dharmik Thakkar @ 2019-05-09 13:39 UTC (permalink / raw)
  To: Yipeng Wang, Sameh Gobriel, Bruce Richardson, Pablo de Lara
  Cc: dev, honnappa.nagarahalli, zhongdahulinfan, Dharmik Thakkar, stable

Currently, in rte_hash_free_key_with_position(), the position returned
to the ring of free_slots leads to an unexpected conflict with a key
already in use.

This patch fixes incorrect position returned to the ring of free_slots.

Bugzilla ID: 261
Fixes: 9d033dac7d7c ("hash: support no free on delete")
Cc: honnappa.nagarahalli@arm.com
Cc: stable@dpdk.org

Reported-by: Linfan <zhongdahulinfan@163.com>
Suggested-by: Linfan <zhongdahulinfan@163.com>
Signed-off-by: Dharmik Thakkar <dharmik.thakkar@arm.com>
---
 lib/librte_hash/rte_cuckoo_hash.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/lib/librte_hash/rte_cuckoo_hash.c b/lib/librte_hash/rte_cuckoo_hash.c
index 261267b7fd3d..8646ca52e60b 100644
--- a/lib/librte_hash/rte_cuckoo_hash.c
+++ b/lib/librte_hash/rte_cuckoo_hash.c
@@ -1587,14 +1587,17 @@ int __rte_experimental
 rte_hash_free_key_with_position(const struct rte_hash *h,
 				const int32_t position)
 {
-	RETURN_IF_TRUE(((h == NULL) || (position == EMPTY_SLOT)), -EINVAL);
+	/*  Key index where key is stored, adding the first dummy index*/
+	uint32_t key_idx = position + 1;
+
+	RETURN_IF_TRUE(((h == NULL) || (key_idx == EMPTY_SLOT)), -EINVAL);
 
 	unsigned int lcore_id, n_slots;
 	struct lcore_cache *cached_free_slots;
 	const int32_t total_entries = h->num_buckets * RTE_HASH_BUCKET_ENTRIES;
 
 	/* Out of bounds */
-	if (position >= total_entries)
+	if (key_idx >= total_entries)
 		return -EINVAL;
 	if (h->ext_table_support && h->readwrite_concur_lf_support) {
 		uint32_t index = h->ext_bkt_to_free[position];
@@ -1619,11 +1622,11 @@ rte_hash_free_key_with_position(const struct rte_hash *h,
 		}
 		/* Put index of new free slot in cache. */
 		cached_free_slots->objs[cached_free_slots->len] =
-					(void *)((uintptr_t)position);
+					(void *)((uintptr_t)key_idx);
 		cached_free_slots->len++;
 	} else {
 		rte_ring_sp_enqueue(h->free_slots,
-				(void *)((uintptr_t)position));
+				(void *)((uintptr_t)key_idx));
 	}
 
 	return 0;
-- 
2.17.1


^ permalink raw reply	[flat|nested] 17+ messages in thread

* [dpdk-stable] [PATCH v3 2/3] hash: fix total entries in free key with position
       [not found]   ` <20190509133924.7153-1-dharmik.thakkar@arm.com>
  2019-05-09 13:39     ` [dpdk-stable] [PATCH v3 1/3] hash: fix position bug " Dharmik Thakkar
@ 2019-05-09 13:39     ` Dharmik Thakkar
       [not found]     ` <20190509171907.14693-1-dharmik.thakkar@arm.com>
  2 siblings, 0 replies; 17+ messages in thread
From: Dharmik Thakkar @ 2019-05-09 13:39 UTC (permalink / raw)
  To: Yipeng Wang, Sameh Gobriel, Bruce Richardson, Pablo de Lara
  Cc: dev, honnappa.nagarahalli, zhongdahulinfan, Dharmik Thakkar, stable

In rte_hash, with current implementation, it is possible that keys
are stored at indexes greater than the number of total entries.

Currently, in rte_hash_free_key_with_position(), due to incorrect
computation of total_entries, application cannot free keys with
indexes greater than the number of total entries.

This patch fixes this incorrect computation of total_entries.

Bugzilla ID: 261
Fixes: 9d033dac7d7c ("hash: support no free on delete")
Cc: honnappa.nagarahalli@arm.com
Cc: stable@dpdk.org

Reported-by: Linfan <zhongdahulinfan@163.com>
Suggested-by: Linfan <zhongdahulinfan@163.com>
Signed-off-by: Dharmik Thakkar <dharmik.thakkar@arm.com>
---
 lib/librte_hash/rte_cuckoo_hash.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/lib/librte_hash/rte_cuckoo_hash.c b/lib/librte_hash/rte_cuckoo_hash.c
index 8646ca52e60b..ed2e96b6f178 100644
--- a/lib/librte_hash/rte_cuckoo_hash.c
+++ b/lib/librte_hash/rte_cuckoo_hash.c
@@ -1594,7 +1594,9 @@ rte_hash_free_key_with_position(const struct rte_hash *h,
 
 	unsigned int lcore_id, n_slots;
 	struct lcore_cache *cached_free_slots;
-	const int32_t total_entries = h->num_buckets * RTE_HASH_BUCKET_ENTRIES;
+	const uint32_t total_entries = h->use_local_cache ?
+		h->entries + (RTE_MAX_LCORE - 1) * (LCORE_CACHE_SIZE - 1) + 1
+							: h->entries + 1;
 
 	/* Out of bounds */
 	if (key_idx >= total_entries)
-- 
2.17.1


^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [dpdk-stable] [PATCH v3 1/3] hash: fix position bug in 'free key with position'
  2019-05-09 13:39     ` [dpdk-stable] [PATCH v3 1/3] hash: fix position bug " Dharmik Thakkar
@ 2019-05-09 15:48       ` Wang, Yipeng1
  2019-05-09 17:25         ` Dharmik Thakkar
  0 siblings, 1 reply; 17+ messages in thread
From: Wang, Yipeng1 @ 2019-05-09 15:48 UTC (permalink / raw)
  To: Dharmik Thakkar, Gobriel, Sameh, Richardson, Bruce,
	De Lara Guarch, Pablo
  Cc: dev, honnappa.nagarahalli, zhongdahulinfan, stable

> -----Original Message-----
> From: Dharmik Thakkar [mailto:dharmik.thakkar@arm.com]
> Sent: Thursday, May 9, 2019 6:39 AM
> To: Wang, Yipeng1 <yipeng1.wang@intel.com>; Gobriel, Sameh
> <sameh.gobriel@intel.com>; Richardson, Bruce <bruce.richardson@intel.com>;
> De Lara Guarch, Pablo <pablo.de.lara.guarch@intel.com>
> Cc: dev@dpdk.org; honnappa.nagarahalli@arm.com;
> zhongdahulinfan@163.com; Dharmik Thakkar <dharmik.thakkar@arm.com>;
> stable@dpdk.org
> Subject: [PATCH v3 1/3] hash: fix position bug in 'free key with position'
> 
> Currently, in rte_hash_free_key_with_position(), the position returned to the
> ring of free_slots leads to an unexpected conflict with a key already in use.
> 
> This patch fixes incorrect position returned to the ring of free_slots.
> 
> Bugzilla ID: 261
> Fixes: 9d033dac7d7c ("hash: support no free on delete")
> Cc: honnappa.nagarahalli@arm.com
> Cc: stable@dpdk.org
> 
> Reported-by: Linfan <zhongdahulinfan@163.com>
> Suggested-by: Linfan <zhongdahulinfan@163.com>
> Signed-off-by: Dharmik Thakkar <dharmik.thakkar@arm.com>
> ---
>  lib/librte_hash/rte_cuckoo_hash.c | 11 +++++++----
>  1 file changed, 7 insertions(+), 4 deletions(-)
> 
> diff --git a/lib/librte_hash/rte_cuckoo_hash.c
> b/lib/librte_hash/rte_cuckoo_hash.c
> index 261267b7fd3d..8646ca52e60b 100644
> --- a/lib/librte_hash/rte_cuckoo_hash.c
> +++ b/lib/librte_hash/rte_cuckoo_hash.c
> @@ -1587,14 +1587,17 @@ int __rte_experimental
> rte_hash_free_key_with_position(const struct rte_hash *h,
>  				const int32_t position)
>  {
> -	RETURN_IF_TRUE(((h == NULL) || (position == EMPTY_SLOT)), -EINVAL);
> +	/*  Key index where key is stored, adding the first dummy index*/
> +	uint32_t key_idx = position + 1;
> +
> +	RETURN_IF_TRUE(((h == NULL) || (key_idx == EMPTY_SLOT)), -EINVAL);
> 
>  	unsigned int lcore_id, n_slots;
>  	struct lcore_cache *cached_free_slots;
>  	const int32_t total_entries = h->num_buckets *
> RTE_HASH_BUCKET_ENTRIES;
> 
>  	/* Out of bounds */
> -	if (position >= total_entries)
> +	if (key_idx >= total_entries)
[Wang, Yipeng] 
Compiling fail after this commit.
/rte_cuckoo_hash.c:1600:14: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare]
  if (key_idx >= total_entries)
please fix.

Please run the test-build and test-meson-build scripts. I currently have some issue with my meson setup on my new system so I will
rely on other reviewers or you guys to pass the meson test.

Logically these two bug fixes are valid and should be upstreamed otherwise this API breaks. But this is the experimental tag for :)

Thanks
Yipeng




^ permalink raw reply	[flat|nested] 17+ messages in thread

* [dpdk-stable] [PATCH v4 1/3] hash: fix position bug in 'free key with position'
       [not found]     ` <20190509171907.14693-1-dharmik.thakkar@arm.com>
@ 2019-05-09 17:19       ` Dharmik Thakkar
  2019-05-09 19:27         ` Wang, Yipeng1
  2019-05-09 17:19       ` [dpdk-stable] [PATCH v4 2/3] hash: fix total entries in free key with position Dharmik Thakkar
  1 sibling, 1 reply; 17+ messages in thread
From: Dharmik Thakkar @ 2019-05-09 17:19 UTC (permalink / raw)
  To: Yipeng Wang, Sameh Gobriel, Bruce Richardson, Pablo de Lara
  Cc: dev, honnappa.nagarahalli, zhongdahulinfan, Dharmik Thakkar, stable

Currently, in rte_hash_free_key_with_position(), the position returned
to the ring of free_slots leads to an unexpected conflict with a key
already in use.

This patch fixes incorrect position returned to the ring of free_slots.

Bugzilla ID: 261
Fixes: 9d033dac7d7c ("hash: support no free on delete")
Cc: honnappa.nagarahalli@arm.com
Cc: stable@dpdk.org

Reported-by: Linfan <zhongdahulinfan@163.com>
Suggested-by: Linfan <zhongdahulinfan@163.com>
Signed-off-by: Dharmik Thakkar <dharmik.thakkar@arm.com>
---
 lib/librte_hash/rte_cuckoo_hash.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/lib/librte_hash/rte_cuckoo_hash.c b/lib/librte_hash/rte_cuckoo_hash.c
index 261267b7fd3d..5029f9f61fae 100644
--- a/lib/librte_hash/rte_cuckoo_hash.c
+++ b/lib/librte_hash/rte_cuckoo_hash.c
@@ -1587,14 +1587,17 @@ int __rte_experimental
 rte_hash_free_key_with_position(const struct rte_hash *h,
 				const int32_t position)
 {
-	RETURN_IF_TRUE(((h == NULL) || (position == EMPTY_SLOT)), -EINVAL);
+	/*  Key index where key is stored, adding the first dummy index*/
+	uint32_t key_idx = position + 1;
+
+	RETURN_IF_TRUE(((h == NULL) || (key_idx == EMPTY_SLOT)), -EINVAL);
 
 	unsigned int lcore_id, n_slots;
 	struct lcore_cache *cached_free_slots;
-	const int32_t total_entries = h->num_buckets * RTE_HASH_BUCKET_ENTRIES;
+	const uint32_t total_entries = h->num_buckets * RTE_HASH_BUCKET_ENTRIES;
 
 	/* Out of bounds */
-	if (position >= total_entries)
+	if (key_idx >= total_entries)
 		return -EINVAL;
 	if (h->ext_table_support && h->readwrite_concur_lf_support) {
 		uint32_t index = h->ext_bkt_to_free[position];
@@ -1619,11 +1622,11 @@ rte_hash_free_key_with_position(const struct rte_hash *h,
 		}
 		/* Put index of new free slot in cache. */
 		cached_free_slots->objs[cached_free_slots->len] =
-					(void *)((uintptr_t)position);
+					(void *)((uintptr_t)key_idx);
 		cached_free_slots->len++;
 	} else {
 		rte_ring_sp_enqueue(h->free_slots,
-				(void *)((uintptr_t)position));
+				(void *)((uintptr_t)key_idx));
 	}
 
 	return 0;
-- 
2.17.1


^ permalink raw reply	[flat|nested] 17+ messages in thread

* [dpdk-stable] [PATCH v4 2/3] hash: fix total entries in free key with position
       [not found]     ` <20190509171907.14693-1-dharmik.thakkar@arm.com>
  2019-05-09 17:19       ` [dpdk-stable] [PATCH v4 1/3] hash: fix position bug in 'free key with position' Dharmik Thakkar
@ 2019-05-09 17:19       ` Dharmik Thakkar
  2019-05-09 19:32         ` Wang, Yipeng1
  1 sibling, 1 reply; 17+ messages in thread
From: Dharmik Thakkar @ 2019-05-09 17:19 UTC (permalink / raw)
  To: Yipeng Wang, Sameh Gobriel, Bruce Richardson, Pablo de Lara
  Cc: dev, honnappa.nagarahalli, zhongdahulinfan, Dharmik Thakkar, stable

In rte_hash, with current implementation, it is possible that keys
are stored at indexes greater than the number of total entries.

Currently, in rte_hash_free_key_with_position(), due to incorrect
computation of total_entries, application cannot free keys with
indexes greater than the number of total entries.

This patch fixes this incorrect computation of total_entries.

Bugzilla ID: 261
Fixes: 9d033dac7d7c ("hash: support no free on delete")
Cc: honnappa.nagarahalli@arm.com
Cc: stable@dpdk.org

Reported-by: Linfan <zhongdahulinfan@163.com>
Suggested-by: Linfan <zhongdahulinfan@163.com>
Signed-off-by: Dharmik Thakkar <dharmik.thakkar@arm.com>
---
 lib/librte_hash/rte_cuckoo_hash.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/lib/librte_hash/rte_cuckoo_hash.c b/lib/librte_hash/rte_cuckoo_hash.c
index 5029f9f61fae..ed2e96b6f178 100644
--- a/lib/librte_hash/rte_cuckoo_hash.c
+++ b/lib/librte_hash/rte_cuckoo_hash.c
@@ -1594,7 +1594,9 @@ rte_hash_free_key_with_position(const struct rte_hash *h,
 
 	unsigned int lcore_id, n_slots;
 	struct lcore_cache *cached_free_slots;
-	const uint32_t total_entries = h->num_buckets * RTE_HASH_BUCKET_ENTRIES;
+	const uint32_t total_entries = h->use_local_cache ?
+		h->entries + (RTE_MAX_LCORE - 1) * (LCORE_CACHE_SIZE - 1) + 1
+							: h->entries + 1;
 
 	/* Out of bounds */
 	if (key_idx >= total_entries)
-- 
2.17.1


^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [dpdk-stable] [PATCH v3 1/3] hash: fix position bug in 'free key with position'
  2019-05-09 15:48       ` Wang, Yipeng1
@ 2019-05-09 17:25         ` Dharmik Thakkar
  0 siblings, 0 replies; 17+ messages in thread
From: Dharmik Thakkar @ 2019-05-09 17:25 UTC (permalink / raw)
  To: Wang, Yipeng1
  Cc: Gobriel, Sameh, Richardson, Bruce, De Lara Guarch, Pablo, dev,
	Honnappa Nagarahalli, zhongdahulinfan, stable, nd



> On May 9, 2019, at 10:48 AM, Wang, Yipeng1 <yipeng1.wang@intel.com> wrote:
> 
>> -----Original Message-----
>> From: Dharmik Thakkar [mailto:dharmik.thakkar@arm.com]
>> Sent: Thursday, May 9, 2019 6:39 AM
>> To: Wang, Yipeng1 <yipeng1.wang@intel.com>; Gobriel, Sameh
>> <sameh.gobriel@intel.com>; Richardson, Bruce <bruce.richardson@intel.com>;
>> De Lara Guarch, Pablo <pablo.de.lara.guarch@intel.com>
>> Cc: dev@dpdk.org; honnappa.nagarahalli@arm.com;
>> zhongdahulinfan@163.com; Dharmik Thakkar <dharmik.thakkar@arm.com>;
>> stable@dpdk.org
>> Subject: [PATCH v3 1/3] hash: fix position bug in 'free key with position'
>> 
>> Currently, in rte_hash_free_key_with_position(), the position returned to the
>> ring of free_slots leads to an unexpected conflict with a key already in use.
>> 
>> This patch fixes incorrect position returned to the ring of free_slots.
>> 
>> Bugzilla ID: 261
>> Fixes: 9d033dac7d7c ("hash: support no free on delete")
>> Cc: honnappa.nagarahalli@arm.com
>> Cc: stable@dpdk.org
>> 
>> Reported-by: Linfan <zhongdahulinfan@163.com>
>> Suggested-by: Linfan <zhongdahulinfan@163.com>
>> Signed-off-by: Dharmik Thakkar <dharmik.thakkar@arm.com>
>> ---
>> lib/librte_hash/rte_cuckoo_hash.c | 11 +++++++----
>> 1 file changed, 7 insertions(+), 4 deletions(-)
>> 
>> diff --git a/lib/librte_hash/rte_cuckoo_hash.c
>> b/lib/librte_hash/rte_cuckoo_hash.c
>> index 261267b7fd3d..8646ca52e60b 100644
>> --- a/lib/librte_hash/rte_cuckoo_hash.c
>> +++ b/lib/librte_hash/rte_cuckoo_hash.c
>> @@ -1587,14 +1587,17 @@ int __rte_experimental
>> rte_hash_free_key_with_position(const struct rte_hash *h,
>> 				const int32_t position)
>> {
>> -	RETURN_IF_TRUE(((h == NULL) || (position == EMPTY_SLOT)), -EINVAL);
>> +	/*  Key index where key is stored, adding the first dummy index*/
>> +	uint32_t key_idx = position + 1;
>> +
>> +	RETURN_IF_TRUE(((h == NULL) || (key_idx == EMPTY_SLOT)), -EINVAL);
>> 
>> 	unsigned int lcore_id, n_slots;
>> 	struct lcore_cache *cached_free_slots;
>> 	const int32_t total_entries = h->num_buckets *
>> RTE_HASH_BUCKET_ENTRIES;
>> 
>> 	/* Out of bounds */
>> -	if (position >= total_entries)
>> +	if (key_idx >= total_entries)
> [Wang, Yipeng] 
> Compiling fail after this commit.
> /rte_cuckoo_hash.c:1600:14: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare]
>  if (key_idx >= total_entries)
> please fix.
Thank you for reporting! I have fixed the issue and updated the patch.
> 
> Please run the test-build and test-meson-build scripts. I currently have some issue with my meson setup on my new system so I will
> rely on other reviewers or you guys to pass the meson test.
I ran the scripts on my setup. Thanks!
> 
> Logically these two bug fixes are valid and should be upstreamed otherwise this API breaks. But this is the experimental tag for :)
> 
> Thanks
> Yipeng


^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [dpdk-stable] [PATCH v4 1/3] hash: fix position bug in 'free key with position'
  2019-05-09 17:19       ` [dpdk-stable] [PATCH v4 1/3] hash: fix position bug in 'free key with position' Dharmik Thakkar
@ 2019-05-09 19:27         ` Wang, Yipeng1
  2019-05-09 20:14           ` Dharmik Thakkar
  0 siblings, 1 reply; 17+ messages in thread
From: Wang, Yipeng1 @ 2019-05-09 19:27 UTC (permalink / raw)
  To: Dharmik Thakkar, Gobriel, Sameh, Richardson, Bruce,
	De Lara Guarch, Pablo
  Cc: dev, honnappa.nagarahalli, zhongdahulinfan, stable



>-----Original Message-----
>From: Dharmik Thakkar [mailto:dharmik.thakkar@arm.com]
>Sent: Thursday, May 9, 2019 10:19 AM
>To: Wang, Yipeng1 <yipeng1.wang@intel.com>; Gobriel, Sameh <sameh.gobriel@intel.com>; Richardson, Bruce
><bruce.richardson@intel.com>; De Lara Guarch, Pablo <pablo.de.lara.guarch@intel.com>
>Cc: dev@dpdk.org; honnappa.nagarahalli@arm.com; zhongdahulinfan@163.com; Dharmik Thakkar <dharmik.thakkar@arm.com>;
>stable@dpdk.org
>Subject: [PATCH v4 1/3] hash: fix position bug in 'free key with position'
>
>Currently, in rte_hash_free_key_with_position(), the position returned
>to the ring of free_slots leads to an unexpected conflict with a key
>already in use.
>
>This patch fixes incorrect position returned to the ring of free_slots.
>
>Bugzilla ID: 261
>Fixes: 9d033dac7d7c ("hash: support no free on delete")
>Cc: honnappa.nagarahalli@arm.com
>Cc: stable@dpdk.org
>
>Reported-by: Linfan <zhongdahulinfan@163.com>
>Suggested-by: Linfan <zhongdahulinfan@163.com>
>Signed-off-by: Dharmik Thakkar <dharmik.thakkar@arm.com>
>---
> lib/librte_hash/rte_cuckoo_hash.c | 13 ++++++++-----
> 1 file changed, 8 insertions(+), 5 deletions(-)
>
>diff --git a/lib/librte_hash/rte_cuckoo_hash.c b/lib/librte_hash/rte_cuckoo_hash.c
>index 261267b7fd3d..5029f9f61fae 100644
>--- a/lib/librte_hash/rte_cuckoo_hash.c
>+++ b/lib/librte_hash/rte_cuckoo_hash.c
>@@ -1587,14 +1587,17 @@ int __rte_experimental
> rte_hash_free_key_with_position(const struct rte_hash *h,
> 				const int32_t position)
> {
>-	RETURN_IF_TRUE(((h == NULL) || (position == EMPTY_SLOT)), -EINVAL);
>+	/*  Key index where key is stored, adding the first dummy index*/
[Wang, Yipeng] Minor issue, missing a space at the end.

Acked-by: Yipeng Wang <yipeng1.wang@intel.com>


^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [dpdk-stable] [PATCH v4 2/3] hash: fix total entries in free key with position
  2019-05-09 17:19       ` [dpdk-stable] [PATCH v4 2/3] hash: fix total entries in free key with position Dharmik Thakkar
@ 2019-05-09 19:32         ` Wang, Yipeng1
  0 siblings, 0 replies; 17+ messages in thread
From: Wang, Yipeng1 @ 2019-05-09 19:32 UTC (permalink / raw)
  To: Dharmik Thakkar, Gobriel, Sameh, Richardson, Bruce,
	De Lara Guarch, Pablo
  Cc: dev, honnappa.nagarahalli, zhongdahulinfan, stable

>-----Original Message-----
>From: Dharmik Thakkar [mailto:dharmik.thakkar@arm.com]
>Sent: Thursday, May 9, 2019 10:19 AM
>To: Wang, Yipeng1 <yipeng1.wang@intel.com>; Gobriel, Sameh <sameh.gobriel@intel.com>; Richardson, Bruce
><bruce.richardson@intel.com>; De Lara Guarch, Pablo <pablo.de.lara.guarch@intel.com>
>Cc: dev@dpdk.org; honnappa.nagarahalli@arm.com; zhongdahulinfan@163.com; Dharmik Thakkar <dharmik.thakkar@arm.com>;
>stable@dpdk.org
>Subject: [PATCH v4 2/3] hash: fix total entries in free key with position
>
>In rte_hash, with current implementation, it is possible that keys
>are stored at indexes greater than the number of total entries.
>
>Currently, in rte_hash_free_key_with_position(), due to incorrect
>computation of total_entries, application cannot free keys with
>indexes greater than the number of total entries.
>
>This patch fixes this incorrect computation of total_entries.
>
>Bugzilla ID: 261
>Fixes: 9d033dac7d7c ("hash: support no free on delete")
>Cc: honnappa.nagarahalli@arm.com
>Cc: stable@dpdk.org
>
>Reported-by: Linfan <zhongdahulinfan@163.com>
>Suggested-by: Linfan <zhongdahulinfan@163.com>
>Signed-off-by: Dharmik Thakkar <dharmik.thakkar@arm.com>
Acked-by: Yipeng Wang <yipeng1.wang@intel.com>

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [dpdk-stable] [PATCH v4 1/3] hash: fix position bug in 'free key with position'
  2019-05-09 19:27         ` Wang, Yipeng1
@ 2019-05-09 20:14           ` Dharmik Thakkar
  2019-05-09 20:23             ` Thomas Monjalon
  0 siblings, 1 reply; 17+ messages in thread
From: Dharmik Thakkar @ 2019-05-09 20:14 UTC (permalink / raw)
  To: Wang, Yipeng1
  Cc: Gobriel, Sameh, Richardson, Bruce, De Lara Guarch, Pablo, dev,
	Honnappa Nagarahalli, zhongdahulinfan, stable, nd



> On May 9, 2019, at 2:27 PM, Wang, Yipeng1 <yipeng1.wang@intel.com> wrote:
> 
> 
> 
>> -----Original Message-----
>> From: Dharmik Thakkar [mailto:dharmik.thakkar@arm.com]
>> Sent: Thursday, May 9, 2019 10:19 AM
>> To: Wang, Yipeng1 <yipeng1.wang@intel.com>; Gobriel, Sameh <sameh.gobriel@intel.com>; Richardson, Bruce
>> <bruce.richardson@intel.com>; De Lara Guarch, Pablo <pablo.de.lara.guarch@intel.com>
>> Cc: dev@dpdk.org; honnappa.nagarahalli@arm.com; zhongdahulinfan@163.com; Dharmik Thakkar <dharmik.thakkar@arm.com>;
>> stable@dpdk.org
>> Subject: [PATCH v4 1/3] hash: fix position bug in 'free key with position'
>> 
>> Currently, in rte_hash_free_key_with_position(), the position returned
>> to the ring of free_slots leads to an unexpected conflict with a key
>> already in use.
>> 
>> This patch fixes incorrect position returned to the ring of free_slots.
>> 
>> Bugzilla ID: 261
>> Fixes: 9d033dac7d7c ("hash: support no free on delete")
>> Cc: honnappa.nagarahalli@arm.com
>> Cc: stable@dpdk.org
>> 
>> Reported-by: Linfan <zhongdahulinfan@163.com>
>> Suggested-by: Linfan <zhongdahulinfan@163.com>
>> Signed-off-by: Dharmik Thakkar <dharmik.thakkar@arm.com>
>> ---
>> lib/librte_hash/rte_cuckoo_hash.c | 13 ++++++++-----
>> 1 file changed, 8 insertions(+), 5 deletions(-)
>> 
>> diff --git a/lib/librte_hash/rte_cuckoo_hash.c b/lib/librte_hash/rte_cuckoo_hash.c
>> index 261267b7fd3d..5029f9f61fae 100644
>> --- a/lib/librte_hash/rte_cuckoo_hash.c
>> +++ b/lib/librte_hash/rte_cuckoo_hash.c
>> @@ -1587,14 +1587,17 @@ int __rte_experimental
>> rte_hash_free_key_with_position(const struct rte_hash *h,
>> 				const int32_t position)
>> {
>> -	RETURN_IF_TRUE(((h == NULL) || (position == EMPTY_SLOT)), -EINVAL);
>> +	/*  Key index where key is stored, adding the first dummy index*/
> [Wang, Yipeng] Minor issue, missing a space at the end.
Is there a need to update the version?
> 
> Acked-by: Yipeng Wang <yipeng1.wang@intel.com>
Thank you!


^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [dpdk-stable] [PATCH v4 1/3] hash: fix position bug in 'free key with position'
  2019-05-09 20:14           ` Dharmik Thakkar
@ 2019-05-09 20:23             ` Thomas Monjalon
  2019-05-09 20:30               ` Dharmik Thakkar
  0 siblings, 1 reply; 17+ messages in thread
From: Thomas Monjalon @ 2019-05-09 20:23 UTC (permalink / raw)
  To: Dharmik Thakkar
  Cc: stable, Wang, Yipeng1, Gobriel, Sameh, Richardson, Bruce,
	De Lara Guarch, Pablo, dev, Honnappa Nagarahalli,
	zhongdahulinfan, nd

09/05/2019 22:14, Dharmik Thakkar:
> > On May 9, 2019, at 2:27 PM, Wang, Yipeng1 <yipeng1.wang@intel.com> wrote:
> >> -	RETURN_IF_TRUE(((h == NULL) || (position == EMPTY_SLOT)), -EINVAL);
> >> +	/*  Key index where key is stored, adding the first dummy index*/
> > [Wang, Yipeng] Minor issue, missing a space at the end.
> Is there a need to update the version?

No, I am applying.




^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [dpdk-stable] [PATCH v4 1/3] hash: fix position bug in 'free key with position'
  2019-05-09 20:23             ` Thomas Monjalon
@ 2019-05-09 20:30               ` Dharmik Thakkar
  0 siblings, 0 replies; 17+ messages in thread
From: Dharmik Thakkar @ 2019-05-09 20:30 UTC (permalink / raw)
  To: thomas
  Cc: stable, Wang, Yipeng1, Gobriel, Sameh, Richardson, Bruce,
	De Lara Guarch, Pablo, dev, Honnappa Nagarahalli,
	zhongdahulinfan, nd



> On May 9, 2019, at 3:23 PM, Thomas Monjalon <thomas@monjalon.net> wrote:
> 
> 09/05/2019 22:14, Dharmik Thakkar:
>>> On May 9, 2019, at 2:27 PM, Wang, Yipeng1 <yipeng1.wang@intel.com> wrote:
>>>> -	RETURN_IF_TRUE(((h == NULL) || (position == EMPTY_SLOT)), -EINVAL);
>>>> +	/*  Key index where key is stored, adding the first dummy index*/
>>> [Wang, Yipeng] Minor issue, missing a space at the end.
>> Is there a need to update the version?
> 
> No, I am applying.
Sounds good. Thank you, Thomas!
> 
> 
> 


^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2019-05-13  9:25 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20190508165121.20471-1-dharmik.thakkar@arm.com>
2019-05-08 16:51 ` [dpdk-stable] [PATCH 1/2] hash: fix bugs in 'free key with position' Dharmik Thakkar
     [not found] ` <20190508225924.21200-1-dharmik.thakkar@arm.com>
2019-05-08 22:59   ` [dpdk-stable] [PATCH v2 " Dharmik Thakkar
2019-05-09  8:29     ` Thomas Monjalon
2019-05-09 10:40       ` 胡林帆
2019-05-09 11:25         ` Thomas Monjalon
2019-05-09 12:38           ` Dharmik Thakkar
     [not found]   ` <20190509133924.7153-1-dharmik.thakkar@arm.com>
2019-05-09 13:39     ` [dpdk-stable] [PATCH v3 1/3] hash: fix position bug " Dharmik Thakkar
2019-05-09 15:48       ` Wang, Yipeng1
2019-05-09 17:25         ` Dharmik Thakkar
2019-05-09 13:39     ` [dpdk-stable] [PATCH v3 2/3] hash: fix total entries in free key with position Dharmik Thakkar
     [not found]     ` <20190509171907.14693-1-dharmik.thakkar@arm.com>
2019-05-09 17:19       ` [dpdk-stable] [PATCH v4 1/3] hash: fix position bug in 'free key with position' Dharmik Thakkar
2019-05-09 19:27         ` Wang, Yipeng1
2019-05-09 20:14           ` Dharmik Thakkar
2019-05-09 20:23             ` Thomas Monjalon
2019-05-09 20:30               ` Dharmik Thakkar
2019-05-09 17:19       ` [dpdk-stable] [PATCH v4 2/3] hash: fix total entries in free key with position Dharmik Thakkar
2019-05-09 19:32         ` Wang, Yipeng1

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