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.0.0-rc2~14 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=eddd8d5d1a04887d1979417f1aca6c2f109bfe50;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. [fixed merge from dev branch] Signed-off-by: Mathieu Desnoyers --- diff --git a/liblttng-ust/ltt-events.c b/liblttng-ust/ltt-events.c index b67a15c6..72e315ec 100644 --- a/liblttng-ust/ltt-events.c +++ b/liblttng-ust/ltt-events.c @@ -1455,3 +1455,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[37]; + + (void) 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 44e8bab4..fa184ad7 100644 --- a/liblttng-ust/lttng-ust-comm.c +++ b/liblttng-ust/lttng-ust-comm.c @@ -832,6 +832,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