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 36005A0A0E for ; Mon, 10 May 2021 18:16:33 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 30A7C40140; Mon, 10 May 2021 18:16:33 +0200 (CEST) Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2057.outbound.protection.outlook.com [40.107.237.57]) by mails.dpdk.org (Postfix) with ESMTP id BD87640140 for ; Mon, 10 May 2021 18:16:31 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=RpMPYrFjHoc/NL8pdq0jN2vBbvbJd/sWidZNE9k4CnLoKFzzAj7Ihj+mVfCBWyQ8fjjwR97KHEEd6G/rdMEe8fxl7H8gZMTiFy79exuO924JT0jw5vODzan8471nGOYuU1aOKIbM05fAo8G47EgNhusW22kKcNRX6vcMRrWSs60wR0ZxX0DFi1SJSYSGdrPBU1yWZlR2e/NEm+OKE2sgMpCWiDr8RmA5k5oYxEDFgWWbScQjvWjEjDMkdTappem0h0pPqc2g28LxvN4Ux8z3dzJI6vHW86RLoaDafYwcJ7aqbWCNCqxJdAyCNjR1ObnuVB94BBKDYZIJb5C5lIiHqQ== 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=HJ2OUnYTkLBXnlBjr9Re2iZXf4CZbbhJ2FIXs/+J2zk=; b=JLttXoPCYtbOoCsTGrj4WzA/Sp+aMrv5xu2yXEwQzNfA19DxVP3vnB9Qgzol0T1ksjwKV4eRec8lYja+ZoAPyq3KrWyNqzoXMYMYkLlI2/yMWB0Nh/3vgLLTCCkhVba3k2dyOwOf3TTkotBap3bs0q+hA/+cToDNMp2kpO4VfV+zxXpStMbMCHTHNpgvkLKUm7aL0oupvbG9YAvZAyKdhLpEWc2cn3jl2IcSygv6VdrRknTKOrHsjyTFXlCN5YElMCwrgY1th7L1zN/4uRlwniyC+xvsMllI0A1a7FOuDcQMPQAMCTEM1eL4r4VASfstNymv7bV7DvN29OiAoO0kPQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.34) smtp.rcpttodomain=arm.com smtp.mailfrom=nvidia.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=HJ2OUnYTkLBXnlBjr9Re2iZXf4CZbbhJ2FIXs/+J2zk=; b=EWI6/w7xYIGLMInCL2pl9B8Gh0xQED+WtRpYgRAJP+nKZtIw4PFTlJYQxCRFcZ5Fwc76wk0aWTVT4kwq82tWdUaUjItbVVeR2p5KMbsrKoooOJeVkaGhl112ZyzM+ZDFmsIXrvfmlUtuJVLISHwh5Zz49BOnqnys6JSNSqpQhPgcsc6ej6TJ1PSxxA4Az3HX0UUNg7K0jfBNveOgnPeB9ydJc318ul7X9frTnZhAVNweiI+AeT1Q6rrTTLBgy865zn1dNpfrSS5zbeaw3/irYCGzQmHfCK9MoHyy6YThNC87C9xl0dMi2TpmshPZF4YUxl08BVDBDExXyf3fiyhcbg== Received: from DM5PR16CA0020.namprd16.prod.outlook.com (2603:10b6:3:c0::30) by DM5PR12MB1370.namprd12.prod.outlook.com (2603:10b6:3:76::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4108.31; Mon, 10 May 2021 16:16:30 +0000 Received: from DM6NAM11FT023.eop-nam11.prod.protection.outlook.com (2603:10b6:3:c0:cafe::93) by DM5PR16CA0020.outlook.office365.com (2603:10b6:3:c0::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4108.24 via Frontend Transport; Mon, 10 May 2021 16:16:30 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.34) smtp.mailfrom=nvidia.com; arm.com; dkim=none (message not signed) header.d=none;arm.com; dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.112.34 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.34; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.34) by DM6NAM11FT023.mail.protection.outlook.com (10.13.173.96) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4108.25 via Frontend Transport; Mon, 10 May 2021 16:16:30 +0000 Received: from nvidia.com (172.20.145.6) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Mon, 10 May 2021 16:16:28 +0000 From: Xueming Li To: Luc Pelletier CC: Luca Boccassi , Olivier Matz , Honnappa Nagarahalli , dpdk stable Date: Tue, 11 May 2021 00:01:24 +0800 Message-ID: <20210510160258.30982-135-xuemingl@nvidia.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210510160258.30982-1-xuemingl@nvidia.com> References: <20210510160258.30982-1-xuemingl@nvidia.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [172.20.145.6] X-ClientProxiedBy: HQMAIL111.nvidia.com (172.20.187.18) To HQMAIL107.nvidia.com (172.20.187.13) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 41cff709-a731-43fe-083e-08d913cef8b4 X-MS-TrafficTypeDiagnostic: DM5PR12MB1370: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: EYbdfn13oQZOTBaByi7udo74iV6UFONBekYAAo585lcQhCQbOlDkNAikqogxqcR5oS8guIBFM7ECR4T3qtQOnPaK8uYb9J0Sd3sbtU7RTbg9Jsb3E5ZVZv9su5rWTiwgAWwXWe03xl0e0uAtAc58jGqiOB+gLD6XD4ixDwY635W0O9CUyopqfFtAfPNKRhOLzkxmgySJZ97IMOQyJUxPmmGuxttRM5bXD9VxqQpogrYliC+edlrgYkXLthkGuIdo8Av3cK/+gLJguWzBa1j0DgQ0W6+7CQIn4hmKgyVRoPA+dAX/qh8veSdp+q2zvpeYdfmnb2TjedRi3g5y/2HeX45wjjKR8uXisbPeExkUYg0PAoPIOxXCbdIMFrGK4Wy6I2M7oHVcF+e+IdBnbQ39GfYJK6WeSHuhHSFP4THQ7sTKMDrMXPcGpcbmVQE8N13v+q0BCENHF5klpygu0cnxyKLkBXO5gCk8QNdZjL3ZD7zPvNI9zvtxr3+p72wCmYIcFHnraS8NaFrZVhj7kny4NNml4OQNxLLUomlADt4YnxdKVNmAdZvktkeQQMYzviDpoMbo8jqlremgjwF0wXlhwK1/Og7/JDecbBTYEqVEpVC0sfbaM/KADk5lXBt+6NXrY6Ogni4p0CfrIZeFfHnHqtozXlQ0fMqUN9zOkKWUHr6wFxnHdl6hnems35aS/6e9vwIh6LP3sTtOX3X5IgZR0jQGC+i/mryXLKizzBqks0+zP2MgwvxoeCZLLBNp4CtxCWUGrgn4aIRhN8YjQ6A3yA== X-Forefront-Antispam-Report: CIP:216.228.112.34; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:schybrid03.nvidia.com; CAT:NONE; SFS:(4636009)(396003)(376002)(39860400002)(346002)(136003)(36840700001)(46966006)(2906002)(54906003)(82740400003)(86362001)(6666004)(36906005)(70586007)(70206006)(82310400003)(36860700001)(7636003)(7696005)(16526019)(186003)(316002)(478600001)(426003)(53546011)(1076003)(26005)(6286002)(5660300002)(2616005)(36756003)(47076005)(8676002)(356005)(4326008)(336012)(966005)(55016002)(8936002)(83380400001)(6916009); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 May 2021 16:16:30.5285 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 41cff709-a731-43fe-083e-08d913cef8b4 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.112.34]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT023.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1370 Subject: [dpdk-stable] patch 'eal: fix race in control thread creation' has been queued to stable release 20.11.2 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" Hi, FYI, your patch has been queued to stable release 20.11.2 Note it hasn't been pushed to http://dpdk.org/browse/dpdk-stable yet. It will be pushed if I get no objections before 05/12/21. So please shout if anyone has objections. Also note that after the patch there's a diff of the upstream commit vs the patch applied to the branch. This will indicate if there was any rebasing needed to apply to the stable branch. If there were code changes for rebasing (ie: not only metadata diffs), please double check that the rebase was correctly done. Queued patches are on a temporary branch at: https://github.com/steevenlee/dpdk This queued commit can be viewed at: https://github.com/steevenlee/dpdk/commit/ea6d0d656192ccdc0220dd3f17d7abebe9a5e3f9 Thanks. Xueming Li --- >From ea6d0d656192ccdc0220dd3f17d7abebe9a5e3f9 Mon Sep 17 00:00:00 2001 From: Luc Pelletier Date: Wed, 7 Apr 2021 16:16:04 -0400 Subject: [PATCH] eal: fix race in control thread creation Cc: Luca Boccassi [ upstream commit 34cc55cce6b180a6c3ee3fcf70a0fd56927f240d ] The creation of control threads uses a pthread barrier for synchronization. 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. Fixes: 3a0d465d4c53 ("eal: fix use-after-free on control thread creation") Signed-off-by: Luc Pelletier Acked-by: Olivier Matz Reviewed-by: Honnappa Nagarahalli --- lib/librte_eal/common/eal_common_thread.c | 49 +++++++++++++---------- 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/lib/librte_eal/common/eal_common_thread.c b/lib/librte_eal/common/eal_common_thread.c index 73a055902a..3347e91bf2 100644 --- a/lib/librte_eal/common/eal_common_thread.c +++ b/lib/librte_eal/common/eal_common_thread.c @@ -170,11 +170,19 @@ struct rte_thread_ctrl_params { void *(*start_routine)(void *); void *arg; pthread_barrier_t configured; + unsigned int refcnt; }; +static void ctrl_params_free(struct rte_thread_ctrl_params *params) +{ + if (__atomic_sub_fetch(¶ms->refcnt, 1, __ATOMIC_ACQ_REL) == 0) { + pthread_barrier_destroy(¶ms->configured); + free(params); + } +} + static void *ctrl_thread_init(void *arg) { - int ret; struct internal_config *internal_conf = eal_get_internal_configuration(); rte_cpuset_t *cpuset = &internal_conf->ctrl_cpuset; @@ -184,11 +192,8 @@ static void *ctrl_thread_init(void *arg) __rte_thread_init(rte_lcore_id(), cpuset); - ret = pthread_barrier_wait(¶ms->configured); - if (ret == PTHREAD_BARRIER_SERIAL_THREAD) { - pthread_barrier_destroy(¶ms->configured); - free(params); - } + pthread_barrier_wait(¶ms->configured); + ctrl_params_free(params); return start_routine(routine_arg); } @@ -210,15 +215,18 @@ rte_ctrl_thread_create(pthread_t *thread, const char *name, params->start_routine = start_routine; params->arg = arg; + params->refcnt = 2; - pthread_barrier_init(¶ms->configured, NULL, 2); - - ret = pthread_create(thread, attr, ctrl_thread_init, (void *)params); + ret = pthread_barrier_init(¶ms->configured, NULL, 2); if (ret != 0) { free(params); return -ret; } + ret = pthread_create(thread, attr, ctrl_thread_init, (void *)params); + if (ret != 0) + goto fail; + if (name != NULL) { ret = rte_thread_setname(*thread, name); if (ret < 0) @@ -227,25 +235,22 @@ rte_ctrl_thread_create(pthread_t *thread, const char *name, } ret = pthread_setaffinity_np(*thread, sizeof(*cpuset), cpuset); - if (ret) - goto fail; + if (ret != 0) + goto fail_cancel; - ret = pthread_barrier_wait(¶ms->configured); - if (ret == PTHREAD_BARRIER_SERIAL_THREAD) { - pthread_barrier_destroy(¶ms->configured); - free(params); - } + pthread_barrier_wait(¶ms->configured); + ctrl_params_free(params); return 0; -fail: - if (PTHREAD_BARRIER_SERIAL_THREAD == - pthread_barrier_wait(¶ms->configured)) { - pthread_barrier_destroy(¶ms->configured); - free(params); - } +fail_cancel: pthread_cancel(*thread); pthread_join(*thread, NULL); + +fail: + pthread_barrier_destroy(¶ms->configured); + free(params); + return -ret; } -- 2.25.1 --- Diff of the applied patch vs upstream commit (please double-check if non-empty: --- --- - 2021-05-10 23:59:30.083675200 +0800 +++ 0136-eal-fix-race-in-control-thread-creation.patch 2021-05-10 23:59:26.530000000 +0800 @@ -1 +1 @@ -From 34cc55cce6b180a6c3ee3fcf70a0fd56927f240d Mon Sep 17 00:00:00 2001 +From ea6d0d656192ccdc0220dd3f17d7abebe9a5e3f9 Mon Sep 17 00:00:00 2001 @@ -4,0 +5,3 @@ +Cc: Luca Boccassi + +[ upstream commit 34cc55cce6b180a6c3ee3fcf70a0fd56927f240d ] @@ -13 +15,0 @@ -Cc: stable@dpdk.org