From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <stable-bounces@dpdk.org>
Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124])
	by inbox.dpdk.org (Postfix) with ESMTP id 3E41E41E23
	for <public@inbox.dpdk.org>; Thu,  9 Mar 2023 22:05:56 +0100 (CET)
Received: from mails.dpdk.org (localhost [127.0.0.1])
	by mails.dpdk.org (Postfix) with ESMTP id 181A440ED7;
	Thu,  9 Mar 2023 22:05:56 +0100 (CET)
Received: from us-smtp-delivery-124.mimecast.com
 (us-smtp-delivery-124.mimecast.com [170.10.133.124])
 by mails.dpdk.org (Postfix) with ESMTP id 1D06A40695
 for <stable@dpdk.org>; Thu,  9 Mar 2023 22:05:54 +0100 (CET)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;
 s=mimecast20190719; t=1678395953;
 h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
 to:to:cc:cc:mime-version:mime-version:content-type:content-type:
 content-transfer-encoding:content-transfer-encoding:
 in-reply-to:in-reply-to:references:references;
 bh=i6BIlfMLOZUSNbdbvcs8KsxMjZbjYaob0LoDTQAyhHc=;
 b=KrRJ83QvsKnbrVYg0KGNZxG8aDbXrrILCLCTc5r2alJUSzBVl9ZMuMiL53/csG6j8FfD1j
 78G6cfh/n8c+C0Npto2nsfa4xHSdwhgBZDj7T0/q+6zTdDJdeS8PBumgMLW8aBoa9nCXTZ
 TQhtoP8o1wdUp9qV509HUDFk0+l4Ir8=
Received: from mail-pf1-f199.google.com (mail-pf1-f199.google.com
 [209.85.210.199]) by relay.mimecast.com with ESMTP with STARTTLS
 (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id
 us-mta-54-yFmFLcbQN3CSVkleBB4fpw-1; Thu, 09 Mar 2023 16:05:52 -0500
X-MC-Unique: yFmFLcbQN3CSVkleBB4fpw-1
Received: by mail-pf1-f199.google.com with SMTP id
 h1-20020a62de01000000b005d943b97706so1753657pfg.0
 for <stable@dpdk.org>; Thu, 09 Mar 2023 13:05:52 -0800 (PST)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20210112; t=1678395951;
 h=content-transfer-encoding:cc:to:subject:message-id:date:from
 :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc
 :subject:date:message-id:reply-to;
 bh=i6BIlfMLOZUSNbdbvcs8KsxMjZbjYaob0LoDTQAyhHc=;
 b=BDoldwXjQy0XqguAxZsrIl20tN87UGU0czWgyslSz0RsJ1M0K61NzVWkV4WRMHvzaL
 xKFkqpNje+cQyvTbXhoIqqU87WAxaEIwUyIlmHR2adg2yfwzYrNjQ+4eRGBF3BLoDYOy
 l7LMj0GkiKDJkj8xD1CTxjYradFxA/n+Y6WQ2p6QZ8xSXy3BylCAxJF7+xAOP16tcsRt
 qRjQGfQWZPqU0F87SYEf6tFhOOWW3zVM2oHOp+IANFw0VQW+fCrv0HLK35f28wsZzCKK
 OxJS/VaxoGSVPGZZSS121a71xqM5+V9fRonLHEWSeXN3dJ9xBDgfFSfFwVJot7MuR1Ow
 xHZQ==
X-Gm-Message-State: AO0yUKU/N6w6tk5bGsr8J3cBV40KIfB4ub5T0SiuY2nQR0We63y9biTu
 ZlVDomKW7ysvxsuB0KzjDDvyjluGkgtg+bCT7zlUX89HLQsLE3ZGGem7zPHOwj27raKDKAXJO5w
 PKKeM/CQ2KlLpX2oNCIl3RZo=
X-Received: by 2002:a17:903:3293:b0:199:1a40:dccc with SMTP id
 jh19-20020a170903329300b001991a40dcccmr8933824plb.9.1678395951336; 
 Thu, 09 Mar 2023 13:05:51 -0800 (PST)
X-Google-Smtp-Source: AK7set8LpsY9h+5N7JMyQg8LZl7ovpmkZslJ9u9fSoSPKFwI/gxN0YmPAlGNkst5aMgdMEo+fWIMO/GyzBKC3Gf7v4I=
X-Received: by 2002:a17:903:3293:b0:199:1a40:dccc with SMTP id
 jh19-20020a170903329300b001991a40dcccmr8933820plb.9.1678395951022; Thu, 09
 Mar 2023 13:05:51 -0800 (PST)
MIME-Version: 1.0
References: <1677782682-27200-1-git-send-email-roretzla@linux.microsoft.com>
 <CAJFAV8xm=qe1W1bLh6G-FXbGREJJiGj+7oQ3QokT8mp18gjphQ@mail.gmail.com>
 <CAJFAV8w=+7xcysnYxJHGiTrpmxFG=_qz-Kp0CTko=yd+0nu3dg@mail.gmail.com>
 <3722941.kQq0lBPeGt@thomas>
 <20230309204935.GA32415@linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net>
In-Reply-To: <20230309204935.GA32415@linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net>
From: David Marchand <david.marchand@redhat.com>
Date: Thu, 9 Mar 2023 22:05:39 +0100
Message-ID: <CAJFAV8ztpFv3hmQyi0dWZVDP5frcne8073w+_3hWGQGLJmDKpA@mail.gmail.com>
Subject: Re: [PATCH 1/2] eal: fix failure race and behavior of thread create
To: Tyler Retzlaff <roretzla@linux.microsoft.com>
Cc: Thomas Monjalon <thomas@monjalon.net>, dev@dpdk.org, stable@dpdk.org
X-Mimecast-Spam-Score: 0
X-Mimecast-Originator: redhat.com
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-BeenThere: stable@dpdk.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: patches for DPDK stable branches <stable.dpdk.org>
List-Unsubscribe: <https://mails.dpdk.org/options/stable>,
 <mailto:stable-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://mails.dpdk.org/archives/stable/>
List-Post: <mailto:stable@dpdk.org>
List-Help: <mailto:stable-request@dpdk.org?subject=help>
List-Subscribe: <https://mails.dpdk.org/listinfo/stable>,
 <mailto:stable-request@dpdk.org?subject=subscribe>
Errors-To: stable-bounces@dpdk.org

On Thu, Mar 9, 2023 at 9:49=E2=80=AFPM Tyler Retzlaff
<roretzla@linux.microsoft.com> wrote:
>
> 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=E2=80=AFPM David Marchand <david.marchand=
@redhat.com> wrote:
> > > > On Thu, Mar 2, 2023 at 7:44=E2=80=AFPM Tyler Retzlaff
> > > > <roretzla@linux.microsoft.com> wrote:
> > > > >
> > > > > In rte_thread_create setting affinity after pthread_create may fa=
il.
> > > > > Such a failure should result in the entire rte_thread_create fail=
ing
> > > > > 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 threa=
d. 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 <roretzla@linux.microsoft.com>
> > > > Reviewed-by: David Marchand <david.marchand@redhat.com>
> > >
> > > 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?

Count on me, I would have complained if there was a CI issue ;-).


>
> >
> > Is it possible to fix the race without using pthread_attr_setaffinity_n=
p?
> >
>
> 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 w=
orker
> 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.

UNH is looking into re-enabling the Alpine job.


For the time being, if you have a github repository, I can propose a
quick patch using GHA:
https://github.com/david-marchand/dpdk/commit/ci

I had tested compilation with a previous version of this patch.
I just added running the unit tests (adding a checks: tests line in
the job matrix), let's see how it goes...
https://github.com/david-marchand/dpdk/actions/runs/4378715081/jobs/7663806=
639


--=20
David Marchand