Skip to contentSkip to conversation

function_graph: Support recording and printing the function return address

PATCH Superseded Donglin Peng 2 participants 3 messages Sep 13, 2024 – Sep 14, 2024

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 function_graph: Support recording and printing the function return address

When using function_graph tracer to analyze the flow of kernel function execution, it is often necessary to quickly locate the exact line of code where the call occurs. While this may be easy at times, it can be more time-consuming when some functions are inlined or the flow is too long.

This feature aims to simplify the process by recording the return address of traced funcions and printing it when outputing trace logs.

To enhance human readability, the prefix 'ret=' is used for the kernel return value, while '<-' serves as the prefix for the return address in trace logs to make it look more like the function tracer.

A new trace option named 'funcgraph-retaddr' has been introduced, and the existing option 'sym-addr' can be used to control the format of the return address.

See below logs with both funcgraph-retval and funcgraph-retaddr enabled.

Then, we can use the faddr2line to locate the source code, for example:

0)             | load_elf_binary() { /* <-bprm_execve+0x249/0x600 */
0)             |   load_elf_phdrs() { /* <-load_elf_binary+0x84/0x1730 */
0)             |     __kmalloc_noprof() { /* <-load_elf_phdrs+0x4a/0xb0 */
0)   3.657 us  |       __cond_resched(); /* <-__kmalloc_noprof+0x28c/0x390 ret=0x0 */
0) + 24.335 us |     } /* __kmalloc_noprof ret=0xffff8882007f3000 */
0)             |     kernel_read() { /* <-load_elf_phdrs+0x6c/0xb0 */
0)             |       rw_verify_area() { /* <-kernel_read+0x2b/0x50 */
0)             |         security_file_permission() { /* <-kernel_read+0x2b/0x50 */
0)             |           selinux_file_permission() { /* <-security_file_permission+0x26/0x40 */
0)             |             __inode_security_revalidate() { /* <-selinux_file_permission+0x6d/0x140 */
0)   2.034 us  |               __cond_resched(); /* <-__inode_security_revalidate+0x5f/0x80 ret=0x0 */
0)   6.602 us  |             } /* __inode_security_revalidate ret=0x0 */
0)   2.214 us  |             avc_policy_seqno(); /* <-selinux_file_permission+0x107/0x140 ret=0x0 */
0) + 16.670 us |           } /* selinux_file_permission ret=0x0 */
0) + 20.809 us |         } /* security_file_permission ret=0x0 */
0) + 25.217 us |       } /* rw_verify_area ret=0x0 */
0)             |       __kernel_read() { /* <-load_elf_phdrs+0x6c/0xb0 */
0)             |         ext4_file_read_iter() { /* <-__kernel_read+0x160/0x2e0 */
$ ./scripts/faddr2line ./vmlinux load_elf_phdrs+0x6c/0xb0
load_elf_phdrs+0x6c/0xb0:
elf_read at fs/binfmt_elf.c:471
(inlined by) load_elf_phdrs at fs/binfmt_elf.c:531

---
rfc -> v1:
- Invoke 'ftrace_graph_ret_addr' to obtain the actual return address
- Refine the prefix preceding the return addess and the return value
- Print the return address firstly when both funcgraph-retval and funcgraph-retaddr are enabled
- Create a new event named 'fgraph_retaddr_entry' in order not to save the return address to the ring buffer when 'funcgraph-retaddr' is disabled, thereby reducing memory overhead
- Add a kernel config named CONFIG_FUNCTION_GRAPH_RETADDR
- Update fgraph-retval.tc

---
 include/linux/ftrace.h                        |  27 ++-
 kernel/trace/Kconfig                          |  10 +
 kernel/trace/fgraph.c                         |  21 +-
 kernel/trace/ftrace.c                         |   3 +-
 kernel/trace/trace.h                          |  11 +-
 kernel/trace/trace_entries.h                  |  19 +-
 kernel/trace/trace_functions_graph.c          | 211 ++++++++++++++----
 kernel/trace/trace_irqsoff.c                  |   3 +-
 kernel/trace/trace_sched_wakeup.c             |   3 +-
 kernel/trace/trace_selftest.c                 |   1 +
 .../ftrace/test.d/ftrace/fgraph-retval.tc     |   2 +-
 11 files changed, 254 insertions(+), 57 deletions(-)
include/linux/ftrace.h +25 -2
index fd5e84d0ec47..8a0d878f6c9c 100644
@@ -1014,6 +1014,17 @@ struct ftrace_graph_ent {
 	int depth;
 } __packed;
 
+/*
+ * Structure that defines an entry function trace with retaddr.
+ * It's already packed but the attribute "packed" is needed
+ * to remove extra padding at the end.
+ */
+struct fgraph_retaddr_ent {
+	unsigned long func; /* Current function */
+	int depth;
+	unsigned long retaddr;  /* Return address */
+} __packed;
+
 /*
  * Structure that defines a return function trace.
  * It's already packed but the attribute "packed" is needed
@@ -1031,19 +1042,29 @@ struct ftrace_graph_ret {
 	unsigned long long rettime;
 } __packed;
 
+struct fgraph_extras;
 struct fgraph_ops;
 
 /* Type of the callback handlers for tracing function graph*/
 typedef void (*trace_func_graph_ret_t)(struct ftrace_graph_ret *,
 				       struct fgraph_ops *); /* return */
 typedef int (*trace_func_graph_ent_t)(struct ftrace_graph_ent *,
-				      struct fgraph_ops *); /* entry */
+				      struct fgraph_ops *,
+				      struct fgraph_extras *); /* entry */
 
-extern int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace, struct fgraph_ops *gops);
+extern int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace,
+				   struct fgraph_ops *gops,
+				   struct fgraph_extras *extras);
 bool ftrace_pids_enabled(struct ftrace_ops *ops);
 
 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
 
+/* Used to convey some extra datas when creating a graph entry */
+struct fgraph_extras {
+	u32 flags;
+	unsigned long retaddr;
+};
+
 struct fgraph_ops {
 	trace_func_graph_ent_t		entryfunc;
 	trace_func_graph_ret_t		retfunc;
@@ -1092,6 +1113,8 @@ unsigned long ftrace_graph_ret_addr(struct task_struct *task, int *idx,
 				    unsigned long ret, unsigned long *retp);
 unsigned long *fgraph_get_task_var(struct fgraph_ops *gops);
 
+u32 graph_tracer_flags_get(u32 flags);
+
 /*
  * Sometimes we don't want to trace a function with the function
  * graph tracer but we want them to keep traced by the usual function
kernel/trace/Kconfig +10 -0
index 721c3b221048..74c2b1d43bb9 100644
@@ -242,6 +242,16 @@ config FUNCTION_GRAPH_RETVAL
 	  enable it via the trace option funcgraph-retval.
 	  See Documentation/trace/ftrace.rst
 
+config FUNCTION_GRAPH_RETADDR
+	bool "Kernel Function Graph Return Address"
+	depends on FUNCTION_GRAPH_TRACER
+	default n
+	help
+	  Support recording and printing the function return address when
+	  using function graph tracer. It can be helpful to locate code line that
+	  the function is called. This feature is off by default, and you can
+	  enable it via the trace option funcgraph-retaddr.
+
 config DYNAMIC_FTRACE
 	bool "enable/disable function tracing dynamically"
 	depends on FUNCTION_TRACER
kernel/trace/fgraph.c +15 -6
index d7d4fb403f6f..e6f019ca11c2 100644
@@ -290,7 +290,8 @@ static inline unsigned long make_data_type_val(int idx, int size, int offset)
 }
 
 /* ftrace_graph_entry set to this to tell some archs to run function graph */
-static int entry_run(struct ftrace_graph_ent *trace, struct fgraph_ops *ops)
+static int entry_run(struct ftrace_graph_ent *trace, struct fgraph_ops *ops,
+		     struct fgraph_extras *extras)
 {
 	return 0;
 }
@@ -484,7 +485,8 @@ int __weak ftrace_disable_ftrace_graph_caller(void)
 #endif
 
 int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace,
-			    struct fgraph_ops *gops)
+			    struct fgraph_ops *gops,
+			    struct fgraph_extras *extras)
 {
 	return 0;
 }
@@ -616,13 +618,19 @@ int function_graph_enter(unsigned long ret, unsigned long func,
 			 unsigned long frame_pointer, unsigned long *retp)
 {
 	struct ftrace_graph_ent trace;
+	struct fgraph_extras extras;
 	unsigned long bitmap = 0;
 	int offset;
 	int i;
+	int idx = 0;
 
 	trace.func = func;
 	trace.depth = ++current->curr_ret_depth;
 
+	extras.flags = graph_tracer_flags_get(TRACE_GRAPH_PRINT_RETADDR);
+	if (extras.flags & TRACE_GRAPH_PRINT_RETADDR)
+		extras.retaddr = ftrace_graph_ret_addr(current, &idx, ret, retp);
+
 	offset = ftrace_push_return_trace(ret, func, frame_pointer, retp, 0);
 	if (offset < 0)
 		goto out;
@@ -631,7 +639,7 @@ int function_graph_enter(unsigned long ret, unsigned long func,
 	if (static_branch_likely(&fgraph_do_direct)) {
 		int save_curr_ret_stack = current->curr_ret_stack;
 
-		if (static_call(fgraph_func)(&trace, fgraph_direct_gops))
+		if (static_call(fgraph_func)(&trace, fgraph_direct_gops, &extras))
 			bitmap |= BIT(fgraph_direct_gops->idx);
 		else
 			/* Clear out any saved storage */
@@ -649,7 +657,7 @@ int function_graph_enter(unsigned long ret, unsigned long func,
 
 			save_curr_ret_stack = current->curr_ret_stack;
 			if (ftrace_ops_test(&gops->ops, func, NULL) &&
-			    gops->entryfunc(&trace, gops))
+			    gops->entryfunc(&trace, gops, &extras))
 				bitmap |= BIT(i);
 			else
 				/* Clear out any saved storage */
@@ -1119,7 +1127,8 @@ void ftrace_graph_exit_task(struct task_struct *t)
 
 #ifdef CONFIG_DYNAMIC_FTRACE
 static int fgraph_pid_func(struct ftrace_graph_ent *trace,
-			   struct fgraph_ops *gops)
+			   struct fgraph_ops *gops,
+			   struct fgraph_extras *extras)
 {
 	struct trace_array *tr = gops->ops.private;
 	int pid;
@@ -1133,7 +1142,7 @@ static int fgraph_pid_func(struct ftrace_graph_ent *trace,
 			return 0;
 	}
 
-	return gops->saved_func(trace, gops);
+	return gops->saved_func(trace, gops, NULL);
 }
 
 void fgraph_update_pid_func(void)
kernel/trace/ftrace.c +2 -1
index 4c28dd177ca6..707ae465ed62 100644
@@ -821,7 +821,8 @@ void ftrace_graph_graph_time_control(bool enable)
 }
 
 static int profile_graph_entry(struct ftrace_graph_ent *trace,
-			       struct fgraph_ops *gops)
+			       struct fgraph_ops *gops,
+			       struct fgraph_extras *extras)
 {
 	struct ftrace_ret_stack *ret_stack;
 
kernel/trace/trace.h +10 -1
index bd3e3069300e..eea43426e3fe 100644
@@ -46,6 +46,7 @@ enum trace_type {
 	TRACE_BRANCH,
 	TRACE_GRAPH_RET,
 	TRACE_GRAPH_ENT,
+	TRACE_GRAPH_RETADDR_ENT,
 	TRACE_USER_STACK,
 	TRACE_BLK,
 	TRACE_BPUTS,
@@ -505,6 +506,8 @@ extern void __ftrace_bad_type(void);
 		IF_ASSIGN(var, ent, struct trace_branch, TRACE_BRANCH); \
 		IF_ASSIGN(var, ent, struct ftrace_graph_ent_entry,	\
 			  TRACE_GRAPH_ENT);		\
+		IF_ASSIGN(var, ent, struct fgraph_retaddr_ent_entry,\
+			  TRACE_GRAPH_RETADDR_ENT);		\
 		IF_ASSIGN(var, ent, struct ftrace_graph_ret_entry,	\
 			  TRACE_GRAPH_RET);		\
 		IF_ASSIGN(var, ent, struct func_repeats_entry,		\
@@ -683,7 +686,8 @@ void trace_default_header(struct seq_file *m);
 void print_trace_header(struct seq_file *m, struct trace_iterator *iter);
 
 void trace_graph_return(struct ftrace_graph_ret *trace, struct fgraph_ops *gops);
-int trace_graph_entry(struct ftrace_graph_ent *trace, struct fgraph_ops *gops);
+int trace_graph_entry(struct ftrace_graph_ent *trace, struct fgraph_ops *gops,
+		      struct fgraph_extras *priv);
 
 void tracing_start_cmdline_record(void);
 void tracing_stop_cmdline_record(void);
@@ -870,6 +874,7 @@ static __always_inline bool ftrace_hash_empty(struct ftrace_hash *hash)
 #define TRACE_GRAPH_GRAPH_TIME          0x400
 #define TRACE_GRAPH_PRINT_RETVAL        0x800
 #define TRACE_GRAPH_PRINT_RETVAL_HEX    0x1000
+#define TRACE_GRAPH_PRINT_RETADDR       0x2000
 #define TRACE_GRAPH_PRINT_FILL_SHIFT	28
 #define TRACE_GRAPH_PRINT_FILL_MASK	(0x3 << TRACE_GRAPH_PRINT_FILL_SHIFT)
 
@@ -891,6 +896,10 @@ extern void graph_trace_close(struct trace_iterator *iter);
 extern int __trace_graph_entry(struct trace_array *tr,
 			       struct ftrace_graph_ent *trace,
 			       unsigned int trace_ctx);
+extern int __trace_graph_retaddr_entry(struct trace_array *tr,
+				struct ftrace_graph_ent *trace,
+				unsigned int trace_ctx,
+				unsigned long retaddr);
 extern void __trace_graph_return(struct trace_array *tr,
 				 struct ftrace_graph_ret *trace,
 				 unsigned int trace_ctx);
kernel/trace/trace_entries.h +18 -1
index c47422b20908..fa214c1d2409 100644
@@ -85,9 +85,25 @@ FTRACE_ENTRY_PACKED(funcgraph_entry, ftrace_graph_ent_entry,
 	F_printk("--> %ps (%d)", (void *)__entry->func, __entry->depth)
 );
 
-/* Function return entry */
+/* Function call entry with a return address */
+FTRACE_ENTRY_PACKED(fgraph_retaddr_entry, fgraph_retaddr_ent_entry,
+
+	TRACE_GRAPH_RETADDR_ENT,
+
+	F_STRUCT(
+		__field_struct(	struct fgraph_retaddr_ent,	graph_ent	)
+		__field_packed(	unsigned long,	graph_ent,	func		)
+		__field_packed(	int,		graph_ent,	depth		)
+		__field_packed(	unsigned long,	graph_ent,	retaddr		)
+	),
+
+	F_printk("--> %ps (%d) <- %ps", (void *)__entry->func, __entry->depth,
+		(void *)__entry->retaddr)
+);
+
 #ifdef CONFIG_FUNCTION_GRAPH_RETVAL
 
+/* Function return entry */
 FTRACE_ENTRY_PACKED(funcgraph_exit, ftrace_graph_ret_entry,
 
 	TRACE_GRAPH_RET,
@@ -110,6 +126,7 @@ FTRACE_ENTRY_PACKED(funcgraph_exit, ftrace_graph_ret_entry,
 
 #else
 
+/* Function return entry */
 FTRACE_ENTRY_PACKED(funcgraph_exit, ftrace_graph_ret_entry,
 
 	TRACE_GRAPH_RET,
kernel/trace/trace_functions_graph.c +168 -43

328 lines not on this page · raw message

kernel/trace/trace_irqsoff.c +2 -1
index fce064e20570..eb3aa36cf10f 100644
@@ -176,7 +176,8 @@ static int irqsoff_display_graph(struct trace_array *tr, int set)
 }
 
 static int irqsoff_graph_entry(struct ftrace_graph_ent *trace,
-			       struct fgraph_ops *gops)
+			       struct fgraph_ops *gops,
+			       struct fgraph_extras *extras)
 {
 	struct trace_array *tr = irqsoff_trace;
 	struct trace_array_cpu *data;
kernel/trace/trace_sched_wakeup.c +2 -1
index 130ca7e7787e..742b9de14ddb 100644
@@ -113,7 +113,8 @@ static int wakeup_display_graph(struct trace_array *tr, int set)
 }
 
 static int wakeup_graph_entry(struct ftrace_graph_ent *trace,
-			      struct fgraph_ops *gops)
+			      struct fgraph_ops *gops,
+			      struct fgraph_extras *extras)
 {
 	struct trace_array *tr = wakeup_trace;
 	struct trace_array_cpu *data;
kernel/trace/trace_selftest.c +1 -0
index c4ad7cd7e778..d3a14ae47e26 100644
@@ -17,6 +17,7 @@ static inline int trace_valid_entry(struct trace_entry *entry)
 	case TRACE_PRINT:
 	case TRACE_BRANCH:
 	case TRACE_GRAPH_ENT:
+	case TRACE_GRAPH_RETADDR_ENT:
 	case TRACE_GRAPH_RET:
 		return 1;
 	}
tools/testing/selftests/ftrace/test.d/ftrace/fgraph-retval.tc +1 -1
index e34c0bdef3ed..e8e46378b88d 100644
@@ -29,7 +29,7 @@ set -e
 
 : "Test printing the error code in signed decimal format"
 echo 0 > options/funcgraph-retval-hex
-count=`cat trace | grep 'proc_reg_write' | grep '= -5' | wc -l`
+count=`cat trace | grep 'proc_reg_write' | grep '=-5' | wc -l`
 if [ $count -eq 0 ]; then
     fail "Return value can not be printed in signed decimal format"
 fi
Signature · 1 line
2.25.1
#1 lore raw
kernel test robot noticed the following build errors:

Hi Donglin,

kernel test robot noticed the following build errors:

[auto build test ERROR on shuah-kselftest/next]
[also build test ERROR on shuah-kselftest/fixes linus/master v6.11-rc7] [cannot apply to next-20240913]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Donglin-Peng/function_graph-Support-recording-and-printing-the-function-return-address/20240913-204403
base:   https://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest.git next
patch link:    https://lore.kernel.org/r/20240913123456.600950-1-dolinux.peng%40gmail.com
patch subject: [PATCH v1] function_graph: Support recording and printing the function return address
config: parisc-allmodconfig (https://download.01.org/0day-ci/archive/20240914/[email protected]/config)
compiler: hppa-linux-gcc (GCC) 14.1.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240914/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All error/warnings (new ones prefixed by >>):

In file included from kernel/trace/trace.c:8677:

>> kernel/trace/trace_selftest.c:910:51: error: initialization of 'int (*)(struct ftrace_graph_ent *, struct fgraph_ops *, struct fgraph_extras *)' from incompatible pointer type 'int (*)(struct ftrace_graph_ent *, struct fgraph_ops *)' [-Wincompatible-pointer-types]
     910 |                         .entryfunc              = store_entry,
         |                                                   ^~~~~~~~~~~
   kernel/trace/trace_selftest.c:910:51: note: (near initialization for 'store_bytes[0].gops.entryfunc')
   kernel/trace/trace_selftest.c:918:51: error: initialization of 'int (*)(struct ftrace_graph_ent *, struct fgraph_ops *, struct fgraph_extras *)' from incompatible pointer type 'int (*)(struct ftrace_graph_ent *, struct fgraph_ops *)' [-Wincompatible-pointer-types]
     918 |                         .entryfunc              = store_entry,
         |                                                   ^~~~~~~~~~~
   kernel/trace/trace_selftest.c:918:51: note: (near initialization for 'store_bytes[1].gops.entryfunc')
   kernel/trace/trace_selftest.c:926:51: error: initialization of 'int (*)(struct ftrace_graph_ent *, struct fgraph_ops *, struct fgraph_extras *)' from incompatible pointer type 'int (*)(struct ftrace_graph_ent *, struct fgraph_ops *)' [-Wincompatible-pointer-types]
     926 |                         .entryfunc              = store_entry,
         |                                                   ^~~~~~~~~~~
   kernel/trace/trace_selftest.c:926:51: note: (near initialization for 'store_bytes[2].gops.entryfunc')
   kernel/trace/trace_selftest.c:934:51: error: initialization of 'int (*)(struct ftrace_graph_ent *, struct fgraph_ops *, struct fgraph_extras *)' from incompatible pointer type 'int (*)(struct ftrace_graph_ent *, struct fgraph_ops *)' [-Wincompatible-pointer-types]
     934 |                         .entryfunc              = store_entry,
         |                                                   ^~~~~~~~~~~
   kernel/trace/trace_selftest.c:934:51: note: (near initialization for 'store_bytes[3].gops.entryfunc')
   kernel/trace/trace_selftest.c: In function 'trace_graph_entry_watchdog':
>> kernel/trace/trace_selftest.c:1029:16: error: too few arguments to function 'trace_graph_entry'
    1029 |         return trace_graph_entry(trace, gops);
         |                ^~~~~~~~~~~~~~~~~
   In file included from kernel/trace/trace.c:54:
   kernel/trace/trace.h:689:5: note: declared here
     689 | int trace_graph_entry(struct ftrace_graph_ent *trace, struct fgraph_ops *gops,
         |     ^~~~~~~~~~~~~~~~~
   kernel/trace/trace_selftest.c: At top level:
   kernel/trace/trace_selftest.c:1033:35: error: initialization of 'int (*)(struct ftrace_graph_ent *, struct fgraph_ops *, struct fgraph_extras *)' from incompatible pointer type 'int (*)(struct ftrace_graph_ent *, struct fgraph_ops *)' [-Wincompatible-pointer-types]
    1033 |         .entryfunc              = &trace_graph_entry_watchdog,
         |                                   ^
   kernel/trace/trace_selftest.c:1033:35: note: (near initialization for 'fgraph_ops.entryfunc')
   kernel/trace/trace_selftest.c: In function 'trace_graph_entry_watchdog':
>> kernel/trace/trace_selftest.c:1030:1: warning: control reaches end of non-void function [-Wreturn-type]
    1030 | }
         | ^

vim +910 kernel/trace/trace_selftest.c

dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   906) 
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   907) static struct fgraph_fixture store_bytes[4] __initdata = {
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   908) 	[0] = {
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   909) 		.gops = {
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03  @910) 			.entryfunc		= store_entry,
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   911) 			.retfunc		= store_return,
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   912) 		},
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   913) 		.store_size = 1,
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   914) 		.store_type_name = "byte",
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   915) 	},
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   916) 	[1] = {
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   917) 		.gops = {
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   918) 			.entryfunc		= store_entry,
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   919) 			.retfunc		= store_return,
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   920) 		},
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   921) 		.store_size = 2,
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   922) 		.store_type_name = "short",
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   923) 	},
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   924) 	[2] = {
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   925) 		.gops = {
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   926) 			.entryfunc		= store_entry,
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   927) 			.retfunc		= store_return,
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   928) 		},
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   929) 		.store_size = 4,
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   930) 		.store_type_name = "word",
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   931) 	},
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   932) 	[3] = {
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   933) 		.gops = {
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   934) 			.entryfunc		= store_entry,
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   935) 			.retfunc		= store_return,
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   936) 		},
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   937) 		.store_size = 8,
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   938) 		.store_type_name = "long long",
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   939) 	},
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   940) };
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   941) 
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   942) static __init int test_graph_storage_multi(void)
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   943) {
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   944) 	struct fgraph_fixture *fixture;
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   945) 	bool printed = false;
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   946) 	int i, ret;
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   947) 
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   948) 	pr_cont("PASSED\n");
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   949) 	pr_info("Testing multiple fgraph storage on a function: ");
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   950) 
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   951) 	for (i = 0; i < ARRAY_SIZE(store_bytes); i++) {
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   952) 		fixture = &store_bytes[i];
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   953) 		ret = init_fgraph_fixture(fixture);
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   954) 		if (ret && ret != -ENODEV) {
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   955) 			pr_cont("*Could not set filter* ");
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   956) 			printed = true;
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   957) 			goto out;
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   958) 		}
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   959) 
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   960) 		ret = register_ftrace_graph(&fixture->gops);
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   961) 		if (ret) {
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   962) 			pr_warn("Failed to init store_bytes fgraph tracing\n");
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   963) 			printed = true;
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   964) 			goto out;
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   965) 		}
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   966) 	}
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   967) 
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   968) 	DYN_FTRACE_TEST_NAME();
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   969) out:
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   970) 	while (--i >= 0) {
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   971) 		fixture = &store_bytes[i];
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   972) 		unregister_ftrace_graph(&fixture->gops);
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   973) 
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   974) 		if (fixture->error_str && !printed) {
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   975) 			pr_cont("*** %s ***", fixture->error_str);
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   976) 			printed = true;
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   977) 		}
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   978) 	}
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   979) 	return printed ? -1 : 0;
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   980) }
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   981) 
47c3c70aa36971 Steven Rostedt (VMware    2024-06-03   982) /* Test the storage passed across function_graph entry and return */
47c3c70aa36971 Steven Rostedt (VMware    2024-06-03   983) static __init int test_graph_storage(void)
47c3c70aa36971 Steven Rostedt (VMware    2024-06-03   984) {
47c3c70aa36971 Steven Rostedt (VMware    2024-06-03   985) 	int ret;
47c3c70aa36971 Steven Rostedt (VMware    2024-06-03   986) 
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   987) 	ret = test_graph_storage_single(&store_bytes[0]);
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   988) 	if (ret)
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   989) 		return ret;
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   990) 	ret = test_graph_storage_single(&store_bytes[1]);
47c3c70aa36971 Steven Rostedt (VMware    2024-06-03   991) 	if (ret)
47c3c70aa36971 Steven Rostedt (VMware    2024-06-03   992) 		return ret;
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   993) 	ret = test_graph_storage_single(&store_bytes[2]);
47c3c70aa36971 Steven Rostedt (VMware    2024-06-03   994) 	if (ret)
47c3c70aa36971 Steven Rostedt (VMware    2024-06-03   995) 		return ret;
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   996) 	ret = test_graph_storage_single(&store_bytes[3]);
47c3c70aa36971 Steven Rostedt (VMware    2024-06-03   997) 	if (ret)
47c3c70aa36971 Steven Rostedt (VMware    2024-06-03   998) 		return ret;
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   999) 	ret = test_graph_storage_multi();
47c3c70aa36971 Steven Rostedt (VMware    2024-06-03  1000) 	if (ret)
47c3c70aa36971 Steven Rostedt (VMware    2024-06-03  1001) 		return ret;
47c3c70aa36971 Steven Rostedt (VMware    2024-06-03  1002) 	return 0;
47c3c70aa36971 Steven Rostedt (VMware    2024-06-03  1003) }
47c3c70aa36971 Steven Rostedt (VMware    2024-06-03  1004) #else
47c3c70aa36971 Steven Rostedt (VMware    2024-06-03  1005) static inline int test_graph_storage(void) { return 0; }
47c3c70aa36971 Steven Rostedt (VMware    2024-06-03  1006) #endif /* CONFIG_DYNAMIC_FTRACE */
47c3c70aa36971 Steven Rostedt (VMware    2024-06-03  1007) 
cf586b61f80229 Frederic Weisbecker       2009-03-22  1008  /* Maximum number of functions to trace before diagnosing a hang */
cf586b61f80229 Frederic Weisbecker       2009-03-22  1009  #define GRAPH_MAX_FUNC_TEST	100000000
cf586b61f80229 Frederic Weisbecker       2009-03-22  1010  
cf586b61f80229 Frederic Weisbecker       2009-03-22  1011  static unsigned int graph_hang_thresh;
cf586b61f80229 Frederic Weisbecker       2009-03-22  1012  
cf586b61f80229 Frederic Weisbecker       2009-03-22  1013  /* Wrap the real function entry probe to avoid possible hanging */
37238abe3cb47b Steven Rostedt (VMware    2024-06-03  1014) static int trace_graph_entry_watchdog(struct ftrace_graph_ent *trace,
37238abe3cb47b Steven Rostedt (VMware    2024-06-03  1015) 				      struct fgraph_ops *gops)
cf586b61f80229 Frederic Weisbecker       2009-03-22  1016  {
cf586b61f80229 Frederic Weisbecker       2009-03-22  1017  	/* This is harmlessly racy, we want to approximately detect a hang */
cf586b61f80229 Frederic Weisbecker       2009-03-22  1018  	if (unlikely(++graph_hang_thresh > GRAPH_MAX_FUNC_TEST)) {
cf586b61f80229 Frederic Weisbecker       2009-03-22  1019  		ftrace_graph_stop();
cf586b61f80229 Frederic Weisbecker       2009-03-22  1020  		printk(KERN_WARNING "BUG: Function graph tracer hang!\n");
19f0423fd55c30 Huang Yiwei               2024-02-23  1021  		if (ftrace_dump_on_oops_enabled()) {
7fe70b579c9e3d Steven Rostedt (Red Hat   2013-03-15  1022) 			ftrace_dump(DUMP_ALL);
7fe70b579c9e3d Steven Rostedt (Red Hat   2013-03-15  1023) 			/* ftrace_dump() disables tracing */
7fe70b579c9e3d Steven Rostedt (Red Hat   2013-03-15  1024) 			tracing_on();
7fe70b579c9e3d Steven Rostedt (Red Hat   2013-03-15  1025) 		}
cf586b61f80229 Frederic Weisbecker       2009-03-22  1026  		return 0;
cf586b61f80229 Frederic Weisbecker       2009-03-22  1027  	}
cf586b61f80229 Frederic Weisbecker       2009-03-22  1028  
37238abe3cb47b Steven Rostedt (VMware    2024-06-03 @1029) 	return trace_graph_entry(trace, gops);
cf586b61f80229 Frederic Weisbecker       2009-03-22 @1030  }
cf586b61f80229 Frederic Weisbecker       2009-03-22  1031  
688f7089d8851b Steven Rostedt (VMware    2018-11-15  1032) static struct fgraph_ops fgraph_ops __initdata  = {
688f7089d8851b Steven Rostedt (VMware    2018-11-15 @1033) 	.entryfunc		= &trace_graph_entry_watchdog,
688f7089d8851b Steven Rostedt (VMware    2018-11-15  1034) 	.retfunc		= &trace_graph_return,
688f7089d8851b Steven Rostedt (VMware    2018-11-15  1035) };
688f7089d8851b Steven Rostedt (VMware    2018-11-15  1036) 
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#2 lore raw
In reply to Donglin Peng
kernel test robot noticed the following build errors:

Hi Donglin,

kernel test robot noticed the following build errors:

[auto build test ERROR on shuah-kselftest/next]
[also build test ERROR on shuah-kselftest/fixes linus/master v6.11-rc7] [cannot apply to next-20240913]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Donglin-Peng/function_graph-Support-recording-and-printing-the-function-return-address/20240913-204403
base:   https://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest.git next
patch link:    https://lore.kernel.org/r/20240913123456.600950-1-dolinux.peng%40gmail.com
patch subject: [PATCH v1] function_graph: Support recording and printing the function return address
config: x86_64-allyesconfig (https://download.01.org/0day-ci/archive/20240915/[email protected]/config)
compiler: clang version 18.1.8 (https://github.com/llvm/llvm-project 3b5b5c1ec4a3095ab096dd780e84d7ab81f3d7ff)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240915/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

In file included from kernel/trace/trace.c:8677:

>> kernel/trace/trace_selftest.c:910:18: error: incompatible function pointer types initializing 'trace_func_graph_ent_t' (aka 'int (*)(struct ftrace_graph_ent *, struct fgraph_ops *, struct fgraph_extras *)') with an expression of type 'int (struct ftrace_graph_ent *, struct fgraph_ops *)' [-Wincompatible-function-pointer-types]
     910 |                         .entryfunc              = store_entry,
         |                                                   ^~~~~~~~~~~
   kernel/trace/trace_selftest.c:918:18: error: incompatible function pointer types initializing 'trace_func_graph_ent_t' (aka 'int (*)(struct ftrace_graph_ent *, struct fgraph_ops *, struct fgraph_extras *)') with an expression of type 'int (struct ftrace_graph_ent *, struct fgraph_ops *)' [-Wincompatible-function-pointer-types]
     918 |                         .entryfunc              = store_entry,
         |                                                   ^~~~~~~~~~~
   kernel/trace/trace_selftest.c:926:18: error: incompatible function pointer types initializing 'trace_func_graph_ent_t' (aka 'int (*)(struct ftrace_graph_ent *, struct fgraph_ops *, struct fgraph_extras *)') with an expression of type 'int (struct ftrace_graph_ent *, struct fgraph_ops *)' [-Wincompatible-function-pointer-types]
     926 |                         .entryfunc              = store_entry,
         |                                                   ^~~~~~~~~~~
   kernel/trace/trace_selftest.c:934:18: error: incompatible function pointer types initializing 'trace_func_graph_ent_t' (aka 'int (*)(struct ftrace_graph_ent *, struct fgraph_ops *, struct fgraph_extras *)') with an expression of type 'int (struct ftrace_graph_ent *, struct fgraph_ops *)' [-Wincompatible-function-pointer-types]
     934 |                         .entryfunc              = store_entry,
         |                                                   ^~~~~~~~~~~
>> kernel/trace/trace_selftest.c:1029:38: error: too few arguments to function call, expected 3, have 2
    1029 |         return trace_graph_entry(trace, gops);
         |                ~~~~~~~~~~~~~~~~~            ^
   kernel/trace/trace.h:689:5: note: 'trace_graph_entry' declared here
     689 | int trace_graph_entry(struct ftrace_graph_ent *trace, struct fgraph_ops *gops,
         |     ^                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     690 |                       struct fgraph_extras *priv);
         |                       ~~~~~~~~~~~~~~~~~~~~~~~~~~

In file included from kernel/trace/trace.c:8677:
kernel/trace/trace_selftest.c:1033:16: error: incompatible function pointer types initializing 'trace_func_graph_ent_t' (aka 'int (*)(struct ftrace_graph_ent *, struct fgraph_ops *, struct fgraph_extras *)') with an expression of type 'int (*)(struct ftrace_graph_ent *, struct fgraph_ops *)' [-Wincompatible-function-pointer-types]
1033 | .entryfunc = &trace_graph_entry_watchdog,
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~
6 errors generated.

vim +910 kernel/trace/trace_selftest.c

dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   906) 
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   907) static struct fgraph_fixture store_bytes[4] __initdata = {
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   908) 	[0] = {
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   909) 		.gops = {
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03  @910) 			.entryfunc		= store_entry,
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   911) 			.retfunc		= store_return,
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   912) 		},
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   913) 		.store_size = 1,
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   914) 		.store_type_name = "byte",
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   915) 	},
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   916) 	[1] = {
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   917) 		.gops = {
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   918) 			.entryfunc		= store_entry,
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   919) 			.retfunc		= store_return,
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   920) 		},
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   921) 		.store_size = 2,
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   922) 		.store_type_name = "short",
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   923) 	},
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   924) 	[2] = {
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   925) 		.gops = {
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   926) 			.entryfunc		= store_entry,
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   927) 			.retfunc		= store_return,
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   928) 		},
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   929) 		.store_size = 4,
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   930) 		.store_type_name = "word",
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   931) 	},
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   932) 	[3] = {
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   933) 		.gops = {
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   934) 			.entryfunc		= store_entry,
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   935) 			.retfunc		= store_return,
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   936) 		},
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   937) 		.store_size = 8,
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   938) 		.store_type_name = "long long",
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   939) 	},
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   940) };
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   941) 
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   942) static __init int test_graph_storage_multi(void)
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   943) {
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   944) 	struct fgraph_fixture *fixture;
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   945) 	bool printed = false;
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   946) 	int i, ret;
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   947) 
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   948) 	pr_cont("PASSED\n");
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   949) 	pr_info("Testing multiple fgraph storage on a function: ");
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   950) 
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   951) 	for (i = 0; i < ARRAY_SIZE(store_bytes); i++) {
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   952) 		fixture = &store_bytes[i];
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   953) 		ret = init_fgraph_fixture(fixture);
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   954) 		if (ret && ret != -ENODEV) {
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   955) 			pr_cont("*Could not set filter* ");
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   956) 			printed = true;
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   957) 			goto out;
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   958) 		}
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   959) 
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   960) 		ret = register_ftrace_graph(&fixture->gops);
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   961) 		if (ret) {
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   962) 			pr_warn("Failed to init store_bytes fgraph tracing\n");
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   963) 			printed = true;
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   964) 			goto out;
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   965) 		}
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   966) 	}
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   967) 
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   968) 	DYN_FTRACE_TEST_NAME();
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   969) out:
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   970) 	while (--i >= 0) {
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   971) 		fixture = &store_bytes[i];
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   972) 		unregister_ftrace_graph(&fixture->gops);
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   973) 
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   974) 		if (fixture->error_str && !printed) {
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   975) 			pr_cont("*** %s ***", fixture->error_str);
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   976) 			printed = true;
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   977) 		}
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   978) 	}
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   979) 	return printed ? -1 : 0;
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   980) }
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   981) 
47c3c70aa36971 Steven Rostedt (VMware    2024-06-03   982) /* Test the storage passed across function_graph entry and return */
47c3c70aa36971 Steven Rostedt (VMware    2024-06-03   983) static __init int test_graph_storage(void)
47c3c70aa36971 Steven Rostedt (VMware    2024-06-03   984) {
47c3c70aa36971 Steven Rostedt (VMware    2024-06-03   985) 	int ret;
47c3c70aa36971 Steven Rostedt (VMware    2024-06-03   986) 
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   987) 	ret = test_graph_storage_single(&store_bytes[0]);
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   988) 	if (ret)
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   989) 		return ret;
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   990) 	ret = test_graph_storage_single(&store_bytes[1]);
47c3c70aa36971 Steven Rostedt (VMware    2024-06-03   991) 	if (ret)
47c3c70aa36971 Steven Rostedt (VMware    2024-06-03   992) 		return ret;
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   993) 	ret = test_graph_storage_single(&store_bytes[2]);
47c3c70aa36971 Steven Rostedt (VMware    2024-06-03   994) 	if (ret)
47c3c70aa36971 Steven Rostedt (VMware    2024-06-03   995) 		return ret;
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   996) 	ret = test_graph_storage_single(&store_bytes[3]);
47c3c70aa36971 Steven Rostedt (VMware    2024-06-03   997) 	if (ret)
47c3c70aa36971 Steven Rostedt (VMware    2024-06-03   998) 		return ret;
dd120af2d5f8f3 Masami Hiramatsu (Google  2024-06-03   999) 	ret = test_graph_storage_multi();
47c3c70aa36971 Steven Rostedt (VMware    2024-06-03  1000) 	if (ret)
47c3c70aa36971 Steven Rostedt (VMware    2024-06-03  1001) 		return ret;
47c3c70aa36971 Steven Rostedt (VMware    2024-06-03  1002) 	return 0;
47c3c70aa36971 Steven Rostedt (VMware    2024-06-03  1003) }
47c3c70aa36971 Steven Rostedt (VMware    2024-06-03  1004) #else
47c3c70aa36971 Steven Rostedt (VMware    2024-06-03  1005) static inline int test_graph_storage(void) { return 0; }
47c3c70aa36971 Steven Rostedt (VMware    2024-06-03  1006) #endif /* CONFIG_DYNAMIC_FTRACE */
47c3c70aa36971 Steven Rostedt (VMware    2024-06-03  1007) 
cf586b61f80229 Frederic Weisbecker       2009-03-22  1008  /* Maximum number of functions to trace before diagnosing a hang */
cf586b61f80229 Frederic Weisbecker       2009-03-22  1009  #define GRAPH_MAX_FUNC_TEST	100000000
cf586b61f80229 Frederic Weisbecker       2009-03-22  1010  
cf586b61f80229 Frederic Weisbecker       2009-03-22  1011  static unsigned int graph_hang_thresh;
cf586b61f80229 Frederic Weisbecker       2009-03-22  1012  
cf586b61f80229 Frederic Weisbecker       2009-03-22  1013  /* Wrap the real function entry probe to avoid possible hanging */
37238abe3cb47b Steven Rostedt (VMware    2024-06-03  1014) static int trace_graph_entry_watchdog(struct ftrace_graph_ent *trace,
37238abe3cb47b Steven Rostedt (VMware    2024-06-03  1015) 				      struct fgraph_ops *gops)
cf586b61f80229 Frederic Weisbecker       2009-03-22  1016  {
cf586b61f80229 Frederic Weisbecker       2009-03-22  1017  	/* This is harmlessly racy, we want to approximately detect a hang */
cf586b61f80229 Frederic Weisbecker       2009-03-22  1018  	if (unlikely(++graph_hang_thresh > GRAPH_MAX_FUNC_TEST)) {
cf586b61f80229 Frederic Weisbecker       2009-03-22  1019  		ftrace_graph_stop();
cf586b61f80229 Frederic Weisbecker       2009-03-22  1020  		printk(KERN_WARNING "BUG: Function graph tracer hang!\n");
19f0423fd55c30 Huang Yiwei               2024-02-23  1021  		if (ftrace_dump_on_oops_enabled()) {
7fe70b579c9e3d Steven Rostedt (Red Hat   2013-03-15  1022) 			ftrace_dump(DUMP_ALL);
7fe70b579c9e3d Steven Rostedt (Red Hat   2013-03-15  1023) 			/* ftrace_dump() disables tracing */
7fe70b579c9e3d Steven Rostedt (Red Hat   2013-03-15  1024) 			tracing_on();
7fe70b579c9e3d Steven Rostedt (Red Hat   2013-03-15  1025) 		}
cf586b61f80229 Frederic Weisbecker       2009-03-22  1026  		return 0;
cf586b61f80229 Frederic Weisbecker       2009-03-22  1027  	}
cf586b61f80229 Frederic Weisbecker       2009-03-22  1028  
37238abe3cb47b Steven Rostedt (VMware    2024-06-03 @1029) 	return trace_graph_entry(trace, gops);
cf586b61f80229 Frederic Weisbecker       2009-03-22  1030  }
cf586b61f80229 Frederic Weisbecker       2009-03-22  1031  
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki