From mboxrd@z Thu Jan 1 00:00:00 1970 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) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 01 Oct 2018 17:18:25 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,329,1534834800"; d="scan'208";a="77691570" Received: from fmsmsx107.amr.corp.intel.com ([10.18.124.205]) by orsmga007.jf.intel.com with ESMTP; 01 Oct 2018 17:18:02 -0700 Received: from fmsmsx153.amr.corp.intel.com (10.18.125.6) by fmsmsx107.amr.corp.intel.com (10.18.124.205) with Microsoft SMTP Server (TLS) id 14.3.319.2; Mon, 1 Oct 2018 17:18:00 -0700 Received: from fmsmsx151.amr.corp.intel.com ([169.254.7.87]) by FMSMSX153.amr.corp.intel.com ([169.254.9.169]) with mapi id 14.03.0319.002; Mon, 1 Oct 2018 17:18:00 -0700 From: "Wang, Yipeng1" To: Honnappa Nagarahalli , "Richardson, Bruce" CC: "Ananyev, Konstantin" , "dev@dpdk.org" , "Gobriel, Sameh" , nd Thread-Topic: [PATCH v4 1/4] hash: fix race condition in iterate Thread-Index: AQHUV4tmAg2+LyLdK02sCmNUWmjPiqUK2QOwgAA8jpA= 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> In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-product: dlpe-windows dlp-version: 11.0.400.15 dlp-reaction: no-action x-ctpclassification: CTP_NT x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiZDk4NmZjOWEtODUzNS00MzY0LThkODYtYTIzNTMwN2I1MGM1IiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX05UIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE3LjEwLjE4MDQuNDkiLCJUcnVzdGVkTGFiZWxIYXNoIjoieTYxeGg2TTZOa0VqTVYwaVZrSkI4UnZPMStUWWhhSytRcEVVZFpBaGdVZ1l1UE5mdm1rNEVzOXRyRWp4ZHNLZSJ9 x-originating-ip: [10.1.200.107] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: Re: [dpdk-dev] [PATCH v4 1/4] hash: fix race condition in iterate 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: Tue, 02 Oct 2018 00:18:27 -0000 >-----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?