From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qk1-x729.google.com (mail-qk1-x729.google.com [IPv6:2607:f8b0:4864:20::729]) by sourceware.org (Postfix) with ESMTPS id 014F8385700A for ; Thu, 15 Apr 2021 19:21:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 014F8385700A Received: by mail-qk1-x729.google.com with SMTP id 130so12209026qkm.4 for ; Thu, 15 Apr 2021 12:21:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=NMy+AOoooh9FF/9wRkTxqvi0LbAp5KIRwrpY/GMHozU=; b=VoYTqGPsugJsPUa9XOhzEJ3NM1KX49qBH0Y2ri+Gdtbkmv4/QcQSxruzinST42ZneS qbViMB1VniaFcFwN1rQV+La9Vk5PZL13chXRNkbbd43j92gge1QjU6onpDlNpquRWpfz +xcVB5Ix9eKxSIbos6uPFiYl5fDM7SrI8MBOUvilt+0cix0UW4TyKm9uNvvjQR52TRpZ 2BLJN90ajaYe5TEfxr8N1yi89npX+w1fkXGMM8q1qyGEICiFKOuHx1AExm+MyvygXLpB CXZCoyVqzM8SZLuzllEW2swczid36T6CdQBVM8ufW5UT8ocsTtNNM7rauOhPSAOsMelr Ixyw== X-Gm-Message-State: AOAM533MsB/V0+Z6bDuUCrfZjYntKdUP6faQ3sapCS6vwmxKsPJC6oaI cEhLvrAMzdKW+88+q8f30FofFHibWdW5sc8O X-Google-Smtp-Source: ABdhPJxGxV33SkNLuJl8JDMNaT8qZvihDF441pNOw6VWEBqMZw9fUGqEjSAWU8UCPc9j7LsGFE7T1A== X-Received: by 2002:a05:620a:2202:: with SMTP id m2mr5034765qkh.396.1618514496395; Thu, 15 Apr 2021 12:21:36 -0700 (PDT) Received: from [192.168.1.132] ([177.194.41.149]) by smtp.gmail.com with ESMTPSA id o23sm2635364qka.16.2021.04.15.12.21.35 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 15 Apr 2021 12:21:36 -0700 (PDT) Subject: Re: [PATCH v2 07/14] elf: Add test case for [BZ #19329] To: libc-alpha@sourceware.org, Szabolcs Nagy References: <8df69dbc6cc31456a99ef4165fd0eeffc4de4678.1618301209.git.szabolcs.nagy@arm.com> From: Adhemerval Zanella Message-ID: Date: Thu, 15 Apr 2021 16:21:33 -0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.1 MIME-Version: 1.0 In-Reply-To: <8df69dbc6cc31456a99ef4165fd0eeffc4de4678.1618301209.git.szabolcs.nagy@arm.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, NICE_REPLY_A, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 15 Apr 2021 19:21:38 -0000 On 13/04/2021 05:19, Szabolcs Nagy via Libc-alpha wrote: > Test concurrent dlopen and pthread_create when the loaded modules have > TLS. This triggers dl-tls assertion failures more reliably than the > nptl/tst-stack4 test. > > The dlopened module has 100 DT_NEEDED dependencies with TLS, they were > reused from an existing TLS test. The number of created threads during > dlopen depends on filesystem speed and hardware, but at most 3 threads > are alive at a time to limit resource usage. > > --- > v5: > - moved from nptl/ to elf/ > - use many tls modules from another test (affects the timing a bit as > these need more relocation processing, but still detects the race) > - use xdlopen > - use stdatomic.h > - moved from tests-internal back to tests > - use acq/rel atomics instead of relaxed, this works too and cleaner. > - moved after bug fix patch. > > v4: > - rebased, updated copyright year. > - moved to tests-internal because of > > v3: > - use the new test support code. > - better Makefile usage so modules are cleaned properly. > > v2: > - undef NDEBUG. > - join nop threads so at most 3 threads exist at a time. > - remove stack size setting (resource usage is no longer a concern). > - stop creating threads after dlopen observably finished. > - print the number of threads created for debugging. LGTM, thanks. Reviewed-by: Adhemerval Zanella > --- > elf/Makefile | 9 ++++-- > elf/tst-tls21.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++ > elf/tst-tls21mod.c | 1 + > 3 files changed, 76 insertions(+), 2 deletions(-) > create mode 100644 elf/tst-tls21.c > create mode 100644 elf/tst-tls21mod.c > > diff --git a/elf/Makefile b/elf/Makefile > index b1344f1133..e9377608eb 100644 > --- a/elf/Makefile > +++ b/elf/Makefile > @@ -223,7 +223,7 @@ tests += restest1 preloadtest loadfail multiload origtest resolvfail \ > tst-single_threaded tst-single_threaded-pthread \ > tst-tls-ie tst-tls-ie-dlmopen argv0test \ > tst-glibc-hwcaps tst-glibc-hwcaps-prepend tst-glibc-hwcaps-mask \ > - tst-tls20 > + tst-tls20 tst-tls21 > # reldep9 > tests-internal += loadtest unload unload2 circleload1 \ > neededtest neededtest2 neededtest3 neededtest4 \ Ok. > @@ -345,7 +345,7 @@ modules-names = testobj1 testobj2 testobj3 testobj4 testobj5 testobj6 \ > libmarkermod2-1 libmarkermod2-2 \ > libmarkermod3-1 libmarkermod3-2 libmarkermod3-3 \ > libmarkermod4-1 libmarkermod4-2 libmarkermod4-3 libmarkermod4-4 \ > - tst-tls20mod-bad > + tst-tls20mod-bad tst-tls21mod > > # Most modules build with _ISOMAC defined, but those filtered out > # depend on internal headers. Ok. > @@ -1932,3 +1932,8 @@ tst-tls20mod-bad.so-no-z-defs = yes > $(objpfx)tst-tls20: $(libdl) $(shared-thread-library) > $(objpfx)tst-tls20.out: $(objpfx)tst-tls20mod-bad.so \ > $(tst-tls-many-dynamic-modules:%=$(objpfx)%.so) > + > +# Reuses tst-tls-many-dynamic-modules > +$(objpfx)tst-tls21: $(libdl) $(shared-thread-library) > +$(objpfx)tst-tls21.out: $(objpfx)tst-tls21mod.so > +$(objpfx)tst-tls21mod.so: $(tst-tls-many-dynamic-modules:%=$(objpfx)%.so) Ok. > diff --git a/elf/tst-tls21.c b/elf/tst-tls21.c > new file mode 100644 > index 0000000000..560bf5813a > --- /dev/null > +++ b/elf/tst-tls21.c > @@ -0,0 +1,68 @@ > +/* Test concurrent dlopen and pthread_create: BZ 19329. > + Copyright (C) 2021 Free Software Foundation, Inc. > + This file is part of the GNU C Library. > + > + The GNU C Library is free software; you can redistribute it and/or > + modify it under the terms of the GNU Lesser General Public > + License as published by the Free Software Foundation; either > + version 2.1 of the License, or (at your option) any later version. > + > + The GNU C Library is distributed in the hope that it will be useful, > + but WITHOUT ANY WARRANTY; without even the implied warranty of > + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU > + Lesser General Public License for more details. > + > + You should have received a copy of the GNU Lesser General Public > + License along with the GNU C Library; if not, see > + . */ > + > +#include > +#include > +#include > +#include > +#include > +#include > + > +#define THREADS 10000 > + > +static atomic_int done; > + > +static void * > +start (void *a) > +{ > + /* Load a module with many dependencies that each have TLS. */ > + xdlopen ("tst-tls21mod.so", RTLD_LAZY); > + atomic_store_explicit (&done, 1, memory_order_release); > + return 0; > +} > + > +static void * > +nop (void *a) > +{ > + return 0; > +} > + > +static int > +do_test (void) > +{ > + pthread_t t1, t2; > + int i; > + > + /* Load a module with lots of dependencies and TLS. */ > + t1 = xpthread_create (0, start, 0); > + > + /* Concurrently create lots of threads until dlopen is observably done. */ > + for (i = 0; i < THREADS; i++) > + { > + if (atomic_load_explicit (&done, memory_order_acquire) != 0) > + break; > + t2 = xpthread_create (0, nop, 0); > + xpthread_join (t2); > + } > + > + xpthread_join (t1); > + printf ("threads created during dlopen: %d\n", i); > + return 0; > +} > + > +#include Ok, > diff --git a/elf/tst-tls21mod.c b/elf/tst-tls21mod.c > new file mode 100644 > index 0000000000..206ece4fb3 > --- /dev/null > +++ b/elf/tst-tls21mod.c > @@ -0,0 +1 @@ > +int __thread x; > Ok.