From: Jakub Jelinek <jakub@redhat.com>
To: Ulrich Drepper <drepper@redhat.com>
Cc: Glibc hackers <libc-hacker@sources.redhat.com>
Subject: [PATCH] i[456]86 rwlock fixes
Date: Mon, 30 Jul 2007 18:08:00 -0000 [thread overview]
Message-ID: <20070730181254.GU4603@sunsite.mff.cuni.cz> (raw)
Hi!
While working on i386 lowlevellock* updates (to match the x86_64/ppc changes
I posted as RFC), I found a couple of bugs in i?86 rwlock code and I think
it is better to post them separately outside of a huge patch, for
backporting etc. purposes:
1) if after futex returns -ETIMEDOUT or gettimeofday comparison jumps
with -ETIMEDOUT stright to label 17 the internal lock isn't acquired
immediately by lock cmpxchgl (== we jump to label 12), %ecx (which
holds the saved futex return value) is first overwritten by
12:
#if MUTEX == 0
movl %ebp, %ecx
#else
leal MUTEX(%ebp), %ecx
#endif
and afterwards inside of __lll_mutex_lock_wait (it will be
FUTEX_WAIT). This means the comparison with -ETIMEDOUT
later on will be always false even if futex returned that
error code and we'll loop again. The effect of this will be that
pthread_rwlock_timed*lock will be looping in this case until
it manages to grab the internal lock immediately without having
to wait. I believe %esi isn't used for anything at this point
(earlier it is used to hold some value from before unlock of
the internal lock until the futex FUTEX_WAIT syscall), then
to pass one of the arguments to that syscall, but then nothing
until it is poped before ret.
2) only documentation issue in rwlock_unlock - the MUTEX != 0
case uses wrong base register, fortunately MUTEX = 0 branch
gets it right and we know MUTEX is 0.
2007-07-30 Jakub Jelinek <jakub@redhat.com>
* sysdeps/unix/sysv/linux/i386/i486/pthread_rwlock_timedrdlock.S
(pthread_rwlock_timedrdlock): Copy futex retval to %esi rather than
%ecx.
* sysdeps/unix/sysv/linux/i386/i486/pthread_rwlock_timedwrlock.S
(pthread_rwlock_timedwrlock): Likewise.
* sysdeps/unix/sysv/linux/i386/i486/pthread_rwlock_unlock.S
(__pthread_rwlock_unlock): Fix MUTEX != 0 args to __lll_*.
--- nptl/sysdeps/unix/sysv/linux/i386/i486/pthread_rwlock_timedrdlock.S.jj 2007-06-04 08:42:06.000000000 +0200
+++ nptl/sysdeps/unix/sysv/linux/i386/i486/pthread_rwlock_timedrdlock.S 2007-07-30 18:10:05.000000000 +0200
@@ -124,7 +124,7 @@ pthread_rwlock_timedrdlock:
leal READERS_WAKEUP(%ebp), %ebx
movl $SYS_futex, %eax
ENTER_KERNEL
- movl %eax, %ecx
+ movl %eax, %esi
17:
/* Reget the lock. */
@@ -139,7 +139,7 @@ pthread_rwlock_timedrdlock:
jnz 12f
13: subl $1, READERS_QUEUED(%ebp)
- cmpl $-ETIMEDOUT, %ecx
+ cmpl $-ETIMEDOUT, %esi
jne 2b
18: movl $ETIMEDOUT, %ecx
@@ -217,7 +217,7 @@ pthread_rwlock_timedrdlock:
call __lll_mutex_lock_wait
jmp 13b
-16: movl $-ETIMEDOUT, %ecx
+16: movl $-ETIMEDOUT, %esi
jmp 17b
19: movl $EINVAL, %ecx
--- nptl/sysdeps/unix/sysv/linux/i386/i486/pthread_rwlock_timedwrlock.S.jj 2007-06-04 08:42:06.000000000 +0200
+++ nptl/sysdeps/unix/sysv/linux/i386/i486/pthread_rwlock_timedwrlock.S 2007-07-30 18:10:59.000000000 +0200
@@ -122,7 +122,7 @@ pthread_rwlock_timedwrlock:
leal WRITERS_WAKEUP(%ebp), %ebx
movl $SYS_futex, %eax
ENTER_KERNEL
- movl %eax, %ecx
+ movl %eax, %esi
17:
/* Reget the lock. */
@@ -137,7 +137,7 @@ pthread_rwlock_timedwrlock:
jnz 12f
13: subl $1, WRITERS_QUEUED(%ebp)
- cmpl $-ETIMEDOUT, %ecx
+ cmpl $-ETIMEDOUT, %esi
jne 2b
18: movl $ETIMEDOUT, %ecx
@@ -210,7 +210,7 @@ pthread_rwlock_timedwrlock:
call __lll_mutex_lock_wait
jmp 13b
-16: movl $-ETIMEDOUT, %ecx
+16: movl $-ETIMEDOUT, %esi
jmp 17b
19: movl $EINVAL, %ecx
--- nptl/sysdeps/unix/sysv/linux/i386/i486/pthread_rwlock_unlock.S.jj 2007-06-04 08:42:06.000000000 +0200
+++ nptl/sysdeps/unix/sysv/linux/i386/i486/pthread_rwlock_unlock.S 2007-07-30 18:19:01.000000000 +0200
@@ -117,7 +117,7 @@ __pthread_rwlock_unlock:
#if MUTEX == 0
movl %edi, %ecx
#else
- leal MUTEX(%edx), %ecx
+ leal MUTEX(%edi), %ecx
#endif
call __lll_mutex_lock_wait
jmp 2b
@@ -126,7 +126,7 @@ __pthread_rwlock_unlock:
#if MUTEX == 0
movl %edi, %eax
#else
- leal MUTEX(%edx), %eax
+ leal MUTEX(%edi), %eax
#endif
call __lll_mutex_unlock_wake
jmp 4b
@@ -135,7 +135,7 @@ __pthread_rwlock_unlock:
#if MUTEX == 0
movl %edi, %eax
#else
- leal MUTEX(%edx), %eax
+ leal MUTEX(%edi), %eax
#endif
call __lll_mutex_unlock_wake
jmp 8b
Jakub
reply other threads:[~2007-07-30 18:08 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20070730181254.GU4603@sunsite.mff.cuni.cz \
--to=jakub@redhat.com \
--cc=drepper@redhat.com \
--cc=libc-hacker@sources.redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).