glibc/sysdeps/nptl
Stefan Liebler 403b4feb22 Fix race in pthread_mutex_lock while promoting to PTHREAD_MUTEX_ELISION_NP [BZ #23275]
The race leads either to pthread_mutex_destroy returning EBUSY
or triggering an assertion (See description in bugzilla).

This patch is fixing the race by ensuring that the elision path is
used in all cases if elision is enabled by the GLIBC_TUNABLES framework.

The __kind variable in struct __pthread_mutex_s is accessed concurrently.
Therefore we are now using the atomic macros.

The new testcase tst-mutex10 is triggering the race on s390x and intel.
Presumably also on power, but I don't have access to a power machine
with lock-elision. At least the code for power is the same as on the other
two architectures.

ChangeLog:

	[BZ #23275]
	* nptl/tst-mutex10.c: New File.
	* nptl/Makefile (tests): Add tst-mutex10.
	(tst-mutex10-ENV): New variable.
	* sysdeps/unix/sysv/linux/s390/force-elision.h: (FORCE_ELISION):
	Ensure that elision path is used if elision is available.
	* sysdeps/unix/sysv/linux/powerpc/force-elision.h (FORCE_ELISION):
	Likewise.
	* sysdeps/unix/sysv/linux/x86/force-elision.h: (FORCE_ELISION):
	Likewise.
	* nptl/pthreadP.h (PTHREAD_MUTEX_TYPE, PTHREAD_MUTEX_TYPE_ELISION)
	(PTHREAD_MUTEX_PSHARED): Use atomic_load_relaxed.
	* nptl/pthread_mutex_consistent.c (pthread_mutex_consistent): Likewise.
	* nptl/pthread_mutex_getprioceiling.c (pthread_mutex_getprioceiling):
	Likewise.
	* nptl/pthread_mutex_lock.c (__pthread_mutex_lock_full)
	(__pthread_mutex_cond_lock_adjust): Likewise.
	* nptl/pthread_mutex_setprioceiling.c (pthread_mutex_setprioceiling):
	Likewise.
	* nptl/pthread_mutex_timedlock.c (__pthread_mutex_timedlock): Likewise.
	* nptl/pthread_mutex_trylock.c (__pthread_mutex_trylock): Likewise.
	* nptl/pthread_mutex_unlock.c (__pthread_mutex_unlock_full): Likewise.
	* sysdeps/nptl/bits/thread-shared-types.h (struct __pthread_mutex_s):
	Add comments.
	* nptl/pthread_mutex_destroy.c (__pthread_mutex_destroy):
	Use atomic_load_relaxed and atomic_store_relaxed.
	* nptl/pthread_mutex_init.c (__pthread_mutex_init):
	Use atomic_store_relaxed.
2018-10-17 12:23:04 +02:00
..
bits Fix race in pthread_mutex_lock while promoting to PTHREAD_MUTEX_ELISION_NP [BZ #23275] 2018-10-17 12:23:04 +02:00
sys Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
Implies Get rid of nptl/sysdeps/pthread/ subdirectory 2014-06-12 13:48:47 -07:00
Makeconfig nptl: Move pthread_atfork to libc_nonshared.a 2018-03-01 08:18:48 +01:00
Makefile Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
Subdirs Get rid of nptl/sysdeps/pthread/ subdirectory 2014-06-12 13:48:47 -07:00
aio_misc.h Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
allocrtsig.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
fork.c Refactor Linux ARCH_FORK implementation 2018-03-07 17:39:40 -03:00
fork.h Refactor atfork handlers 2018-02-22 16:43:59 -03:00
futex-internal.h [BZ #20271] Add newlines in __libc_fatal calls. 2018-08-31 18:04:32 -07:00
gai_misc.h Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
internaltypes.h Fix comment typo 2018-05-08 14:59:13 +02:00
jmp-unwind.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
libc-lock.h Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
libc-lockP.h Refactor atfork handlers 2018-02-22 16:43:59 -03:00
librt-cancellation.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
lowlevellock-futex.h Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
lowlevellock.h Fix blocking pthread_join. [BZ #23137] 2018-05-04 10:00:59 +02:00
malloc-machine.h Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
pthread-functions.h libc: Extend __libc_freeres framework (Bug 23329). 2018-06-29 22:39:06 -04:00
pthread.h Revert Intel CET changes to __jmp_buf_tag (Bug 22743) 2018-01-25 23:43:46 -08:00
setxid.h Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
shm-directory.h Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
stdio-lock.h Mechanically remove _IO_ name aliases for types and constants. 2018-02-21 14:11:05 -05:00
tcb-offsets.h Get rid of nptl/sysdeps/pthread/ subdirectory 2014-06-12 13:48:47 -07:00
threads.h Fix ISO C threads installed header and HURD assumption 2018-07-25 17:27:45 -03:00
timer_routines.h Move NPTL-specific code to NPTL-specific header 2018-02-27 00:48:24 +01:00
tst-mqueue8x.c Get rid of nptl/sysdeps/pthread/ subdirectory 2014-06-12 13:48:47 -07:00
unwind-forcedunwind.c libc: Extend __libc_freeres framework (Bug 23329). 2018-06-29 22:39:06 -04:00