From: Mathieu Desnoyers Date: Thu, 1 Mar 2012 17:00:04 +0000 (-0500) Subject: Fix: fix deadlock with dlopen() lttng-ust X-Git-Tag: v2.1.0-rc1~97^2~7 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=60c089cf52bf7ffdddbbbdd32278aeeb83bd5c97;p=lttng-ust.git Fix: fix deadlock with dlopen() lttng-ust Pre-"fault" the libuuid TLS outside of the ust lock to ensure that we never deadlock with the linker mutex in libc. This mutex is held both for TLS fixup of dlopen'd libs, and across execution of all constructors. We therefore have a reverse use of this mutex wrt ust lock, that we fix by forcing the TLS fixup to happen very early in the lttng-ust constructor. Signed-off-by: Mathieu Desnoyers --- diff --git a/liblttng-ust/ltt-events.c b/liblttng-ust/ltt-events.c index 40cf3f91..d6f569e8 100644 --- a/liblttng-ust/ltt-events.c +++ b/liblttng-ust/ltt-events.c @@ -1458,3 +1458,16 @@ int ltt_wildcard_disable(struct session_wildcard *wildcard) wildcard->enabled = 0; return 0; } + +/* + * Take the TLS "fault" in libuuid if dlopen'd, which can take the + * dynamic linker mutex, outside of the UST lock, since the UST lock is + * taken in constructors, which are called with dynamic linker mutex + * held. + */ +void lttng_fixup_event_tls(void) +{ + unsigned char uuid[LTTNG_UST_UUID_STR_LEN]; + + (void) lttng_ust_uuid_generate(uuid); +} diff --git a/liblttng-ust/ltt-tracer-core.h b/liblttng-ust/ltt-tracer-core.h index fdb73119..7fdf3c9e 100644 --- a/liblttng-ust/ltt-tracer-core.h +++ b/liblttng-ust/ltt-tracer-core.h @@ -37,4 +37,6 @@ struct ltt_event; void ust_lock(void); void ust_unlock(void); +void lttng_fixup_event_tls(void); + #endif /* _LTT_TRACER_CORE_H */ diff --git a/liblttng-ust/lttng-ust-comm.c b/liblttng-ust/lttng-ust-comm.c index 36f57efb..ba69f5ff 100644 --- a/liblttng-ust/lttng-ust-comm.c +++ b/liblttng-ust/lttng-ust-comm.c @@ -827,6 +827,13 @@ void __attribute__((constructor)) lttng_ust_init(void) if (uatomic_xchg(&initialized, 1) == 1) return; + /* + * Fixup interdependency between TLS fixup mutex (which happens + * to be the dynamic linker mutex) and ust_lock, taken within + * the ust lock. + */ + lttng_fixup_event_tls(); + /* * We want precise control over the order in which we construct * our sub-libraries vs starting to receive commands from