public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug nptl/26801] New: pthread_mutex_clocklock with CLOCK_MONOTONIC can fail on PI futexs
@ 2020-10-28 13:54 yeatesrichardr at johndeere dot com
  2020-10-28 13:59 ` [Bug nptl/26801] " yeatesrichardr at johndeere dot com
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: yeatesrichardr at johndeere dot com @ 2020-10-28 13:54 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=26801

            Bug ID: 26801
           Summary: pthread_mutex_clocklock with CLOCK_MONOTONIC can fail
                    on PI futexs
           Product: glibc
           Version: 2.30
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: nptl
          Assignee: unassigned at sourceware dot org
          Reporter: yeatesrichardr at johndeere dot com
                CC: drepper.fsp at gmail dot com
  Target Milestone: ---

Created attachment 12925
  --> https://sourceware.org/bugzilla/attachment.cgi?id=12925&action=edit
Test program showing early return from pthread_mutex_clocklock()

When a pthread mutex is ROBUST_NP, ERRORCHECK, and PRIO_INHERIT (other
combination may fall into this same category) and pthread_mutex_clocklock() is
used with CLOCK_MONOTONIC, the call will return immediately with ETIMEDOUT if
the mutex is already taken at the time of the call.

This was tested with glibc 2.30, but still appears to be present in the latest
source code. The root cause is at line 381 of pthread_mutex_timedlock.c:
   int e = futex_lock_pi64 (&mutex->__data.__lock, abstime, private);
Here, the CLOCK_MONOTONIC abstime is being passed to futex_lock_pi64 which
requires a CLOCK_REALTIME abstime. Of course, a CLOCK_MONOTONIC looks a lot
"earlier" than a CLOCK_REALTIME, so it times out immediately.

It's not sufficient to convert from CLOCK_MONOTONIC to CLOCK_REALTIME since
that would violate the assumption one is using, that changes to the wall clock
time won't interfere with CLOCK_MONOTONIC timed waits.

This was tested with kernel 5.4.47.

Example program is attached.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug nptl/26801] pthread_mutex_clocklock with CLOCK_MONOTONIC can fail on PI futexs
  2020-10-28 13:54 [Bug nptl/26801] New: pthread_mutex_clocklock with CLOCK_MONOTONIC can fail on PI futexs yeatesrichardr at johndeere dot com
@ 2020-10-28 13:59 ` yeatesrichardr at johndeere dot com
  2020-10-28 14:01 ` [Bug nptl/26801] pthread_mutex_clocklock with CLOCK_MONOTONIC can fail on PI mutexes yeatesrichardr at johndeere dot com
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: yeatesrichardr at johndeere dot com @ 2020-10-28 13:59 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=26801

--- Comment #1 from Ric Yeates <yeatesrichardr at johndeere dot com> ---
Forgot to include example output.

$ futex_bug
FAILURE: ETIMEDOUT should have been returned after 10 or more seconds, returned
after 0 seconds.

$ uname -a
Linux PCMA4MA000002.local.domain 5.4.47-2.2.0 #1 SMP PREEMPT Mon Oct 26
23:52:12 UTC 2020 aarch64 GNU/Linux

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug nptl/26801] pthread_mutex_clocklock with CLOCK_MONOTONIC can fail on PI mutexes
  2020-10-28 13:54 [Bug nptl/26801] New: pthread_mutex_clocklock with CLOCK_MONOTONIC can fail on PI futexs yeatesrichardr at johndeere dot com
  2020-10-28 13:59 ` [Bug nptl/26801] " yeatesrichardr at johndeere dot com
@ 2020-10-28 14:01 ` yeatesrichardr at johndeere dot com
  2020-10-28 17:33 ` yeatesrichardr at johndeere dot com
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: yeatesrichardr at johndeere dot com @ 2020-10-28 14:01 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=26801

Ric Yeates <yeatesrichardr at johndeere dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|pthread_mutex_clocklock     |pthread_mutex_clocklock
                   |with CLOCK_MONOTONIC can    |with CLOCK_MONOTONIC can
                   |fail on PI futexs           |fail on PI mutexes

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug nptl/26801] pthread_mutex_clocklock with CLOCK_MONOTONIC can fail on PI mutexes
  2020-10-28 13:54 [Bug nptl/26801] New: pthread_mutex_clocklock with CLOCK_MONOTONIC can fail on PI futexs yeatesrichardr at johndeere dot com
  2020-10-28 13:59 ` [Bug nptl/26801] " yeatesrichardr at johndeere dot com
  2020-10-28 14:01 ` [Bug nptl/26801] pthread_mutex_clocklock with CLOCK_MONOTONIC can fail on PI mutexes yeatesrichardr at johndeere dot com
@ 2020-10-28 17:33 ` yeatesrichardr at johndeere dot com
  2020-10-28 20:02 ` adhemerval.zanella at linaro dot org
  2020-11-25 15:31 ` adhemerval.zanella at linaro dot org
  4 siblings, 0 replies; 6+ messages in thread
From: yeatesrichardr at johndeere dot com @ 2020-10-28 17:33 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=26801

Ric Yeates <yeatesrichardr at johndeere dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |yeatesrichardr at johndeere dot co
                   |                            |m

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug nptl/26801] pthread_mutex_clocklock with CLOCK_MONOTONIC can fail on PI mutexes
  2020-10-28 13:54 [Bug nptl/26801] New: pthread_mutex_clocklock with CLOCK_MONOTONIC can fail on PI futexs yeatesrichardr at johndeere dot com
                   ` (2 preceding siblings ...)
  2020-10-28 17:33 ` yeatesrichardr at johndeere dot com
@ 2020-10-28 20:02 ` adhemerval.zanella at linaro dot org
  2020-11-25 15:31 ` adhemerval.zanella at linaro dot org
  4 siblings, 0 replies; 6+ messages in thread
From: adhemerval.zanella at linaro dot org @ 2020-10-28 20:02 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=26801

Adhemerval Zanella <adhemerval.zanella at linaro dot org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |adhemerval.zanella at linaro dot o
                   |                            |rg

--- Comment #2 from Adhemerval Zanella <adhemerval.zanella at linaro dot org> ---
We need kernel support for FUTEX_LOCK_PI with CLOCK_REALTIME due possible non
continuous clock, but currently Linux does not supporting set the clock for the
PI operations (it always assumes CLOCK_REALTIME).

I think it would be better to just return EINVAL is a clock different than
CLOCK_REALTIME is used with pthread_mutex_clocklock and PTHREAD_PRIO_INHERIT.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug nptl/26801] pthread_mutex_clocklock with CLOCK_MONOTONIC can fail on PI mutexes
  2020-10-28 13:54 [Bug nptl/26801] New: pthread_mutex_clocklock with CLOCK_MONOTONIC can fail on PI futexs yeatesrichardr at johndeere dot com
                   ` (3 preceding siblings ...)
  2020-10-28 20:02 ` adhemerval.zanella at linaro dot org
@ 2020-11-25 15:31 ` adhemerval.zanella at linaro dot org
  4 siblings, 0 replies; 6+ messages in thread
From: adhemerval.zanella at linaro dot org @ 2020-11-25 15:31 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=26801

Adhemerval Zanella <adhemerval.zanella at linaro dot org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
           Assignee|unassigned at sourceware dot org   |adhemerval.zanella at linaro dot o
                   |                            |rg
   Target Milestone|---                         |2.33
             Status|UNCONFIRMED                 |RESOLVED

--- Comment #3 from Adhemerval Zanella <adhemerval.zanella at linaro dot org> ---
Fixed on 2.33.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2020-11-25 15:31 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-28 13:54 [Bug nptl/26801] New: pthread_mutex_clocklock with CLOCK_MONOTONIC can fail on PI futexs yeatesrichardr at johndeere dot com
2020-10-28 13:59 ` [Bug nptl/26801] " yeatesrichardr at johndeere dot com
2020-10-28 14:01 ` [Bug nptl/26801] pthread_mutex_clocklock with CLOCK_MONOTONIC can fail on PI mutexes yeatesrichardr at johndeere dot com
2020-10-28 17:33 ` yeatesrichardr at johndeere dot com
2020-10-28 20:02 ` adhemerval.zanella at linaro dot org
2020-11-25 15:31 ` adhemerval.zanella at linaro dot org

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).