public inbox for glibc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Samuel Thibault <sthibaul@sourceware.org>
To: glibc-cvs@sourceware.org
Subject: [glibc] htl: Fix sem_wait race between read and gsync_wait
Date: Thu, 29 Dec 2022 23:42:06 +0000 (GMT)	[thread overview]
Message-ID: <20221229234206.137FA3858C53@sourceware.org> (raw)

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=289b098c9e21e2805e3835f9b5780235ab14a290

commit 289b098c9e21e2805e3835f9b5780235ab14a290
Author: Samuel Thibault <samuel.thibault@ens-lyon.org>
Date:   Fri Dec 30 00:40:18 2022 +0100

    htl: Fix sem_wait race between read and gsync_wait
    
    If the value changes between sem_wait's read and the gsync_wait call,
    the kernel will return KERN_INVALID_ARGUMENT, which we have to interpret
    as the value having already changed.
    
    This fixes applications (e.g. libgo) seeing sem_wait erroneously return
    KERN_INVALID_ARGUMENT.

Diff:
---
 sysdeps/htl/sem-timedwait.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/sysdeps/htl/sem-timedwait.c b/sysdeps/htl/sem-timedwait.c
index 1b1eec9f59..c610804b08 100644
--- a/sysdeps/htl/sem-timedwait.c
+++ b/sysdeps/htl/sem-timedwait.c
@@ -79,7 +79,7 @@ __sem_timedwait_internal (sem_t *restrict sem,
 		      ((unsigned int *) &sem->data) + SEM_VALUE_OFFSET,
 		      0, flags);
 
-	  if (err != 0)
+	  if (err != 0 && err != KERN_INVALID_ARGUMENT)
 	    {
 	      /* Error, interruption or timeout, abort.  */
 	      if (err == KERN_TIMEDOUT)
@@ -138,7 +138,7 @@ __sem_timedwait_internal (sem_t *restrict sem,
 		err = __lll_wait_intr (&isem->value,
 			  SEM_NWAITERS_MASK, flags);
 
-	      if (err != 0)
+	      if (err != 0 && err != KERN_INVALID_ARGUMENT)
 		{
 		  /* Error, interruption or timeout, abort.  */
 		  if (err == KERN_TIMEDOUT)

                 reply	other threads:[~2022-12-29 23:42 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=20221229234206.137FA3858C53@sourceware.org \
    --to=sthibaul@sourceware.org \
    --cc=glibc-cvs@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).