Commit 8a224ffb authored by Chengming Zhou's avatar Chengming Zhou Committed by Steven Rostedt (VMware)

ftrace: Setup correct FTRACE_FL_REGS flags for module

When module loaded and enabled, we will use __ftrace_replace_code
for module if any ftrace_ops referenced it found. But we will get
wrong ftrace_addr for module rec in ftrace_get_addr_new, because
rec->flags has not been setup correctly. It can cause the callback
function of a ftrace_ops has FTRACE_OPS_FL_SAVE_REGS to be called
with pt_regs set to NULL.
So setup correct FTRACE_FL_REGS flags for rec when we call
referenced_filters to find ftrace_ops references it.

Link: https://lkml.kernel.org/r/20200728180554.65203-1-zhouchengming@bytedance.com

Cc: stable@vger.kernel.org
Fixes: 8c4f3c3f ("ftrace: Check module functions being traced on reload")
Signed-off-by: default avatarChengming Zhou <zhouchengming@bytedance.com>
Signed-off-by: default avatarMuchun Song <songmuchun@bytedance.com>
Signed-off-by: default avatarSteven Rostedt (VMware) <rostedt@goodmis.org>
parent 96b4833b
...@@ -6198,8 +6198,11 @@ static int referenced_filters(struct dyn_ftrace *rec) ...@@ -6198,8 +6198,11 @@ static int referenced_filters(struct dyn_ftrace *rec)
int cnt = 0; int cnt = 0;
for (ops = ftrace_ops_list; ops != &ftrace_list_end; ops = ops->next) { for (ops = ftrace_ops_list; ops != &ftrace_list_end; ops = ops->next) {
if (ops_references_rec(ops, rec)) if (ops_references_rec(ops, rec)) {
cnt++; cnt++;
if (ops->flags & FTRACE_OPS_FL_SAVE_REGS)
rec->flags |= FTRACE_FL_REGS;
}
} }
return cnt; return cnt;
...@@ -6378,8 +6381,8 @@ void ftrace_module_enable(struct module *mod) ...@@ -6378,8 +6381,8 @@ void ftrace_module_enable(struct module *mod)
if (ftrace_start_up) if (ftrace_start_up)
cnt += referenced_filters(rec); cnt += referenced_filters(rec);
/* This clears FTRACE_FL_DISABLED */ rec->flags &= ~FTRACE_FL_DISABLED;
rec->flags = cnt; rec->flags += cnt;
if (ftrace_start_up && cnt) { if (ftrace_start_up && cnt) {
int failed = __ftrace_replace_code(rec, 1); int failed = __ftrace_replace_code(rec, 1);
......
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