Skip to content

Commit b96d0c5

Browse files
HSM6236rostedt
authored andcommitted
fgraph: Fix thresh_return nosleeptime double-adjust
trace_graph_thresh_return() called handle_nosleeptime() and then delegated to trace_graph_return(), which calls handle_nosleeptime() again. When sleep-time accounting is disabled this double-adjusts calltime and can produce bogus durations (including underflow). Fix this by computing rettime once, applying handle_nosleeptime() only once, using the adjusted calltime for threshold comparison, and writing the return event directly via __trace_graph_return() when the threshold is met. Cc: [email protected] Link: https://patch.msgid.link/[email protected] Fixes: 3c9880f ("ftrace: Use a running sleeptime instead of saving on shadow stack") Acked-by: Masami Hiramatsu (Google) <[email protected]> Signed-off-by: Shengming Hu <[email protected]> Signed-off-by: Steven Rostedt (Google) <[email protected]>
1 parent 6ca8379 commit b96d0c5

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

kernel/trace/trace_functions_graph.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -403,8 +403,12 @@ static void trace_graph_thresh_return(struct ftrace_graph_ret *trace,
403403
unsigned long *task_var = fgraph_get_task_var(gops);
404404
struct fgraph_times *ftimes;
405405
struct trace_array *tr;
406+
unsigned int trace_ctx;
407+
u64 calltime, rettime;
406408
int size;
407409

410+
rettime = trace_clock_local();
411+
408412
ftrace_graph_addr_finish(gops, trace);
409413

410414
if (*task_var & TRACE_GRAPH_NOTRACE) {
@@ -419,11 +423,13 @@ static void trace_graph_thresh_return(struct ftrace_graph_ret *trace,
419423
tr = gops->private;
420424
handle_nosleeptime(tr, trace, ftimes, size);
421425

422-
if (tracing_thresh &&
423-
(trace_clock_local() - ftimes->calltime < tracing_thresh))
426+
calltime = ftimes->calltime;
427+
428+
if (tracing_thresh && (rettime - calltime < tracing_thresh))
424429
return;
425-
else
426-
trace_graph_return(trace, gops, fregs);
430+
431+
trace_ctx = tracing_gen_ctx();
432+
__trace_graph_return(tr, trace, trace_ctx, calltime, rettime);
427433
}
428434

429435
static struct fgraph_ops funcgraph_ops = {

0 commit comments

Comments
 (0)