From: David Goulet Date: Tue, 22 Jan 2013 17:13:13 +0000 (-0500) Subject: Fix: add missing rcu lock for UST lookup X-Git-Tag: v2.1.2~23 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=d861c9074f19f590c4bd2bf6da482ab3968bf0ab;p=lttng-tools.git Fix: add missing rcu lock for UST lookup Trace UST channel and event were not protected by RCU lock when calling their find function. Furthermore, the event lookup was not protected at all during and after the lookup. Signed-off-by: David Goulet --- diff --git a/src/bin/lttng-sessiond/cmd.c b/src/bin/lttng-sessiond/cmd.c index 8c6204c4d..8bffdc406 100644 --- a/src/bin/lttng-sessiond/cmd.c +++ b/src/bin/lttng-sessiond/cmd.c @@ -766,6 +766,8 @@ int cmd_disable_channel(struct ltt_session *session, int domain, usess = session->ust_session; + rcu_read_lock(); + switch (domain) { case LTTNG_DOMAIN_KERNEL: { @@ -810,6 +812,7 @@ int cmd_disable_channel(struct ltt_session *session, int domain, ret = LTTNG_OK; error: + rcu_read_unlock(); return ret; } @@ -830,6 +833,8 @@ int cmd_enable_channel(struct ltt_session *session, DBG("Enabling channel %s for session %s", attr->name, session->name); + rcu_read_lock(); + switch (domain) { case LTTNG_DOMAIN_KERNEL: { @@ -898,6 +903,7 @@ int cmd_enable_channel(struct ltt_session *session, } error: + rcu_read_unlock(); return ret; } @@ -910,6 +916,8 @@ int cmd_disable_event(struct ltt_session *session, int domain, { int ret; + rcu_read_lock(); + switch (domain) { case LTTNG_DOMAIN_KERNEL: { @@ -968,6 +976,7 @@ int cmd_disable_event(struct ltt_session *session, int domain, ret = LTTNG_OK; error: + rcu_read_unlock(); return ret; } @@ -979,6 +988,8 @@ int cmd_disable_event_all(struct ltt_session *session, int domain, { int ret; + rcu_read_lock(); + switch (domain) { case LTTNG_DOMAIN_KERNEL: { @@ -1037,6 +1048,7 @@ int cmd_disable_event_all(struct ltt_session *session, int domain, ret = LTTNG_OK; error: + rcu_read_unlock(); return ret; } @@ -1126,6 +1138,8 @@ int cmd_enable_event(struct ltt_session *session, int domain, assert(event); assert(channel_name); + rcu_read_lock(); + switch (domain) { case LTTNG_DOMAIN_KERNEL: { @@ -1219,6 +1233,7 @@ int cmd_enable_event(struct ltt_session *session, int domain, ret = LTTNG_OK; error: + rcu_read_unlock(); return ret; } @@ -1235,6 +1250,8 @@ int cmd_enable_event_all(struct ltt_session *session, int domain, assert(session); assert(channel_name); + rcu_read_lock(); + switch (domain) { case LTTNG_DOMAIN_KERNEL: { @@ -1365,6 +1382,7 @@ int cmd_enable_event_all(struct ltt_session *session, int domain, ret = LTTNG_OK; error: + rcu_read_unlock(); return ret; } diff --git a/src/bin/lttng-sessiond/context.c b/src/bin/lttng-sessiond/context.c index cee61f764..ef5e3e1f0 100644 --- a/src/bin/lttng-sessiond/context.c +++ b/src/bin/lttng-sessiond/context.c @@ -223,6 +223,8 @@ int context_ust_add(struct ltt_ust_session *usess, int domain, struct lttng_ht *chan_ht; struct ltt_ust_channel *uchan = NULL; + rcu_read_lock(); + /* * Define which channel's hashtable to use from the domain or quit if * unknown domain. @@ -285,5 +287,6 @@ int context_ust_add(struct ltt_ust_session *usess, int domain, } error: + rcu_read_unlock(); return ret; } diff --git a/src/bin/lttng-sessiond/trace-ust.c b/src/bin/lttng-sessiond/trace-ust.c index 3d9390db2..801e89077 100644 --- a/src/bin/lttng-sessiond/trace-ust.c +++ b/src/bin/lttng-sessiond/trace-ust.c @@ -116,7 +116,8 @@ no_match: } /* - * Find the channel in the hashtable. + * Find the channel in the hashtable and return channel pointer. RCU read side + * lock MUST be acquired before calling this. */ struct ltt_ust_channel *trace_ust_find_channel_by_name(struct lttng_ht *ht, char *name) @@ -124,14 +125,11 @@ struct ltt_ust_channel *trace_ust_find_channel_by_name(struct lttng_ht *ht, struct lttng_ht_node_str *node; struct lttng_ht_iter iter; - rcu_read_lock(); lttng_ht_lookup(ht, (void *)name, &iter); node = lttng_ht_iter_get_node_str(&iter); if (node == NULL) { - rcu_read_unlock(); goto error; } - rcu_read_unlock(); DBG2("Trace UST channel %s found by name", name); @@ -143,7 +141,8 @@ error: } /* - * Find the event in the hashtable. + * Find the event in the hashtable and return event pointer. RCU read side lock + * MUST be acquired before calling this. */ struct ltt_ust_event *trace_ust_find_event(struct lttng_ht *ht, char *name, struct lttng_filter_bytecode *filter, int loglevel)