linux-api.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Florian Weimer <fweimer@redhat.com>
To: libc-alpha@sourceware.org
Cc: linux-api@vger.kernel.org,
	Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
	Jeremy Linton <jeremy.linton@arm.com>,
	Vincenzo Frascino <vincenzo.frascino@arm.com>,
	Rich Felker <dalias@libc.org>
Subject: Bringing rseq back into glibc
Date: Thu, 18 Nov 2021 11:17:36 +0100	[thread overview]
Message-ID: <87wnl5u5rz.fsf@oldenburg.str.redhat.com> (raw)

I would like to bring back rseq for glibc 2.35.  I propose the following
steps:

1. Enable rseq registration in glibc, for internal use only.  This time,
   put the rseq area into struct pthread, not into a initial-exec TLS
   symbol.  (This helps to avoid with initial-exec TLS bloat with dlopen
   and simplifies initialization somewhat.)

2. Add a tunable to disable rseq registration in glibc.  This way, if
   there is already an rseq user, it can be made to work again by
   setting the tunable.

3. Implement sched_getcpu on top of rseq.

4. Add public symbols __rseq_abi_offset, __rseq_abi_size (currently 32
   or 0), __rseq_abi_flags (currently 0).  __rseq_abi_offset is the
   offset to add to the thread pointer (see __builtin_thread_pointer) to
   get to the rseq area.  They will be public ABI symbols.  These
   variables are initialized before user code runs, and changing the
   results in undefined behavior.

Under this model, the rseq area offset is clearly constant across all
threads.  (This was previously implied by using initial-exec TLS
memory.)  rseq registration failure is indicated by __rseq_abi_size ==
0.  If the size is non-zero, rseq will be registered on all threads
created by glibc, and all the time as far as user code is concernes.
(This assumes that if rseq registration succeeds on the main thread, it
will succeed on all other threads.  We will terminate the process if
not.)  For example, if a JIT compiler sees __rseq_abi_size >= 32, in
generated code, it can inline a version of sched_getcpu that
materializes the thread pointer and loads the cpu_id field from the rseq
area, without further checks.  Under the old TLS-based model, it was
less clear that this was a valid optimization.

Furthermore, I believe this approach will be more compatible with
potential future kernel changes in this area.  If the kernel tells us
some day through the auxiliary vector that we should register a 128-byte
rseq area with 64-byte alignment, we can make that happen and change
__rseq_abi_offset and __rseq_abi_size accordingly.

Steps 1 to 3 are backportable to previous glibc version, especially to
2.34 with its integrated libpthread.

Comments?  As I said, I'd like to bring these changes into glibc 2.35,
hopefully in early December.

Thanks,
Florian


             reply	other threads:[~2021-11-18 10:18 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-18 10:17 Florian Weimer [this message]
2021-11-18 16:32 ` Bringing rseq back into glibc Mathieu Desnoyers
2021-11-18 16:54   ` Florian Weimer
2021-11-18 17:52     ` Mathieu Desnoyers
2021-11-18 18:42 ` Noah Goldstein
2021-11-18 18:55   ` Florian Weimer
2021-11-18 18:48 ` Cristian Rodríguez
2021-11-18 19:41   ` Mathieu Desnoyers

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=87wnl5u5rz.fsf@oldenburg.str.redhat.com \
    --to=fweimer@redhat.com \
    --cc=dalias@libc.org \
    --cc=jeremy.linton@arm.com \
    --cc=libc-alpha@sourceware.org \
    --cc=linux-api@vger.kernel.org \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=vincenzo.frascino@arm.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.
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).