glibc/sysdeps
Stefan Liebler 314e181dc9 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.

(cherry picked from commit 403b4feb22)
2018-10-18 12:36:15 +02:00
..
aarch64 aarch64,falkor: Use vector registers for memcpy 2018-06-29 22:45:59 +05:30
alpha Mark _init and _fini as hidden [BZ #23145] 2018-06-08 10:28:52 -07:00
arm Mark _init and _fini as hidden [BZ #23145] 2018-06-08 10:28:52 -07:00
generic x86: Support IBT and SHSTK in Intel CET [BZ #21598] 2018-07-16 14:08:27 -07:00
gnu hurd: Fix shmid_ds's shm_segsz field type 2018-06-02 21:52:43 +02:00
hppa Mark _init and _fini as hidden [BZ #23145] 2018-06-08 10:28:52 -07:00
htl hurd: Avoid PLTs for __pthread_get/setspecific 2018-08-09 01:30:13 +02:00
hurd Fix ISO C threads installed header and HURD assumption 2018-07-25 17:27:45 -03:00
i386 i386: Use _dl_runtime_[resolve|profile]_shstk for SHSTK [BZ #23716] 2018-10-09 19:35:50 -07:00
ia64 Mark _init and _fini as hidden [BZ #23145] 2018-06-08 10:28:52 -07:00
ieee754 ldbl-128ibm-compat: Add printf_size 2018-07-02 10:51:01 -03:00
init_array sysdeps/init_array: Add PREINIT_FUNCTION to crti.S 2018-01-29 10:22:26 -08:00
m68k m68k: Reorganize log1p and significand implementations 2018-06-22 21:34:28 -03:00
mach hurd: Fix exec usage of mach_setup_thread 2018-08-01 00:10:03 +02:00
microblaze Mark _init and _fini as hidden [BZ #23145] 2018-06-08 10:28:52 -07:00
mips Mark _init and _fini as hidden [BZ #23145] 2018-06-08 10:28:52 -07:00
nios2 Mark _init and _fini as hidden [BZ #23145] 2018-06-08 10:28:52 -07:00
nptl Fix race in pthread_mutex_lock while promoting to PTHREAD_MUTEX_ELISION_NP [BZ #23275] 2018-10-18 12:36:15 +02:00
posix Fix Linux fcntl OFD locks for non-LFS architectures (BZ#20251) 2018-06-26 13:22:53 -03:00
powerpc Update powerpc-nofpu ulps. 2018-07-26 22:51:06 +00:00
pthread hurd: fix sigevent's sigev_notify_attributes field type 2018-04-19 21:43:44 +02:00
riscv Regen RISC-V rvd ULPs 2018-08-22 18:55:44 +02:00
s390 Mark _init and _fini as hidden [BZ #23145] 2018-06-08 10:28:52 -07:00
sh Update SH libm-tests-ulps 2018-07-31 10:33:53 -03:00
sparc Mark _init and _fini as hidden [BZ #23145] 2018-06-08 10:28:52 -07:00
unix Fix race in pthread_mutex_lock while promoting to PTHREAD_MUTEX_ELISION_NP [BZ #23275] 2018-10-18 12:36:15 +02:00
wordsize-32 Use libc_hidden_* for strtoumax (bug 15105). 2018-02-28 14:16:21 +00:00
wordsize-64 Use libc_hidden_* for strtoumax (bug 15105). 2018-02-28 14:16:21 +00:00
x86 x86/CET: Fix property note parser [BZ #23467] 2018-07-30 16:15:38 -07:00
x86_64 x86: Rename __glibc_reserved2 to ssp_base in tcbhead_t 2018-07-25 04:39:39 -07:00