From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id BBE6AA0C47; Tue, 6 Jul 2021 16:27:23 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 53E764128B; Tue, 6 Jul 2021 16:27:23 +0200 (CEST) Received: from mx0a-00103a01.pphosted.com (mx0b-00103a01.pphosted.com [67.231.152.227]) by mails.dpdk.org (Postfix) with ESMTP id 229EB4120E for ; Tue, 6 Jul 2021 16:27:21 +0200 (CEST) Received: from pps.filterd (m0002317.ppops.net [127.0.0.1]) by mx0b-00103a01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 166EHn09029694 for ; Tue, 6 Jul 2021 10:27:20 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ciena.com; h=from : to : subject : date : message-id : content-type : mime-version; s=06252019; bh=yFGwqbP44Fzt6H4SqDh/PV6sUqjpJiG4/HLF8Y0CBF0=; b=WugGdSOe82IC/w9eWV1rZizxax/dqnenPll1laJbuGqZyogmmkjqopsLupF+Aj5LklZK bZcfoMLAg83advs8hWuZ7G9WjvhRJb+TpaRbTF8ZTHD0F6j/sTfX8ugovKSxE6g30f9Y 7kr+mJGAMB0crB2ASbesXgMWVn2WF5LytdlKF0jK2LDSYGv+vRh9lxOngjpTHuslIcop TlpWUMVTbdBSVotFjSx08cZ6Y/6yCEZoJalzQwC4+CVjU90lJzhhf/QIAwKd+TGrwGye v/kf2OGSMZWDhCJvE41t4t7ooOLZnEw5ajD+/cF7FTrEDmhxvjcxy2jBcj6buXRy85W/ DQ== Received: from nam11-bn8-obe.outbound.protection.outlook.com (mail-bn8nam11lp2172.outbound.protection.outlook.com [104.47.58.172]) by mx0b-00103a01.pphosted.com with ESMTP id 39mr8nr43r-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 06 Jul 2021 10:27:20 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=A+TSF05gVUXMsYUupm/8wDunNf8GzauGJG1efZehz5zRaNKXsgwDrzNI+ZwBR8AtFoOU1rfWCcFGf5GsO2lnXZMQM0x4wz8sN/2tmx/wyc+iZxDPi77l0RTqC8h1jV25cbUfhDabZWDaUbAETneYYZ62Psc3R23hMkQq27gSXfaq1xoiwKqo0DA4JZP1xPP/ochc2Cl3O3aOPuoE5PU+wkEZ5Dnl9t44MEffCo63jSordFUdRb4ZGSVvQ2dsZ9YPl4vYW5BYSpoCI7knuZqqfF2B+W2YV8DxAE7K4lcTwacHhvw372DJ4+pEtbDcv5Smm7ge4i/M9qd+uK5up8RL9w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=yFGwqbP44Fzt6H4SqDh/PV6sUqjpJiG4/HLF8Y0CBF0=; b=O/4kIfAnPNZtO9Vc4sJeJox4rDT6f73QvY1Owv1302717d3ogUQ/oOYRnefXB8F1CggtOOppdsDqVK24Ic2CFGissOXO9lbSEWxYeZJT162mCPqeye7Cl80RA3uu3JUlpnPeQNHPT3KPnXHg7wKlcKLYDWITrCvn/MaElIkPZHShyA2+3mGtUeJVEH4Jj4vqMcgEiGCX6O2Hb0GlCWXJx7BZc+3/PEoDVTaYmPexQ3Fkm9hVZGbgu7NphNzssrWLiTt2ZA3nCbYDzwZ5iJ8693Vn0WGmvdxuxol0ZR1q7p2SOZjsHL5T7IYt2MCOzas9K352L7BssZQOw0cG6LY1xA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=ciena.com; dmarc=pass action=none header.from=ciena.com; dkim=pass header.d=ciena.com; arc=none Received: from DM5PR0401MB3590.namprd04.prod.outlook.com (2603:10b6:4:78::34) by DM5PR0401MB3704.namprd04.prod.outlook.com (2603:10b6:4:7f::36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4219.20; Tue, 6 Jul 2021 14:27:18 +0000 Received: from DM5PR0401MB3590.namprd04.prod.outlook.com ([fe80::c43b:68c0:57a0:489e]) by DM5PR0401MB3590.namprd04.prod.outlook.com ([fe80::c43b:68c0:57a0:489e%7]) with mapi id 15.20.4287.033; Tue, 6 Jul 2021 14:27:18 +0000 From: "Alipour, Mehrdad" To: "dev@dpdk.org" Thread-Topic: rte_table_hash_ext.c: rte_table_hash_ext_lookup is non-reentrant Thread-Index: AddycfVgTFDRoEGmTP+AmNOg19ifFA== Date: Tue, 6 Jul 2021 14:27:18 +0000 Message-ID: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: dpdk.org; dkim=none (message not signed) header.d=none;dpdk.org; dmarc=none action=none header.from=ciena.com; x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 1cf47454-5a2b-492b-12d1-08d9408a28e2 x-ms-traffictypediagnostic: DM5PR0401MB3704: x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:8882; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: 2rmaZV6ZVWqGd1XNumS3pWtW6Gc+0x8Op71wHANHybGLo9RwVpX7ObGBPgg1YZifMWORqZQNp0wYlMNY0w4CFt0Pn18rngds/YZnVetdZh7U9z70DDXnarFDdzpLsoGexshleXbE4U7fTiMNqL/wyYZQ/Ta3uIkBE7MqXwfpqCa7FJIkOgbQyIoBQHURK/BX8ynxnZV/BLtPzuZGKseY+iVuQ60JO11ngiR5G1ZF2hOADRUK0UuPOIj8PZS6WpSi9XeoJbwmoYuQMSVeQqyixx2D9irAoNazZQTWefDXwSUsZwiM1JdWUVpnVp7s2E2OvhUfILB1X8DqXoRwTKW/vxuEyr5fa/5qHDviHgGZe2XYi64sjRoX6uHFVpjqbrqkoFJMd/9UG473u8s1RrEWCyDDd8c62dfu1tF11x74EiVXu8Km0JI25zIl2BXK7DfW+Vcsus3hOH7uBtWjFbbOyRKbsZD/Gs+bWc7NH5m+vVTiKrRrRqfProdw4ywx/w7aWXtYCzeBt0IRO8sRd7guajYnwzECs9ilo0mTr1C6BHToN9O+dNye5B18Wti3TVQu6avOr2u9WWlDWiIrmmkyXiOHznVyu2DOksaVYsd9aW/TVKJRDHG5sZA6CPb0ggRcuODlaN5irUKZQ86V954jUw== x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DM5PR0401MB3590.namprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(136003)(346002)(376002)(39860400002)(366004)(396003)(478600001)(2906002)(66556008)(5660300002)(86362001)(9686003)(52536014)(64756008)(26005)(38100700002)(33656002)(6506007)(8936002)(66476007)(71200400001)(66446008)(316002)(6916009)(8676002)(76116006)(55236004)(66946007)(7696005)(186003)(9326002)(55016002)(122000001); DIR:OUT; SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?s4m25NCmEsJjS9nkvdMaBINp3DMkQwcBrY4i7+c6sCniDVAWrCwwqp46GLlM?= =?us-ascii?Q?HF+0Xb/TTxHsqmZlDdtHu4wBr+39zjesbFwbAt64PBfTrn8O61oE3Dxcrd4x?= =?us-ascii?Q?+ybcESuVIjBtVMzi5B9+hgOJxRU43YNX72LTHLobxk3eBoiWR2VS40AakZVz?= =?us-ascii?Q?fwejRCDZ7ifIK3ahSCeaIlbj7/QVonf01pwRWtDefIPzNex++4dy9BCS11Iz?= =?us-ascii?Q?TTYHokloMqEzqLY/USld0WQeOdyPv/lbf2fmpAMfbQ+5CWZbIQUiYIynn2V3?= =?us-ascii?Q?2BlVym9njfl/aHh75xXMey/BDNOxb3YI2j9KekVFtlQcAXy65br3d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2ajuSMoE2Ivt1bH4NWOM/1vuUZFSP5TMazm?= =?us-ascii?Q?5TTOCV9nYWDTSUU6CPc5LIpXlPhr5gb9MfF21ASosjd6EC/6RpAP6breQssv?= =?us-ascii?Q?oZG3LbfRCa7peHiTCjF7dMdG?= x-ms-exchange-transport-forked: True MIME-Version: 1.0 X-OriginatorOrg: ciena.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: DM5PR0401MB3590.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1cf47454-5a2b-492b-12d1-08d9408a28e2 X-MS-Exchange-CrossTenant-originalarrivaltime: 06 Jul 2021 14:27:18.4595 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 457a2b01-0019-42ba-a449-45f99e96b60a X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: esp+cSVk69uZc6bFzHHWxJad5W8mrRkGUI3hLpkNkXR9mss9TVKMEUgJvWlRzDBC1TAN2Hn4/rOnROcVEWZanA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR0401MB3704 X-Proofpoint-ORIG-GUID: UUMCpJaKlxH67oQUlA12O-SqdlknHw4L X-Proofpoint-GUID: UUMCpJaKlxH67oQUlA12O-SqdlknHw4L X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391, 18.0.790 definitions=2021-07-06_07:2021-07-02, 2021-07-06 signatures=0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable X-Content-Filtered-By: Mailman/MimeDel 2.1.29 Subject: [dpdk-dev] rte_table_hash_ext.c: rte_table_hash_ext_lookup is non-reentrant X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Hi, We have tested lib/librte_table/rte_table_hash_ext.c: rte_table_hash_ext_lo= okup using dpdk 19.11 and it appears that the function is not reentrant safe causing incorrect ha= sh lookup misses at very small rate (< 0.005%) when invoked by multiple threads in parallel. The reason for reentrancy issue is as follows: Embedding the "grinders" array in the rte_table_hash structure results in a hash lookup that is non-reentrant because temporary values are stored in the grinders array during the hash lookup. The fix is to put the grinders array on the stack. We propose the following change to fix the reentrancy issue (courtesy of Br= ian Hiltscher, bhiltsch@ciena.com): diff --git a/lib/librte_table/rte_table_hash_ext.c b/lib/librte_table/rte_t= able_hash_ext.c index 802a24fe0..4a1504c54 100644 --- a/lib/librte_table/rte_table_hash_ext.c +++ b/lib/librte_table/rte_table_hash_ext.c @@ -66,6 +66,15 @@ struct grinder { uint32_t key_index; }; +/* + * Embedding the "grinders" array in the rte_table_hash + * structure results in a hash lookup that is non-reentrant + * because temporary values are stored in the grinders array + * during the hash lookup. The fix is to put the grinders + * array on the stack. + */ +#define FIX_HASH_BUG 1 + struct rte_table_hash { struct rte_table_stats stats; @@ -85,10 +94,10 @@ struct rte_table_hash { uint32_t data_size_shl; uint32_t key_stack_tos; uint32_t bkt_ext_stack_tos; - +#ifndef FIX_HASH_BUG /* Grinder */ struct grinder grinders[RTE_PORT_IN_BURST_SIZE_MAX]; - +#endif /* Tables */ uint64_t *key_mask; struct bucket *buckets; @@ -856,7 +865,12 @@ static int rte_table_hash_ext_lookup( void **entries) { struct rte_table_hash *t =3D (struct rte_table_hash *) table; - struct grinder *g =3D t->grinders; +#ifndef FIX_HASH_BUG + struct grinder *g =3D t->grinders; +#else + struct grinder grinders[RTE_PORT_IN_BURST_SIZE_MAX]; + struct grinder *g =3D grinders; // make grinders structure per= thread +#endif Thanks, Mehrdad Alipour malipour@ciena.com