function_graph: Use new curr_ret_depth to manage depth instead of curr_ret_stack
authorSteven Rostedt (VMware) <rostedt@goodmis.org>
Mon, 19 Nov 2018 13:07:12 +0000 (08:07 -0500)
committerSteven Rostedt (VMware) <rostedt@goodmis.org>
Wed, 28 Nov 2018 01:31:54 +0000 (20:31 -0500)
commit39eb456dacb543de90d3bc6a8e0ac5cf51ac475e
tree790493fbeb31636acf0149ea92b146dc03f7c90d
parentd125f3f866df88da5a85df00291f88f0baa89f7c
function_graph: Use new curr_ret_depth to manage depth instead of curr_ret_stack

Currently, the depth of the ret_stack is determined by curr_ret_stack index.
The issue is that there's a race between setting of the curr_ret_stack and
calling of the callback attached to the return of the function.

Commit 03274a3ffb44 ("tracing/fgraph: Adjust fgraph depth before calling
trace return callback") moved the calling of the callback to after the
setting of the curr_ret_stack, even stating that it was safe to do so, when
in fact, it was the reason there was a barrier() there (yes, I should have
commented that barrier()).

Not only does the curr_ret_stack keep track of the current call graph depth,
it also keeps the ret_stack content from being overwritten by new data.

The function profiler, uses the "subtime" variable of ret_stack structure
and by moving the curr_ret_stack, it allows for interrupts to use the same
structure it was using, corrupting the data, and breaking the profiler.

To fix this, there needs to be two variables to handle the call stack depth
and the pointer to where the ret_stack is being used, as they need to change
at two different locations.

Cc: stable@kernel.org
Fixes: 03274a3ffb449 ("tracing/fgraph: Adjust fgraph depth before calling trace return callback")
Reviewed-by: Masami Hiramatsu <mhiramat@kernel.org>
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
include/linux/sched.h
kernel/trace/ftrace.c
kernel/trace/trace_functions_graph.c