From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Florian Weimer Newsgroups: gmane.comp.lib.glibc.alpha Subject: Re: [PATCH 3/3] Refactor atfork handlers Date: Fri, 23 Feb 2018 11:41:15 +0100 Message-ID: <6e23cc90-c734-3261-f89d-de9b83bb0a6b@redhat.com> References: <1518008967-8310-1-git-send-email-adhemerval.zanella@linaro.org> <1518008967-8310-3-git-send-email-adhemerval.zanella@linaro.org> <88a58530-092d-4daa-1096-97a1bf8e08ff@redhat.com> <7b71dd04-afd0-9ff0-79c3-3d47cbd77ee2@redhat.com> <4aad8145-b06f-4d95-315a-73d5f2253971@linaro.org> <9d8251a8-7604-9846-ebde-409786e2ebf4@redhat.com> <780cefa6-543f-1a04-4b4e-9059a30d211b@linaro.org> <2fc18517-d23d-a298-e458-88ceff1cfc33@linaro.org> <9a266bea-818d-64da-198e-64f1c19a7915@redhat.com> <6d6bc007-7418-4667-bf2f-0ba2256cdbec@linaro.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: blaine.gmane.org 1519382365 20431 195.159.176.226 (23 Feb 2018 10:39:25 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Fri, 23 Feb 2018 10:39:25 +0000 (UTC) User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 Cc: libc-alpha@sourceware.org To: Adhemerval Zanella Original-X-From: libc-alpha-return-90528-glibc-alpha=m.gmane.org@sourceware.org Fri Feb 23 11:39:21 2018 Return-path: Envelope-to: glibc-alpha@blaine.gmane.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:subject:to:cc:references:from:message-id:date :mime-version:in-reply-to:content-type :content-transfer-encoding; q=dns; s=default; b=GXJg2K4C2sWMIZrC vAAk0Caq4+5bvVnyWID0ZjsdID8Gv2oorbulWuBhzwpnwlHhLrKUhqqKPwLr3mKf I4AqW0DxIAofPRbQHxPbQmTXHhIpxNHwtWyGSHXxDw63jyODPxwZCXZ4iOJgmuBI EN9d24UFFErFx65ZecYGKCLWp68= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:subject:to:cc:references:from:message-id:date :mime-version:in-reply-to:content-type :content-transfer-encoding; s=default; bh=+GW+E3XTQ51ndjWEOnGFmN yiY1Y=; b=fGrXyIhl5EZ/uGa5rEIcNWeYk/PRhhLKH+601/oAFBIC1aqj3nAIFB 8Yk8kVkpJRlEc6xFsQc2yoOnmxX/BPSiy7hTlcC8STsUfeTCVXAZ/PqQuhUq/ifG AEzQoSb+RW1w8nUHloMnRC+UoJ+oGfpAQuBc01dMNtG/Dp4884zok= Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Original-Sender: libc-alpha-owner@sourceware.org Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.7 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_LOW,T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=Aside, H*r:sk:dhcp-19, H*RU:sk:dhcp-19, Hx-spam-relays-external:sk:dhcp-19 X-HELO: mx1.redhat.com In-Reply-To: <6d6bc007-7418-4667-bf2f-0ba2256cdbec@linaro.org> Xref: news.gmane.org gmane.comp.lib.glibc.alpha:82860 Archived-At: Received: from server1.sourceware.org ([209.132.180.131] helo=sourceware.org) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1epAl2-0004fS-CF for glibc-alpha@blaine.gmane.org; Fri, 23 Feb 2018 11:39:16 +0100 Received: (qmail 78927 invoked by alias); 23 Feb 2018 10:41:19 -0000 Received: (qmail 78914 invoked by uid 89); 23 Feb 2018 10:41:19 -0000 On 02/20/2018 03:23 PM, Adhemerval Zanella wrote: > Aside of the two scenarios (callbacks issuing fork/pthread_atfork), the only > other scenario I see which might trigger a deadlock in this case is a signal > handler issuing fork/pthread_atfork. > > Former is BZ#4737 and my understanding is this should be a EWONTFIX due > indication future POSIX specification to interpret fork as async-signal-unsafe > (comment #19 and I am not sure if fork could be made async-signal-safe with > ticket locks as Rich stated in comment #21). > > Regarding later I think pthread_atfork is inherent async-signal-unsafe due > it might return ENOMEM indicating it might allocate memory and our malloc > is also async-signal-unsafe. > > Am I missing a scenario you might be considering? I looked at the acquired locks during fork, and you are right, the corner cases where a deadlock can happen in the upstream sources are quite obscure. However, we do not currently acquire any ld.so locks, and I think I've seen patches which change that (because upstream is buggy and crash in the new child process). If any ld.so locks are acquired around fork, then we have a lock ordering conflict in case an ELF constructor calls pthread_register_atfork (which is an extremely natural thing to do), like this: Fork: pthread_register_atfork lock rtld load lock dlopen: rtld load lock calling ELF constructors, and then: pthread_register_atfork lock The older lock-free code avoids this. You could do the same even with locks if you created a copy of the handler list on the heap. Thanks, Florian