From: Mathieu Desnoyers Date: Sat, 1 Oct 2016 22:59:17 +0000 (-0400) Subject: Fix: perform TLS fixup in all UST entry points from each thread X-Git-Tag: v2.9.0-rc1~7 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=c362addf1c50e1d3202a26ff96738b71b4f9a531;p=lttng-ust.git Fix: perform TLS fixup in all UST entry points from each thread Each entry point into lttng-ust that end up taking the ust lock need to perform a TLS fixup for each thread. Add a TLS fixup in both listener threads, in fork and base address dump helper libs, and in app context and tracepoint probe registration/unregistration functions, which can be called from application threads. Those ensure we don't take the libc dl lock within the ust lock when performing the TLS lazy fixup. Signed-off-by: Mathieu Desnoyers --- diff --git a/liblttng-ust/lttng-context-provider.c b/liblttng-ust/lttng-context-provider.c index c580891a..8e065abe 100644 --- a/liblttng-ust/lttng-context-provider.c +++ b/liblttng-ust/lttng-context-provider.c @@ -68,6 +68,8 @@ int lttng_ust_context_provider_register(struct lttng_ust_context_provider *provi uint32_t hash; int ret = 0; + lttng_ust_fixup_tls(); + /* Provider name starts with "$app.". */ if (strncmp("$app.", provider->name, strlen("$app.") != 0)) return -EINVAL; @@ -95,6 +97,8 @@ end: void lttng_ust_context_provider_unregister(struct lttng_ust_context_provider *provider) { + lttng_ust_fixup_tls(); + if (ust_lock()) goto end; lttng_ust_context_set_session_provider(provider->name, diff --git a/liblttng-ust/lttng-probes.c b/liblttng-ust/lttng-probes.c index 5e2d2966..390265ad 100644 --- a/liblttng-ust/lttng-probes.c +++ b/liblttng-ust/lttng-probes.c @@ -195,6 +195,8 @@ int lttng_probe_register(struct lttng_probe_desc *desc) { int ret = 0; + lttng_ust_fixup_tls(); + /* * If version mismatch, don't register, but don't trigger assert * on caller. The version check just prints an error. @@ -235,6 +237,8 @@ int ltt_probe_register(struct lttng_probe_desc *desc) void lttng_probe_unregister(struct lttng_probe_desc *desc) { + lttng_ust_fixup_tls(); + if (!check_provider_version(desc)) return; diff --git a/liblttng-ust/lttng-tracer-core.h b/liblttng-ust/lttng-tracer-core.h index 44aca749..ba232f32 100644 --- a/liblttng-ust/lttng-tracer-core.h +++ b/liblttng-ust/lttng-tracer-core.h @@ -62,5 +62,6 @@ void lttng_ust_dummy_record(struct lttng_ctx_field *field, void lttng_ust_dummy_get_value(struct lttng_ctx_field *field, struct lttng_ctx_value *value); int lttng_context_is_app(const char *name); +void lttng_ust_fixup_tls(void); #endif /* _LTTNG_TRACER_CORE_H */ diff --git a/liblttng-ust/lttng-ust-comm.c b/liblttng-ust/lttng-ust-comm.c index a84316a9..1720bca9 100644 --- a/liblttng-ust/lttng-ust-comm.c +++ b/liblttng-ust/lttng-ust-comm.c @@ -396,6 +396,16 @@ void lttng_fixup_urcu_bp_tls(void) rcu_read_unlock(); } +void lttng_ust_fixup_tls(void) +{ + lttng_fixup_urcu_bp_tls(); + lttng_fixup_ringbuffer_tls(); + lttng_fixup_vtid_tls(); + lttng_fixup_nest_count_tls(); + lttng_fixup_procname_tls(); + lttng_fixup_ust_mutex_nest_tls(); +} + int lttng_get_notify_socket(void *owner) { struct sock_info *info = owner; @@ -1303,6 +1313,7 @@ void *ust_listener_thread(void *arg) int sock, ret, prev_connect_failed = 0, has_waited = 0; long timeout; + lttng_ust_fixup_tls(); /* * If available, add '-ust' to the end of this thread's * process name @@ -1575,12 +1586,7 @@ void __attribute__((constructor)) lttng_ust_init(void) * to be the dynamic linker mutex) and ust_lock, taken within * the ust lock. */ - lttng_fixup_urcu_bp_tls(); - lttng_fixup_ringbuffer_tls(); - lttng_fixup_vtid_tls(); - lttng_fixup_nest_count_tls(); - lttng_fixup_procname_tls(); - lttng_fixup_ust_mutex_nest_tls(); + lttng_ust_fixup_tls(); lttng_ust_loaded = 1; @@ -1811,6 +1817,9 @@ void ust_before_fork(sigset_t *save_sigset) sigset_t all_sigs; int ret; + /* Fixup lttng-ust TLS. */ + lttng_ust_fixup_tls(); + if (URCU_TLS(lttng_ust_nest_count)) return; /* Disable signals */ diff --git a/liblttng-ust/lttng-ust-statedump.c b/liblttng-ust/lttng-ust-statedump.c index 644af303..171cbaec 100644 --- a/liblttng-ust/lttng-ust-statedump.c +++ b/liblttng-ust/lttng-ust-statedump.c @@ -551,6 +551,12 @@ void lttng_ust_dl_update(void *ip) if (getenv("LTTNG_UST_WITHOUT_BADDR_STATEDUMP")) return; + /* + * Fixup lttng-ust TLS when called from dlopen/dlclose + * instrumentation. + */ + lttng_ust_fixup_tls(); + data.exec_found = 0; data.first = true; data.cancel = false;