• Steven Rostedt (VMware)'s avatar
    function_graph: Use new curr_ret_depth to manage depth instead of curr_ret_stack · 39eb456d
    Steven Rostedt (VMware) authored
    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 03274a3f ("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: 03274a3f ("tracing/fgraph: Adjust fgraph depth before calling trace return callback")
    Reviewed-by: default avatarMasami Hiramatsu <mhiramat@kernel.org>
    Signed-off-by: default avatarSteven Rostedt (VMware) <rostedt@goodmis.org>
    39eb456d
trace_functions_graph.c 38.8 KB