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 38E5241E21; Thu, 9 Mar 2023 21:49:38 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id C1F0840ED7; Thu, 9 Mar 2023 21:49:37 +0100 (CET) Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by mails.dpdk.org (Postfix) with ESMTP id D013340695; Thu, 9 Mar 2023 21:49:35 +0100 (CET) Received: by linux.microsoft.com (Postfix, from userid 1086) id 2435920C14D5; Thu, 9 Mar 2023 12:49:35 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 2435920C14D5 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1678394975; bh=njBUslsRgX/mKdi0rYDsVUPA0uc7NyJJ504gC82lxLg=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=T3g0Lun31eJ3/OIGKV5iZ/PgN3LI3/kwpbyYQw2E1rbXYO6Q3QG5ayBV3K7WXk97s xdxO84vU3BUjK/ITirW1XttTAIgA9OjI7/pbnQQ1DyE+Dyzv+D8rLv7joZa2yp27cW DxloNAacePWzl1LDRGlQYMHrC1LFJhIgw+nkLIZU= Date: Thu, 9 Mar 2023 12:49:35 -0800 From: Tyler Retzlaff To: Thomas Monjalon Cc: David Marchand , dev@dpdk.org, stable@dpdk.org Subject: Re: [PATCH 1/2] eal: fix failure race and behavior of thread create Message-ID: <20230309204935.GA32415@linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net> References: <1677782682-27200-1-git-send-email-roretzla@linux.microsoft.com> <3722941.kQq0lBPeGt@thomas> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <3722941.kQq0lBPeGt@thomas> User-Agent: Mutt/1.5.21 (2010-09-15) 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 On Thu, Mar 09, 2023 at 10:58:06AM +0100, Thomas Monjalon wrote: > 09/03/2023 10:17, David Marchand: > > On Tue, Mar 7, 2023 at 3:33 PM David Marchand wrote: > > > On Thu, Mar 2, 2023 at 7:44 PM Tyler Retzlaff > > > wrote: > > > > > > > > In rte_thread_create setting affinity after pthread_create may fail. > > > > Such a failure should result in the entire rte_thread_create failing > > > > but doesn't. > > > > > > > > Additionally if there is a failure to set affinity a race exists where > > > > the creating thread will free ctx and depending on scheduling of the new > > > > thread it may also free ctx (double free). > > > > > > > > Resolve both of the above issues by using the pthread_setaffinity_np > > > > prior to thread creation to set the affinity of the created thread. By > > > > doing this no failure paths exist after pthread_create returns > > > > successfully. > > > > > > > > Fixes: ce6e911d20f6 ("eal: add thread lifetime API") > > > > Cc: stable@dpdk.org > > > > Cc: roretzla@linux.microsoft.com > > > > > > > > Signed-off-by: Tyler Retzlaff > > > Reviewed-by: David Marchand > > > > Series applied, thanks. > > Unfortunately we cannot merge this patch > because it does not compile on Alpine Linux (musl libc): > > lib/eal/unix/rte_thread.c:160:31: error: > implicit declaration of function 'pthread_attr_setaffinity_np' i didn't get any CI failure for this. did i just miss it? > > Is it possible to fix the race without using pthread_attr_setaffinity_np? > it seems we never allowed threads to be created with a set affinity when using pthread_create directly (that was portable to alpine linux). for worker threads the start_routine is setting the affinity from the new thread. certainly we can make this work by doing the same thing, but we'll have to adjust the start routine wrapper to synchronize/wait for the new thread to set the affinity and if it fails terminate the new thread cleanly. i don't have a way to build for alpine linux or run the unit tests, does someone want to make the above suggested adjustment? or i can try and make a patch but someone else will have to carefully review and test. let me know how you'd like to proceed. ty