]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
function_graph: Move graph notrace bit to shadow stack global var
authorSteven Rostedt (VMware) <rostedt@goodmis.org>
Mon, 3 Jun 2024 19:07:22 +0000 (15:07 -0400)
committerSteven Rostedt (Google) <rostedt@goodmis.org>
Tue, 4 Jun 2024 14:37:44 +0000 (10:37 -0400)
The use of the task->trace_recursion for the logic used for the function
graph no-trace was a bit of an abuse of that variable. Now that there
exists global vars that are per stack for registered graph traces, use
that instead.

Link: https://lore.kernel.org/linux-trace-kernel/171509107907.162236.6564679266777519065.stgit@devnote2
Link: https://lore.kernel.org/linux-trace-kernel/20240603190823.796709456@goodmis.org
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Cc: Florent Revest <revest@chromium.org>
Cc: Martin KaFai Lau <martin.lau@linux.dev>
Cc: bpf <bpf@vger.kernel.org>
Cc: Sven Schnelle <svens@linux.ibm.com>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: Alan Maguire <alan.maguire@oracle.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Guo Ren <guoren@kernel.org>
Reviewed-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
include/linux/trace_recursion.h
kernel/trace/trace.h
kernel/trace/trace_functions_graph.c

index fdfb6f66718affafb56cf7581b8efe29aa32a239..ae04054a1be360e249c337da1905bd13d73f98ca 100644 (file)
@@ -44,13 +44,6 @@ enum {
  */
        TRACE_IRQ_BIT,
 
-       /*
-        * To implement set_graph_notrace, if this bit is set, we ignore
-        * function graph tracing of called functions, until the return
-        * function is called to clear it.
-        */
-       TRACE_GRAPH_NOTRACE_BIT,
-
        /* Used to prevent recursion recording from recursing. */
        TRACE_RECORD_RECURSION_BIT,
 };
index 82d879dc63ff8608fd8645037e84841846c02d8e..b37402e3f0c99911255d5e2acd30215da75e1660 100644 (file)
@@ -919,8 +919,17 @@ enum {
 
        TRACE_GRAPH_DEPTH_START_BIT,
        TRACE_GRAPH_DEPTH_END_BIT,
+
+       /*
+        * To implement set_graph_notrace, if this bit is set, we ignore
+        * function graph tracing of called functions, until the return
+        * function is called to clear it.
+        */
+       TRACE_GRAPH_NOTRACE_BIT,
 };
 
+#define TRACE_GRAPH_NOTRACE            (1 << TRACE_GRAPH_NOTRACE_BIT)
+
 static inline unsigned long ftrace_graph_depth(unsigned long *task_var)
 {
        return (*task_var >> TRACE_GRAPH_DEPTH_START_BIT) & 3;
index 66cce73e94f8966702282b524045811328887da6..13d0387ac6a66b4c31ff0664ab9a31ff784db02f 100644 (file)
@@ -130,6 +130,7 @@ static inline int ftrace_graph_ignore_irqs(void)
 int trace_graph_entry(struct ftrace_graph_ent *trace,
                      struct fgraph_ops *gops)
 {
+       unsigned long *task_var = fgraph_get_task_var(gops);
        struct trace_array *tr = gops->private;
        struct trace_array_cpu *data;
        unsigned long flags;
@@ -138,7 +139,7 @@ int trace_graph_entry(struct ftrace_graph_ent *trace,
        int ret;
        int cpu;
 
-       if (trace_recursion_test(TRACE_GRAPH_NOTRACE_BIT))
+       if (*task_var & TRACE_GRAPH_NOTRACE)
                return 0;
 
        /*
@@ -149,7 +150,7 @@ int trace_graph_entry(struct ftrace_graph_ent *trace,
         * returning from the function.
         */
        if (ftrace_graph_notrace_addr(trace->func)) {
-               trace_recursion_set(TRACE_GRAPH_NOTRACE_BIT);
+               *task_var |= TRACE_GRAPH_NOTRACE_BIT;
                /*
                 * Need to return 1 to have the return called
                 * that will clear the NOTRACE bit.
@@ -240,6 +241,7 @@ void __trace_graph_return(struct trace_array *tr,
 void trace_graph_return(struct ftrace_graph_ret *trace,
                        struct fgraph_ops *gops)
 {
+       unsigned long *task_var = fgraph_get_task_var(gops);
        struct trace_array *tr = gops->private;
        struct trace_array_cpu *data;
        unsigned long flags;
@@ -249,8 +251,8 @@ void trace_graph_return(struct ftrace_graph_ret *trace,
 
        ftrace_graph_addr_finish(gops, trace);
 
-       if (trace_recursion_test(TRACE_GRAPH_NOTRACE_BIT)) {
-               trace_recursion_clear(TRACE_GRAPH_NOTRACE_BIT);
+       if (*task_var & TRACE_GRAPH_NOTRACE) {
+               *task_var &= ~TRACE_GRAPH_NOTRACE;
                return;
        }