Skip to content

Commit 8a224ff

Browse files
Chengming Zhourostedt
authored andcommitted
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/[email protected] Cc: [email protected] Fixes: 8c4f3c3 ("ftrace: Check module functions being traced on reload") Signed-off-by: Chengming Zhou <[email protected]> Signed-off-by: Muchun Song <[email protected]> Signed-off-by: Steven Rostedt (VMware) <[email protected]>
1 parent 96b4833 commit 8a224ff

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

kernel/trace/ftrace.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6198,8 +6198,11 @@ static int referenced_filters(struct dyn_ftrace *rec)
61986198
int cnt = 0;
61996199

62006200
for (ops = ftrace_ops_list; ops != &ftrace_list_end; ops = ops->next) {
6201-
if (ops_references_rec(ops, rec))
6202-
cnt++;
6201+
if (ops_references_rec(ops, rec)) {
6202+
cnt++;
6203+
if (ops->flags & FTRACE_OPS_FL_SAVE_REGS)
6204+
rec->flags |= FTRACE_FL_REGS;
6205+
}
62036206
}
62046207

62056208
return cnt;
@@ -6378,8 +6381,8 @@ void ftrace_module_enable(struct module *mod)
63786381
if (ftrace_start_up)
63796382
cnt += referenced_filters(rec);
63806383

6381-
/* This clears FTRACE_FL_DISABLED */
6382-
rec->flags = cnt;
6384+
rec->flags &= ~FTRACE_FL_DISABLED;
6385+
rec->flags += cnt;
63836386

63846387
if (ftrace_start_up && cnt) {
63856388
int failed = __ftrace_replace_code(rec, 1);

0 commit comments

Comments
 (0)