[v4,2/3] hash: fix total entries in free key with position

Message ID 20190509171907.14693-3-dharmik.thakkar@arm.com (mailing list archive)
State Accepted, archived
Headers
Series hash: fix bugs in 'free key with position' |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK

Commit Message

Dharmik Thakkar May 9, 2019, 5:19 p.m. UTC
  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(-)
  

Comments

Wang, Yipeng1 May 9, 2019, 7:32 p.m. UTC | #1
>-----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>
  

Patch

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)