LKML Archive on
help / color / mirror / Atom feed
From: Florian Weimer <>
To: Mathieu Desnoyers <>
Cc: carlos <>, Peter Zijlstra <>,
	"Paul E. McKenney" <>,
	Boqun Feng <>,
	Thomas Gleixner <>,
	linux-kernel <>,
	libc-alpha <>
Subject: Re: Restartable Sequences system call merged into Linux
Date: Wed, 13 Jun 2018 10:21:32 +0200	[thread overview]
Message-ID: <> (raw)
In-Reply-To: <>

On 06/12/2018 06:31 PM, Mathieu Desnoyers wrote:
> ----- On Jun 12, 2018, at 9:11 AM, Florian Weimer wrote:
>> On 06/11/2018 10:04 PM, Mathieu Desnoyers wrote:
>>> ----- On Jun 11, 2018, at 3:55 PM, Florian Weimer wrote:
>>>> On 06/11/2018 09:49 PM, Mathieu Desnoyers wrote:
>>>>> It should be noted that there can be only one rseq TLS area registered per
>>>>> thread,
>>>>> which can then be used by many libraries and by the executable, so this is a
>>>>> process-wide (per-thread) resource that we need to manage carefully.
>>>> Is it possible to resize the area after thread creation, perhaps even
>>>> from other threads?
>>> I'm not sure why we would want to resize it. The per-thread area is fixed-size.
>>> Its layout is here: include/uapi/linux/rseq.h: struct rseq
>> Looks I was mistaken and this is very similar to the robust mutex list.
>> Should we treat it the same way?  Always allocate it for each new thread
>> and register it with the kernel?
> That would be an efficient way to do it, indeed. There is very little
> performance overhead to have rseq registered for all threads, whether or
> not they intend to run rseq critical sections.
>>> The ABI is designed so that all users (program and libraries) can interact
>>> through this per-thread TLS area.
>> Then the user code needs just the address of the structure.
> Yes.

So we'd add

   struct rseq *rseq_location (void);

and be done with it?  It would return the address of the thread-local 
variable, similar to __errno_location.

Or we could add something like this:

   extern __thread struct rseq pthread_rseq_area_np
     __attribute__ ((__tls_model__ ("initial-exec")));

But of course only for recent-enough GNU compilers (and Clang, which 
identifies itself as GNU).

The advantage of the function call is that it often results in more 
compact code.  Making the initial-exec nature part of the ABI has the 
advantage that the applications could use the fact of the constant 
offset to the thread pointer if they desire to do so.

Would we need to document which glibc functions use 
pthread_rseq_area_np, so that applications do not call them when they 
itself use the area?

Do we actually need to use RSEQ_FLAG_UNREGISTER prior to thread exit? 
Why can't the kernel do it for us?

>     - requires all rseq users to upgrade to newer glibc. Early rseq users
>       (libs and applications) registering their own rseq TLS will conflict
>       with newer glibc.

We will need to do something about stack unwinding and longjmp anyway (I 
assume the kernel already handles signals for us), so it may not be 
possible to use restartable sequences in any substantial way with a 
system upgrade anyway.

> B) exposes a strong __rseq_abi symbol:
>     - should ideally *not* be global-dynamic for performance reasons, but
>       testing shows that using initial-exec causes issues in situations where
> ends up being dlopen'd (e.g. java virtual machine dlopening
>       the lttng-ust tracer linked against,

Just an aside:

You can work around that using preloading.  On the glibc side, we could 
also make the initial reserve configurable.  On 64-bit, there really is 
no reason not to use a different TCB allocation scheme which would allow 
you to create a few threads before the initial-exec TLS area cannot be 

The existing approach dates back to LinuxThreads and its TCB collocated 
with the the stack.  But changes in the next few months are not very likely.

> C) __rseq_abi symbol declared weak within each user (application, librseq,
>     other libraries, glibc):

We can multiple two non-weak definitions for the symbol.  It should work 
as long as only the definition in glibc has a symbol version.

__rseq_abi as a name is problematic because it's in the internal namespace.


  reply	other threads:[~2018-06-13  8:21 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-11 19:49 Mathieu Desnoyers
2018-06-11 19:55 ` Florian Weimer
2018-06-11 20:04   ` Mathieu Desnoyers
2018-06-12 13:11     ` Florian Weimer
2018-06-12 16:31       ` Mathieu Desnoyers
2018-06-13  8:21         ` Florian Weimer [this message]
2018-06-14 12:27         ` Pavel Machek
2018-06-14 13:01           ` Mathieu Desnoyers
2018-06-14 13:25             ` Pavel Machek
2018-06-14 13:32               ` Florian Weimer
2018-06-14 13:46                 ` Mathieu Desnoyers
2018-06-15  5:10                   ` Florian Weimer
2018-06-15 17:44                     ` Mathieu Desnoyers
2018-06-14 13:38               ` Mathieu Desnoyers
2018-06-14 13:49                 ` Pavel Machek
2018-06-14 14:00                   ` Florian Weimer
2018-06-14 14:36                     ` Mathieu Desnoyers
2018-06-14 14:41                       ` Florian Weimer
2018-06-14 15:09                         ` Mathieu Desnoyers
2018-06-15  5:09             ` Florian Weimer
2018-06-15 17:50               ` Mathieu Desnoyers
2018-06-15  5:07           ` Florian Weimer
2018-06-13 11:48 ` Heiko Carstens
2018-06-13 16:14   ` Mathieu Desnoyers
2018-06-13 19:53     ` 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:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \ \ \ \ \ \ \ \ \ \ \
    --subject='Re: Restartable Sequences system call merged into Linux' \

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

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).