Skip to contentSkip to conversation

lib/hash: new feature adding existing key

PATCH New Abdullah Ömer Yamaç 5 participants 8 messages Mar 13, 2023 – Oct 3, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 lib/hash: new feature adding existing key

In some use cases inserting data with the same key shouldn't be overwritten. We use a new flag in this patch to disable overwriting data for the same key.

---
Cc: Yipeng Wang <[email protected]>

---
 lib/hash/rte_cuckoo_hash.c | 10 +++++++++-
 lib/hash/rte_cuckoo_hash.h |  2 ++
 lib/hash/rte_hash.h        |  4 ++++
 3 files changed, 15 insertions(+), 1 deletion(-)
lib/hash/rte_cuckoo_hash.c +9 -1
index 829b79c89a..cd87d6e4cd 100644
@@ -32,7 +32,8 @@
 				   RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY | \
 				   RTE_HASH_EXTRA_FLAGS_EXT_TABLE |	\
 				   RTE_HASH_EXTRA_FLAGS_NO_FREE_ON_DEL | \
-				   RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY_LF)
+				   RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY_LF | \
+				   RTE_HASH_EXTRA_FLAGS_DISABLE_UPDATE_EXISTING_KEY)
 
 #define FOR_EACH_BUCKET(CURRENT_BKT, START_BUCKET)                            \
 	for (CURRENT_BKT = START_BUCKET;                                      \
@@ -148,6 +149,7 @@ rte_hash_create(const struct rte_hash_parameters *params)
 	unsigned int readwrite_concur_support = 0;
 	unsigned int writer_takes_lock = 0;
 	unsigned int no_free_on_del = 0;
+	unsigned int no_update_data = 0;
 	uint32_t *ext_bkt_to_free = NULL;
 	uint32_t *tbl_chng_cnt = NULL;
 	struct lcore_cache *local_free_slots = NULL;
@@ -216,6 +218,9 @@ rte_hash_create(const struct rte_hash_parameters *params)
 		no_free_on_del = 1;
 	}
 
+	if (params->extra_flag & RTE_HASH_EXTRA_FLAGS_DISABLE_UPDATE_EXISTING_KEY)
+		no_update_data = 1;
+
 	/* Store all keys and leave the first entry as a dummy entry for lookup_bulk */
 	if (use_local_cache)
 		/*
@@ -428,6 +433,7 @@ rte_hash_create(const struct rte_hash_parameters *params)
 	h->ext_table_support = ext_table_support;
 	h->writer_takes_lock = writer_takes_lock;
 	h->no_free_on_del = no_free_on_del;
+	h->no_update_data = no_update_data;
 	h->readwrite_concur_lf_support = readwrite_concur_lf_support;
 
 #if defined(RTE_ARCH_X86)
@@ -699,6 +705,8 @@ search_and_update(const struct rte_hash *h, void *data, const void *key,
 			k = (struct rte_hash_key *) ((char *)keys +
 					bkt->key_idx[i] * h->key_entry_size);
 			if (rte_hash_cmp_eq(key, k->key, h) == 0) {
+				if (h->no_update_data == 1)
+					return -EALRDY;
 				/* The store to application data at *data
 				 * should not leak after the store to pdata
 				 * in the key store. i.e. pdata is the guard
lib/hash/rte_cuckoo_hash.h +2 -0
index eb2644f74b..e8b7283ec2 100644
@@ -193,6 +193,8 @@ struct rte_hash {
 	/**< If read-write concurrency support is enabled */
 	uint8_t ext_table_support;     /**< Enable extendable bucket table */
 	uint8_t no_free_on_del;
+	/**< If update is prohibited on adding same key */
+	uint8_t no_update_data;
 	/**< If key index should be freed on calling rte_hash_del_xxx APIs.
 	 * If this is set, rte_hash_free_key_with_position must be called to
 	 * free the key index associated with the deleted entry.
lib/hash/rte_hash.h +4 -0
index a399346d02..f8afb4e06d 100644
@@ -55,6 +55,10 @@ extern "C" {
  */
 #define RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY_LF 0x20
 
+/** Flag to disable updating data of existing key
+ */
+#define RTE_HASH_EXTRA_FLAGS_DISABLE_UPDATE_EXISTING_KEY 0x40
+
 /**
  * The type of hash value of a key.
  * It should be a value of at least 32bit with fully random pattern.
Signature · 1 line
2.34.1
#1 lore raw

PATCH 1/1 lib/hash: new feature adding existing key

In some use cases inserting data with the same key shouldn't be overwritten. We use a new flag in this patch to disable overwriting data for the same key.

---
Cc: Yipeng Wang <[email protected]>

---
 lib/hash/rte_cuckoo_hash.c | 10 +++++++++-
 lib/hash/rte_cuckoo_hash.h |  2 ++
 lib/hash/rte_hash.h        |  4 ++++
 3 files changed, 15 insertions(+), 1 deletion(-)
lib/hash/rte_cuckoo_hash.c +9 -1
index 829b79c89a..cd87d6e4cd 100644
@@ -32,7 +32,8 @@
 				   RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY | \
 				   RTE_HASH_EXTRA_FLAGS_EXT_TABLE |	\
 				   RTE_HASH_EXTRA_FLAGS_NO_FREE_ON_DEL | \
-				   RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY_LF)
+				   RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY_LF | \
+				   RTE_HASH_EXTRA_FLAGS_DISABLE_UPDATE_EXISTING_KEY)
 
 #define FOR_EACH_BUCKET(CURRENT_BKT, START_BUCKET)                            \
 	for (CURRENT_BKT = START_BUCKET;                                      \
@@ -148,6 +149,7 @@ rte_hash_create(const struct rte_hash_parameters *params)
 	unsigned int readwrite_concur_support = 0;
 	unsigned int writer_takes_lock = 0;
 	unsigned int no_free_on_del = 0;
+	unsigned int no_update_data = 0;
 	uint32_t *ext_bkt_to_free = NULL;
 	uint32_t *tbl_chng_cnt = NULL;
 	struct lcore_cache *local_free_slots = NULL;
@@ -216,6 +218,9 @@ rte_hash_create(const struct rte_hash_parameters *params)
 		no_free_on_del = 1;
 	}
 
+	if (params->extra_flag & RTE_HASH_EXTRA_FLAGS_DISABLE_UPDATE_EXISTING_KEY)
+		no_update_data = 1;
+
 	/* Store all keys and leave the first entry as a dummy entry for lookup_bulk */
 	if (use_local_cache)
 		/*
@@ -428,6 +433,7 @@ rte_hash_create(const struct rte_hash_parameters *params)
 	h->ext_table_support = ext_table_support;
 	h->writer_takes_lock = writer_takes_lock;
 	h->no_free_on_del = no_free_on_del;
+	h->no_update_data = no_update_data;
 	h->readwrite_concur_lf_support = readwrite_concur_lf_support;
 
 #if defined(RTE_ARCH_X86)
@@ -699,6 +705,8 @@ search_and_update(const struct rte_hash *h, void *data, const void *key,
 			k = (struct rte_hash_key *) ((char *)keys +
 					bkt->key_idx[i] * h->key_entry_size);
 			if (rte_hash_cmp_eq(key, k->key, h) == 0) {
+				if (h->no_update_data == 1)
+					return -EINVAL;
 				/* The store to application data at *data
 				 * should not leak after the store to pdata
 				 * in the key store. i.e. pdata is the guard
lib/hash/rte_cuckoo_hash.h +2 -0
index eb2644f74b..e8b7283ec2 100644
@@ -193,6 +193,8 @@ struct rte_hash {
 	/**< If read-write concurrency support is enabled */
 	uint8_t ext_table_support;     /**< Enable extendable bucket table */
 	uint8_t no_free_on_del;
+	/**< If update is prohibited on adding same key */
+	uint8_t no_update_data;
 	/**< If key index should be freed on calling rte_hash_del_xxx APIs.
 	 * If this is set, rte_hash_free_key_with_position must be called to
 	 * free the key index associated with the deleted entry.
lib/hash/rte_hash.h +4 -0
index a399346d02..f8afb4e06d 100644
@@ -55,6 +55,10 @@ extern "C" {
  */
 #define RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY_LF 0x20
 
+/** Flag to disable updating data of existing key
+ */
+#define RTE_HASH_EXTRA_FLAGS_DISABLE_UPDATE_EXISTING_KEY 0x40
+
 /**
  * The type of hash value of a key.
  * It should be a value of at least 32bit with fully random pattern.
Signature · 1 line
2.34.1
#2 lore raw

lib/hash/rte_hash.h

Quoted 14 lines · On Mon, 13 Mar 2023 07:35:48 +0000 Abdullah Ömer Yamaç…
lib/hash/rte_cuckoo_hash.h +2 -0
index eb2644f74b..e8b7283ec2 100644
@@ -193,6 +193,8 @@ struct rte_hash {
 	/**< If read-write concurrency support is enabled */
 	uint8_t ext_table_support;     /**< Enable extendable bucket table */
 	uint8_t no_free_on_del;
+	/**< If update is prohibited on adding same key */
+	uint8_t no_update_data;
 	/**< If key index should be freed on calling rte_hash_del_xxx APIs.
 	 * If this is set, rte_hash_free_key_with_position must be called to
 	 * free the key index associated with the deleted entry.
lib/hash/rte_hash.h +0 -0

This ends up being an ABI change. So needs to wait for 23.11 release

#4 lore raw

PATCH v2 1/1 lib/hash: new feature adding existing key

From: Abdullah Ömer Yamaç <[email protected]>

In some use cases inserting data with the same key shouldn't be overwritten. We use a new flag in this patch to disable overwriting data for the same key.

---
Cc: Yipeng Wang <[email protected]>
Cc: Sameh Gobriel <[email protected]>
Cc: Bruce Richardson <[email protected]>
Cc: Vladimir Medvedkin <[email protected]>
Cc: David Marchand <[email protected]>

---
 lib/hash/rte_cuckoo_hash.c | 10 +++++++++-
 lib/hash/rte_cuckoo_hash.h |  2 ++
 lib/hash/rte_hash.h        |  4 ++++
 3 files changed, 15 insertions(+), 1 deletion(-)
lib/hash/rte_cuckoo_hash.c +9 -1
index 19b23f2a97..fe8f21bee4 100644
@@ -32,7 +32,8 @@
 				   RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY | \
 				   RTE_HASH_EXTRA_FLAGS_EXT_TABLE |	\
 				   RTE_HASH_EXTRA_FLAGS_NO_FREE_ON_DEL | \
-				   RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY_LF)
+				   RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY_LF | \
+				   RTE_HASH_EXTRA_FLAGS_DISABLE_UPDATE_EXISTING_KEY)
 
 #define FOR_EACH_BUCKET(CURRENT_BKT, START_BUCKET)                            \
 	for (CURRENT_BKT = START_BUCKET;                                      \
@@ -148,6 +149,7 @@ rte_hash_create(const struct rte_hash_parameters *params)
 	unsigned int readwrite_concur_support = 0;
 	unsigned int writer_takes_lock = 0;
 	unsigned int no_free_on_del = 0;
+	unsigned int no_update_data = 0;
 	uint32_t *ext_bkt_to_free = NULL;
 	uint32_t *tbl_chng_cnt = NULL;
 	struct lcore_cache *local_free_slots = NULL;
@@ -216,6 +218,9 @@ rte_hash_create(const struct rte_hash_parameters *params)
 		no_free_on_del = 1;
 	}
 
+	if (params->extra_flag & RTE_HASH_EXTRA_FLAGS_DISABLE_UPDATE_EXISTING_KEY)
+		no_update_data = 1;
+
 	/* Store all keys and leave the first entry as a dummy entry for lookup_bulk */
 	if (use_local_cache)
 		/*
@@ -428,6 +433,7 @@ rte_hash_create(const struct rte_hash_parameters *params)
 	h->ext_table_support = ext_table_support;
 	h->writer_takes_lock = writer_takes_lock;
 	h->no_free_on_del = no_free_on_del;
+	h->no_update_data = no_update_data;
 	h->readwrite_concur_lf_support = readwrite_concur_lf_support;
 
 #if defined(RTE_ARCH_X86)
@@ -707,6 +713,8 @@ search_and_update(const struct rte_hash *h, void *data, const void *key,
 			k = (struct rte_hash_key *) ((char *)keys +
 					bkt->key_idx[i] * h->key_entry_size);
 			if (rte_hash_cmp_eq(key, k->key, h) == 0) {
+				if (h->no_update_data == 1)
+					return -EINVAL;
 				/* The store to application data at *data
 				 * should not leak after the store to pdata
 				 * in the key store. i.e. pdata is the guard
lib/hash/rte_cuckoo_hash.h +2 -0
index eb2644f74b..e8b7283ec2 100644
@@ -193,6 +193,8 @@ struct rte_hash {
 	/**< If read-write concurrency support is enabled */
 	uint8_t ext_table_support;     /**< Enable extendable bucket table */
 	uint8_t no_free_on_del;
+	/**< If update is prohibited on adding same key */
+	uint8_t no_update_data;
 	/**< If key index should be freed on calling rte_hash_del_xxx APIs.
 	 * If this is set, rte_hash_free_key_with_position must be called to
 	 * free the key index associated with the deleted entry.
lib/hash/rte_hash.h +4 -0
index 7ecc021111..ca5b4841d2 100644
@@ -55,6 +55,10 @@ extern "C" {
  */
 #define RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY_LF 0x20
 
+/** Flag to disable updating data of existing key
+ */
+#define RTE_HASH_EXTRA_FLAGS_DISABLE_UPDATE_EXISTING_KEY 0x40
+
 /**
  * The type of hash value of a key.
  * It should be a value of at least 32bit with fully random pattern.
Signature · 1 line
2.34.1
#5 lore raw

Any review please?
If maintainers agree with the idea, we should announce the ABI change.

23/10/2023 10:29, Abdullah Ömer Yamaç:

Quoted 98 lines

From: Abdullah Ömer Yamaç <[email protected]>

In some use cases inserting data with the same key shouldn't be overwritten. We use a new flag in this patch to disable overwriting data for the same key.

---
Cc: Yipeng Wang <[email protected]>
Cc: Sameh Gobriel <[email protected]>
Cc: Bruce Richardson <[email protected]>
Cc: Vladimir Medvedkin <[email protected]>
Cc: David Marchand <[email protected]>

---
 lib/hash/rte_cuckoo_hash.c | 10 +++++++++-
 lib/hash/rte_cuckoo_hash.h |  2 ++
 lib/hash/rte_hash.h        |  4 ++++
 3 files changed, 15 insertions(+), 1 deletion(-)
lib/hash/rte_cuckoo_hash.c +9 -1
index 19b23f2a97..fe8f21bee4 100644
@@ -32,7 +32,8 @@
 				   RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY | \
 				   RTE_HASH_EXTRA_FLAGS_EXT_TABLE |	\
 				   RTE_HASH_EXTRA_FLAGS_NO_FREE_ON_DEL | \
-				   RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY_LF)
+				   RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY_LF | \
+				   RTE_HASH_EXTRA_FLAGS_DISABLE_UPDATE_EXISTING_KEY)
 
 #define FOR_EACH_BUCKET(CURRENT_BKT, START_BUCKET)                            \
 	for (CURRENT_BKT = START_BUCKET;                                      \
@@ -148,6 +149,7 @@ rte_hash_create(const struct rte_hash_parameters *params)
 	unsigned int readwrite_concur_support = 0;
 	unsigned int writer_takes_lock = 0;
 	unsigned int no_free_on_del = 0;
+	unsigned int no_update_data = 0;
 	uint32_t *ext_bkt_to_free = NULL;
 	uint32_t *tbl_chng_cnt = NULL;
 	struct lcore_cache *local_free_slots = NULL;
@@ -216,6 +218,9 @@ rte_hash_create(const struct rte_hash_parameters *params)
 		no_free_on_del = 1;
 	}
 
+	if (params->extra_flag & RTE_HASH_EXTRA_FLAGS_DISABLE_UPDATE_EXISTING_KEY)
+		no_update_data = 1;
+
 	/* Store all keys and leave the first entry as a dummy entry for lookup_bulk */
 	if (use_local_cache)
 		/*
@@ -428,6 +433,7 @@ rte_hash_create(const struct rte_hash_parameters *params)
 	h->ext_table_support = ext_table_support;
 	h->writer_takes_lock = writer_takes_lock;
 	h->no_free_on_del = no_free_on_del;
+	h->no_update_data = no_update_data;
 	h->readwrite_concur_lf_support = readwrite_concur_lf_support;
 
 #if defined(RTE_ARCH_X86)
@@ -707,6 +713,8 @@ search_and_update(const struct rte_hash *h, void *data, const void *key,
 			k = (struct rte_hash_key *) ((char *)keys +
 					bkt->key_idx[i] * h->key_entry_size);
 			if (rte_hash_cmp_eq(key, k->key, h) == 0) {
+				if (h->no_update_data == 1)
+					return -EINVAL;
 				/* The store to application data at *data
 				 * should not leak after the store to pdata
 				 * in the key store. i.e. pdata is the guard
lib/hash/rte_cuckoo_hash.h +2 -0
index eb2644f74b..e8b7283ec2 100644
@@ -193,6 +193,8 @@ struct rte_hash {
 	/**< If read-write concurrency support is enabled */
 	uint8_t ext_table_support;     /**< Enable extendable bucket table */
 	uint8_t no_free_on_del;
+	/**< If update is prohibited on adding same key */
+	uint8_t no_update_data;
 	/**< If key index should be freed on calling rte_hash_del_xxx APIs.
 	 * If this is set, rte_hash_free_key_with_position must be called to
 	 * free the key index associated with the deleted entry.
lib/hash/rte_hash.h +4 -0
index 7ecc021111..ca5b4841d2 100644
@@ -55,6 +55,10 @@ extern "C" {
  */
 #define RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY_LF 0x20
 
+/** Flag to disable updating data of existing key
+ */
+#define RTE_HASH_EXTRA_FLAGS_DISABLE_UPDATE_EXISTING_KEY 0x40
+
 /**
  * The type of hash value of a key.
  * It should be a value of at least 32bit with fully random pattern.
#6 lore raw
Quoted 64 lines · On Fri, 16 Feb 2024 13:43:52 +0100 Thomas Monjalon <[email protected]> wrote:

Any review please?
If maintainers agree with the idea, we should announce the ABI change.

23/10/2023 10:29, Abdullah Ömer Yamaç:

Quoted 59 lines

From: Abdullah Ömer Yamaç <[email protected]>

In some use cases inserting data with the same key shouldn't be overwritten. We use a new flag in this patch to disable overwriting data for the same key.

---
Cc: Yipeng Wang <[email protected]>
Cc: Sameh Gobriel <[email protected]>
Cc: Bruce Richardson <[email protected]>
Cc: Vladimir Medvedkin <[email protected]>
Cc: David Marchand <[email protected]>

---
 lib/hash/rte_cuckoo_hash.c | 10 +++++++++-
 lib/hash/rte_cuckoo_hash.h |  2 ++
 lib/hash/rte_hash.h        |  4 ++++
 3 files changed, 15 insertions(+), 1 deletion(-)
lib/hash/rte_cuckoo_hash.c +7 -1
index 19b23f2a97..fe8f21bee4 100644
@@ -32,7 +32,8 @@
 				   RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY | \
 				   RTE_HASH_EXTRA_FLAGS_EXT_TABLE |	\
 				   RTE_HASH_EXTRA_FLAGS_NO_FREE_ON_DEL | \
-				   RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY_LF)
+				   RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY_LF | \
+				   RTE_HASH_EXTRA_FLAGS_DISABLE_UPDATE_EXISTING_KEY)
 
 #define FOR_EACH_BUCKET(CURRENT_BKT, START_BUCKET)                            \
 	for (CURRENT_BKT = START_BUCKET;                                      \
@@ -148,6 +149,7 @@ rte_hash_create(const struct rte_hash_parameters *params)
 	unsigned int readwrite_concur_support = 0;
 	unsigned int writer_takes_lock = 0;
 	unsigned int no_free_on_del = 0;
+	unsigned int no_update_data = 0;
 	uint32_t *ext_bkt_to_free = NULL;
 	uint32_t *tbl_chng_cnt = NULL;
 	struct lcore_cache *local_free_slots = NULL;
@@ -216,6 +218,9 @@ rte_hash_create(const struct rte_hash_parameters *params)
 		no_free_on_del = 1;
 	}
 
+	if (params->extra_flag & RTE_HASH_EXTRA_FLAGS_DISABLE_UPDATE_EXISTING_KEY)
+		no_update_data = 1;
+
 	/* Store all keys and leave the first entry as a dummy entry for lookup_bulk */
 	if (use_local_cache)
 		/*
@@ -428,6 +433,7 @@ rte_hash_create(const struct rte_hash_parameters *params)
 	h->ext_table_support = ext_table_support;
 	h->writer_takes_lock = writer_takes_lock;
 	h->no_free_on_del = no_free_on_del;
+	h->no_update_data = no_update_data;
 	h->readwrite_concur_lf_support = readwrite_concur_lf_support;
 
Quoted 7 lines

lib/hash/rte_cuckoo_hash.c search_and_update(const struct rte_hash *h, void *data, const void *key, · line 717

Quoted 7 lines
lib/hash/rte_cuckoo_hash.c +2 -0
 #if defined(RTE_ARCH_X86)
@@ -707,6 +713,8 @@ search_and_update(const struct rte_hash *h, void *data, const void *key,
 			k = (struct rte_hash_key *) ((char *)keys +
 					bkt->key_idx[i] * h->key_entry_size);
 			if (rte_hash_cmp_eq(key, k->key, h) == 0) {
+				if (h->no_update_data == 1)
+					return -EINVAL;

This is buggy, the caller assumes -1 on error in several places. See:

	ret = search_and_update(h, data, key, prim_bkt, sig);
	if (ret != -1) {
		__hash_rw_writer_unlock(h);
		*ret_val = ret;
		return 1;
	}

These paths would exercised when table had to expand.

Also any new functionality like this would need tests in functional test.

#7 lore raw

PATCH v2 1/1 lib/hash: new feature adding existing key

In reply to David Marchand

In some use cases inserting data with the same key shouldn't be overwritten. We use a new flag in this patch to disable overwriting data for the same key.

---
Cc: Yipeng Wang <[email protected]>
Cc: Sameh Gobriel <[email protected]>
Cc: Bruce Richardson <[email protected]>
Cc: Vladimir Medvedkin <[email protected]>
Cc: David Marchand <[email protected]>

---
 lib/hash/rte_cuckoo_hash.c | 10 +++++++++-
 lib/hash/rte_cuckoo_hash.h |  2 ++
 lib/hash/rte_hash.h        |  4 ++++
 3 files changed, 15 insertions(+), 1 deletion(-)
lib/hash/rte_cuckoo_hash.c +9 -1
index 19b23f2a97..fe8f21bee4 100644
@@ -32,7 +32,8 @@
 				   RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY | \
 				   RTE_HASH_EXTRA_FLAGS_EXT_TABLE |	\
 				   RTE_HASH_EXTRA_FLAGS_NO_FREE_ON_DEL | \
-				   RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY_LF)
+				   RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY_LF | \
+				   RTE_HASH_EXTRA_FLAGS_DISABLE_UPDATE_EXISTING_KEY)
 
 #define FOR_EACH_BUCKET(CURRENT_BKT, START_BUCKET)                            \
 	for (CURRENT_BKT = START_BUCKET;                                      \
@@ -148,6 +149,7 @@ rte_hash_create(const struct rte_hash_parameters *params)
 	unsigned int readwrite_concur_support = 0;
 	unsigned int writer_takes_lock = 0;
 	unsigned int no_free_on_del = 0;
+	unsigned int no_update_data = 0;
 	uint32_t *ext_bkt_to_free = NULL;
 	uint32_t *tbl_chng_cnt = NULL;
 	struct lcore_cache *local_free_slots = NULL;
@@ -216,6 +218,9 @@ rte_hash_create(const struct rte_hash_parameters *params)
 		no_free_on_del = 1;
 	}
 
+	if (params->extra_flag & RTE_HASH_EXTRA_FLAGS_DISABLE_UPDATE_EXISTING_KEY)
+		no_update_data = 1;
+
 	/* Store all keys and leave the first entry as a dummy entry for lookup_bulk */
 	if (use_local_cache)
 		/*
@@ -428,6 +433,7 @@ rte_hash_create(const struct rte_hash_parameters *params)
 	h->ext_table_support = ext_table_support;
 	h->writer_takes_lock = writer_takes_lock;
 	h->no_free_on_del = no_free_on_del;
+	h->no_update_data = no_update_data;
 	h->readwrite_concur_lf_support = readwrite_concur_lf_support;
 
 #if defined(RTE_ARCH_X86)
@@ -707,6 +713,8 @@ search_and_update(const struct rte_hash *h, void *data, const void *key,
 			k = (struct rte_hash_key *) ((char *)keys +
 					bkt->key_idx[i] * h->key_entry_size);
 			if (rte_hash_cmp_eq(key, k->key, h) == 0) {
+				if (h->no_update_data == 1)
+					return -EINVAL;
 				/* The store to application data at *data
 				 * should not leak after the store to pdata
 				 * in the key store. i.e. pdata is the guard
lib/hash/rte_cuckoo_hash.h +2 -0
index eb2644f74b..e8b7283ec2 100644
@@ -193,6 +193,8 @@ struct rte_hash {
 	/**< If read-write concurrency support is enabled */
 	uint8_t ext_table_support;     /**< Enable extendable bucket table */
 	uint8_t no_free_on_del;
+	/**< If update is prohibited on adding same key */
+	uint8_t no_update_data;
 	/**< If key index should be freed on calling rte_hash_del_xxx APIs.
 	 * If this is set, rte_hash_free_key_with_position must be called to
 	 * free the key index associated with the deleted entry.
lib/hash/rte_hash.h +4 -0
index 7ecc021111..ca5b4841d2 100644
@@ -55,6 +55,10 @@ extern "C" {
  */
 #define RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY_LF 0x20
 
+/** Flag to disable updating data of existing key
+ */
+#define RTE_HASH_EXTRA_FLAGS_DISABLE_UPDATE_EXISTING_KEY 0x40
+
 /**
  * The type of hash value of a key.
  * It should be a value of at least 32bit with fully random pattern.
Signature · 1 line
2.34.1