public inbox for libc-stable@sourceware.org
 help / color / mirror / Atom feed
From: fweimer@redhat.com (Florian Weimer)
To: libc-stable@sourceware.org
Subject: [2.25 COMMITTED] pthread_cond_broadcast: Fix waiters-after-spinning case [BZ #23538]
Date: Mon, 01 Jan 2018 00:00:00 -0000	[thread overview]
Message-ID: <20180827180446.C7773439B9CEA@oldenburg.str.redhat.com> (raw)

From: Martin Kuchta <martin.kuchta@netapp.com>

(cherry picked from commit 99ea93ca31795469d2a1f1570f17a5c39c2eb7e2)

2018-08-27 Martin Kuchta  <martin.kuchta@netapp.com>
	   Torvald Riegel  <triegel@redhat.com>

	[BZ #23538]
	* nptl/pthread_cond_common.c (__condvar_quiesce_and_switch_g1):
	Update r to include the set wake-request flag if waiters are
	remaining after spinning.

diff --git a/NEWS b/NEWS
index dafec5d82d..abe90d1422 100644
--- a/NEWS
+++ b/NEWS
@@ -84,6 +84,7 @@ The following bugs are resolved with this release:
   [22685] powerpc: Fix syscalls during early process initialization
   [22715] x86-64: Properly align La_x86_64_retval to VEC_SIZE
   [22774] malloc: Integer overflow in malloc (CVE-2018-6551)
+  [23538] pthread_cond_broadcast: Fix waiters-after-spinning case
 \f
 Version 2.25
 
diff --git a/nptl/pthread_cond_common.c b/nptl/pthread_cond_common.c
index 7c63ef9b89..886f0abcb3 100644
--- a/nptl/pthread_cond_common.c
+++ b/nptl/pthread_cond_common.c
@@ -406,8 +406,12 @@ __condvar_quiesce_and_switch_g1 (pthread_cond_t *cond, uint64_t wseq,
 	{
 	  /* There is still a waiter after spinning.  Set the wake-request
 	     flag and block.  Relaxed MO is fine because this is just about
-	     this futex word.  */
-	  r = atomic_fetch_or_relaxed (cond->__data.__g_refs + g1, 1);
+	     this futex word.
+
+	     Update r to include the set wake-request flag so that the upcoming
+	     futex_wait only blocks if the flag is still set (otherwise, we'd
+	     violate the basic client-side futex protocol).  */
+	  r = atomic_fetch_or_relaxed (cond->__data.__g_refs + g1, 1) | 1;
 
 	  if ((r >> 1) > 0)
 	    futex_wait_simple (cond->__data.__g_refs + g1, r, private);

                 reply	other threads:[~2018-08-27 18:04 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=20180827180446.C7773439B9CEA@oldenburg.str.redhat.com \
    --to=fweimer@redhat.com \
    --cc=libc-stable@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).