glibc: fix pthread_cond_broadcast issue (arm)

pthread_mutex functions such as pthread_cond_wait(), pthread_mutex_unlock() return
errors after PTHREAD_PRIO_INHERIT is enabled

Reference:
https://sourceware.org/bugzilla/show_bug.cgi?id=18463

Upstream patches:
https://sourceware.org/git/?p=glibc.git;a=commitdiff;h=f0e3925bf3b8df6940c3346db17e42615979d458
https://sourceware.org/git/?p=glibc.git;a=commitdiff;h=13cb8f76da9d9420330796f469dbf10643ba5b12
https://sourceware.org/git/?p=glibc.git;a=commitdiff;h=23b5cae1af04f2d912910fdaf73cb482265798c1
https://sourceware.org/git/?p=glibc.git;a=commitdiff;h=ed19993b5b0d05d62cc883571519a67dae481a14
https://sourceware.org/git/?p=glibc.git;a=commitdiff;h=2e4cf778972573221e9b87fd992844ea9b67b9bf
https://sourceware.org/git/?p=glibc.git;a=commitdiff;h=abff18c0c6055ca5d1cd46923fd1205c057139a5

This issue is Morty specific (glibc 2.24).
The issue is no longer present in glibc 2.25 (master branch).

(From OE-Core rev: 6dc1f1c3cc871d00ecd59d5aeeef86b7e6965750)

Signed-off-by: Catalin Enache <catalin.enache@windriver.com>
Signed-off-by: Armin Kuster <akuster808@gmail.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Catalin Enache
2017-07-07 19:43:34 +03:00
committed by Richard Purdie
parent 5b2a7393f9
commit e6955b7d0d
7 changed files with 10786 additions and 0 deletions

View File

@@ -0,0 +1,58 @@
From ce74a620bf9e1a40b7ba06d35160e20633a4d8bb Mon Sep 17 00:00:00 2001
From: Catalin Enache <catalin.enache@windriver.com>
Date: Fri, 7 Jul 2017 13:11:16 +0300
Subject: [PATCH 1/6] Add atomic_exchange_relaxed.
* include/atomic.h (atomic_exchange_relaxed): New
Upstream-Status: Backport
Author: Torvald Riegel <triegel@redhat.com>
Signed-off-by: Catalin Enache <catalin.enache@windriver.com>
---
ChangeLog | 4 ++++
include/atomic.h | 9 +++++++++
2 files changed, 13 insertions(+)
diff --git a/ChangeLog b/ChangeLog
index 0fbda90..cb87279 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2016-08-05 Torvald Riegel <triegel@redhat.com>
+
+ * include/atomic.h (atomic_exchange_relaxed): New.
+
2016-01-28 Carlos O'Donell <carlos@redhat.com>
Alexey Makhalov <amakhalov@vmware.com>
Florian Weimer <fweimer@redhat.com>
diff --git a/include/atomic.h b/include/atomic.h
index ad3db25..129ee24 100644
--- a/include/atomic.h
+++ b/include/atomic.h
@@ -588,6 +588,9 @@ void __atomic_link_error (void);
__atomic_compare_exchange_n ((mem), (expected), (desired), 1, \
__ATOMIC_RELEASE, __ATOMIC_RELAXED); })
+# define atomic_exchange_relaxed(mem, desired) \
+ ({ __atomic_check_size((mem)); \
+ __atomic_exchange_n ((mem), (desired), __ATOMIC_RELAXED); })
# define atomic_exchange_acquire(mem, desired) \
({ __atomic_check_size((mem)); \
__atomic_exchange_n ((mem), (desired), __ATOMIC_ACQUIRE); })
@@ -684,6 +687,12 @@ void __atomic_link_error (void);
*(expected) == __atg103_expected; })
# endif
+/* XXX Fall back to acquire MO because archs do not define a weaker
+ atomic_exchange. */
+# ifndef atomic_exchange_relaxed
+# define atomic_exchange_relaxed(mem, val) \
+ atomic_exchange_acq ((mem), (val))
+# endif
# ifndef atomic_exchange_acquire
# define atomic_exchange_acquire(mem, val) \
atomic_exchange_acq ((mem), (val))
--
2.10.2

View File

@@ -0,0 +1,124 @@
From b85e30e655027132c4326d2fdde010c517165aaf Mon Sep 17 00:00:00 2001
From: Catalin Enache <catalin.enache@windriver.com>
Date: Fri, 30 Jun 2017 14:27:34 +0300
Subject: [PATCH 2/6] Add atomic operations required by the new condition
variable.
* include/atomic.h (atomic_fetch_and_relaxed,
atomic_fetch_and_release, atomic_fetch_or_release,
atomic_fetch_xor_release): New.
Upstream-Status: Backport
Author: Torvald Riegel <triegel@redhat.com>
Signed-off-by: Catalin Enache <catalin.enache@windriver.com>
---
ChangeLog | 6 ++++++
include/atomic.h | 47 +++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 53 insertions(+)
diff --git a/ChangeLog b/ChangeLog
index cb87279..96b6da2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2016-08-09 Torvald Riegel <triegel@redhat.com>
+
+ * include/atomic.h (atomic_fetch_and_relaxed,
+ atomic_fetch_and_release, atomic_fetch_or_release,
+ atomic_fetch_xor_release): New.
+
2016-08-05 Torvald Riegel <triegel@redhat.com>
* include/atomic.h (atomic_exchange_relaxed): New.
diff --git a/include/atomic.h b/include/atomic.h
index 129ee24..5a8e7e7 100644
--- a/include/atomic.h
+++ b/include/atomic.h
@@ -611,9 +611,15 @@ void __atomic_link_error (void);
({ __atomic_check_size((mem)); \
__atomic_fetch_add ((mem), (operand), __ATOMIC_ACQ_REL); })
+# define atomic_fetch_and_relaxed(mem, operand) \
+ ({ __atomic_check_size((mem)); \
+ __atomic_fetch_and ((mem), (operand), __ATOMIC_RELAXED); })
# define atomic_fetch_and_acquire(mem, operand) \
({ __atomic_check_size((mem)); \
__atomic_fetch_and ((mem), (operand), __ATOMIC_ACQUIRE); })
+# define atomic_fetch_and_release(mem, operand) \
+ ({ __atomic_check_size((mem)); \
+ __atomic_fetch_and ((mem), (operand), __ATOMIC_RELEASE); })
# define atomic_fetch_or_relaxed(mem, operand) \
({ __atomic_check_size((mem)); \
@@ -621,6 +627,13 @@ void __atomic_link_error (void);
# define atomic_fetch_or_acquire(mem, operand) \
({ __atomic_check_size((mem)); \
__atomic_fetch_or ((mem), (operand), __ATOMIC_ACQUIRE); })
+# define atomic_fetch_or_release(mem, operand) \
+ ({ __atomic_check_size((mem)); \
+ __atomic_fetch_or ((mem), (operand), __ATOMIC_RELEASE); })
+
+# define atomic_fetch_xor_release(mem, operand) \
+ ({ __atomic_check_size((mem)); \
+ __atomic_fetch_xor ((mem), (operand), __ATOMIC_RELEASE); })
#else /* !USE_ATOMIC_COMPILER_BUILTINS */
@@ -724,12 +737,24 @@ void __atomic_link_error (void);
atomic_exchange_and_add_acq ((mem), (operand)); })
# endif
+/* XXX Fall back to acquire MO because archs do not define a weaker
+ atomic_and_val. */
+# ifndef atomic_fetch_and_relaxed
+# define atomic_fetch_and_relaxed(mem, operand) \
+ atomic_fetch_and_acquire ((mem), (operand))
+# endif
/* XXX The default for atomic_and_val has acquire semantics, but this is not
documented. */
# ifndef atomic_fetch_and_acquire
# define atomic_fetch_and_acquire(mem, operand) \
atomic_and_val ((mem), (operand))
# endif
+# ifndef atomic_fetch_and_release
+/* XXX This unnecessarily has acquire MO. */
+# define atomic_fetch_and_release(mem, operand) \
+ ({ atomic_thread_fence_release (); \
+ atomic_and_val ((mem), (operand)); })
+# endif
/* XXX The default for atomic_or_val has acquire semantics, but this is not
documented. */
@@ -743,6 +768,28 @@ void __atomic_link_error (void);
# define atomic_fetch_or_relaxed(mem, operand) \
atomic_fetch_or_acquire ((mem), (operand))
# endif
+/* XXX Contains an unnecessary acquire MO because archs do not define a weaker
+ atomic_or_val. */
+# ifndef atomic_fetch_or_release
+# define atomic_fetch_or_release(mem, operand) \
+ ({ atomic_thread_fence_release (); \
+ atomic_fetch_or_acquire ((mem), (operand)); })
+# endif
+
+# ifndef atomic_fetch_xor_release
+# define atomic_fetch_xor_release(mem, operand) \
+ ({ __typeof (*(mem)) __atg104_old; \
+ __typeof (mem) __atg104_memp = (mem); \
+ __typeof (*(mem)) __atg104_op = (operand); \
+ \
+ do \
+ __atg104_old = (*__atg104_memp); \
+ while (__builtin_expect \
+ (atomic_compare_and_exchange_bool_rel ( \
+ __atg104_memp, __atg104_old ^ __atg104_op, __atg104_old), 0));\
+ \
+ __atg104_old; })
+#endif
#endif /* !USE_ATOMIC_COMPILER_BUILTINS */
--
2.10.2

View File

@@ -0,0 +1,149 @@
From 27b7131d3d8133bf3a5ce72d4e4ff4dfadd71f20 Mon Sep 17 00:00:00 2001
From: Catalin Enache <catalin.enache@windriver.com>
Date: Fri, 30 Jun 2017 12:08:29 +0300
Subject: [PATCH 5/6] Remove __ASSUME_REQUEUE_PI
The new cond var implementation (ed19993b5b0d) removed all the
__ASSUME_{REQUEUE_PI,FUTEX_LOCK_PI} internal usage so there is no
need to keep defining it. This patch removes all USE_REQUEUE_PI
and __ASSUME_REQUEUE_PI. It is as follow up from BZ#18463.
Checked with a build for x86_64-linux-gnu, arm-linux-gnueabhf,
m68-linux-gnu, mips64-linux-gnu, and sparc64-linux-gnu.
* nptl/pthreadP.h (USE_REQUEUE_PI): Remove ununsed macro.
* sysdeps/unix/sysv/linux/arm/kernel-features.h
(__ASSUME_REQUEUE_PI): Likewise.
* sysdeps/unix/sysv/linux/kernel-features.h
(__ASSUME_REQUEUE_PI): Likewise.
* sysdeps/unix/sysv/linux/m68k/kernel-features.h
(__ASSUME_REQUEUE_PI): Likewise.
* sysdeps/unix/sysv/linux/mips/kernel-features.h
(__ASSUME_REQUEUE_PI): Likewise.
* sysdeps/unix/sysv/linux/sparc/kernel-features.h
(__ASSUME_REQUEUE_PI): Likewise.
Upstream-Status: Backport
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Signed-off-by: Catalin Enache <catalin.enache@windriver.com>
---
ChangeLog | 14 ++++++++++++++
nptl/pthreadP.h | 12 ------------
sysdeps/unix/sysv/linux/arm/kernel-features.h | 1 -
sysdeps/unix/sysv/linux/kernel-features.h | 5 -----
sysdeps/unix/sysv/linux/m68k/kernel-features.h | 1 -
sysdeps/unix/sysv/linux/mips/kernel-features.h | 1 -
sysdeps/unix/sysv/linux/sparc/kernel-features.h | 1 -
7 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index c94db7b..44c518b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2017-04-04 Adhemerval Zanella <adhemerval.zanella@linaro.org>
+
+ * nptl/pthreadP.h (USE_REQUEUE_PI): Remove ununsed macro.
+ * sysdeps/unix/sysv/linux/arm/kernel-features.h
+ (__ASSUME_REQUEUE_PI): Likewise.
+ * sysdeps/unix/sysv/linux/kernel-features.h
+ (__ASSUME_REQUEUE_PI): Likewise.
+ * sysdeps/unix/sysv/linux/m68k/kernel-features.h
+ (__ASSUME_REQUEUE_PI): Likewise.
+ * sysdeps/unix/sysv/linux/mips/kernel-features.h
+ (__ASSUME_REQUEUE_PI): Likewise.
+ * sysdeps/unix/sysv/linux/sparc/kernel-features.h
+ (__ASSUME_REQUEUE_PI): Likewise.
+
2016-12-31 Torvald Riegel <triegel@redhat.com>
[BZ #13165]
diff --git a/nptl/pthreadP.h b/nptl/pthreadP.h
index e9992bc..730c4ad 100644
--- a/nptl/pthreadP.h
+++ b/nptl/pthreadP.h
@@ -594,18 +594,6 @@ extern void __wait_lookup_done (void) attribute_hidden;
# define PTHREAD_STATIC_FN_REQUIRE(name) __asm (".globl " #name);
#endif
-/* Test if the mutex is suitable for the FUTEX_WAIT_REQUEUE_PI operation. */
-#if (defined lll_futex_wait_requeue_pi \
- && defined __ASSUME_REQUEUE_PI)
-# define USE_REQUEUE_PI(mut) \
- ((mut) && (mut) != (void *) ~0l \
- && (((mut)->__data.__kind \
- & (PTHREAD_MUTEX_PRIO_INHERIT_NP | PTHREAD_MUTEX_ROBUST_NORMAL_NP)) \
- == PTHREAD_MUTEX_PRIO_INHERIT_NP))
-#else
-# define USE_REQUEUE_PI(mut) 0
-#endif
-
/* Returns 0 if POL is a valid scheduling policy. */
static inline int
check_sched_policy_attr (int pol)
diff --git a/sysdeps/unix/sysv/linux/arm/kernel-features.h b/sysdeps/unix/sysv/linux/arm/kernel-features.h
index 6ca607e..339ad45 100644
--- a/sysdeps/unix/sysv/linux/arm/kernel-features.h
+++ b/sysdeps/unix/sysv/linux/arm/kernel-features.h
@@ -23,7 +23,6 @@
futex_atomic_cmpxchg_inatomic, depending on kernel
configuration. */
#if __LINUX_KERNEL_VERSION < 0x030E03
-# undef __ASSUME_REQUEUE_PI
# undef __ASSUME_SET_ROBUST_LIST
#endif
diff --git a/sysdeps/unix/sysv/linux/kernel-features.h b/sysdeps/unix/sysv/linux/kernel-features.h
index 1d3b554..9f2cf9f 100644
--- a/sysdeps/unix/sysv/linux/kernel-features.h
+++ b/sysdeps/unix/sysv/linux/kernel-features.h
@@ -101,11 +101,6 @@
#define __ASSUME_PREADV 1
#define __ASSUME_PWRITEV 1
-/* Support for FUTEX_*_REQUEUE_PI was added in 2.6.31 (but some
- architectures lack futex_atomic_cmpxchg_inatomic in some
- configurations). */
-#define __ASSUME_REQUEUE_PI 1
-
/* Support for recvmmsg functionality was added in 2.6.33. The macros
defined correspond to those for accept4. */
#if __LINUX_KERNEL_VERSION >= 0x020621
diff --git a/sysdeps/unix/sysv/linux/m68k/kernel-features.h b/sysdeps/unix/sysv/linux/m68k/kernel-features.h
index 46ec601..174c1c6 100644
--- a/sysdeps/unix/sysv/linux/m68k/kernel-features.h
+++ b/sysdeps/unix/sysv/linux/m68k/kernel-features.h
@@ -51,6 +51,5 @@
/* No support for PI futexes or robust mutexes before 3.10 for m68k. */
#if __LINUX_KERNEL_VERSION < 0x030a00
-# undef __ASSUME_REQUEUE_PI
# undef __ASSUME_SET_ROBUST_LIST
#endif
diff --git a/sysdeps/unix/sysv/linux/mips/kernel-features.h b/sysdeps/unix/sysv/linux/mips/kernel-features.h
index b486d90..a795911c 100644
--- a/sysdeps/unix/sysv/linux/mips/kernel-features.h
+++ b/sysdeps/unix/sysv/linux/mips/kernel-features.h
@@ -24,7 +24,6 @@
/* The MIPS kernel does not support futex_atomic_cmpxchg_inatomic if
emulating LL/SC. */
#if __mips == 1 || defined _MIPS_ARCH_R5900
-# undef __ASSUME_REQUEUE_PI
# undef __ASSUME_SET_ROBUST_LIST
#endif
diff --git a/sysdeps/unix/sysv/linux/sparc/kernel-features.h b/sysdeps/unix/sysv/linux/sparc/kernel-features.h
index 69c9c7c..dd3ddf0 100644
--- a/sysdeps/unix/sysv/linux/sparc/kernel-features.h
+++ b/sysdeps/unix/sysv/linux/sparc/kernel-features.h
@@ -34,6 +34,5 @@
/* 32-bit SPARC kernels do not support
futex_atomic_cmpxchg_inatomic. */
#if !defined __arch64__ && !defined __sparc_v9__
-# undef __ASSUME_REQUEUE_PI
# undef __ASSUME_SET_ROBUST_LIST
#endif
--
2.10.2

View File

@@ -0,0 +1,81 @@
From b671f20cc160238b62894d032a55baf85867106e Mon Sep 17 00:00:00 2001
From: Catalin Enache <catalin.enache@windriver.com>
Date: Fri, 30 Jun 2017 19:12:43 +0300
Subject: [PATCH 6/6] Fix atomic_fetch_xor_release.
No code uses atomic_fetch_xor_release except for the upcoming
conditional variable rewrite. Therefore there is no user
visible bug here. The use of atomic_compare_and_exchange_bool_rel
is removed (since it doesn't exist anymore), and is replaced
by atomic_compare_exchange_weak_release.
We use weak_release because it provides better performance in
the loop (the weak semantic) and because the xor is release MO
(the release semantic). We don't reload expected in the loop
because atomic_compare_and_exchange_weak_release does this for
us as part of the CAS failure.
It is otherwise a fairly plain conversion that fixes building
the new condvar for 32-bit x86. Passes all regression tests
for x86.
Upstream-Status: Backport
Author: Carlos O'Donell <carlos@systemhalted.org>
Signed-off-by: Catalin Enache <catalin.enache@windriver.com>
---
ChangeLog | 6 ++++++
include/atomic.h | 19 +++++++++++--------
2 files changed, 17 insertions(+), 8 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 44c518b..893262d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2016-10-26 Carlos O'Donell <carlos@redhat.com>
+
+ * include/atomic.h
+ [USE_COMPILER_ATOMIC_BUILTINS && !atomic_fetch_xor_release]
+ (atomic_fetch_xor_release): Use atomic_compare_exchange_weak_release.
+
2017-04-04 Adhemerval Zanella <adhemerval.zanella@linaro.org>
* nptl/pthreadP.h (USE_REQUEUE_PI): Remove ununsed macro.
diff --git a/include/atomic.h b/include/atomic.h
index 5a8e7e7..c8b4664 100644
--- a/include/atomic.h
+++ b/include/atomic.h
@@ -777,18 +777,21 @@ void __atomic_link_error (void);
# endif
# ifndef atomic_fetch_xor_release
+/* Failing the atomic_compare_exchange_weak_release reloads the value in
+ __atg104_expected, so we need only do the XOR again and retry. */
# define atomic_fetch_xor_release(mem, operand) \
- ({ __typeof (*(mem)) __atg104_old; \
- __typeof (mem) __atg104_memp = (mem); \
+ ({ __typeof (mem) __atg104_memp = (mem); \
+ __typeof (*(mem)) __atg104_expected = (*__atg104_memp); \
+ __typeof (*(mem)) __atg104_desired; \
__typeof (*(mem)) __atg104_op = (operand); \
\
do \
- __atg104_old = (*__atg104_memp); \
- while (__builtin_expect \
- (atomic_compare_and_exchange_bool_rel ( \
- __atg104_memp, __atg104_old ^ __atg104_op, __atg104_old), 0));\
- \
- __atg104_old; })
+ __atg104_desired = __atg104_expected ^ __atg104_op; \
+ while (__glibc_unlikely \
+ (atomic_compare_exchange_weak_release ( \
+ __atg104_memp, &__atg104_expected, __atg104_desired) \
+ == 0)); \
+ __atg104_expected; })
#endif
#endif /* !USE_ATOMIC_COMPILER_BUILTINS */
--
2.10.2

View File

@@ -39,6 +39,12 @@ SRC_URI = "${GLIBC_GIT_URI};branch=${SRCBRANCH};name=glibc \
file://0026-build_local_scope.patch \
file://0028-Bug-20116-Fix-use-after-free-in-pthread_create.patch \
file://CVE-2016-6323.patch \
file://0001-Add-atomic_exchange_relaxed.patch \
file://0002-Add-atomic-operations-required-by-the-new-condition-.patch \
file://0003-Add-pretty-printers-for-the-NPTL-lock-types.patch \
file://0004-New-condvar-implementation-that-provides-stronger-or.patch \
file://0005-Remove-__ASSUME_REQUEUE_PI.patch \
file://0006-Fix-atomic_fetch_xor_release.patch \
"
SRC_URI += "\