From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Wang, Yipeng1" Subject: Re: [PATCH v4 1/4] hash: fix race condition in iterate Date: Tue, 2 Oct 2018 00:17:59 +0000 Message-ID: References: <1537993618-92630-1-git-send-email-yipeng1.wang@intel.com> <1538155426-145177-1-git-send-email-yipeng1.wang@intel.com> <1538155426-145177-2-git-send-email-yipeng1.wang@intel.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Cc: "Ananyev, Konstantin" , "dev@dpdk.org" , "Gobriel, Sameh" , nd To: Honnappa Nagarahalli , "Richardson, Bruce" Return-path: Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by dpdk.org (Postfix) with ESMTP id 993965323 for ; Tue, 2 Oct 2018 02:18:26 +0200 (CEST) In-Reply-To: Content-Language: en-US List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" >-----Original Message----- >From: Honnappa Nagarahalli [mailto:Honnappa.Nagarahalli@arm.com] >> @@ -1317,16 +1317,19 @@ rte_hash_iterate(const struct rte_hash *h, const >> void **key, void **data, uint32 >> bucket_idx =3D *next / RTE_HASH_BUCKET_ENTRIES; >> idx =3D *next % RTE_HASH_BUCKET_ENTRIES; >> >> + __hash_rw_reader_lock(h); >This does not work well with the lock-less changes I am making. We should= leave the lock in its original position. Instead change the >while loop as follows: > >while ((position =3D h->buckets[bucket_idx].key_idx[idx]) =3D=3D EMPTY_SLO= T) > >> /* If current position is empty, go to the next one */ >> while (h->buckets[bucket_idx].key_idx[idx] =3D=3D EMPTY_SLOT) { >> (*next)++; >> /* End of table */ >> - if (*next =3D=3D total_entries) >> + if (*next =3D=3D total_entries) { >> + __hash_rw_reader_unlock(h); >> return -ENOENT; >> + } >> bucket_idx =3D *next / RTE_HASH_BUCKET_ENTRIES; >> idx =3D *next % RTE_HASH_BUCKET_ENTRIES; >> } >> - __hash_rw_reader_lock(h); >> + >> /* Get position of entry in key table */ >> position =3D h->buckets[bucket_idx].key_idx[idx]; >If we change the while loop as I suggested as above, we can remove this li= ne. > >> next_key =3D (struct rte_hash_key *) ((char *)h->key_store + [Wang, Yipeng] Sorry that I did not realize you already have it in your pat= ch set and I agree. Do you want to export it as a bug fix in your patch set? I will remove my c= hange. For the lock free, do we need to protect it with version counter? Imagine t= he following corner case: While the iterator read the key and data, there is a writer deleted, remove= d, and recycled the key-data pair, and write a new key and data into it. While the writer are writing, will th= e reader reads out wrong key/data, or mismatched key/data?