When rte_hash_add_key_data() is called with an existing key, the old
data pointer is silently overwritten. With RCU-protected readers still
potentially accessing the old data, the application cannot safely free
it since the old pointer is never returned.

This series provides two ways to address the problem:

* Automatic: when RCU is configured with a free_key_data_func callback,
  rte_hash_add_key_data() now automatically defers freeing the old data
  on overwrite. No caller changes are needed.

* Explicit: a new rte_hash_replace_key_data() API returns the previous
  data pointer via an output parameter, giving the caller full control
  over the old pointer's life cycle. No automatic deferred free is
  performed in that case.

v2:

* New patch to fallback to SYNC mode when DQ fails on delete.
* Check key_idx == EMPTY_SLOT in DQ mode to differentiate when old_data is NULL.
* Also fallback to SYNC mode when DQ fails on replace.

Robin Jarry (3):
  hash: avoid leaking entries on RCU defer queue failure
  hash: free replaced data on overwrite when RCU is configured
  hash: add replace API returning old data on overwrite

 app/test/test_hash.c                   | 214 +++++++++++++++++++++++++
 doc/guides/rel_notes/release_26_03.rst |  12 ++
 lib/hash/rte_cuckoo_hash.c             | 150 +++++++++++++----
 lib/hash/rte_hash.h                    |  75 ++++++++-
 4 files changed, 415 insertions(+), 36 deletions(-)

-- 
2.53.0

Reply via email to