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 333E0A0A0A for ; Fri, 21 May 2021 17:49:29 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 2A6B74069D; Fri, 21 May 2021 17:49:29 +0200 (CEST) Received: from mail-qk1-f170.google.com (mail-qk1-f170.google.com [209.85.222.170]) by mails.dpdk.org (Postfix) with ESMTP id 81CF24069D for ; Fri, 21 May 2021 17:49:28 +0200 (CEST) Received: by mail-qk1-f170.google.com with SMTP id 82so8794700qki.8 for ; Fri, 21 May 2021 08:49:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=TgPEeCOb3QsLovSDx9Srzj46B6MaknMH+FScpohkTuk=; b=sthEwL16oGEYF9LrHCOjTY3s5/NUgt0Kb64dJKvty6nsRx0Dn4xqGDOmAmbriYae/b rp+KqE8vHJBxxUDtvqNiIZqO9FT5Phi/zN8DZF33h04JMoxBHKLwB0XF/8m7PU2iePFG N9fZ95d9N4D1GM7VLrKtNybrO2I8yCV+qdqVeXp3mZSrRH51wOJ8CVOEBPPdiikTqvr6 BHi/TgUmKhlwCOdS8NzV73ENjeyVLX+Kk8cwwCj2IiNdJ3Tw02rXOtFjo4s9/GvgBP0M MZVyNwW+cxUMqcJBotwrwF9tnH/H3Z9qfEhrGU2Ebh5Bg4XY3jsswSJtjIPOGP52uv07 tXvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=TgPEeCOb3QsLovSDx9Srzj46B6MaknMH+FScpohkTuk=; b=YmF3xFDTlQKIakl/isp1TihPiGLetSwsIeSeyiaZV23Ad+Tl7HIo8oBBNZgx9ZtyyZ l/CU2RjfDw3B/MVijSuZVK2t3LkDNiERP1HdA15Yud+zrOgiYu9UdOI5BAqtI/HGOQef roTZn420xYs/Bz3LDHzwgGFbYhjYF0i37/AEBM2jhOVtuJRDB3fbHhIzgKIKoVYlhbr2 3kjGjNsahHh9aOGKebUn/dSAwfHdiP1BLBM6algFb3ynVeTmER5xPVEzBn7H6cN72RZd g6nJUyHXg4kLTt4PuoVW2sGVVv2w7HPRuIJ3bKfkYnqsoHzxNtZP4wvRMPwsAJzCW48K 9OtA== X-Gm-Message-State: AOAM533aTzcY8kfOhBd2bAxNBh889dWseJ40mCtwnXQYMa0WScvFARwG l111qic6Z0wEdLYYwS7KSc4= X-Google-Smtp-Source: ABdhPJwiCfd5IXiyUdHqnWcLieq2QEkEBxoEu8wDpU3/41msTsHhKLc4PdEWQWRguWJd2s4NfCdlDg== X-Received: by 2002:a37:e113:: with SMTP id c19mr14177028qkm.329.1621612168011; Fri, 21 May 2021 08:49:28 -0700 (PDT) Received: from localhost.localdomain (bras-base-hullpq2034w-grc-18-74-15-213-177.dsl.bell.ca. [74.15.213.177]) by smtp.gmail.com with ESMTPSA id q12sm4813969qtl.13.2021.05.21.08.49.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 May 2021 08:49:27 -0700 (PDT) From: Luc Pelletier To: christian.ehrhardt@canonical.com, stable@dpdk.org Cc: Luc Pelletier Date: Fri, 21 May 2021 11:49:07 -0400 Message-Id: <20210521154907.320565-2-lucp.at.work@gmail.com> In-Reply-To: <20210521154907.320565-1-lucp.at.work@gmail.com> References: <20210521154907.320565-1-lucp.at.work@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-stable] [PATCH 19.11.9 2/2] eal: fix hang in control 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" [ upstream commit af68c1d699be6c369e296b775bdbf13ae18b79cc ] The affinity of a control thread is set after it has been launched. If setting the affinity fails, pthread_cancel is called followed by a call to pthread_join, which can hang forever if the thread's start routine doesn't call a pthread cancellation point. This patch modifies the logic so that the control thread exits gracefully if the affinity cannot be set successfully and removes the call to pthread_cancel. Fixes: 6383d2642b62 ("eal: set name when creating a control thread") --- lib/librte_eal/common/eal_common_thread.c | 29 +++++++++++++---------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/lib/librte_eal/common/eal_common_thread.c b/lib/librte_eal/common/eal_common_thread.c index a5089ae49..b1e5c2a08 100644 --- a/lib/librte_eal/common/eal_common_thread.c +++ b/lib/librte_eal/common/eal_common_thread.c @@ -161,12 +161,16 @@ static void ctrl_params_free(struct rte_thread_ctrl_params *params) static void *rte_thread_init(void *arg) { struct rte_thread_ctrl_params *params = arg; - void *(*start_routine)(void *) = params->start_routine; + void *(*start_routine)(void *); void *routine_arg = params->arg; pthread_barrier_wait(¶ms->configured); + start_routine = params->start_routine; ctrl_params_free(params); + if (start_routine == NULL) + return NULL; + return start_routine(routine_arg); } @@ -188,14 +192,12 @@ rte_ctrl_thread_create(pthread_t *thread, const char *name, params->refcnt = 2; ret = pthread_barrier_init(¶ms->configured, NULL, 2); - if (ret != 0) { - free(params); - return -ret; - } + if (ret != 0) + goto fail_no_barrier; ret = pthread_create(thread, attr, rte_thread_init, (void *)params); if (ret != 0) - goto fail; + goto fail_with_barrier; if (name != NULL) { ret = rte_thread_setname(*thread, name); @@ -206,19 +208,22 @@ rte_ctrl_thread_create(pthread_t *thread, const char *name, ret = pthread_setaffinity_np(*thread, sizeof(*cpuset), cpuset); if (ret != 0) - goto fail_cancel; + params->start_routine = NULL; pthread_barrier_wait(¶ms->configured); ctrl_params_free(params); - return 0; + if (ret != 0) + /* start_routine has been set to NULL above; */ + /* ctrl thread will exit immediately */ + pthread_join(*thread, NULL); -fail_cancel: - pthread_cancel(*thread); - pthread_join(*thread, NULL); + return -ret; -fail: +fail_with_barrier: (void)pthread_barrier_destroy(¶ms->configured); + +fail_no_barrier: free(params); return -ret; -- 2.25.1