Skip to contentSkip to conversation

ftrace: safe traversal of ftrace_hash hlist

PATCH Applied Abhishek Sagar 2 participants 2 messages May 24, 2008 – May 27, 2008

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ftrace: safe traversal of ftrace_hash hlist

Hi Steven,

I noticed that concurrent instances of ftrace_record_ip() have a race between ftrace_hash list traversal during ftrace_ip_in_hash() (before acquiring ftrace_shutdown_lock) and ftrace_add_hash().If it's so then this should fix it.

---
Accommodate traversal of ftrace_hash hlist with concurrent insertions.

kernel/trace/ftrace.c +2 -2
index 89bd9a6..bfba25c 100644
@@ -201,7 +201,7 @@ ftrace_ip_in_hash(unsigned long ip, unsigned long key)
 	struct hlist_node *t;
 	int found = 0;
 
-	hlist_for_each_entry(p, t, &ftrace_hash[key], node) {
+	hlist_for_each_entry_rcu(p, t, &ftrace_hash[key], node) {
 		if (p->ip == ip) {
 			found = 1;
 			break;
@@ -214,7 +214,7 @@ ftrace_ip_in_hash(unsigned long ip, unsigned long key)
 static inline void
 ftrace_add_hash(struct dyn_ftrace *node, unsigned long key)
 {
-	hlist_add_head(&node->node, &ftrace_hash[key]);
+	hlist_add_head_rcu(&node->node, &ftrace_hash[key]);
 }
 
 static void ftrace_free_rec(struct dyn_ftrace *rec)
#1 lore raw
Quoted 6 lines · Abhishek Sagar

Hi Steven,

I noticed that concurrent instances of ftrace_record_ip() have a race between ftrace_hash list traversal during ftrace_ip_in_hash() (before acquiring ftrace_shutdown_lock) and ftrace_add_hash().If it's so then this should fix it.

Applied. Thanks,

tglx