Skip to content

Commit

Permalink
ftrace: Add more checks for FTRACE_FL_DISABLED in processing ip records
Browse files Browse the repository at this point in the history
When a module is first loaded and its function ip records are added to the
ftrace list of functions to modify, they are set to DISABLED, as their text
is still in a read only state. When the module is fully loaded, and can be
updated, the flag is cleared, and if their's any functions that should be
tracing them, it is updated at that moment.

But there's several locations that do record accounting and should ignore
records that are marked as disabled, or they can cause issues.

Alexei already fixed one location, but others need to be addressed.

Cc: stable@vger.kernel.org
Fixes: b7ffffb "ftrace: Add infrastructure for delayed enabling of module functions"
Reported-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
  • Loading branch information
Steven Rostedt (Red Hat) committed Nov 14, 2016
1 parent 977c1f9 commit 546fece
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions kernel/trace/ftrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -1862,6 +1862,10 @@ static int __ftrace_hash_update_ipmodify(struct ftrace_ops *ops,

/* Update rec->flags */
do_for_each_ftrace_rec(pg, rec) {

if (rec->flags & FTRACE_FL_DISABLED)
continue;

/* We need to update only differences of filter_hash */
in_old = !!ftrace_lookup_ip(old_hash, rec->ip);
in_new = !!ftrace_lookup_ip(new_hash, rec->ip);
Expand All @@ -1884,6 +1888,10 @@ static int __ftrace_hash_update_ipmodify(struct ftrace_ops *ops,

/* Roll back what we did above */
do_for_each_ftrace_rec(pg, rec) {

if (rec->flags & FTRACE_FL_DISABLED)
continue;

if (rec == end)
goto err_out;

Expand Down Expand Up @@ -2397,6 +2405,10 @@ void __weak ftrace_replace_code(int enable)
return;

do_for_each_ftrace_rec(pg, rec) {

if (rec->flags & FTRACE_FL_DISABLED)
continue;

failed = __ftrace_replace_code(rec, enable);
if (failed) {
ftrace_bug(failed, rec);
Expand Down Expand Up @@ -3598,6 +3610,10 @@ match_records(struct ftrace_hash *hash, char *func, int len, char *mod)
goto out_unlock;

do_for_each_ftrace_rec(pg, rec) {

if (rec->flags & FTRACE_FL_DISABLED)
continue;

if (ftrace_match_record(rec, &func_g, mod_match, exclude_mod)) {
ret = enter_record(hash, rec, clear_filter);
if (ret < 0) {
Expand Down Expand Up @@ -3793,6 +3809,9 @@ register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,

do_for_each_ftrace_rec(pg, rec) {

if (rec->flags & FTRACE_FL_DISABLED)
continue;

if (!ftrace_match_record(rec, &func_g, NULL, 0))
continue;

Expand Down Expand Up @@ -4685,6 +4704,9 @@ ftrace_set_func(unsigned long *array, int *idx, int size, char *buffer)

do_for_each_ftrace_rec(pg, rec) {

if (rec->flags & FTRACE_FL_DISABLED)
continue;

if (ftrace_match_record(rec, &func_g, NULL, 0)) {
/* if it is in the array */
exists = false;
Expand Down

0 comments on commit 546fece

Please sign in to comment.