]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
fgraph: Fix thresh_return nosleeptime double-adjust
authorShengming Hu <hu.shengming@zte.com.cn>
Sat, 21 Feb 2026 03:33:14 +0000 (11:33 +0800)
committerSteven Rostedt (Google) <rostedt@goodmis.org>
Wed, 4 Mar 2026 03:11:20 +0000 (22:11 -0500)
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>
kernel/trace/trace_functions_graph.c

index 817d0f1696b6fb8e28f4a51e1356ebdc2455373d..0d2d3a2ea7dda08e9dae9c26156d8a3e2d07fdd9 100644 (file)
@@ -403,8 +403,12 @@ static void trace_graph_thresh_return(struct ftrace_graph_ret *trace,
        unsigned long *task_var = fgraph_get_task_var(gops);
        struct fgraph_times *ftimes;
        struct trace_array *tr;
+       unsigned int trace_ctx;
+       u64 calltime, rettime;
        int size;
 
+       rettime = trace_clock_local();
+
        ftrace_graph_addr_finish(gops, trace);
 
        if (*task_var & TRACE_GRAPH_NOTRACE) {
@@ -419,11 +423,13 @@ static void trace_graph_thresh_return(struct ftrace_graph_ret *trace,
        tr = gops->private;
        handle_nosleeptime(tr, trace, ftimes, size);
 
-       if (tracing_thresh &&
-           (trace_clock_local() - ftimes->calltime < tracing_thresh))
+       calltime = ftimes->calltime;
+
+       if (tracing_thresh && (rettime - calltime < tracing_thresh))
                return;
-       else
-               trace_graph_return(trace, gops, fregs);
+
+       trace_ctx = tracing_gen_ctx();
+       __trace_graph_return(tr, trace, trace_ctx, calltime, rettime);
 }
 
 static struct fgraph_ops funcgraph_ops = {