Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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: stable@vger.kernel.org
Link: https://patch.msgid.link/20260221113314048jE4VRwIyZEALiYByGK0My@zte.com.cn
Fixes: 3c9880f3ab52b ("ftrace: Use a running sleeptime instead of saving on shadow stack")
Acked-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Signed-off-by: Shengming Hu <hu.shengming@zte.com.cn>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>

authored by

Shengming Hu and committed by
Steven Rostedt (Google)
b96d0c59 6ca8379b

+10 -4
+10 -4
kernel/trace/trace_functions_graph.c
··· 403 403 unsigned long *task_var = fgraph_get_task_var(gops); 404 404 struct fgraph_times *ftimes; 405 405 struct trace_array *tr; 406 + unsigned int trace_ctx; 407 + u64 calltime, rettime; 406 408 int size; 409 + 410 + rettime = trace_clock_local(); 407 411 408 412 ftrace_graph_addr_finish(gops, trace); 409 413 ··· 423 419 tr = gops->private; 424 420 handle_nosleeptime(tr, trace, ftimes, size); 425 421 426 - if (tracing_thresh && 427 - (trace_clock_local() - ftimes->calltime < tracing_thresh)) 422 + calltime = ftimes->calltime; 423 + 424 + if (tracing_thresh && (rettime - calltime < tracing_thresh)) 428 425 return; 429 - else 430 - trace_graph_return(trace, gops, fregs); 426 + 427 + trace_ctx = tracing_gen_ctx(); 428 + __trace_graph_return(tr, trace, trace_ctx, calltime, rettime); 431 429 } 432 430 433 431 static struct fgraph_ops funcgraph_ops = {