Fix: fix deadlock with dlopen() lttng-ust
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Thu, 1 Mar 2012 17:00:04 +0000 (12:00 -0500)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Thu, 1 Mar 2012 17:36:32 +0000 (12:36 -0500)
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 <mathieu.desnoyers@efficios.com>
liblttng-ust/ltt-events.c
liblttng-ust/ltt-tracer-core.h
liblttng-ust/lttng-ust-comm.c

index b67a15c67b51fef30683b99a0c929dffef06fcfb..72e315ec8593bb229f83788a681f84aae3e36147 100644 (file)
@@ -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);
+}
index fdb73119816d5a38a4d056bd0a21d6e4fe4df5ca..7fdf3c9efc52b892bda0140359d46083b0ccc0c1 100644 (file)
@@ -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 */
index 44e8bab4c24ca4aa2a77b72727288c9b24c8e67d..fa184ad74270d50dfe29e45c3c0984a2b2d6c4b5 100644 (file)
@@ -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
This page took 0.027091 seconds and 4 git commands to generate.