public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "yeatesrichardr at johndeere dot com" <sourceware-bugzilla@sourceware.org>
To: glibc-bugs@sourceware.org
Subject: [Bug nptl/26801] New: pthread_mutex_clocklock with CLOCK_MONOTONIC can fail on PI futexs
Date: Wed, 28 Oct 2020 13:54:30 +0000	[thread overview]
Message-ID: <bug-26801-131@http.sourceware.org/bugzilla/> (raw)

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.

             reply	other threads:[~2020-10-28 13:54 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-28 13:54 yeatesrichardr at johndeere dot com [this message]
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

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=bug-26801-131@http.sourceware.org/bugzilla/ \
    --to=sourceware-bugzilla@sourceware.org \
    --cc=glibc-bugs@sourceware.org \
    /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).