Browse Source

function_graph: Reverse the order of pushing the ret_stack and the callback

The function graph profiler uses the ret_stack to store the "subtime" and
reuse it by nested functions and also on the return. But the current logic
has the profiler callback called before the ret_stack is updated, and it is
just modifying the ret_stack that will later be allocated (it's just lucky
that the "subtime" is not touched when it is allocated).

This could also cause a crash if we are at the end of the ret_stack when
this happens.

By reversing the order of the allocating the ret_stack and then calling the
callbacks attached to a function being traced, the ret_stack entry is no
longer used before it is allocated.

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>
Steven Rostedt (VMware) 6 years ago
parent
commit
7c6ea35ef5
1 changed files with 6 additions and 4 deletions
  1. 6 4
      kernel/trace/trace_functions_graph.c

+ 6 - 4
kernel/trace/trace_functions_graph.c

@@ -188,15 +188,17 @@ int function_graph_enter(unsigned long ret, unsigned long func,
 	trace.func = func;
 	trace.func = func;
 	trace.depth = ++current->curr_ret_depth;
 	trace.depth = ++current->curr_ret_depth;
 
 
-	/* Only trace if the calling function expects to */
-	if (!ftrace_graph_entry(&trace))
-		goto out;
-
 	if (ftrace_push_return_trace(ret, func,
 	if (ftrace_push_return_trace(ret, func,
 				     frame_pointer, retp))
 				     frame_pointer, retp))
 		goto out;
 		goto out;
 
 
+	/* Only trace if the calling function expects to */
+	if (!ftrace_graph_entry(&trace))
+		goto out_ret;
+
 	return 0;
 	return 0;
+ out_ret:
+	current->curr_ret_stack--;
  out:
  out:
 	current->curr_ret_depth--;
 	current->curr_ret_depth--;
 	return -EBUSY;
 	return -EBUSY;