Skip to content

Commit e0a413f

Browse files
Steven Rostedtrostedt
authored andcommitted
tracing: Warn on output if the function tracer was found corrupted
As the function tracer is very intrusive, lots of self checks are performed on the tracer and if something is found to be strange it will shut itself down keeping it from corrupting the rest of the kernel. This shutdown may still allow functions to be traced, as the tracing only stops new modifications from happening. Trying to stop the function tracer itself can cause more harm as it requires code modification. Although a WARN_ON() is executed, a user may not notice it. To help the user see that something isn't right with the tracing of the system a big warning is added to the output of the tracer that lets the user know that their data may be incomplete. Reported-by: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
1 parent e36de1d commit e0a413f

3 files changed

Lines changed: 25 additions & 0 deletions

File tree

‎kernel/trace/ftrace.c‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3862,6 +3862,14 @@ void ftrace_kill(void)
38623862
clear_ftrace_function();
38633863
}
38643864

3865+
/**
3866+
* Test if ftrace is dead or not.
3867+
*/
3868+
int ftrace_is_dead(void)
3869+
{
3870+
return ftrace_disabled;
3871+
}
3872+
38653873
/**
38663874
* register_ftrace_function - register a function for profiling
38673875
* @ops - ops structure that holds the function for profiling.

‎kernel/trace/trace.c‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2160,6 +2160,14 @@ void trace_default_header(struct seq_file *m)
21602160
}
21612161
}
21622162

2163+
static void test_ftrace_alive(struct seq_file *m)
2164+
{
2165+
if (!ftrace_is_dead())
2166+
return;
2167+
seq_printf(m, "# WARNING: FUNCTION TRACING IS CORRUPTED\n");
2168+
seq_printf(m, "# MAY BE MISSING FUNCTION EVENTS\n");
2169+
}
2170+
21632171
static int s_show(struct seq_file *m, void *v)
21642172
{
21652173
struct trace_iterator *iter = v;
@@ -2169,6 +2177,7 @@ static int s_show(struct seq_file *m, void *v)
21692177
if (iter->tr) {
21702178
seq_printf(m, "# tracer: %s\n", iter->trace->name);
21712179
seq_puts(m, "#\n");
2180+
test_ftrace_alive(m);
21722181
}
21732182
if (iter->trace && iter->trace->print_header)
21742183
iter->trace->print_header(m);
@@ -4613,6 +4622,12 @@ __ftrace_dump(bool disable_tracing, enum ftrace_dump_mode oops_dump_mode)
46134622

46144623
tracing_off();
46154624

4625+
/* Did function tracer already get disabled? */
4626+
if (ftrace_is_dead()) {
4627+
printk("# WARNING: FUNCTION TRACING IS CORRUPTED\n");
4628+
printk("# MAY BE MISSING FUNCTION EVENTS\n");
4629+
}
4630+
46164631
if (disable_tracing)
46174632
ftrace_kill();
46184633

‎kernel/trace/trace.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,11 +579,13 @@ static inline int ftrace_trace_task(struct task_struct *task)
579579

580580
return test_tsk_trace_trace(task);
581581
}
582+
extern int ftrace_is_dead(void);
582583
#else
583584
static inline int ftrace_trace_task(struct task_struct *task)
584585
{
585586
return 1;
586587
}
588+
static inline int ftrace_is_dead(void) { return 0; }
587589
#endif
588590

589591
/*

0 commit comments

Comments
 (0)