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 B5B5AA0C44 for ; Mon, 12 Apr 2021 12:38:02 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 74ABA1410CC; Mon, 12 Apr 2021 12:38:02 +0200 (CEST) Received: from mellanox.co.il (mail-il-dmz.mellanox.com [193.47.165.129]) by mails.dpdk.org (Postfix) with ESMTP id E0F6A1410CC for ; Mon, 12 Apr 2021 12:38:00 +0200 (CEST) Received: from Internal Mail-Server by MTLPINE1 (envelope-from talshn@nvidia.com) with SMTP; 12 Apr 2021 13:38:00 +0300 Received: from nvidia.com (l-wincomp04-vm.mtl.labs.mlnx [10.237.1.5]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id 13CAc0eH001008; Mon, 12 Apr 2021 13:38:00 +0300 From: Tal Shnaiderman To: dev@dpdk.org Cc: thomas@monjalon.net, pallavi.kadam@intel.com, dmitry.kozliuk@gmail.com, navasile@linux.microsoft.com, dmitrym@microsoft.com, david.marchand@redhat.com, lucp.at.work@gmail.com, stable@dpdk.org Date: Mon, 12 Apr 2021 13:37:44 +0300 Message-Id: <20210412103744.13496-1-talshn@nvidia.com> X-Mailer: git-send-email 2.16.1.windows.4 In-Reply-To: <20210410195433.13416-1-talshn@nvidia.com> References: <20210410195433.13416-1-talshn@nvidia.com> Subject: [dpdk-stable] [PATCH v2] eal/windows: fix pthreads macros return values 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" The macro definitions of the following pthread functions return incorrect values from the inner function return code. while pthread_barrier_init, pthread_barrier_destroy and pthread_cancel return 0 in a case of success and non zero (errno) value otherwise the shimming functions InitializeSynchronizationBarrier, DeleteSynchronizationBarrier and TerminateThread return FALSE (0) in a case of failure and TRUE(1) in a case of success. This issue was undetected as none of the functions return codes was checked until such check was added in commit 34cc55cce6b1 ("eal: fix race in control thread creation") exposing the issue by failing pthread_barrier_init and rte_eal_init on Windows as a result. The fix aligned the return value of the 3 function with the expected pthread API return values. Fixes: e8428a9d89f1 ("eal/windows: add some basic functions and macros") Cc: stable@dpdk.org Signed-off-by: Tal Shnaiderman --- v2: -fix unused value warning in MinGW-64 [DmitryK] -remove unneeded "fixes" comment [DavidM] --- lib/librte_eal/common/eal_common_thread.c | 4 ++-- lib/librte_eal/windows/include/pthread.h | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/librte_eal/common/eal_common_thread.c b/lib/librte_eal/common/eal_common_thread.c index 03dbcd9e86..1a52f42a2b 100644 --- a/lib/librte_eal/common/eal_common_thread.c +++ b/lib/librte_eal/common/eal_common_thread.c @@ -176,7 +176,7 @@ struct rte_thread_ctrl_params { 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); + (void)pthread_barrier_destroy(¶ms->configured); free(params); } } @@ -251,7 +251,7 @@ rte_ctrl_thread_create(pthread_t *thread, const char *name, return -ret; fail_with_barrier: - pthread_barrier_destroy(¶ms->configured); + (void)pthread_barrier_destroy(¶ms->configured); fail_no_barrier: free(params); diff --git a/lib/librte_eal/windows/include/pthread.h b/lib/librte_eal/windows/include/pthread.h index 9aeab1fa70..1939b0121c 100644 --- a/lib/librte_eal/windows/include/pthread.h +++ b/lib/librte_eal/windows/include/pthread.h @@ -35,12 +35,12 @@ typedef CRITICAL_SECTION pthread_mutex_t; typedef SYNCHRONIZATION_BARRIER pthread_barrier_t; #define pthread_barrier_init(barrier, attr, count) \ - InitializeSynchronizationBarrier(barrier, count, -1) + !InitializeSynchronizationBarrier(barrier, count, -1) #define pthread_barrier_wait(barrier) EnterSynchronizationBarrier(barrier, \ SYNCHRONIZATION_BARRIER_FLAGS_BLOCK_ONLY) #define pthread_barrier_destroy(barrier) \ - DeleteSynchronizationBarrier(barrier) -#define pthread_cancel(thread) TerminateThread((HANDLE) thread, 0) + !DeleteSynchronizationBarrier(barrier) +#define pthread_cancel(thread) !TerminateThread((HANDLE) thread, 0) /* pthread function overrides */ #define pthread_self() \ -- 2.16.1.windows.4