mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Rich Felker <dalias@libc.org>
To: libc-alpha@sourceware.org, musl@lists.openwall.com,
	linux-api@vger.kernel.org
Subject: [musl] Re: Robust mutex ABI problem (kernel docs regression)
Date: Thu, 11 Jan 2024 11:59:26 -0500	[thread overview]
Message-ID: <20240111165926.GT4163@brightrain.aerifal.cx> (raw)
In-Reply-To: <20240111164620.GS4163@brightrain.aerifal.cx>

On Thu, Jan 11, 2024 at 11:46:21AM -0500, Rich Felker wrote:
> It came to my attention while reviewing some proposals for additional
> error checking in musl libc that the kernel folks introduced a quiet
> regression in the futex ABI for robust mutexes.
> 
> Prior to kernel commit 9c40365a65d62d7c06a95fb331b3442cb02d2fd9, bit
> 29 of the futex lock word was reserved, meaning it could never be part
> of a TID. This allowed both glibc and musl to use special values like
> (glibc):
> 
> /* Magic cookie representing robust mutex with dead owner.  */
> #define PTHREAD_MUTEX_INCONSISTENT      INT_MAX
> /* Magic cookie representing not recoverable robust mutex.  */
> #define PTHREAD_MUTEX_NOTRECOVERABLE    (INT_MAX - 1)
> 
> to represent special states needed for robust mutex consistency
> handling, without the risk that, when masked with FUTEX_TID_MASK
> (0x3fffffff), they could be equal to the TID of a real task, which
> could result in the kernel robustlist-processing mishandling them.

On further investigation, it looks like glibc is not using these
directly in the futex word but keeping them in a separate owner field
protected by the lock. I'll try to follow up with what it actually is
doing, but I don't see a way, without at least having one reserved
value in the low 30 bits (FUTEX_TID_MASK), to represent a lock that
cannot be taken by any task. I'm guessing glibc does some dance of
actually taking the lock then releasing it in this case..?

On musl we keep the entire state in the lock word so that it's all
atomic.

Rich

      reply	other threads:[~2024-01-11 16:59 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-11 16:46 [musl] " Rich Felker
2024-01-11 16:59 ` Rich Felker [this message]

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=20240111165926.GT4163@brightrain.aerifal.cx \
    --to=dalias@libc.org \
    --cc=libc-alpha@sourceware.org \
    --cc=linux-api@vger.kernel.org \
    --cc=musl@lists.openwall.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.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

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 NNTP newsgroup(s).