From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by dpdk.org (Postfix) with ESMTP id 36F0A1F5; Fri, 7 Jul 2017 15:54:08 +0200 (CEST) Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga105.jf.intel.com with ESMTP; 07 Jul 2017 06:54:07 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.40,323,1496127600"; d="scan'208";a="122405404" Received: from silpixa00399464.ir.intel.com (HELO silpixa00399464.ger.corp.intel.com) ([10.237.222.157]) by orsmga005.jf.intel.com with ESMTP; 07 Jul 2017 06:54:06 -0700 From: Pablo de Lara To: dev@dpdk.org Cc: mstolarchuk , stable@dpdk.org Date: Fri, 7 Jul 2017 06:54:25 +0100 Message-Id: <20170707055425.9357-1-pablo.de.lara.guarch@intel.com> X-Mailer: git-send-email 2.9.4 In-Reply-To: <1495801830-36849-1-git-send-email-mike.stolarchuk@bigswitch.com> References: <1495801830-36849-1-git-send-email-mike.stolarchuk@bigswitch.com> Subject: [dpdk-dev] [PATCH v2] hash: fix lock release on add X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 07 Jul 2017 13:54:08 -0000 From: mstolarchuk When adding items to a hash table with multiple threads, there is an spinlock used to prevent data corruption (unless Transactional Memory is supported). If there is a failure, the spinlock should be released, but there were cases where that was not happening. Fixes: be856325cba3 ("hash: add scalable multi-writer insertion with Intel TSX") CC: stable@dpdk.org Signed-off-by: mstolarchuk Acked-by: Pablo de Lara --- Changes in v2: - Fixed commit message lib/librte_hash/rte_cuckoo_hash.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/librte_hash/rte_cuckoo_hash.c b/lib/librte_hash/rte_cuckoo_hash.c index 80391cf..5b2b8dd 100644 --- a/lib/librte_hash/rte_cuckoo_hash.c +++ b/lib/librte_hash/rte_cuckoo_hash.c @@ -539,8 +539,10 @@ __rte_hash_add_key_with_hash(const struct rte_hash *h, const void *key, n_slots = rte_ring_mc_dequeue_burst(h->free_slots, cached_free_slots->objs, LCORE_CACHE_SIZE, NULL); - if (n_slots == 0) - return -ENOSPC; + if (n_slots == 0) { + ret = -ENOSPC; + goto failure; + } cached_free_slots->len += n_slots; } @@ -549,8 +551,10 @@ __rte_hash_add_key_with_hash(const struct rte_hash *h, const void *key, cached_free_slots->len--; slot_id = cached_free_slots->objs[cached_free_slots->len]; } else { - if (rte_ring_sc_dequeue(h->free_slots, &slot_id) != 0) - return -ENOSPC; + if (rte_ring_sc_dequeue(h->free_slots, &slot_id) != 0) { + ret = -ENOSPC; + goto failure; + } } new_k = RTE_PTR_ADD(keys, (uintptr_t)slot_id * h->key_entry_size); @@ -660,6 +664,7 @@ __rte_hash_add_key_with_hash(const struct rte_hash *h, const void *key, /* Error in addition, store new slot back in the ring and return error */ enqueue_slot_back(h, cached_free_slots, (void *)((uintptr_t) new_idx)); +failure: if (h->add_key == ADD_KEY_MULTIWRITER) rte_spinlock_unlock(h->multiwriter_lock); return ret; -- 2.9.4