From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by dpdk.org (Postfix) with ESMTP id CC3221B490 for ; Wed, 10 Oct 2018 04:01:54 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 09 Oct 2018 19:01:53 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,362,1534834800"; d="scan'208";a="90665422" Received: from fmsmsx103.amr.corp.intel.com ([10.18.124.201]) by orsmga003.jf.intel.com with ESMTP; 09 Oct 2018 18:55:30 -0700 Received: from fmsmsx123.amr.corp.intel.com (10.18.125.38) by FMSMSX103.amr.corp.intel.com (10.18.124.201) with Microsoft SMTP Server (TLS) id 14.3.319.2; Tue, 9 Oct 2018 18:55:29 -0700 Received: from fmsmsx151.amr.corp.intel.com ([169.254.7.87]) by fmsmsx123.amr.corp.intel.com ([169.254.7.84]) with mapi id 14.03.0319.002; Tue, 9 Oct 2018 18:55:29 -0700 From: "Wang, Yipeng1" To: Qiaobin Fu , "Richardson, Bruce" , "De Lara Guarch, Pablo" CC: "dev@dpdk.org" , "doucette@bu.edu" , "Wiles, Keith" , "Gobriel, Sameh" , "Tai, Charlie" , "stephen@networkplumber.org" , "nd@arm.com" , "honnappa.nagarahalli@arm.com" , "michel@digirati.com.br" Thread-Topic: [PATCH v4 1/2] hash table: fix a bug in rte_hash_iterate() Thread-Index: AQHUYAaL+MFxM86EZ0KSVMMaX2PDGaUXuBLw Date: Wed, 10 Oct 2018 01:55:28 +0000 Message-ID: References: <20180831165101.20026-1-qiaobinf@bu.edu> <20181009192907.85650-1-qiaobinf@bu.edu> In-Reply-To: <20181009192907.85650-1-qiaobinf@bu.edu> 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: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiNDNiMTBlNmQtMmY0Mi00NDRiLTg0NjctNDJhYTBkYjg0YzM1IiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX05UIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE3LjEwLjE4MDQuNDkiLCJUcnVzdGVkTGFiZWxIYXNoIjoiam5tMWptR1dNdDEyc2xCUjdFV3RFeXAxWUcranZPSVZUZjk5Q2dFRVRDSEQ0VHVSUmVNK1JvbzM5ZXBPM1ROKyJ9 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/2] hash table: fix a bug in rte_hash_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: Wed, 10 Oct 2018 02:01:55 -0000 Hi Qiaobin, This patch: http://patchwork.dpdk.org/patch/46105/ covers the bug. Honnapp= a suggested a fix that would work well for the lock free implementation as = well. >-----Original Message----- >From: Qiaobin Fu [mailto:qiaobinf@bu.edu] >Sent: Tuesday, October 9, 2018 12:29 PM >To: Richardson, Bruce ; De Lara Guarch, Pablo = >Cc: dev@dpdk.org; doucette@bu.edu; Wiles, Keith ; G= obriel, Sameh ; Tai, Charlie >; stephen@networkplumber.org; nd@arm.com; honnappa.= nagarahalli@arm.com; Wang, Yipeng1 >; michel@digirati.com.br; qiaobinf@bu.edu >Subject: [PATCH v4 1/2] hash table: fix a bug in rte_hash_iterate() > >In current implementation of rte_hash_iterate(), it >tries to obtain the lock after the while loop. However, >this may lead to a bug. Notice the following racing condition: > >1. The while loop above finishes because it finds > a not empty slot. But it does so without a lock. >2. Then we get the lock. >3. The position that was once not empty is now empty. > BUG because next_key is invalid. > >This patch fixes this small bug. > >Signed-off-by: Qiaobin Fu >Reviewed-by: Michel Machado >--- > lib/librte_hash/rte_cuckoo_hash.c | 6 ++++-- > 1 file changed, 4 insertions(+), 2 deletions(-) > >diff --git a/lib/librte_hash/rte_cuckoo_hash.c b/lib/librte_hash/rte_cucko= o_hash.c >index f7b86c8c9..a3e76684d 100644 >--- a/lib/librte_hash/rte_cuckoo_hash.c >+++ b/lib/librte_hash/rte_cuckoo_hash.c >@@ -1317,16 +1317,18 @@ rte_hash_iterate(const struct rte_hash *h, const v= oid **key, void **data, uint32 > bucket_idx =3D *next / RTE_HASH_BUCKET_ENTRIES; > idx =3D *next % RTE_HASH_BUCKET_ENTRIES; > >+ __hash_rw_reader_lock(h); > /* 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]; > next_key =3D (struct rte_hash_key *) ((char *)h->key_store + >-- >2.17.1