From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39048) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YTua1-0005dS-Va for qemu-devel@nongnu.org; Fri, 06 Mar 2015 10:54:26 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YTuZx-0000P7-NY for qemu-devel@nongnu.org; Fri, 06 Mar 2015 10:54:25 -0500 Received: from mx1.redhat.com ([209.132.183.28]:42708) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YTuZx-0000Ow-Fj for qemu-devel@nongnu.org; Fri, 06 Mar 2015 10:54:21 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t26FsKe9032472 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Fri, 6 Mar 2015 10:54:20 -0500 Message-ID: <54F9CDAB.6030602@redhat.com> Date: Fri, 06 Mar 2015 08:54:19 -0700 From: Eric Blake MIME-Version: 1.0 References: <1425633735-26796-1-git-send-email-pbonzini@redhat.com> <1425633735-26796-2-git-send-email-pbonzini@redhat.com> In-Reply-To: <1425633735-26796-2-git-send-email-pbonzini@redhat.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="MN30dQKpmxdGD6A6pmlJ1ush5fFd5fAbv" Subject: Re: [Qemu-devel] [PATCH 1/2] qemu-thread: do not use PTHREAD_MUTEX_ERRORCHECK List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Paolo Bonzini , qemu-devel@nongnu.org This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --MN30dQKpmxdGD6A6pmlJ1ush5fFd5fAbv Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 03/06/2015 02:22 AM, Paolo Bonzini wrote: > PTHREAD_MUTEX_ERRORCHECK is completely broken with respect to fork. > The way to safely do fork is to bring all threads to a quiescent > state by acquiring locks (either in callers---as we do for the > iothread mutex---or using pthread_atfork's prepare callbacks) > and then release them in the child. That, and POSIX itself says that pthread_atfork is a dangerous API, and should not be used if at all possible, because it is broken by design. >=20 > The problem is that releasing error-checking locks in the child > fails under glibc with EPERM, because the mutex stores a different > owner tid than the duplicated thread in the child process. Is that a bug in glibc? > We > could make it work for locks acquired via pthread_atfork, by > recreating the mutex in the child instead of unlocking it > (we know that there are no other threads that could have taken > the mutex; but when the lock is acquired in fork's caller > that would not be possible. >=20 > The simplest solution is just to forgo error checking. >=20 > Signed-off-by: Paolo Bonzini > --- > util/qemu-thread-posix.c | 6 +----- > 1 file changed, 1 insertion(+), 5 deletions(-) I'm not sure that weakening things is always the wisest idea, but you've provided some good arguments for why we want it here, so: Reviewed-by: Eric Blake >=20 > diff --git a/util/qemu-thread-posix.c b/util/qemu-thread-posix.c > index 50a29d8..ba67cec 100644 > --- a/util/qemu-thread-posix.c > +++ b/util/qemu-thread-posix.c > @@ -51,12 +51,8 @@ static void error_exit(int err, const char *msg) > void qemu_mutex_init(QemuMutex *mutex) > { > int err; > - pthread_mutexattr_t mutexattr; > =20 > - pthread_mutexattr_init(&mutexattr); > - pthread_mutexattr_settype(&mutexattr, PTHREAD_MUTEX_ERRORCHECK); > - err =3D pthread_mutex_init(&mutex->lock, &mutexattr); > - pthread_mutexattr_destroy(&mutexattr); > + err =3D pthread_mutex_init(&mutex->lock, NULL); > if (err) > error_exit(err, __func__); > } >=20 --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --MN30dQKpmxdGD6A6pmlJ1ush5fFd5fAbv Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBCAAGBQJU+c2rAAoJEKeha0olJ0NqfYgIAIeC9wIwiEBMe8snJhkXSGsr G2HsYm8KRXuVzENJHSNwkho3af/EAu5EoRSjbMnHXuqJrikkikvnu5tKCy6e0/ov 2SlwZJyVlH3w+tf2GB2JquDP+xwvfoLQEICnCIpcg3cTJmtgxorSyQx1T4vs7tmE 4QOtJOVB8OYDHwEWWFpJWEbx47Bmw+TDFl0kZb4itUhN1erq86Zq+6KPSHr+ke5j TJlMeZ+on5sEepkU+XQKFGCqRxcx7opmg80NP367gQK22Zwn/nW21E9siIGfc3eM fKOIVo0/e+PuDJOkPt60lpn4yEaKcJnS24uBuK2DNdOu0VxpKiIvhkmTyfAg0k4= =s7No -----END PGP SIGNATURE----- --MN30dQKpmxdGD6A6pmlJ1ush5fFd5fAbv--