From: Mathieu Desnoyers Date: Thu, 14 Feb 2019 21:39:57 +0000 (-0500) Subject: Fix: additional compiler barriers for procname context X-Git-Tag: v2.12.0-rc1~55 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=2c44512a8bb58e1b566c285137c0c38dfa26278f;p=lttng-ust.git Fix: additional compiler barriers for procname context Use additional volatile load/stores and compiler barriers to make sure the compiler do not reorder the nesting counter wrt procname cache content load/stores. Signed-off-by: Mathieu Desnoyers --- diff --git a/liblttng-ust/lttng-context-procname.c b/liblttng-ust/lttng-context-procname.c index 95d5f28d..8c1520ad 100644 --- a/liblttng-ust/lttng-context-procname.c +++ b/liblttng-ust/lttng-context-procname.c @@ -49,24 +49,29 @@ static DEFINE_URCU_TLS(int, procname_nesting); static inline char *wrapper_getprocname(void) { - int nesting = URCU_TLS(procname_nesting); + int nesting = CMM_LOAD_SHARED(URCU_TLS(procname_nesting)); if (caa_unlikely(nesting >= PROCNAME_NESTING_MAX)) return ""; if (caa_unlikely(!URCU_TLS(cached_procname)[nesting][0])) { CMM_STORE_SHARED(URCU_TLS(procname_nesting), nesting + 1); + /* Increment nesting before updating cache. */ + cmm_barrier(); lttng_ust_getprocname(URCU_TLS(cached_procname)[nesting]); URCU_TLS(cached_procname)[nesting][LTTNG_UST_PROCNAME_LEN - 1] = '\0'; + /* Decrement nesting after updating cache. */ + cmm_barrier(); CMM_STORE_SHARED(URCU_TLS(procname_nesting), nesting); } return URCU_TLS(cached_procname)[nesting]; } +/* Reset should not be called from a signal handler. */ void lttng_context_procname_reset(void) { - URCU_TLS(cached_procname)[1][0] = '\0'; + CMM_STORE_SHARED(URCU_TLS(cached_procname)[1][0], '\0'); CMM_STORE_SHARED(URCU_TLS(procname_nesting), 1); - URCU_TLS(cached_procname)[0][0] = '\0'; + CMM_STORE_SHARED(URCU_TLS(cached_procname)[0][0], '\0'); CMM_STORE_SHARED(URCU_TLS(procname_nesting), 0); }