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 150A4A0C42 for ; Wed, 7 Apr 2021 19:15:29 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id EA3BB140EF6; Wed, 7 Apr 2021 19:15:28 +0200 (CEST) Received: from EUR04-VI1-obe.outbound.protection.outlook.com (mail-eopbgr80085.outbound.protection.outlook.com [40.107.8.85]) by mails.dpdk.org (Postfix) with ESMTP id CA1D1140EB7; Wed, 7 Apr 2021 19:15:26 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=m80Q/Qlx2nXJ2sqFehWxklDD5VXQZ9iQc3h+IMhv9Yw=; b=iQBU1/I4fJm7NtWMPF+Mk3QjCxP6aTdie8kKZ4d2awyeKkfLG9a8z4B2LORRnyOAI/h4wei3N/y7Gz+BtxNyKC2QEk/NhyxoJzVt4uWIxOGazkGWUUAfm0fI34F6iMBlpFu5NosK8wHM6KfEyMu3JyFVy81VMsfXmlinx6UGARY= Received: from DB6PR1001CA0031.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:4:55::17) by DB8PR08MB5097.eurprd08.prod.outlook.com (2603:10a6:10:38::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3999.29; Wed, 7 Apr 2021 17:15:20 +0000 Received: from DB5EUR03FT049.eop-EUR03.prod.protection.outlook.com (2603:10a6:4:55:cafe::2e) by DB6PR1001CA0031.outlook.office365.com (2603:10a6:4:55::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.17 via Frontend Transport; Wed, 7 Apr 2021 17:15:20 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; dpdk.org; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;dpdk.org; dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by DB5EUR03FT049.mail.protection.outlook.com (10.152.20.191) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.17 via Frontend Transport; Wed, 7 Apr 2021 17:15:20 +0000 Received: ("Tessian outbound 81a4524e9a48:v90"); Wed, 07 Apr 2021 17:15:20 +0000 X-CR-MTA-TID: 64aa7808 Received: from f3e830ae4574.2 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 704647FB-12C3-48CE-A301-263C3E8E9793.1; Wed, 07 Apr 2021 17:15:10 +0000 Received: from EUR02-VE1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id f3e830ae4574.2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Wed, 07 Apr 2021 17:15:10 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=R9x8sBFW0q7CYH824Kq9+2etScvndKsZEEqxKBHFKsSQFNn1ghhrtV6G+FOrcIPT4iJ243ro/ILfBchzUiLm7TqemHQXLgmUBzrVE2bMEFi3n3mNGL8RuBY2vIYtGEZ0pHTCasQHjINQdmiFKrX0qe/RG+I0191XUPEmzWMU7GQHbnj1LJFsjoRIdIbd7CWX71/Dihp2FkRRGWsXd8EkmAyzv4enjQ3cSBaEZ6hCjOQtCd9r6fKqLC41Y9al8Edt64vO9eSCSTyaS57tbj7DIciB3XzYn/Rx1rtW+A10J9M1133Sd6nootah1N417XMj1W1bQCLpCZW7eEzEY9YKtQ== 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=m80Q/Qlx2nXJ2sqFehWxklDD5VXQZ9iQc3h+IMhv9Yw=; b=DAVEaCejp664xWn+loY2C71MwXxLELIMbJNOKL4u/Og6UNMKRaPN1H/FkgbNnKuCur4HxJtJBxximTzgFGFa9AEIZ/mg7ca3+ZozGX+RE7TjxgxPlGPQG0vq0nN1q87P5HE0k+pX5p3LyWSV9lAiLp4VSc+xyFVEH4oUlc18qcT+jWVZv3NxFp0YMw81cUfNrkHMVYM165rgxTnUSmIX8lcg9p0pzYVPIc7NKXyPj9BScNg4bcyQEQaJdNJ4Y5vSmTsZzItGnFStThT2LABW3pw+aOKUGYVzUrBoJi2fXPiU7uJHbvo7v1XCwVvtrZgbm5zm6C089UHg1+HBRY/WxQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=m80Q/Qlx2nXJ2sqFehWxklDD5VXQZ9iQc3h+IMhv9Yw=; b=iQBU1/I4fJm7NtWMPF+Mk3QjCxP6aTdie8kKZ4d2awyeKkfLG9a8z4B2LORRnyOAI/h4wei3N/y7Gz+BtxNyKC2QEk/NhyxoJzVt4uWIxOGazkGWUUAfm0fI34F6iMBlpFu5NosK8wHM6KfEyMu3JyFVy81VMsfXmlinx6UGARY= Received: from DBAPR08MB5814.eurprd08.prod.outlook.com (2603:10a6:10:1b1::6) by DB6PR0802MB2376.eurprd08.prod.outlook.com (2603:10a6:4:86::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3999.29; Wed, 7 Apr 2021 17:15:08 +0000 Received: from DBAPR08MB5814.eurprd08.prod.outlook.com ([fe80::2994:a01e:2de:f94e]) by DBAPR08MB5814.eurprd08.prod.outlook.com ([fe80::2994:a01e:2de:f94e%7]) with mapi id 15.20.3999.032; Wed, 7 Apr 2021 17:15:07 +0000 From: Honnappa Nagarahalli To: Luc Pelletier , "olivier.matz@6wind.com" , "jianfeng.tan@intel.com" CC: "dev@dpdk.org" , "stable@dpdk.org" , nd , Honnappa Nagarahalli , nd Thread-Topic: [PATCH v7] eal: fix race in ctrl thread creation Thread-Index: AQHXK8YtV456JnGi00mYYkTWQ01X6aqpRjWQ Date: Wed, 7 Apr 2021 17:15:07 +0000 Message-ID: References: <20210407145722.GN1650@platinum> <20210407152903.130730-1-lucp.at.work@gmail.com> In-Reply-To: <20210407152903.130730-1-lucp.at.work@gmail.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ts-tracking-id: F59FE8FB7F80AE4FBADC3C1EDF116DB5.0 x-checkrecipientchecked: true Authentication-Results-Original: gmail.com; dkim=none (message not signed) header.d=none;gmail.com; dmarc=none action=none header.from=arm.com; x-originating-ip: [70.113.13.105] x-ms-publictraffictype: Email X-MS-Office365-Filtering-Correlation-Id: 189b411d-8315-44d1-9288-08d8f9e8b8f7 x-ms-traffictypediagnostic: DB6PR0802MB2376:|DB8PR08MB5097: x-ms-exchange-transport-forked: True X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true nodisclaimer: true x-ms-oob-tlc-oobclassifiers: OLM:10000;OLM:10000; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: soXLuI94gwv7VfSBWrFqVLhcs0MvlrhekuBbGLu9iK+un3gy7yc7pjzOatlLatEIBI3lDiJI70QMITAGchV92M7hzBlF1SCWPV4yXSSqk2H0JmeERICi6SKbOEGxNCdQ3NN688V/OEXYJ47S98e3A7yVHrxSYrPY7MSUZ/MT8nOq+Jni7tDGkeWnMXth/eKneyuvRu5eKkm07xi6WzNgTE8MIjxJ3BQjLRatBXLDe0Bjm+lhvYy12HEQz1/ebPElRpzdtoeumu10Y5mc8DQPM6Uu9FPRrBJthGU2Gf8ZBjJRV+iJm0hXGCvtWb0UxqDL+1AxEZDhoRPv2p0s8OxMGBvMwtc+jwdR+yBdN1UKjk4ZH97AzsSkZXLQK1xn1aSNgWV/O7zWrdXtah+ur3iQbrKw7h1z2Oi+gsMzqEe4zespjHKxYr0KujodWL57G8LQh/o2N2lLfOYFC60WXpiGM4ai0ImBYJSrX9XiR+L48ViQ2kB8ggEurWMSxQfNNHiIw6atO87ail90f8luFXaQk11LPMYCy5m0V50t38DBZG55A/86plPYTTvZhwaOga07LOeO1eWlY3zHxpqx4ZpVJR3qG/dDbBPxUqHVirvUXlU8DyPo8h5LsT/NW6KptZVAlcEMv2eQTbpDm16lBjTXxsnzE/DLutwhZCJUWzheHvI= X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DBAPR08MB5814.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(136003)(396003)(346002)(376002)(39860400002)(71200400001)(33656002)(316002)(55016002)(4326008)(478600001)(2906002)(38100700001)(9686003)(86362001)(83380400001)(76116006)(6506007)(64756008)(110136005)(26005)(7696005)(5660300002)(8936002)(186003)(8676002)(66556008)(52536014)(66476007)(66946007)(66446008)(54906003); DIR:OUT; SFP:1101; x-ms-exchange-antispam-messagedata: =?us-ascii?Q?N3F6Ox9Fgft1iBIsW1H6tu5pjr1tU/4deYp5T/vjjhRkw4tw5UPMCboO6cJ2?= =?us-ascii?Q?+sKhdQmeDdfuzf4zHbaCPwKrAqCXK8OjgHCjgGqoEBhz+avMNVImn2m0MBY/?= =?us-ascii?Q?AF0w94OY6Gx3QLztU4oHBDWr5X6ErOL1jN2FkZxHFxmoEYCznjv+PTVAbCpO?= =?us-ascii?Q?KU7VIcf1JRuWJylkpVp++CQK6uM/H9hAS/kd1tkUJy6cwF32aUPP7sCGqJut?= =?us-ascii?Q?RuB1p+tWs3aDdBRTIepM7eyH7JLahx+Ruh+h4nt1ZyFnt1QXIiXpDq3BLRmS?= =?us-ascii?Q?SLfuu7gl1jhKCjoWxjitafDqoPj3upybHKaIZ/B4RlsIoTWmjUMnFEXGGWG/?= =?us-ascii?Q?UrGwD6f9IiSBmqzSY13REfxAZBKYaeGSmFVVfExBtjrFR8Oww6FAvimlC+iJ?= =?us-ascii?Q?dIbRJ8emonYoq0omgGAFtcJb08OULzfHBiCCRexJr+xHsSVbnaLqZy+SYniu?= =?us-ascii?Q?FVmx0DybllabYe4huUdkS5mcDr0zIERxpFlEcCOOvYueFnrGWmQSbnEhK5d+?= =?us-ascii?Q?cmYedG4UbzkonryV55fIuItzNOio+9onwerRyP5hG7rXAHfKEK/K3/ypH82H?= =?us-ascii?Q?nsaU6zOeFBoCQCwkTNFaavN/yBmd53IA01z2JbEAf9jpO6Z/R+Kx2UMaFzUX?= =?us-ascii?Q?+tbWMy/XBzGkqdaktjHhjXfwP25CLFOIsP2PIrqG6zmJnGPnRIXHjNbHhWBW?= =?us-ascii?Q?rQD4nM4fgiyd9Kmj4DHg402i82JE93qnQ3HXcGNR8fn2e2e8x14qIilO9mcz?= =?us-ascii?Q?oxjXz1S81ooaMGrxPdzjwlDA2j5YVBraGs/DSXGvL2SteR9Nhps8VqgSygFV?= =?us-ascii?Q?DzLxHCJBTDsIuGjAL2R2ElHFiALie1H5aJtIp+EYK0eWVdUe3oU+/bxU+azk?= =?us-ascii?Q?pEYsYrQknj8SWKRCDWy0VPWh2/vyKsnAA5POPZDZQQhluDstBGCcgzBZiPzC?= =?us-ascii?Q?2DRCc+LCucmqz52bH6AU4x4ELqTJ32DBgkrqnnxFdFjB5C6ruL+zLRxnvQYm?= =?us-ascii?Q?HE2dCwIpiokd4E8ZPK5GPROrjSvmFWM6i0Hyx/7ohk4KCCDbOWRzOTAU2qzx?= =?us-ascii?Q?uRLiQc2cqS7WFY8f7Uf9r++hCOsOk6nz9QEeCwsoRFhWWbZ1L2IqUTeTf7CA?= =?us-ascii?Q?ZL/orupe6iFMAxDt1GpFvk35/goIRQ5lO+Npy0VcLIyk10IlDstBE5Ue04z9?= =?us-ascii?Q?sJ0bCy4b3OUycl/AqmE4u1U/49WctMmMC+jQb6L8/8E26NSqOlBOUpTnz4Xj?= =?us-ascii?Q?8tRD7gs6ob0Xxe+9BZs92vxkK8D0xLeYEaEZA0+YKox79sHBzVXaXuSbt83z?= =?us-ascii?Q?YEeheyukuYaVP79CYoDTB+Rn?= Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB6PR0802MB2376 Original-Authentication-Results: gmail.com; dkim=none (message not signed) header.d=none;gmail.com; dmarc=none action=none header.from=arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: DB5EUR03FT049.eop-EUR03.prod.protection.outlook.com X-MS-Office365-Filtering-Correlation-Id-Prvs: be084690-2aca-4f37-c09a-08d8f9e8b193 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 8YykePdsij6yCDYHUYyZPwi+KiKcqrUwjazM4ZxFEdlcCG2W/peHEXnc6hY8TSA9wmP0Nax8SVEmzidw7kjhDttYPXHcLPmFoSzmdkNgEzJUXNoFoshzvHUvN8FVXg5OdQY/xHyy7Abmuyd+jY2GgCff8Hrs6KFSIwLr0tg81okqt/2+EYDv3cclEOzuzsYbAK7mIjK32uHbwXnGrDcEL1WQlzngTNaXxcUeL9mHZBUfHQKFf9Of0lXsgXNQTQrryTKj/8poN85f6L7Ye65h9r5U9kq12uIpj7yWcbsVCG+zUTw9xcCkMRuu91HZb/k/+nk0qp6bvNZfpBuViZwrwrlJw0xb5Xi1CjuYEIGvXbjwzjyhC4Lv6Wz2Nc5EPio3cQlh4WtZbtsabN53EVEAT9OplNXtD5L0LErvnrHS+zAs+FsOhgkJLMQ9OS1CT3StqO/gQ/E8n386Dn/71q4lhHw4UnI6KoBNGsb4UmyM3sg7UY8hQSXB1wRoYjT8SfzrLcDTxLhdlHGfAfyHzkUh/YkTxApJSX/D+xJG/9rbMQ758QnBbOBARPXWKBJpe4p7Nu6DK6gjrsp3AtsuAgpWHANxMMA98MZUXv5UZdqTuUAPFt/GJLkKk5ihmMqEcrBAGXP1Hgq1K5WOotpu10kgyg== X-Forefront-Antispam-Report: CIP:63.35.35.123; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:64aa7808-outbound-1.mta.getcheckrecipient.com; PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com; CAT:NONE; SFS:(4636009)(376002)(136003)(346002)(396003)(39860400002)(46966006)(36840700001)(81166007)(8936002)(2906002)(356005)(54906003)(110136005)(316002)(55016002)(9686003)(8676002)(86362001)(36860700001)(82740400003)(7696005)(5660300002)(450100002)(70586007)(82310400003)(52536014)(336012)(6506007)(4326008)(186003)(83380400001)(26005)(33656002)(47076005)(478600001)(70206006); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Apr 2021 17:15:20.3796 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 189b411d-8315-44d1-9288-08d8f9e8b8f7 X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d; Ip=[63.35.35.123]; Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: DB5EUR03FT049.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB8PR08MB5097 Subject: Re: [dpdk-stable] [PATCH v7] eal: fix race in ctrl thread creation X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org Sender: "stable" > Subject: [PATCH v7] eal: fix race in ctrl thread creation >=20 > The creation of control threads uses a pthread barrier for synchronizatio= n. > This patch fixes a race condition where the pthread barrier could get > destroyed while one of the threads has not yet returned from the > pthread_barrier_wait function, which could result in undefined behaviour. >=20 > Fixes: 3a0d465d4c53 ("eal: fix use-after-free on control thread creation"= ) > Cc: jianfeng.tan@intel.com > Cc: stable@dpdk.org >=20 > Signed-off-by: Luc Pelletier Overall, this LGTM. Just wondering if this should be split into 2 commits. 1) Fix the race condition with refcnt. 2) Remove the use of pthread_cancel I have some observations below. > --- >=20 > Hi Olivier, >=20 > Olivier, thanks for pointing out that pthread_barrier_wait acts as a full > memory barrier; I didn't know that was explicitly specified in the "full memory barrier" just says that the memory operations prior and after = the barrier will not be mixed. It does not guarantee that the modification = done by one core are 'visible' to other cores. Additional code is required = to ensure that the modifications are visible. For ex: in the following code= setting start_routine=3DNULL is not guaranteed to be visible to other core= s if pthread_barrier_wait is just a full barrier. The particular wording used in the reference is "synchronize memory with re= spect to other threads". I am not exactly sure what is means, but may be sa= fe to assume it means the updates are 'visible' to other cores (as the lock= ing APIs are part of the list and they guarantee the visibility aspects). May be we can simplify this during 21.11 release as we will have the abilit= y to make more invasive changes. > documentation. I've changed it to use a regular read/write. >=20 > Hi Honnappa, >=20 > I have not changed the code to use pthread_attr_setaffinity_np because th= e > attr parameter is const. I could make a copy of the provided attributes a= nd > use that instead, but I think this would still violate the spirit of the = API and, > AFAICT, there's no official mechanism for copying a pthread_attr_t. Ok, thank you. >=20 > Please let me know what you think. >=20 > lib/librte_eal/common/eal_common_thread.c | 63 +++++++++++++---------- > 1 file changed, 35 insertions(+), 28 deletions(-) >=20 > diff --git a/lib/librte_eal/common/eal_common_thread.c > b/lib/librte_eal/common/eal_common_thread.c > index 73a055902..d4e09f84b 100644 > --- a/lib/librte_eal/common/eal_common_thread.c > +++ b/lib/librte_eal/common/eal_common_thread.c > @@ -170,25 +170,34 @@ struct rte_thread_ctrl_params { > void *(*start_routine)(void *); > void *arg; > pthread_barrier_t configured; > + unsigned int refcnt; > }; >=20 > +static void ctrl_params_free(struct rte_thread_ctrl_params *params) { > + if (__atomic_sub_fetch(¶ms->refcnt, 1, __ATOMIC_ACQ_REL) =3D=3D > 0) { > + pthread_barrier_destroy(¶ms->configured); > + free(params); > + } > +} > + > static void *ctrl_thread_init(void *arg) { > - int ret; > struct internal_config *internal_conf =3D > eal_get_internal_configuration(); > rte_cpuset_t *cpuset =3D &internal_conf->ctrl_cpuset; > struct rte_thread_ctrl_params *params =3D arg; > - void *(*start_routine)(void *) =3D params->start_routine; > + void *(*start_routine)(void *); > void *routine_arg =3D params->arg; >=20 > __rte_thread_init(rte_lcore_id(), cpuset); >=20 > - ret =3D pthread_barrier_wait(¶ms->configured); > - if (ret =3D=3D PTHREAD_BARRIER_SERIAL_THREAD) { > - pthread_barrier_destroy(¶ms->configured); > - free(params); > - } > + pthread_barrier_wait(¶ms->configured); > + start_routine =3D params->start_routine; > + ctrl_params_free(params); > + > + if (start_routine =3D=3D NULL) > + return NULL; >=20 > return start_routine(routine_arg); > } > @@ -210,14 +219,15 @@ rte_ctrl_thread_create(pthread_t *thread, const > char *name, >=20 > params->start_routine =3D start_routine; > params->arg =3D arg; > + params->refcnt =3D 2; >=20 > - pthread_barrier_init(¶ms->configured, NULL, 2); > + ret =3D pthread_barrier_init(¶ms->configured, NULL, 2); > + if (ret !=3D 0) > + goto fail_no_barrier; >=20 > ret =3D pthread_create(thread, attr, ctrl_thread_init, (void *)params); > - if (ret !=3D 0) { > - free(params); > - return -ret; > - } > + if (ret !=3D 0) > + goto fail_with_barrier; >=20 > if (name !=3D NULL) { > ret =3D rte_thread_setname(*thread, name); @@ -227,25 > +237,22 @@ rte_ctrl_thread_create(pthread_t *thread, const char *name, > } >=20 > ret =3D pthread_setaffinity_np(*thread, sizeof(*cpuset), cpuset); > - if (ret) > - goto fail; > + if (ret !=3D 0) > + params->start_routine =3D NULL; > + pthread_barrier_wait(¶ms->configured); > + ctrl_params_free(params); >=20 > - ret =3D pthread_barrier_wait(¶ms->configured); > - if (ret =3D=3D PTHREAD_BARRIER_SERIAL_THREAD) { > - pthread_barrier_destroy(¶ms->configured); > - free(params); > - } > + if (ret !=3D 0) A comment here on why the pthread_join will not wait indefinitely will help= . Splitting the patch will also help understand the changes better. > + pthread_join(*thread, NULL); >=20 > - return 0; > + return -ret; > + > +fail_with_barrier: > + pthread_barrier_destroy(¶ms->configured); > + > +fail_no_barrier: > + free(params); >=20 > -fail: > - if (PTHREAD_BARRIER_SERIAL_THREAD =3D=3D > - pthread_barrier_wait(¶ms->configured)) { > - pthread_barrier_destroy(¶ms->configured); > - free(params); > - } > - pthread_cancel(*thread); > - pthread_join(*thread, NULL); > return -ret; > } >=20 > -- > 2.25.1