about summary refs log tree commit diff
path: root/nptl
diff options
context:
space:
mode:
authorAdhemerval Zanella <adhemerval.zanella@linaro.org>2020-11-25 17:15:51 -0300
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>2020-11-27 09:59:13 -0300
commit71eeae0325a95f5e5d7ec4a27a6a6c357e0c8ef4 (patch)
tree470fe6a8c1ab863ad0c400d6e19924c2d265ac68 /nptl
parent9ff2674ef82eccd5ae5dfa6bb733c0e3613764c6 (diff)
downloadglibc-71eeae0325a95f5e5d7ec4a27a6a6c357e0c8ef4.tar.gz
glibc-71eeae0325a95f5e5d7ec4a27a6a6c357e0c8ef4.tar.xz
glibc-71eeae0325a95f5e5d7ec4a27a6a6c357e0c8ef4.zip
nptl: Fix PTHREAD_PRIO_PROTECT timed lock
The 878fe624d4 changed lll_futex_timed_wait, which expects a relative
timeout, with a __futex_abstimed_wait64, which expects an absolute
timeout.  However the code still passes a relative timeout.

Also, the PTHREAD_PRIO_PROTECT support for clocks different than
CLOCK_REALTIME was broken since the inclusion of
pthread_mutex_clocklock (9d20e22e46) since lll_futex_timed_wait
always use CLOCK_REALTIME.

This patch fixes by removing the relative time calculation.  It
also adds some xtests that tests both thread and inter-process
usage.

Checked on x86_64-linux-gnu.
Diffstat (limited to 'nptl')
-rw-r--r--nptl/Makefile3
-rw-r--r--nptl/pthread_mutex_timedlock.c29
-rw-r--r--nptl/tst-mutexpp5.c2
-rw-r--r--nptl/tst-mutexpp9.c2
4 files changed, 11 insertions, 25 deletions
diff --git a/nptl/Makefile b/nptl/Makefile
index a48426a396..94d805f0d4 100644
--- a/nptl/Makefile
+++ b/nptl/Makefile
@@ -309,7 +309,8 @@ tests-internal := tst-robustpi8 tst-rwlock19 tst-rwlock20 \
 		  tst-setgetname \
 
 xtests = tst-setuid1 tst-setuid1-static tst-setuid2 \
-	tst-mutexpp1 tst-mutexpp6 tst-mutexpp10 tst-setgroups
+	tst-mutexpp1 tst-mutexpp6 tst-mutexpp10 tst-setgroups \
+	tst-mutexpp5 tst-mutexpp9
 
 # This test can run into task limits because of a linux kernel bug
 # and then cause the make process to fail too, see bug 24537.
diff --git a/nptl/pthread_mutex_timedlock.c b/nptl/pthread_mutex_timedlock.c
index aaaafa21ce..74adffe790 100644
--- a/nptl/pthread_mutex_timedlock.c
+++ b/nptl/pthread_mutex_timedlock.c
@@ -547,30 +547,11 @@ __pthread_mutex_clocklock_common (pthread_mutex_t *mutex,
 			goto failpp;
 		      }
 
-		    struct __timespec64 rt;
-
-		    /* Get the current time.  */
-		    __clock_gettime64 (CLOCK_REALTIME, &rt);
-
-		    /* Compute relative timeout.  */
-		    rt.tv_sec = abstime->tv_sec - rt.tv_sec;
-		    rt.tv_nsec = abstime->tv_nsec - rt.tv_nsec;
-		    if (rt.tv_nsec < 0)
-		      {
-			rt.tv_nsec += 1000000000;
-			--rt.tv_sec;
-		      }
-
-		    /* Already timed out?  */
-		    if (rt.tv_sec < 0)
-		      {
-			result = ETIMEDOUT;
-			goto failpp;
-		      }
-
-		    __futex_abstimed_wait64 (
-		      (unsigned int *) &mutex->__data.__lock, clockid,
-		      ceilval | 2, &rt, PTHREAD_MUTEX_PSHARED (mutex));
+		    int e = __futex_abstimed_wait64 (
+		      (unsigned int *) &mutex->__data.__lock, ceilval | 2,
+		      clockid, abstime, PTHREAD_MUTEX_PSHARED (mutex));
+		    if (e == ETIMEDOUT)
+		      return ETIMEDOUT;
 		  }
 	      }
 	    while (atomic_compare_and_exchange_val_acq (&mutex->__data.__lock,
diff --git a/nptl/tst-mutexpp5.c b/nptl/tst-mutexpp5.c
new file mode 100644
index 0000000000..a864a390ca
--- /dev/null
+++ b/nptl/tst-mutexpp5.c
@@ -0,0 +1,2 @@
+#define ENABLE_PP 1
+#include "tst-mutex5.c"
diff --git a/nptl/tst-mutexpp9.c b/nptl/tst-mutexpp9.c
new file mode 100644
index 0000000000..c848c74c7e
--- /dev/null
+++ b/nptl/tst-mutexpp9.c
@@ -0,0 +1,2 @@
+#define ENABLE_PP 1
+#include "tst-mutex9.c"