<p dir="ltr">Merged in master, stable-2.7, stable-2.6 and stable-2.5.</p>
<p dir="ltr">Thanks,<br>
Jérémie</p>
<div class="gmail_quote">On Aug 6, 2015 15:02, "Mathieu Desnoyers" <<a href="mailto:mathieu.desnoyers@efficios.com">mathieu.desnoyers@efficios.com</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">After review, a great deal of caller sites miss the RCU read-side lock<br>
when using the hash table modification functions. This is a case where<br>
having a slight performance degradation might be worthwhile if we can be<br>
a bit more stability. So instead of playing whack-a-mole, add the RCU<br>
read-side lock in the hash table modification functions to ensure<br>
protection from ABA.<br>
<br>
Signed-off-by: Mathieu Desnoyers <<a href="mailto:mathieu.desnoyers@efficios.com">mathieu.desnoyers@efficios.com</a>><br>
---<br>
src/common/hashtable/hashtable.c | 45 +++++++++++++++++++++++++++++++++++++++-<br>
1 file changed, 44 insertions(+), 1 deletion(-)<br>
<br>
diff --git a/src/common/hashtable/hashtable.c b/src/common/hashtable/hashtable.c<br>
index 3a38cbf..d1049d1 100644<br>
--- a/src/common/hashtable/hashtable.c<br>
+++ b/src/common/hashtable/hashtable.c<br>
@@ -34,6 +34,13 @@ static unsigned long min_hash_alloc_size = 1;<br>
static unsigned long max_hash_buckets_size = 0;<br>
<br>
/*<br>
+ * Getter/lookup functions need to be called with RCU read-side lock<br>
+ * held. However, modification functions (add, add_unique, replace, del)<br>
+ * take the RCU lock internally, so it does not matter whether the<br>
+ * caller hold the RCU lock or not.<br>
+ */<br>
+<br>
+/*<br>
* Match function for string node.<br>
*/<br>
static int match_str(struct cds_lfht_node *node, const void *key)<br>
@@ -253,8 +260,11 @@ void lttng_ht_add_unique_str(struct lttng_ht *ht,<br>
assert(ht->ht);<br>
assert(node);<br>
<br>
+ /* RCU read lock protects from ABA. */<br>
+ rcu_read_lock();<br>
node_ptr = cds_lfht_add_unique(ht->ht, ht->hash_fct(node->key, lttng_ht_seed),<br>
ht->match_fct, node->key, &node->node);<br>
+ rcu_read_unlock();<br>
assert(node_ptr == &node->node);<br>
}<br>
<br>
@@ -268,8 +278,11 @@ void lttng_ht_add_str(struct lttng_ht *ht,<br>
assert(ht->ht);<br>
assert(node);<br>
<br>
+ /* RCU read lock protects from ABA. */<br>
+ rcu_read_lock();<br>
cds_lfht_add(ht->ht, ht->hash_fct(node->key, lttng_ht_seed),<br>
&node->node);<br>
+ rcu_read_unlock();<br>
}<br>
<br>
/*<br>
@@ -281,8 +294,11 @@ void lttng_ht_add_ulong(struct lttng_ht *ht, struct lttng_ht_node_ulong *node)<br>
assert(ht->ht);<br>
assert(node);<br>
<br>
+ /* RCU read lock protects from ABA. */<br>
+ rcu_read_lock();<br>
cds_lfht_add(ht->ht, ht->hash_fct((void *) node->key, lttng_ht_seed),<br>
&node->node);<br>
+ rcu_read_unlock();<br>
}<br>
<br>
/*<br>
@@ -295,8 +311,11 @@ void lttng_ht_add_u64(struct lttng_ht *ht, struct lttng_ht_node_u64 *node)<br>
assert(ht->ht);<br>
assert(node);<br>
<br>
+ /* RCU read lock protects from ABA. */<br>
+ rcu_read_lock();<br>
cds_lfht_add(ht->ht, ht->hash_fct(&node->key, lttng_ht_seed),<br>
&node->node);<br>
+ rcu_read_unlock();<br>
}<br>
<br>
/*<br>
@@ -310,9 +329,12 @@ void lttng_ht_add_unique_ulong(struct lttng_ht *ht,<br>
assert(ht->ht);<br>
assert(node);<br>
<br>
+ /* RCU read lock protects from ABA. */<br>
+ rcu_read_lock();<br>
node_ptr = cds_lfht_add_unique(ht->ht,<br>
ht->hash_fct((void *) node->key, lttng_ht_seed), ht->match_fct,<br>
(void *) node->key, &node->node);<br>
+ rcu_read_unlock();<br>
assert(node_ptr == &node->node);<br>
}<br>
<br>
@@ -327,9 +349,12 @@ void lttng_ht_add_unique_u64(struct lttng_ht *ht,<br>
assert(ht->ht);<br>
assert(node);<br>
<br>
+ /* RCU read lock protects from ABA. */<br>
+ rcu_read_lock();<br>
node_ptr = cds_lfht_add_unique(ht->ht,<br>
ht->hash_fct(&node->key, lttng_ht_seed), ht->match_fct,<br>
&node->key, &node->node);<br>
+ rcu_read_unlock();<br>
assert(node_ptr == &node->node);<br>
}<br>
<br>
@@ -344,9 +369,12 @@ void lttng_ht_add_unique_two_u64(struct lttng_ht *ht,<br>
assert(ht->ht);<br>
assert(node);<br>
<br>
+ /* RCU read lock protects from ABA. */<br>
+ rcu_read_lock();<br>
node_ptr = cds_lfht_add_unique(ht->ht,<br>
ht->hash_fct((void *) &node->key, lttng_ht_seed), ht->match_fct,<br>
(void *) &node->key, &node->node);<br>
+ rcu_read_unlock();<br>
assert(node_ptr == &node->node);<br>
}<br>
<br>
@@ -361,9 +389,12 @@ struct lttng_ht_node_ulong *lttng_ht_add_replace_ulong(struct lttng_ht *ht,<br>
assert(ht->ht);<br>
assert(node);<br>
<br>
+ /* RCU read lock protects from ABA. */<br>
+ rcu_read_lock();<br>
node_ptr = cds_lfht_add_replace(ht->ht,<br>
ht->hash_fct((void *) node->key, lttng_ht_seed), ht->match_fct,<br>
(void *) node->key, &node->node);<br>
+ rcu_read_unlock();<br>
if (!node_ptr) {<br>
return NULL;<br>
} else {<br>
@@ -383,9 +414,12 @@ struct lttng_ht_node_u64 *lttng_ht_add_replace_u64(struct lttng_ht *ht,<br>
assert(ht->ht);<br>
assert(node);<br>
<br>
+ /* RCU read lock protects from ABA. */<br>
+ rcu_read_lock();<br>
node_ptr = cds_lfht_add_replace(ht->ht,<br>
ht->hash_fct(&node->key, lttng_ht_seed), ht->match_fct,<br>
&node->key, &node->node);<br>
+ rcu_read_unlock();<br>
if (!node_ptr) {<br>
return NULL;<br>
} else {<br>
@@ -399,11 +433,17 @@ struct lttng_ht_node_u64 *lttng_ht_add_replace_u64(struct lttng_ht *ht,<br>
*/<br>
int lttng_ht_del(struct lttng_ht *ht, struct lttng_ht_iter *iter)<br>
{<br>
+ int ret;<br>
+<br>
assert(ht);<br>
assert(ht->ht);<br>
assert(iter);<br>
<br>
- return cds_lfht_del(ht->ht, iter->iter.node);<br>
+ /* RCU read lock protects from ABA. */<br>
+ rcu_read_lock();<br>
+ ret = cds_lfht_del(ht->ht, iter->iter.node);<br>
+ rcu_read_unlock();<br>
+ return ret;<br>
}<br>
<br>
/*<br>
@@ -441,7 +481,10 @@ unsigned long lttng_ht_get_count(struct lttng_ht *ht)<br>
assert(ht);<br>
assert(ht->ht);<br>
<br>
+ /* RCU read lock protects from ABA and allows RCU traversal. */<br>
+ rcu_read_lock();<br>
cds_lfht_count_nodes(ht->ht, &scb, &count, &sca);<br>
+ rcu_read_unlock();<br>
<br>
return count;<br>
}<br>
--<br>
2.1.4<br>
<br>
</blockquote></div>