]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
fgraph: Check ftrace_pids_enabled on registration for early filtering
authorShengming Hu <hu.shengming@zte.com.cn>
Wed, 26 Nov 2025 09:33:31 +0000 (17:33 +0800)
committerSteven Rostedt (Google) <rostedt@goodmis.org>
Wed, 26 Nov 2025 20:41:16 +0000 (15:41 -0500)
When registering ftrace_graph, check if ftrace_pids_enabled is active.
If enabled, assign entryfunc to fgraph_pid_func to ensure filtering
is performed before executing the saved original entry function.

Cc: stable@vger.kernel.org
Cc: <wang.yaxin@zte.com.cn>
Cc: <mhiramat@kernel.org>
Cc: <mark.rutland@arm.com>
Cc: <mathieu.desnoyers@efficios.com>
Cc: <zhang.run@zte.com.cn>
Cc: <yang.yang29@zte.com.cn>
Link: https://patch.msgid.link/20251126173331679XGVF98NLhyLJRdtNkVZ6w@zte.com.cn
Fixes: df3ec5da6a1e7 ("function_graph: Add pid tracing back to function graph tracer")
Signed-off-by: Shengming Hu <hu.shengming@zte.com.cn>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
kernel/trace/fgraph.c

index d6222bb99d1d758004532497323a966650c8cb51..599f2939cd940c37f51a8877e5042e84d0e7d953 100644 (file)
@@ -1377,6 +1377,13 @@ int register_ftrace_graph(struct fgraph_ops *gops)
 
        ftrace_graph_active++;
 
+       /* Always save the function, and reset at unregistering */
+       gops->saved_func = gops->entryfunc;
+#ifdef CONFIG_DYNAMIC_FTRACE
+       if (ftrace_pids_enabled(&gops->ops))
+               gops->entryfunc = fgraph_pid_func;
+#endif
+
        if (ftrace_graph_active == 2)
                ftrace_graph_disable_direct(true);
 
@@ -1396,8 +1403,6 @@ int register_ftrace_graph(struct fgraph_ops *gops)
        } else {
                init_task_vars(gops->idx);
        }
-       /* Always save the function, and reset at unregistering */
-       gops->saved_func = gops->entryfunc;
 
        gops->ops.flags |= FTRACE_OPS_FL_GRAPH;