From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-eopbgr60055.outbound.protection.outlook.com [40.107.6.55]) by dpdk.org (Postfix) with ESMTP id 1E7834CA2 for ; Mon, 1 Oct 2018 22:23:05 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector1-arm-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=LwDZzo3EuXjrwFdAbfYs4BJDptzygHttt50co6GQWno=; b=O+sHS+1UbVSaTcC0eWdopfAsyvsghCbd4tOSXI9V+giIP9EsTPFa829ARknit6YwDMBJR+IdyFd9hHH7qhmpCX9jSBed+TCpF1FaHdCIo9IggEbOJ0Dq1J5WnxQD1o1isQKUn+1wuZnHVxI0SAvMCK/ijsdTtp0GHuimTOtljeM= Received: from AM6PR08MB3672.eurprd08.prod.outlook.com (20.177.115.29) by AM6PR08MB3160.eurprd08.prod.outlook.com (52.135.164.21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1185.20; Mon, 1 Oct 2018 20:23:04 +0000 Received: from AM6PR08MB3672.eurprd08.prod.outlook.com ([fe80::f423:e46a:a03c:e928]) by AM6PR08MB3672.eurprd08.prod.outlook.com ([fe80::f423:e46a:a03c:e928%2]) with mapi id 15.20.1185.024; Mon, 1 Oct 2018 20:23:04 +0000 From: Honnappa Nagarahalli To: Yipeng Wang , "bruce.richardson@intel.com" CC: "konstantin.ananyev@intel.com" , "dev@dpdk.org" , "sameh.gobriel@intel.com" , nd Thread-Topic: [PATCH v4 1/4] hash: fix race condition in iterate Thread-Index: AQHUV4tm+fMzDOJTHUePY/TAu0BeyKUK2QOw Date: Mon, 1 Oct 2018 20:23:04 +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: <1538155426-145177-2-git-send-email-yipeng1.wang@intel.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [217.140.111.135] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; AM6PR08MB3160; 6:Z1OMmvUmUHEIXnTrNgd/9y0t/NBJlzABDLmT39bTi9rWsjhzZJ7YmZsRZUT6Pgg4LwhfO3at+qbt2SMRHqyMfxqmAr+VO9Q8Sd8f3QQz8uWGyHBdwldChP1PJdEpexz6rmd3nPgar0VTuKOQzAUThwSd3XWcLKDvv4u86zmPlpa0Xv5dPRNSi4iJGEaef5bP+U0HRQpxCO/wBk4yH14lxsNzcQHlLxLcfJ1nl4GzYPA4gK0PMVUvZlRNtvc9vlnvZAc8pfWqeIWDZ4/+p0XsVLFF+d/cjmZvhHHovZ8k+U+MAzWJLoXstxmracfcK8vGAhMDbQFqEsi3fNE+qYOatsnroUNEYgECPRtq4IanDGwpuUeOn4Z958Gc1SWgjucIDPIYjsnE9edO5S1hYveBtAglq2mJaY47F97+mxq0lU6yO3zFQHwf2vowtNv1p4Z+CjxZzzQs2EMW2DtWL6F6CQ==; 5:Y0kZkqbDbLf46gwgesU+ZY3IYfQ23o+i8rINayR3eR2p2C9qqj2NpNhUXHtQ6CliWWVaGUeXDQg0iiuZGq+xjY0kHfqZpuo5RnlJ8DaMzPIpvtlydOgCYuz49O9WNvwo6i96pjOjF6BzCSqQGao5g9r6YlvreBSeFU8TNDjZ5eM=; 7:v/CYsVq8XON2X24nIkaHX81FzLZ0MRalAk+mZNcmmqmgnXocE14ObQho+6Wnp/CsUwn33el6Q0/jcnfjDc3AcqMFxXAFULIBcRP7BoLQshGQPwc2/yeTjLtMQp2k4Lp7A68i58cYRs0dbI9hoPdyjOpPOLJxJbVS1YPq1AVkGgmPFx8kcRyLxSeuHUqbzCEaKIr9BYbzciuQRSai9DFgQGH0El1vLbOvfa4E8pQoTP73p90ffNA7mF45Ng25dUCr x-ms-exchange-antispam-srfa-diagnostics: SOS; x-ms-office365-filtering-correlation-id: fff4f94c-0a0f-4adb-18e9-08d627dbb12a x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989299)(4534165)(4627221)(201703031133081)(201702281549075)(8990200)(5600074)(711020)(4618075)(2017052603328)(7153060)(7193020); SRVR:AM6PR08MB3160; x-ms-traffictypediagnostic: AM6PR08MB3160: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Honnappa.Nagarahalli@arm.com; nodisclaimer: True x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(228905959029699)(180628864354917); x-ms-exchange-senderadcheck: 1 x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(10201501046)(3002001)(3231355)(944501410)(52105095)(93006095)(93001095)(6055026)(149066)(150057)(6041310)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(20161123558120)(20161123564045)(201708071742011)(7699051)(76991041); SRVR:AM6PR08MB3160; BCL:0; PCL:0; RULEID:; SRVR:AM6PR08MB3160; x-forefront-prvs: 0812095267 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(39860400002)(136003)(346002)(366004)(376002)(396003)(199004)(189003)(8936002)(5660300001)(68736007)(256004)(53936002)(14454004)(106356001)(6246003)(33656002)(446003)(6116002)(8676002)(3846002)(25786009)(11346002)(476003)(26005)(2900100001)(105586002)(5250100002)(99286004)(66066001)(72206003)(71190400001)(6436002)(110136005)(71200400001)(6506007)(2501003)(55016002)(9686003)(4326008)(478600001)(2906002)(81156014)(316002)(81166006)(102836004)(305945005)(76176011)(86362001)(54906003)(14444005)(186003)(74316002)(7736002)(486006)(97736004)(7696005)(229853002); DIR:OUT; SFP:1101; SCL:1; SRVR:AM6PR08MB3160; H:AM6PR08MB3672.eurprd08.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; received-spf: None (protection.outlook.com: arm.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: 9WIEl3JoNkuxtZBvvEcWQM4H/rmzRBjVvmE18JYvsQ5S4yQgD7KwOvDjU0pnchmEIW9ECLVIdVbs/YTUqyijsrTmtAJtft5koMZYAqHq5rAivb8aliAV/kwvAh/Ezxz36BbATMD3bsvNxku8NyTWnTLCDF+Xktgwne+mjzvbd2N7kapsCBKM5ezC/9n/gjPBTvb+4u/QrkJcIGfHiIgG5gh+XDQ09IeaHOTUO/4eMURD6DFJFAyEIg3x/bBGxDUoSBpWNnodbfm3djcen7vKj+fGM1UkbnTLxoTOP7FCznsqCy1DLrppnsOgM6AZmk6FrAZDNziSvLcN09usIhlyYrms4Kx28pXG9qaCgdftj1U= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-Network-Message-Id: fff4f94c-0a0f-4adb-18e9-08d627dbb12a X-MS-Exchange-CrossTenant-originalarrivaltime: 01 Oct 2018 20:23:04.2526 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB3160 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: Mon, 01 Oct 2018 20:23:05 -0000 >=20 > In rte_hash_iterate, the reader lock did not protect the while loop which > checks empty entry. This created a race condition that the entry may beco= me > empty when enters the lock, then a wrong key data value would be read out= . >=20 > This commit extends the protected region. >=20 > Fixes: f2e3001b53ec ("hash: support read/write concurrency") > Cc: stable@dpdk.org >=20 > Signed-off-by: Yipeng Wang > Reported-by: Honnappa Nagarahalli > --- > lib/librte_hash/rte_cuckoo_hash.c | 7 +++++-- > 1 file changed, 5 insertions(+), 2 deletions(-) >=20 > diff --git a/lib/librte_hash/rte_cuckoo_hash.c > b/lib/librte_hash/rte_cuckoo_hash.c > index f7b86c8..eba13e9 100644 > --- a/lib/librte_hash/rte_cuckoo_hash.c > +++ b/lib/librte_hash/rte_cuckoo_hash.c > @@ -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; >=20 > + __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 f= ollows: while ((position =3D h->buckets[bucket_idx].key_idx[idx]) =3D=3D EMPTY_SLOT= ) > /* 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 lin= e. > next_key =3D (struct rte_hash_key *) ((char *)h->key_store + > -- > 2.7.4