- Handle EAGAIN from FUTEX_WAIT_REQUEUE_PI (#552960)

- Add {dist}
  - Correct return value from pthread_create when stack alloction fails.
This commit is contained in:
Jeff Law 2011-12-15 21:56:41 -07:00
parent 341defed2c
commit 73a44fd641
3 changed files with 250 additions and 1 deletions

226
glibc-rh552960.patch Normal file
View File

@ -0,0 +1,226 @@
diff -rup a/nptl/sysdeps/unix/sysv/linux/i386/i486/pthread_cond_wait.S b/nptl/sysdeps/unix/sysv/linux/i386/i486/pthread_cond_wait.S
--- a/nptl/sysdeps/unix/sysv/linux/i386/i486/pthread_cond_wait.S 2011-12-15 10:45:09.759232551 -0700
+++ b/nptl/sysdeps/unix/sysv/linux/i386/i486/pthread_cond_wait.S 2011-12-15 15:11:57.534479377 -0700
@@ -137,6 +137,7 @@ __pthread_cond_wait:
cmpl $PI_BIT, %eax
jne 18f
+90:
movl $(FUTEX_WAIT_REQUEUE_PI|FUTEX_PRIVATE_FLAG), %ecx
movl %ebp, %edx
xorl %esi, %esi
@@ -150,6 +151,9 @@ __pthread_cond_wait:
sete 16(%esp)
je 19f
+ cmpl $-EAGAIN, %eax
+ je 91f
+
/* Normal and PI futexes dont mix. Use normal futex functions only
if the kernel does not support the PI futex functions. */
cmpl $-ENOSYS, %eax
@@ -394,6 +398,78 @@ __pthread_cond_wait:
#endif
call __lll_unlock_wake
jmp 11b
+
+91:
+.LcleanupSTART2:
+ /* FUTEX_WAIT_REQUEUE_PI returned EAGAIN. We need to
+ call it again. */
+
+ /* Get internal lock. */
+ movl $1, %edx
+ xorl %eax, %eax
+ LOCK
+#if cond_lock == 0
+ cmpxchgl %edx, (%ebx)
+#else
+ cmpxchgl %edx, cond_lock(%ebx)
+#endif
+ jz 92f
+
+#if cond_lock == 0
+ movl %ebx, %edx
+#else
+ leal cond_lock(%ebx), %edx
+#endif
+#if (LLL_SHARED-LLL_PRIVATE) > 255
+ xorl %ecx, %ecx
+#endif
+ cmpl $-1, dep_mutex(%ebx)
+ setne %cl
+ subl $1, %ecx
+ andl $(LLL_SHARED-LLL_PRIVATE), %ecx
+#if LLL_PRIVATE != 0
+ addl $LLL_PRIVATE, %ecx
+#endif
+ call __lll_lock_wait
+
+92:
+ /* Increment the cond_futex value again, so it can be used as a new
+ expected value. */
+ addl $1, cond_futex(%ebx)
+ movl cond_futex(%ebx), %ebp
+
+ /* Unlock. */
+ LOCK
+#if cond_lock == 0
+ subl $1, (%ebx)
+#else
+ subl $1, cond_lock(%ebx)
+#endif
+ je 93f
+#if cond_lock == 0
+ movl %ebx, %eax
+#else
+ leal cond_lock(%ebx), %eax
+#endif
+#if (LLL_SHARED-LLL_PRIVATE) > 255
+ xorl %ecx, %ecx
+#endif
+ cmpl $-1, dep_mutex(%ebx)
+ setne %cl
+ subl $1, %ecx
+ andl $(LLL_SHARED-LLL_PRIVATE), %ecx
+#if LLL_PRIVATE != 0
+ addl $LLL_PRIVATE, %ecx
+#endif
+ call __lll_unlock_wake
+
+93:
+ /* Set the rest of SYS_futex args for FUTEX_WAIT_REQUEUE_PI. */
+ xorl %ecx, %ecx
+ movl dep_mutex(%ebx), %edi
+ jmp 90b
+.LcleanupEND2:
+
.size __pthread_cond_wait, .-__pthread_cond_wait
versioned_symbol (libpthread, __pthread_cond_wait, pthread_cond_wait,
GLIBC_2_3_2)
@@ -566,6 +642,10 @@ __condvar_w_cleanup:
.long .LcleanupEND-.Lsub_cond_futex
.long __condvar_w_cleanup-.LSTARTCODE
.uleb128 0
+ .long .LcleanupSTART2-.LSTARTCODE
+ .long .LcleanupEND2-.LcleanupSTART2
+ .long __condvar_w_cleanup-.LSTARTCODE
+ .uleb128 0
.long .LcallUR-.LSTARTCODE
.long .LENDCODE-.LcallUR
.long 0
diff -rup a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_wait.S b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_wait.S
--- a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_wait.S 2011-12-15 10:45:09.764232551 -0700
+++ b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_wait.S 2011-12-15 15:12:49.287474417 -0700
@@ -23,6 +23,7 @@
#include <lowlevelcond.h>
#include <tcb-offsets.h>
#include <pthread-pi-defines.h>
+#include <pthread-errnos.h>
#include <stap-probe.h>
#include <kernel-features.h>
@@ -136,11 +137,14 @@ __pthread_cond_wait:
cmpl $PI_BIT, %eax
jne 61f
+90:
movl $(FUTEX_WAIT_REQUEUE_PI|FUTEX_PRIVATE_FLAG), %esi
movl $SYS_futex, %eax
syscall
movl $1, %r8d
+ cmpq $-EAGAIN, %rax
+ je 91f
#ifdef __ASSUME_REQUEUE_PI
jmp 62f
#else
@@ -327,6 +331,70 @@ __pthread_cond_wait:
13: movq %r10, %rax
jmp 14b
+
+91:
+.LcleanupSTART2:
+ /* FUTEX_WAIT_REQUEUE_PI returned EAGAIN. We need to
+ call it again. */
+ movq 8(%rsp), %rdi
+
+ /* Get internal lock. */
+ movl $1, %esi
+ xorl %eax, %eax
+ LOCK
+#if cond_lock == 0
+ cmpxchgl %esi, (%rdi)
+#else
+ cmpxchgl %esi, cond_lock(%rdi)
+#endif
+ jz 92f
+
+#if cond_lock != 0
+ addq $cond_lock, %rdi
+#endif
+ cmpq $-1, dep_mutex-cond_lock(%rdi)
+ movl $LLL_PRIVATE, %eax
+ movl $LLL_SHARED, %esi
+ cmovne %eax, %esi
+ callq __lll_lock_wait
+#if cond_lock != 0
+ subq $cond_lock, %rdi
+#endif
+92:
+ /* Increment the cond_futex value again, so it can be used as a new
+ expected value. */
+ incl cond_futex(%rdi)
+ movl cond_futex(%rdi), %edx
+
+ /* Release internal lock. */
+ LOCK
+#if cond_lock == 0
+ decl (%rdi)
+#else
+ decl cond_lock(%rdi)
+#endif
+ jz 93f
+
+#if cond_lock != 0
+ addq $cond_lock, %rdi
+#endif
+ cmpq $-1, dep_mutex-cond_lock(%rdi)
+ movl $LLL_PRIVATE, %eax
+ movl $LLL_SHARED, %esi
+ cmovne %eax, %esi
+ /* The call preserves %rdx. */
+ callq __lll_unlock_wake
+#if cond_lock != 0
+ subq $cond_lock, %rdi
+#endif
+93:
+ /* Set the rest of SYS_futex args for FUTEX_WAIT_REQUEUE_PI. */
+ xorq %r10, %r10
+ movq dep_mutex(%rdi), %r8
+ leaq cond_futex(%rdi), %rdi
+ jmp 90b
+.LcleanupEND2:
+
.size __pthread_cond_wait, .-__pthread_cond_wait
versioned_symbol (libpthread, __pthread_cond_wait, pthread_cond_wait,
GLIBC_2_3_2)
@@ -479,11 +547,15 @@ __condvar_cleanup1:
.uleb128 .LcleanupSTART-.LSTARTCODE
.uleb128 .LcleanupEND-.LcleanupSTART
.uleb128 __condvar_cleanup1-.LSTARTCODE
- .uleb128 0
+ .uleb128 0
+ .uleb128 .LcleanupSTART2-.LSTARTCODE
+ .uleb128 .LcleanupEND2-.LcleanupSTART2
+ .uleb128 __condvar_cleanup1-.LSTARTCODE
+ .uleb128 0
.uleb128 .LcallUR-.LSTARTCODE
.uleb128 .LENDCODE-.LcallUR
.uleb128 0
- .uleb128 0
+ .uleb128 0
.Lcstend:

14
glibc-rh767746.patch Normal file
View File

@ -0,0 +1,14 @@
--- a/nptl/pthread_create.c 2011-12-13 11:41:37.000000000 -0700
+++ b/nptl/pthread_create.c 2011-12-14 10:03:13.000000000 -0700
@@ -440,8 +440,9 @@
int err = ALLOCATE_STACK (iattr, &pd);
if (__builtin_expect (err != 0, 0))
/* Something went wrong. Maybe a parameter of the attributes is
- invalid or we could not allocate memory. */
- return err;
+ invalid or we could not allocate memory. Note we have to
+ translate error codes. */
+ return err == ENOMEM ? EAGAIN : err;
/* Initialize the TCB. All initializations with zero should be

View File

@ -28,7 +28,7 @@
Summary: The GNU libc libraries
Name: glibc
Version: %{glibcversion}
Release: 23
Release: 24%{?dist}
# GPLv2+ is used in a bunch of programs, LGPLv2+ is used for libraries.
# Things that are linked directly into dynamically linked programs
# and shared libraries (e.g. crt files, lib*_nonshared.a) have an additional
@ -52,6 +52,8 @@ Patch8: %{name}-fdelt.patch
Patch9: %{name}-rh708455.patch
Patch10: %{name}-rh750811.patch
Patch11: %{name}-rh758252.patch
Patch12: %{name}-rh767746.patch
Patch13: %{name}-rh552960.patch
Buildroot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
Obsoletes: glibc-profile < 2.4
Obsoletes: nss_db
@ -280,6 +282,8 @@ rm -rf %{glibcportsdir}
%patch9 -p1
%patch10 -p1
%patch11 -p1
%patch12 -p1
%patch13 -p1
# A lot of programs still misuse memcpy when they have to use
# memmove. The memcpy implementation below is not tolerant at
@ -1132,6 +1136,11 @@ rm -f *.filelist*
%endif
%changelog
* Thu Dec 15 2011 Jeff Law <law@redhat.com> - 2.14.90-24
- Handle EAGAIN from FUTEX_WAIT_REQUEUE_PI (#552960)
- Add {dist}
- Correct return value from pthread_create when stack alloction fails.
* Wed Dec 7 2011 Jeff Law <law@redhat.com> - 2.14.90-23
- Fix a wrong constant in powerpc hypot implementation (#750811)
#13534 in python bug database