unofficial mirror of libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Florian Weimer <fweimer@redhat.com>
To: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Cc: libc-alpha@sourceware.org
Subject: Re: [PATCH 3/3] Refactor atfork handlers
Date: Fri, 23 Feb 2018 11:41:15 +0100	[thread overview]
Message-ID: <6e23cc90-c734-3261-f89d-de9b83bb0a6b@redhat.com> (raw)
In-Reply-To: <6d6bc007-7418-4667-bf2f-0ba2256cdbec@linaro.org>

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


  reply	other threads:[~2018-02-23 10:39 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-07 13:09 [PATCH 1/3] Refactor Linux ARCH_FORK implementation Adhemerval Zanella
2018-02-07 13:09 ` [PATCH 2/3] dynarray: Implement remove function Adhemerval Zanella
2018-02-07 14:48   ` Alexander Monakov
2018-02-07 16:06     ` Adhemerval Zanella
2018-02-07 13:09 ` [PATCH 3/3] Refactor atfork handlers Adhemerval Zanella
2018-02-07 15:07   ` Florian Weimer
2018-02-07 17:16     ` Adhemerval Zanella
2018-02-08  8:32       ` Florian Weimer
2018-02-08 12:50         ` Adhemerval Zanella
2018-02-20 11:29           ` Florian Weimer
2018-02-20 13:00             ` Adhemerval Zanella
2018-02-20 13:05               ` Florian Weimer
2018-02-20 13:27                 ` Adhemerval Zanella
2018-02-20 13:42                   ` Florian Weimer
2018-02-20 13:48                     ` Adhemerval Zanella
2018-02-20 13:58                       ` Florian Weimer
2018-02-20 14:23                         ` Adhemerval Zanella
2018-02-23 10:41                           ` Florian Weimer [this message]
2018-02-23 12:10                             ` Adhemerval Zanella
2018-02-27  8:25                               ` Florian Weimer
2018-03-07 16:51 ` [PATCH 1/3] Refactor Linux ARCH_FORK implementation Adhemerval Zanella
2018-03-08 12:05 ` Florian Weimer
2018-03-08 12:58   ` Adhemerval Zanella

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/libc/involved.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6e23cc90-c734-3261-f89d-de9b83bb0a6b@redhat.com \
    --to=fweimer@redhat.com \
    --cc=adhemerval.zanella@linaro.org \
    --cc=libc-alpha@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).