All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
To: Florian Weimer <fweimer@redhat.com>
Cc: Rich Felker <dalias@libc.org>, carlos <carlos@redhat.com>,
	Joseph Myers <joseph@codesourcery.com>,
	Szabolcs Nagy <szabolcs.nagy@arm.com>,
	libc-alpha <libc-alpha@sourceware.org>,
	Thomas Gleixner <tglx@linutronix.de>, Ben Maurer <bmaurer@fb.com>,
	Peter Zijlstra <peterz@infradead.org>,
	"Paul E. McKenney" <paulmck@linux.vnet.ibm.com>,
	Boqun Feng <boqun.feng@gmail.com>,
	Will Deacon <will.deacon@arm.com>,
	Dave Watson <davejwatson@fb.com>, Paul Turner <pjt@google.com>,
	linux-kernel <linux-kernel@vger.kernel.org>,
	linux-api <linux-api@vger.kernel.org>
Subject: Re: [RFC PATCH v4 1/5] glibc: Perform rseq(2) registration at nptl init and thread creation
Date: Thu, 22 Nov 2018 11:47:42 -0500 (EST)	[thread overview]
Message-ID: <1045257294.10291.1542905262086.JavaMail.zimbra@efficios.com> (raw)
In-Reply-To: <87wop5xeit.fsf@oldenburg.str.redhat.com>

----- On Nov 22, 2018, at 11:28 AM, Florian Weimer fweimer@redhat.com wrote:

> * Mathieu Desnoyers:
> 
>> Here is one scenario: we have 2 early adopter libraries using rseq which
>> are deployed in an environment with an older glibc (which does not
>> support rseq).
>>
>> Of course, none of those libraries can be dlclose'd unless they somehow
>> track all registered threads.
> 
> Well, you can always make them NODELETE so that dlclose is not an issue.
> If the library is small enough, that shouldn't be a problem.

That's indeed what I do with lttng-ust, mainly due to use of pthread_key.

> 
>> But let's focus on how exactly those libraries can handle lazily
>> registering rseq. They can use pthread_key, and pthread_setspecific on
>> first use by the thread to setup a destructor function to be invoked
>> at thread exit. But each early adopter library is unaware of the
>> other, so if we just use a "is_initialized" flag, the first destructor
>> to run will unregister rseq while the second library may still be
>> using it.
> 
> I don't think you need unregistering if the memory is initial-exec TLS
> memory.  Initial-exec TLS memory is tied directly to the TCB and cannot
> be freed while the thread is running, so it should be safe to put the
> rseq area there even if glibc knows nothing about it.

Is it true for user-supplied stacks as well ?

> Then you'll only
> need a mechanism to find the address of the actually active rseq area
> (which you probably have to store in a TLS variable for performance
> reasons).  And that part you need whether you have reference counter or
> not.

I'm not sure I follow your thoughts here. Currently, the __rseq_abi
TLS symbol identifies a structure registered to the kernel. The
"currently active" rseq critical section is identified by the field
"rseq_cs" within the __rseq_abi structure.

So here when you say "actually active rseq area", do you mean the
currently registered struct rseq (__rseq_abi) or the currently running
rseq critical section ? (pointed to by __rseq_abi.rseq_cs)

One issue here is that early adopter libraries cannot always use
the IE model. I tried using it for other TLS variables in lttng-ust, and
it ended up hanging our CI tests when tracing a sample application with
lttng-ust under a Java virtual machine: being dlopen'd in a process that
possibly already exhausts the number of available backup TLS IE entries
seems to have odd effects. This is why I'm worried about using the IE model
within lttng-ust.

So using the IE model for glibc makes sense, because nobody dlopen
glibc AFAIK. But it's not so simple for early adopter libraries which
can be dlopen'd.

> 
>> The same problem arises if we have an application early adopter which
>> explicitly deal with rseq, with a library early adopter. The issue is
>> similar, except that the application will explicitly want to unregister
>> rseq before exiting the thread, which leaves a race window where rseq
>> is unregistered, but the library may still need to use it.
>>
>> The reference counter solves this: only the last rseq user for a thread
>> performs unregistration.
> 
> If you do explicit unregistration, you will run into issues related to
> destructor ordering.  You should really find a way to avoid that.

The per-thread reference counter is a way to avoid issues that arise from
lack of destructor ordering. Is it an acceptable approach for you, or
you have something else in mind ?

Thanks,

Mathieu

-- 
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com

  reply	other threads:[~2018-11-22 16:47 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-21 18:39 [RFC PATCH v4 1/5] glibc: Perform rseq(2) registration at nptl init and thread creation Mathieu Desnoyers
2018-11-21 18:39 ` [RFC PATCH v4 2/5] glibc: sched_getcpu(): use rseq cpu_id TLS on Linux Mathieu Desnoyers
2018-11-22 14:36 ` [RFC PATCH v4 1/5] glibc: Perform rseq(2) registration at nptl init and thread creation Rich Felker
2018-11-22 15:04   ` Mathieu Desnoyers
2018-11-22 15:11     ` Florian Weimer
2018-11-22 15:17       ` Rich Felker
2018-11-22 15:21         ` Florian Weimer
2018-11-22 15:33           ` Mathieu Desnoyers
2018-11-22 15:44             ` Rich Felker
2018-11-22 16:24             ` Szabolcs Nagy
2018-11-22 18:35               ` Mathieu Desnoyers
2018-11-22 19:01                 ` Rich Felker
2018-11-22 19:36                   ` Mathieu Desnoyers
2018-11-22 15:14     ` Rich Felker
2018-11-22 15:47       ` Mathieu Desnoyers
2018-11-22 16:28         ` Florian Weimer
2018-11-22 16:47           ` Mathieu Desnoyers [this message]
2018-11-22 16:59             ` Florian Weimer
2018-11-22 17:10               ` Rich Felker
2018-11-23 13:10                 ` Florian Weimer
2018-11-23 14:28                   ` Rich Felker
2018-11-23 17:05                     ` Mathieu Desnoyers
2018-11-23 17:30                       ` Rich Felker
2018-11-23 17:39                         ` Florian Weimer
2018-11-23 17:44                           ` Rich Felker
2018-11-23 18:01                             ` Florian Weimer
2018-11-23 17:52                         ` Mathieu Desnoyers
2018-11-23 18:35                           ` Rich Felker
2018-11-23 21:09                             ` Mathieu Desnoyers
2018-11-26  8:28                               ` Florian Weimer
2018-11-26 15:51                                 ` Mathieu Desnoyers
2018-11-26 16:03                                   ` Florian Weimer
2018-11-26 17:10                                     ` Rich Felker
2018-11-26 19:22                                       ` Mathieu Desnoyers
2018-12-03 21:30                                         ` Mathieu Desnoyers
2018-11-26 16:30                                   ` Mathieu Desnoyers
2018-11-26 17:07                                     ` Rich Felker
2018-12-05 17:24                                       ` Mathieu Desnoyers
2018-11-26 11:56                               ` Szabolcs Nagy
2018-11-22 17:29               ` Mathieu Desnoyers
2018-11-23 13:29                 ` Florian Weimer

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=1045257294.10291.1542905262086.JavaMail.zimbra@efficios.com \
    --to=mathieu.desnoyers@efficios.com \
    --cc=bmaurer@fb.com \
    --cc=boqun.feng@gmail.com \
    --cc=carlos@redhat.com \
    --cc=dalias@libc.org \
    --cc=davejwatson@fb.com \
    --cc=fweimer@redhat.com \
    --cc=joseph@codesourcery.com \
    --cc=libc-alpha@sourceware.org \
    --cc=linux-api@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=paulmck@linux.vnet.ibm.com \
    --cc=peterz@infradead.org \
    --cc=pjt@google.com \
    --cc=szabolcs.nagy@arm.com \
    --cc=tglx@linutronix.de \
    --cc=will.deacon@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.