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:00:04 +0000 (12:00 -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.

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 40cf3f916ee4c0056f2cde795bb857f4920a5230..d6f569e8a28bcdfc546dca4008dcf727e1226f53 100644 (file)
@@ -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);
+}
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 36f57efb25f4d97c31bcb04b7fd207f2807b9a8c..ba69f5fff35a84c14fa97e64de461957f634a37f 100644 (file)
@@ -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
This page took 0.028658 seconds and 4 git commands to generate.