From patchwork Fri Dec 10 04:28:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 48746 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 681923858404 for ; Fri, 10 Dec 2021 04:30:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 681923858404 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1639110647; bh=tlLJJsp2iYNLlHwo2O7shc3tuy3xPTM8tGCvZjbuyD4=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=Bmyrv97rqEqFZIL3nPX8tVuk5px3I8SMI3WrR8jzBL7NNFs1JFGyWp9kAQ4r4clqj wOLPD/i9WPzhWkzxV9C20q2iACNhmp9e/PzjtjOgED0lcdEznBrMSZzrPZiwS1e9RX Qmqbb4zvW1YYTTOz4a2sdnByy/xL50uwII5nD+z8= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id A81B83858025 for ; Fri, 10 Dec 2021 04:28:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A81B83858025 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-300-m7CwfVMCOUGN2MTpRo9rOQ-1; Thu, 09 Dec 2021 23:28:32 -0500 X-MC-Unique: m7CwfVMCOUGN2MTpRo9rOQ-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1795910151E0; Fri, 10 Dec 2021 04:28:31 +0000 (UTC) Received: from oldenburg.str.redhat.com (unknown [10.39.193.123]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 24CC260BD8; Fri, 10 Dec 2021 04:28:29 +0000 (UTC) To: libc-alpha@sourceware.org Subject: [PATCH] nptl: Add one more barrier to nptl/tst-create1 Date: Fri, 10 Dec 2021 05:28:28 +0100 Message-ID: <87tufhcccz.fsf@oldenburg.str.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.3 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_NUMSUBJECT, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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-Patchwork-Original-From: Florian Weimer via Libc-alpha From: Florian Weimer Reply-To: Florian Weimer Cc: Szabolcs Nagy Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" Without the bar_ctor_finish barrier, it was possible that thread2 re-locked user_lock before ctor had a chance to lock it. ctor then blocked in its locking operation, xdlopen from the main thread did not return, and thread2 was stuck waiting in bar_dtor: thread 1: started. thread 2: started. thread 2: locked user_lock. constructor started: 0. thread 1: in ctor: started. thread 3: started. thread 3: done. thread 2: unlocked user_lock. thread 2: locked user_lock. Fixes test in commit 83b5323261bb72313bffcf37476c1b8f0847c736 ("elf: Avoid deadlock between pthread_create and ctors [BZ #28357]"). Tested on x86_64-gnu-linux with lots and lots of iterations in a loop. Reviewed-by: Szabolcs Nagy --- sysdeps/pthread/tst-create1.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sysdeps/pthread/tst-create1.c b/sysdeps/pthread/tst-create1.c index 932586c309..763ded8d79 100644 --- a/sysdeps/pthread/tst-create1.c +++ b/sysdeps/pthread/tst-create1.c @@ -33,6 +33,7 @@ thread 2: lock(user_lock) -> pthread_create */ static pthread_barrier_t bar_ctor; +static pthread_barrier_t bar_ctor_finish; static pthread_barrier_t bar_dtor; static pthread_mutex_t user_lock = PTHREAD_MUTEX_INITIALIZER; @@ -46,6 +47,7 @@ ctor (void) xpthread_mutex_unlock (&user_lock); dprintf (1, "thread 1: in ctor: unlocked user_lock.\n"); dprintf (1, "thread 1: in ctor: done.\n"); + xpthread_barrier_wait (&bar_ctor_finish); } void @@ -81,6 +83,7 @@ thread2 (void *a) xpthread_mutex_unlock (&user_lock); dprintf (1, "thread 2: unlocked user_lock.\n"); xpthread_join (t3); + xpthread_barrier_wait (&bar_ctor_finish); xpthread_mutex_lock (&user_lock); dprintf (1, "thread 2: locked user_lock.\n"); @@ -99,6 +102,7 @@ thread1 (void) { dprintf (1, "thread 1: started.\n"); xpthread_barrier_init (&bar_ctor, NULL, 2); + xpthread_barrier_init (&bar_ctor_finish, NULL, 2); xpthread_barrier_init (&bar_dtor, NULL, 2); pthread_t t2 = xpthread_create (0, thread2, 0); void *p = xdlopen ("tst-create1mod.so", RTLD_NOW | RTLD_GLOBAL);