This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH v2] Fix pthread_cond_*wait with requeue-PI on i386


The recent addition of requeue-PI support for i386 broke PI mutexes.
https://bugzilla.redhat.com/show_bug.cgi?id=548989

When the FUTEX_WAIT_REQUEUE_PI operation was successful,
pthread_cond_wait and pthread_cont_timedwait fail to call
__pthread_mutex_cond_lock_adjust, leaving the mutex in a weird state.

I attached a simple testcase to the BZ:
https://bugzilla.redhat.com/show_bug.cgi?id=548989#c16

This patch fixes the bug for me and for several other people who
tested it.

At one point in one build in Koji (Fedora build system) there was an
unexpected failure in the testsuite:
  tst-robustpi8: pthread_mutex_lock.c:312: __pthread_mutex_lock_full:
  Assertion `(-(e)) != 3 || !robust' failed.
  Didn't expect signal from child: got `Aborted'
However, I and Dinakar were both unable to reproduce it. It may be
unrelated to the patch.

[v2: moved the "Remove cancellation handler." comment.]

Michal

2010-01-15  Michal Schmidt  <mschmidt@redhat.com>

	* nptl/sysdeps/unix/sysv/linux/i386/i486/pthread_cond_timedwait.S:
	Fix pthread_cond_timedwait with requeue-PI.
	* nptl/sysdeps/unix/sysv/linux/i386/i486/pthread_cond_wait.S:
	Fix pthread_cond_wait with requeue-PI.
---

 .../sysv/linux/i386/i486/pthread_cond_timedwait.S  |    8 ++++----
 .../unix/sysv/linux/i386/i486/pthread_cond_wait.S  |    5 ++---
 2 files changed, 6 insertions(+), 7 deletions(-)

diff --git a/nptl/sysdeps/unix/sysv/linux/i386/i486/pthread_cond_timedwait.S b/nptl/sysdeps/unix/sysv/linux/i386/i486/pthread_cond_timedwait.S
index 218762a..bf97702 100644
--- a/nptl/sysdeps/unix/sysv/linux/i386/i486/pthread_cond_timedwait.S
+++ b/nptl/sysdeps/unix/sysv/linux/i386/i486/pthread_cond_timedwait.S
@@ -326,15 +326,14 @@ __pthread_cond_timedwait:
 #endif
 	jne	10f
 
-11:	xorl	%eax, %eax
+11:	movl	24+FRAME_SIZE(%esp), %eax
 	/* With requeue_pi, the mutex lock is held in the kernel.  */
 	movl	24(%esp), %ecx
 	testl	%ecx, %ecx
-	jnz	26f
+	jnz	27f
 
-	/* Remove cancellation handler.  */
-	movl	24+FRAME_SIZE(%esp), %eax
 	call	__pthread_mutex_cond_lock
+	/* Remove cancellation handler.  */
 26:	addl	$FRAME_SIZE, %esp
 	cfi_adjust_cfa_offset(-FRAME_SIZE);
 
@@ -366,6 +365,7 @@ __pthread_cond_timedwait:
 	cfi_restore_state
 
 27:	call	__pthread_mutex_cond_lock_adjust
+	xorl	%eax, %eax
 	jmp	26b
 
 	/* Initial locking failed.  */
diff --git a/nptl/sysdeps/unix/sysv/linux/i386/i486/pthread_cond_wait.S b/nptl/sysdeps/unix/sysv/linux/i386/i486/pthread_cond_wait.S
index b3b8bc4..ea2f42e 100644
--- a/nptl/sysdeps/unix/sysv/linux/i386/i486/pthread_cond_wait.S
+++ b/nptl/sysdeps/unix/sysv/linux/i386/i486/pthread_cond_wait.S
@@ -247,12 +247,11 @@ __pthread_cond_wait:
 	jne	10f
 
 	/* With requeue_pi, the mutex lock is held in the kernel.  */
-11:	xorl	%eax, %eax
+11:	movl	24+FRAME_SIZE(%esp), %eax
 	movl	16(%esp), %ecx
 	testl	%ecx, %ecx
-	jnz	20f
+	jnz	21f
 
-	movl	24+FRAME_SIZE(%esp), %eax
 	call	__pthread_mutex_cond_lock
 20:	addl	$FRAME_SIZE, %esp
 	cfi_adjust_cfa_offset(-FRAME_SIZE);


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]