unofficial mirror of libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Lukasz Majewski <lukma@denx.de>
To: Joseph Myers <joseph@codesourcery.com>,
	Paul Eggert <eggert@cs.ucla.edu>,
	Adhemerval Zanella <adhemerval.zanella@linaro.org>
Cc: Florian Weimer <fweimer@redhat.com>,
	Stefan Liebler <stli@linux.ibm.com>,
	GNU C Library <libc-alpha@sourceware.org>,
	Andreas Schwab <schwab@suse.de>,
	Stepan Golosunov <stepan@golosunov.pp.ru>,
	Alistair Francis <alistair.francis@wdc.com>
Subject: [PATCH] y2038: nptl: Provide __futex_clock_wait_bitset64 to support 64 bit bitset
Date: Mon, 19 Oct 2020 16:57:39 +0200	[thread overview]
Message-ID: <20201019145739.32361-1-lukma@denx.de> (raw)

The commit:
"y2038: nptl: Convert pthread_mutex_{clock|timed}lock to support 64 bit"
SHA1: 29e9874a048f47e2d46c40253036c8d2de921548

introduced support for 64 bit timeouts. Unfortunately, it was missing the
code for bitset - i.e. lll_futex_clock_wait_bitset C preprocessor macro
was used. As a result the 64 bit struct __timespec64 was coerced to 32
bit struct timespec and regression visible as timeout was observed
(nptl/tst-robust10 on s390).

Reported-by: Stefan Liebler <stli@linux.ibm.com>
---
 nptl/pthread_mutex_timedlock.c |  2 +-
 sysdeps/nptl/futex-internal.c  | 48 +++++++++++++++++++++++++++++++++-
 sysdeps/nptl/futex-internal.h  |  5 ++++
 3 files changed, 53 insertions(+), 2 deletions(-)

diff --git a/nptl/pthread_mutex_timedlock.c b/nptl/pthread_mutex_timedlock.c
index dc40399f02..fe9e651f6c 100644
--- a/nptl/pthread_mutex_timedlock.c
+++ b/nptl/pthread_mutex_timedlock.c
@@ -268,7 +268,7 @@ __pthread_mutex_clocklock_common (pthread_mutex_t *mutex,
 	  assume_other_futex_waiters |= FUTEX_WAITERS;
 
 	  /* Block using the futex.  */
-	  int err = lll_futex_clock_wait_bitset (&mutex->__data.__lock,
+	  int err = __futex_clock_wait_bitset64 (&mutex->__data.__lock,
 	      oldval, clockid, abstime,
 	      PTHREAD_ROBUST_MUTEX_PSHARED (mutex));
 	  /* The futex call timed out.  */
diff --git a/sysdeps/nptl/futex-internal.c b/sysdeps/nptl/futex-internal.c
index 2e1919f056..a978ad0ad2 100644
--- a/sysdeps/nptl/futex-internal.c
+++ b/sysdeps/nptl/futex-internal.c
@@ -70,7 +70,28 @@ __futex_abstimed_wait32 (unsigned int* futex_word,
                                 abstime != NULL ? &ts32 : NULL,
                                 NULL /* Unused.  */, FUTEX_BITSET_MATCH_ANY);
 }
-#endif
+
+static int
+__futex_clock_wait_bitset32 (int *futexp, int val, clockid_t clockid,
+                             const struct __timespec64 *abstime, int private)
+{
+  struct timespec ts32;
+
+  if (abstime != NULL && ! in_time_t_range (abstime->tv_sec))
+    return -EOVERFLOW;
+
+  const unsigned int clockbit =
+    (clockid == CLOCK_REALTIME) ? FUTEX_CLOCK_REALTIME : 0;
+  const int op = __lll_private_flag (FUTEX_WAIT_BITSET | clockbit, private);
+
+  if (abstime != NULL)
+    ts32 = valid_timespec64_to_timespec (*abstime);
+
+  return INTERNAL_SYSCALL_CALL (futex, futexp, op, val,
+                                abstime != NULL ? &ts32 : NULL,
+                                NULL /* Unused.  */, FUTEX_BITSET_MATCH_ANY);
+}
+#endif /* ! __ASSUME_TIME64_SYSCALLS */
 
 int
 __futex_abstimed_wait_cancelable64 (unsigned int* futex_word,
@@ -222,3 +243,28 @@ __futex_clocklock_wait64 (int *futex, int val, clockid_t clockid,
 
   return -err;
 }
+
+int
+__futex_clock_wait_bitset64 (int *futexp, int val, clockid_t clockid,
+                             const struct __timespec64 *abstime,
+                             int private)
+{
+  long int ret;
+  if (! lll_futex_supported_clockid (clockid))
+    {
+      return -EINVAL;
+    }
+
+  const unsigned int clockbit =
+    (clockid == CLOCK_REALTIME) ? FUTEX_CLOCK_REALTIME : 0;
+  const int op = __lll_private_flag (FUTEX_WAIT_BITSET | clockbit, private);
+
+  ret = INTERNAL_SYSCALL_CALL (futex_time64, futexp, op, val,
+                               abstime, NULL /* Unused.  */,
+                               FUTEX_BITSET_MATCH_ANY);
+#ifndef __ASSUME_TIME64_SYSCALLS
+  if (ret == -ENOSYS)
+    ret = __futex_clock_wait_bitset32 (futexp, val, clockid, abstime, private);
+#endif
+  return ret;
+}
diff --git a/sysdeps/nptl/futex-internal.h b/sysdeps/nptl/futex-internal.h
index 8a5f62768f..cd356e4fa8 100644
--- a/sysdeps/nptl/futex-internal.h
+++ b/sysdeps/nptl/futex-internal.h
@@ -603,4 +603,9 @@ __futex_clocklock64 (int *futex, clockid_t clockid,
   return err;
 }
 
+int
+__futex_clock_wait_bitset64 (int *futexp, int val, clockid_t clockid,
+                             const struct __timespec64 *abstime,
+                             int private) attribute_hidden;
+
 #endif  /* futex-internal.h */
-- 
2.20.1


             reply	other threads:[~2020-10-19 14:59 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-19 14:57 Lukasz Majewski [this message]
2020-10-20 11:01 ` [PATCH] y2038: nptl: Provide __futex_clock_wait_bitset64 to support 64 bit bitset Stefan Liebler via Libc-alpha
2020-10-20 13:31   ` Lukasz Majewski
2020-10-21  6:49     ` Stefan Liebler via Libc-alpha

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

  List information: https://www.gnu.org/software/libc/involved.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201019145739.32361-1-lukma@denx.de \
    --to=lukma@denx.de \
    --cc=adhemerval.zanella@linaro.org \
    --cc=alistair.francis@wdc.com \
    --cc=eggert@cs.ucla.edu \
    --cc=fweimer@redhat.com \
    --cc=joseph@codesourcery.com \
    --cc=libc-alpha@sourceware.org \
    --cc=schwab@suse.de \
    --cc=stepan@golosunov.pp.ru \
    --cc=stli@linux.ibm.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).