Skip to content

Commit

Permalink
ftrace: Remove freeing of old_hash from ftrace_hash_move()
Browse files Browse the repository at this point in the history
ftrace_hash_move() currently frees the old hash that is passed to it
after replacing the pointer with the new hash. Instead of having the
function do that chore, have the caller perform the free.

This lets the ftrace_hash_move() be used a bit more freely, which
is needed for changing the way the trampoline logic is done.

Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
  • Loading branch information
Steven Rostedt (Red Hat) committed Sep 10, 2014
1 parent f7aad4e commit 3296fc4
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions kernel/trace/ftrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -1316,7 +1316,6 @@ ftrace_hash_move(struct ftrace_ops *ops, int enable,
struct ftrace_func_entry *entry;
struct hlist_node *tn;
struct hlist_head *hhd;
struct ftrace_hash *old_hash;
struct ftrace_hash *new_hash;
int size = src->count;
int bits = 0;
Expand Down Expand Up @@ -1361,9 +1360,7 @@ ftrace_hash_move(struct ftrace_ops *ops, int enable,
*/
ftrace_hash_rec_disable_modify(ops, enable);

old_hash = *dst;
rcu_assign_pointer(*dst, new_hash);
free_ftrace_hash_rcu(old_hash);

ftrace_hash_rec_enable_modify(ops, enable);

Expand Down Expand Up @@ -3408,6 +3405,7 @@ register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
{
struct ftrace_func_probe *entry;
struct ftrace_hash **orig_hash = &trace_probe_ops.func_hash->filter_hash;
struct ftrace_hash *old_hash = *orig_hash;
struct ftrace_hash *hash;
struct ftrace_page *pg;
struct dyn_ftrace *rec;
Expand All @@ -3426,7 +3424,7 @@ register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,

mutex_lock(&trace_probe_ops.func_hash->regex_lock);

hash = alloc_and_copy_ftrace_hash(FTRACE_HASH_DEFAULT_BITS, *orig_hash);
hash = alloc_and_copy_ftrace_hash(FTRACE_HASH_DEFAULT_BITS, old_hash);
if (!hash) {
count = -ENOMEM;
goto out;
Expand Down Expand Up @@ -3485,7 +3483,9 @@ register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
} while_for_each_ftrace_rec();

ret = ftrace_hash_move(&trace_probe_ops, 1, orig_hash, hash);
if (ret < 0)
if (!ret)
free_ftrace_hash_rcu(old_hash);
else
count = ret;

__enable_ftrace_function_probe();
Expand All @@ -3512,13 +3512,15 @@ __unregister_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
struct ftrace_func_probe *entry;
struct ftrace_func_probe *p;
struct ftrace_hash **orig_hash = &trace_probe_ops.func_hash->filter_hash;
struct ftrace_hash *old_hash = *orig_hash;
struct list_head free_list;
struct ftrace_hash *hash;
struct hlist_node *tmp;
char str[KSYM_SYMBOL_LEN];
int type = MATCH_FULL;
int i, len = 0;
char *search;
int ret;

if (glob && (strcmp(glob, "*") == 0 || !strlen(glob)))
glob = NULL;
Expand Down Expand Up @@ -3577,8 +3579,11 @@ __unregister_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
* Remove after the disable is called. Otherwise, if the last
* probe is removed, a null hash means *all enabled*.
*/
ftrace_hash_move(&trace_probe_ops, 1, orig_hash, hash);
ret = ftrace_hash_move(&trace_probe_ops, 1, orig_hash, hash);
synchronize_sched();
if (!ret)
free_ftrace_hash_rcu(old_hash);

list_for_each_entry_safe(entry, p, &free_list, free_list) {
list_del(&entry->free_list);
ftrace_free_entry(entry);
Expand Down Expand Up @@ -3776,6 +3781,7 @@ ftrace_set_hash(struct ftrace_ops *ops, unsigned char *buf, int len,
unsigned long ip, int remove, int reset, int enable)
{
struct ftrace_hash **orig_hash;
struct ftrace_hash *old_hash;
struct ftrace_hash *hash;
int ret;

Expand Down Expand Up @@ -3810,10 +3816,12 @@ ftrace_set_hash(struct ftrace_ops *ops, unsigned char *buf, int len,
}

mutex_lock(&ftrace_lock);
old_hash = *orig_hash;
ret = ftrace_hash_move(ops, enable, orig_hash, hash);
if (!ret)
if (!ret) {
ftrace_ops_update_code(ops);

free_ftrace_hash_rcu(old_hash);
}
mutex_unlock(&ftrace_lock);

out_regex_unlock:
Expand Down Expand Up @@ -4022,6 +4030,7 @@ int ftrace_regex_release(struct inode *inode, struct file *file)
struct seq_file *m = (struct seq_file *)file->private_data;
struct ftrace_iterator *iter;
struct ftrace_hash **orig_hash;
struct ftrace_hash *old_hash;
struct trace_parser *parser;
int filter_hash;
int ret;
Expand Down Expand Up @@ -4051,11 +4060,13 @@ int ftrace_regex_release(struct inode *inode, struct file *file)
orig_hash = &iter->ops->func_hash->notrace_hash;

mutex_lock(&ftrace_lock);
old_hash = *orig_hash;
ret = ftrace_hash_move(iter->ops, filter_hash,
orig_hash, iter->hash);
if (!ret)
if (!ret) {
ftrace_ops_update_code(iter->ops);

free_ftrace_hash_rcu(old_hash);
}
mutex_unlock(&ftrace_lock);
}

Expand Down

0 comments on commit 3296fc4

Please sign in to comment.