From: Christian Schoenebeck <qemu_oss@crudebyte.com>
To: qemu-devel@nongnu.org
Cc: Paolo Bonzini <pbonzini@redhat.com>,
Geoffrey McRae <geoff@hostfission.com>,
Gerd Hoffmann <kraxel@redhat.com>
Subject: PTHREAD_MUTEX_ERRORCHECK and fork()
Date: Wed, 26 Aug 2020 15:48:28 +0200 [thread overview]
Message-ID: <1803832.CiF9An4F11@silver> (raw)
In-Reply-To: <592c10e0-8800-a847-89cc-b877ddf286c8@redhat.com>
On Freitag, 21. August 2020 15:13:35 CEST Paolo Bonzini wrote:
> On 20/08/20 14:00, Christian Schoenebeck wrote:
> > One way would be a recursive type and logging a warning, which you
> > obviously don't like; another option would be an assertion fault instead
> > to make developers immediately aware about the double lock on early
> > testing. Because on a large scale project like this, it is almost
> > impossible for all developers to be aware about all implied locks. Don't
> > you think so?
> >
> > At least IMO the worst case would be a double unlock on a non-recursive
> > main thread mutex and running silently into undefined behaviour.
>
> Yes, more assertions are always fine.
>
> We were using errorcheck mutexes until a few years ago, unfortunately we
> couldn't because they are broken with respect to fork (commit 24fa90499,
> "qemu-thread: do not use PTHREAD_MUTEX_ERRORCHECK", 2015-03-05).
I had a go on this one; you still get EPERM when trying to
pthread_mutex_unlock() from a forked child process on a
PTHREAD_MUTEX_ERRORCHECK mutex locked by parent process.
The common opinion though seems to be that unlocking parent's lock(s) by child
process was illegal:
https://groups.google.com/forum/#!topic/comp.programming.threads/ywMInaZjmqo
https://sourceware.org/bugzilla/show_bug.cgi?id=2745
The relevant section from POSIX:
fork - create a new process
...
A process shall be created with a single thread. If a multi-threaded
process calls fork(), the new process shall contain a replica of the
calling thread and its entire address space, possibly including the states
of mutexes and other resources. Consequently, to avoid errors, the child
process may only execute async-signal-safe operations until such time as
one of the exec functions is called.
https://pubs.opengroup.org/onlinepubs/9699919799/
Best regards,
Christian Schoenebeck
next prev parent reply other threads:[~2020-08-26 13:49 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-19 6:29 [PATCH v5 0/1] audio/jack: fix use after free segfault Geoffrey McRae
2020-08-19 6:29 ` [PATCH v5 1/1] " Geoffrey McRae
2020-08-19 15:21 ` Christian Schoenebeck
2020-08-19 15:27 ` Geoffrey McRae
2020-08-20 5:37 ` Gerd Hoffmann
2020-08-20 10:06 ` Christian Schoenebeck
2020-08-20 10:54 ` Paolo Bonzini
2020-08-20 12:00 ` Christian Schoenebeck
2020-08-21 13:13 ` Paolo Bonzini
2020-08-26 13:48 ` Christian Schoenebeck [this message]
2020-08-21 11:12 ` recursive locks (in general) Christian Schoenebeck
2020-08-21 13:08 ` Paolo Bonzini
2020-08-21 15:25 ` Christian Schoenebeck
2020-08-21 11:28 ` [PATCH v5 1/1] audio/jack: fix use after free segfault Geoffrey McRae
2020-08-21 13:13 ` Paolo Bonzini
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1803832.CiF9An4F11@silver \
--to=qemu_oss@crudebyte.com \
--cc=geoff@hostfission.com \
--cc=kraxel@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.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 NNTP newsgroup(s).