aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAriadne Conill <ariadne@dereferenced.org>2020-05-22 11:57:07 -0600
committerAriadne Conill <ariadne@dereferenced.org>2020-05-22 11:57:34 -0600
commitafc38b4a14533b4d1c22a11c1b248be0372ec040 (patch)
treefdd35de63017b00cdb80da7a2609a14531ecfe18
parent1db1e7109f49b3346387a288c2433b01c5d90a49 (diff)
downloadaports-afc38b4a14533b4d1c22a11c1b248be0372ec040.tar.gz
aports-afc38b4a14533b4d1c22a11c1b248be0372ec040.tar.bz2
aports-afc38b4a14533b4d1c22a11c1b248be0372ec040.tar.xz
main/musl: don't use libc.threads_minus_1 to bypass locking in threaded mode
-rw-r--r--main/musl/APKBUILD4
-rw-r--r--main/musl/dont-use-threads-minus-1-for-skipping-locks.patch70
2 files changed, 73 insertions, 1 deletions
diff --git a/main/musl/APKBUILD b/main/musl/APKBUILD
index 579bc56409..c68fe9eff7 100644
--- a/main/musl/APKBUILD
+++ b/main/musl/APKBUILD
@@ -2,7 +2,7 @@
# Maintainer: Timo Teräs <timo.teras@iki.fi>
pkgname=musl
pkgver=1.1.24
-pkgrel=7
+pkgrel=8
pkgdesc="the musl c library (libc) implementation"
url="https://musl.libc.org/"
arch="all"
@@ -31,6 +31,7 @@ source="https://musl.libc.org/releases/musl-$pkgver.tar.gz
ppc64-fpregset_t.patch
fix-remaining-direct-use-of-stat-syscalls-outside.patch
set-AD-bit-in-dns-queries-suppress-for-internal-use.patch
+ dont-use-threads-minus-1-for-skipping-locks.patch
ldconfig
__stack_chk_fail_local.c
@@ -186,6 +187,7 @@ e7133ce2f0b172e2da03567e41f03bef58b6ff8eaac614494751228bcc102c39cbe312f0beb567c5
3de8e50519e33a55d2cc737b56011a7178d1c83230477d46e11e67195e08e74bff735c6013de6ff170bb2390e89bfca9919cc8728c064b3eeaab2035dd7e5c08 ppc64-fpregset_t.patch
d277e45af78ed2bd9f556ae30636783fc401b4d0a339d6e37b77f18ed1486f48fc631e3455f8764ddbc7d9aba41a270ab345ec3495955dfd22b27a306441ba2a fix-remaining-direct-use-of-stat-syscalls-outside.patch
dd46ef77b71d34b6207611be59dd4555b4e53fd7169732b9e5ee9a66f1e8da69fcca6634f895b9d34d8861d37ac0eaa86618f5f3f3a81cf9c47321d1c5d37ee5 set-AD-bit-in-dns-queries-suppress-for-internal-use.patch
+1372f9ddcfd48df8929ea5af76dd5e806f89c9d7b70b8a19b8480987b7fab5632e939370f4160cd2c132549cfcda0f4470ad5b2d46f74fd615ef1e9f2f77a72c dont-use-threads-minus-1-for-skipping-locks.patch
8d3a2d5315fc56fee7da9abb8b89bb38c6046c33d154c10d168fb35bfde6b0cf9f13042a3bceee34daf091bc409d699223735dcf19f382eeee1f6be34154f26f ldconfig
062bb49fa54839010acd4af113e20f7263dde1c8a2ca359b5fb2661ef9ed9d84a0f7c3bc10c25dcfa10bb3c5a4874588dff636ac43d5dbb3d748d75400756d0b __stack_chk_fail_local.c
0d80f37b34a35e3d14b012257c50862dfeb9d2c81139ea2dfa101d981d093b009b9fa450ba27a708ac59377a48626971dfc58e20a3799084a65777a0c32cbc7d getconf.c
diff --git a/main/musl/dont-use-threads-minus-1-for-skipping-locks.patch b/main/musl/dont-use-threads-minus-1-for-skipping-locks.patch
new file mode 100644
index 0000000000..6d40ebacf4
--- /dev/null
+++ b/main/musl/dont-use-threads-minus-1-for-skipping-locks.patch
@@ -0,0 +1,70 @@
+commit cbcb082e045e28abce2b3f72e922c6ccdcb96c06
+Author: Rich Felker <dalias@aerifal.cx>
+Date: Thu May 21 23:32:45 2020 -0400
+
+ don't use libc.threads_minus_1 as relaxed atomic for skipping locks
+
+ after all but the last thread exits, the next thread to observe
+ libc.threads_minus_1==0 and conclude that it can skip locking fails to
+ synchronize with any changes to memory that were made by the
+ last-exiting thread. this can produce data races.
+
+ on some archs, at least x86, memory synchronization is unlikely to be
+ a problem; however, with the inline locks in malloc, skipping the lock
+ also eliminated the compiler barrier, and caused code that needed to
+ re-check chunk in-use bits after obtaining the lock to reuse a stale
+ value, possibly from before the process became single-threaded. this
+ in turn produced corruption of the heap state.
+
+ some uses of libc.threads_minus_1 remain, especially for allocation of
+ new TLS in the dynamic linker; otherwise, it could be removed
+ entirely. it's made non-volatile to reflect that the remaining
+ accesses are only made under lock on the thread list.
+
+ instead of libc.threads_minus_1, libc.threaded is now used for
+ skipping locks. the difference is that libc.threaded is permanently
+ true once an additional thread has been created. this will produce
+ some performance regression in processes that are mostly
+ single-threaded but occasionally creating threads. in the future it
+ may be possible to bring back the full lock-skipping, but more care
+ needs to be taken to produce a safe design.
+
+diff --git a/src/internal/libc.h b/src/internal/libc.h
+index ac97dc7e..c0614852 100644
+--- a/src/internal/libc.h
++++ b/src/internal/libc.h
+@@ -21,7 +21,7 @@ struct __libc {
+ int can_do_threads;
+ int threaded;
+ int secure;
+- volatile int threads_minus_1;
++ int threads_minus_1;
+ size_t *auxv;
+ struct tls_module *tls_head;
+ size_t tls_size, tls_align, tls_cnt;
+diff --git a/src/malloc/malloc.c b/src/malloc/malloc.c
+index 96982596..2553a62e 100644
+--- a/src/malloc/malloc.c
++++ b/src/malloc/malloc.c
+@@ -26,7 +26,7 @@ int __malloc_replaced;
+
+ static inline void lock(volatile int *lk)
+ {
+- if (libc.threads_minus_1)
++ if (libc.threaded)
+ while(a_swap(lk, 1)) __wait(lk, lk+1, 1, 1);
+ }
+
+diff --git a/src/thread/__lock.c b/src/thread/__lock.c
+index 45557c88..5b9b144e 100644
+--- a/src/thread/__lock.c
++++ b/src/thread/__lock.c
+@@ -18,7 +18,7 @@
+
+ void __lock(volatile int *l)
+ {
+- if (!libc.threads_minus_1) return;
++ if (!libc.threaded) return;
+ /* fast path: INT_MIN for the lock, +1 for the congestion */
+ int current = a_cas(l, 0, INT_MIN + 1);
+ if (!current) return;