Commit 7818b388 authored by Steven Rostedt (Red Hat)'s avatar Steven Rostedt (Red Hat) Committed by Steven Rostedt

ftrace: Use manual free after synchronize_sched() not call_rcu_sched()

The entries to the probe hash must be freed after a synchronize_sched()
after the entry has been removed from the hash.

As the entries are registered with ops that may have their own callbacks,
and these callbacks may sleep, we can not use call_rcu_sched() because
the rcu callbacks registered with that are called from a softirq context.

Instead of using call_rcu_sched(), manually save the entries on a free_list
and at the end of the loop that removes the entries, do a synchronize_sched()
and then go through the free_list, freeing the entries.

Cc: Paul McKenney <paulmck@linux.vnet.ibm.com>
Signed-off-by: default avatarSteven Rostedt <rostedt@goodmis.org>
parent e67efb93
...@@ -1068,7 +1068,7 @@ struct ftrace_func_probe { ...@@ -1068,7 +1068,7 @@ struct ftrace_func_probe {
unsigned long flags; unsigned long flags;
unsigned long ip; unsigned long ip;
void *data; void *data;
struct rcu_head rcu; struct list_head free_list;
}; };
struct ftrace_func_entry { struct ftrace_func_entry {
...@@ -2978,11 +2978,8 @@ static void __disable_ftrace_function_probe(void) ...@@ -2978,11 +2978,8 @@ static void __disable_ftrace_function_probe(void)
} }
static void ftrace_free_entry_rcu(struct rcu_head *rhp) static void ftrace_free_entry(struct ftrace_func_probe *entry)
{ {
struct ftrace_func_probe *entry =
container_of(rhp, struct ftrace_func_probe, rcu);
if (entry->ops->free) if (entry->ops->free)
entry->ops->free(entry->ops, entry->ip, &entry->data); entry->ops->free(entry->ops, entry->ip, &entry->data);
kfree(entry); kfree(entry);
...@@ -3092,7 +3089,9 @@ __unregister_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops, ...@@ -3092,7 +3089,9 @@ __unregister_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
{ {
struct ftrace_func_entry *rec_entry; struct ftrace_func_entry *rec_entry;
struct ftrace_func_probe *entry; struct ftrace_func_probe *entry;
struct ftrace_func_probe *p;
struct ftrace_hash **orig_hash = &trace_probe_ops.filter_hash; struct ftrace_hash **orig_hash = &trace_probe_ops.filter_hash;
struct list_head free_list;
struct ftrace_hash *hash; struct ftrace_hash *hash;
struct hlist_node *n, *tmp; struct hlist_node *n, *tmp;
char str[KSYM_SYMBOL_LEN]; char str[KSYM_SYMBOL_LEN];
...@@ -3120,6 +3119,8 @@ __unregister_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops, ...@@ -3120,6 +3119,8 @@ __unregister_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
/* Hmm, should report this somehow */ /* Hmm, should report this somehow */
goto out_unlock; goto out_unlock;
INIT_LIST_HEAD(&free_list);
for (i = 0; i < FTRACE_FUNC_HASHSIZE; i++) { for (i = 0; i < FTRACE_FUNC_HASHSIZE; i++) {
struct hlist_head *hhd = &ftrace_func_hash[i]; struct hlist_head *hhd = &ftrace_func_hash[i];
...@@ -3146,7 +3147,7 @@ __unregister_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops, ...@@ -3146,7 +3147,7 @@ __unregister_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
free_hash_entry(hash, rec_entry); free_hash_entry(hash, rec_entry);
hlist_del_rcu(&entry->node); hlist_del_rcu(&entry->node);
call_rcu_sched(&entry->rcu, ftrace_free_entry_rcu); list_add(&entry->free_list, &free_list);
} }
} }
__disable_ftrace_function_probe(); __disable_ftrace_function_probe();
...@@ -3155,6 +3156,12 @@ __unregister_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops, ...@@ -3155,6 +3156,12 @@ __unregister_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
* probe is removed, a null hash means *all enabled*. * probe is removed, a null hash means *all enabled*.
*/ */
ftrace_hash_move(&trace_probe_ops, 1, orig_hash, hash); ftrace_hash_move(&trace_probe_ops, 1, orig_hash, hash);
synchronize_sched();
list_for_each_entry_safe(entry, p, &free_list, free_list) {
list_del(&entry->free_list);
ftrace_free_entry(entry);
}
out_unlock: out_unlock:
mutex_unlock(&ftrace_lock); mutex_unlock(&ftrace_lock);
free_ftrace_hash(hash); free_ftrace_hash(hash);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment