Skip to contentSkip to conversation

add function arguments to ftrace

PATCH In review Sven Schnelle 6 participants 28 messages Sep 4, 2024 – Oct 7, 2024

Subsystems (17)
Arm (32-bit) x86 PowerPC MIPS +13 more subsystems
lore
Share & tools
lore

Sven Schnelle

author reviewer
#0 lore raw

cover add function arguments to ftrace

These patches add support for printing function arguments in ftrace.

Example usage:

function tracer:

cd /sys/kernel/tracing/
echo icmp_rcv >set_ftrace_filter
echo function >current_tracer
echo 1 >options/func-args
ping -c 10 127.0.0.1
[..]
cat trace
[..]

            ping-1277    [030] ..s1.    39.120939: icmp_rcv(skb = 0xa0ecab00) <-ip_protocol_deliver_rcu
            ping-1277    [030] ..s1.    39.120946: icmp_rcv(skb = 0xa0ecac00) <-ip_protocol_deliver_rcu
            ping-1277    [030] ..s1.    40.179724: icmp_rcv(skb = 0xa0ecab00) <-ip_protocol_deliver_rcu
            ping-1277    [030] ..s1.    40.179730: icmp_rcv(skb = 0xa0ecac00) <-ip_protocol_deliver_rcu
            ping-1277    [030] ..s1.    41.219700: icmp_rcv(skb = 0xa0ecab00) <-ip_protocol_deliver_rcu
            ping-1277    [030] ..s1.    41.219706: icmp_rcv(skb = 0xa0ecac00) <-ip_protocol_deliver_rcu
            ping-1277    [030] ..s1.    42.259717: icmp_rcv(skb = 0xa0ecab00) <-ip_protocol_deliver_rcu
            ping-1277    [030] ..s1.    42.259725: icmp_rcv(skb = 0xa0ecac00) <-ip_protocol_deliver_rcu
            ping-1277    [030] ..s1.    43.299735: icmp_rcv(skb = 0xa0ecab00) <-ip_protocol_deliver_rcu
            ping-1277    [030] ..s1.    43.299742: icmp_rcv(skb = 0xa0ecac00) <-ip_protocol_deliver_rcu

function graph:

cd /sys/kernel/tracing
echo icmp_rcv >set_graph_function
echo function_graph >current_tracer
echo 1 >options/funcgraph-args

ping -c 1 127.0.0.1

cat trace

 30)               |  icmp_rcv(skb = 0xa0ecab00) {
 30)               |    __skb_checksum_complete(skb = 0xa0ecab00) {
 30)               |      skb_checksum(skb = 0xa0ecab00, offset = 0, len = 64, csum = 0) {
 30)               |        __skb_checksum(skb = 0xa0ecab00, offset = 0, len = 64, csum = 0, ops = 0x232e0327a88) {
 30)   0.418 us    |          csum_partial(buff = 0xa0d20924, len = 64, sum = 0)
 30)   0.985 us    |        }
 30)   1.463 us    |      }
 30)   2.039 us    |    }

[..]

Sven Schnelle (7):
tracing: add ftrace_regs to function_graph_enter() x86/tracing: pass ftrace_regs to function_graph_enter() s390/tracing: pass ftrace_regs to function_graph_enter() Add print_function_args()
tracing: add config option for print arguments in ftrace
tracing: add support for function argument to graph tracer
tracing: add arguments to function tracer

 arch/arm/kernel/ftrace.c             |  2 +-
 arch/arm64/kernel/ftrace.c           |  2 +-
 arch/csky/kernel/ftrace.c            |  2 +-
 arch/loongarch/kernel/ftrace.c       |  2 +-
 arch/loongarch/kernel/ftrace_dyn.c   |  2 +-
 arch/microblaze/kernel/ftrace.c      |  2 +-
 arch/mips/kernel/ftrace.c            |  2 +-
 arch/parisc/kernel/ftrace.c          |  2 +-
 arch/powerpc/kernel/trace/ftrace.c   |  2 +-
 arch/riscv/kernel/ftrace.c           |  2 +-
 arch/s390/kernel/entry.h             |  4 +-
 arch/s390/kernel/ftrace.c            |  4 +-
 arch/sh/kernel/ftrace.c              |  2 +-
 arch/sparc/kernel/ftrace.c           |  2 +-
 arch/x86/include/asm/ftrace.h        |  2 +-
 arch/x86/kernel/ftrace.c             |  6 +-
 include/linux/ftrace.h               |  4 +-
 kernel/trace/Kconfig                 | 12 ++++
 kernel/trace/fgraph.c                |  7 ++-
 kernel/trace/trace.c                 |  8 ++-
 kernel/trace/trace.h                 |  4 +-
 kernel/trace/trace_entries.h         |  7 ++-
 kernel/trace/trace_functions.c       | 46 ++++++++++++++--
 kernel/trace/trace_functions_graph.c | 74 +++++++++++++------------
 kernel/trace/trace_irqsoff.c         |  4 +-
 kernel/trace/trace_output.c          | 82 +++++++++++++++++++++++++++-
 kernel/trace/trace_output.h          |  9 +++
 kernel/trace/trace_sched_wakeup.c    |  4 +-
 28 files changed, 228 insertions(+), 73 deletions(-)

--
2.43.0

author reviewer
#1 lore raw

PATCH 1/7 tracing: add ftrace_regs to function_graph_enter()

Will be used later for showing function arguments in the function graph tracer.

---
 arch/arm/kernel/ftrace.c           | 2 +-
 arch/arm64/kernel/ftrace.c         | 2 +-
 arch/csky/kernel/ftrace.c          | 2 +-
 arch/loongarch/kernel/ftrace.c     | 2 +-
 arch/loongarch/kernel/ftrace_dyn.c | 2 +-
 arch/microblaze/kernel/ftrace.c    | 2 +-
 arch/mips/kernel/ftrace.c          | 2 +-
 arch/parisc/kernel/ftrace.c        | 2 +-
 arch/powerpc/kernel/trace/ftrace.c | 2 +-
 arch/riscv/kernel/ftrace.c         | 2 +-
 arch/s390/kernel/ftrace.c          | 2 +-
 arch/sh/kernel/ftrace.c            | 2 +-
 arch/sparc/kernel/ftrace.c         | 2 +-
 arch/x86/kernel/ftrace.c           | 2 +-
 include/linux/ftrace.h             | 3 ++-
 kernel/trace/fgraph.c              | 3 ++-
 16 files changed, 18 insertions(+), 16 deletions(-)
arch/arm/kernel/ftrace.c +1 -1
index e61591f33a6c..1f8802439e34 100644
@@ -267,7 +267,7 @@ void prepare_ftrace_return(unsigned long *parent, unsigned long self_addr,
 	old = *parent;
 	*parent = return_hooker;
 
-	if (function_graph_enter(old, self_addr, frame_pointer, NULL))
+	if (function_graph_enter(old, self_addr, frame_pointer, NULL, NULL))
 		*parent = old;
 }
 
arch/arm64/kernel/ftrace.c +1 -1
index a650f5e11fc5..686fbebb0432 100644
@@ -472,7 +472,7 @@ void prepare_ftrace_return(unsigned long self_addr, unsigned long *parent,
 	old = *parent;
 
 	if (!function_graph_enter(old, self_addr, frame_pointer,
-	    (void *)frame_pointer)) {
+	    (void *)frame_pointer, NULL)) {
 		*parent = return_hooker;
 	}
 }
arch/csky/kernel/ftrace.c +1 -1
index 50bfcf129078..c12af268c1cb 100644
@@ -156,7 +156,7 @@ void prepare_ftrace_return(unsigned long *parent, unsigned long self_addr,
 	old = *parent;
 
 	if (!function_graph_enter(old, self_addr,
-			*(unsigned long *)frame_pointer, parent)) {
+			*(unsigned long *)frame_pointer, parent, NULL)) {
 		/*
 		 * For csky-gcc function has sub-call:
 		 * subi	sp,	sp, 8
arch/loongarch/kernel/ftrace.c +1 -1
index 8c3ec1bc7aad..43d908b01718 100644
@@ -61,7 +61,7 @@ void prepare_ftrace_return(unsigned long self_addr,
 	if (ftrace_get_parent_ra_addr(self_addr, &ra_off))
 		goto out;
 
-	if (!function_graph_enter(old, self_addr, 0, NULL))
+	if (!function_graph_enter(old, self_addr, 0, NULL, NULL))
 		*(unsigned long *)(callsite_sp + ra_off) = return_hooker;
 
 	return;
arch/loongarch/kernel/ftrace_dyn.c +1 -1
index bff058317062..eab16231d09d 100644
@@ -233,7 +233,7 @@ void prepare_ftrace_return(unsigned long self_addr, unsigned long *parent)
 
 	old = *parent;
 
-	if (!function_graph_enter(old, self_addr, 0, parent))
+	if (!function_graph_enter(old, self_addr, 0, parent, NULL))
 		*parent = return_hooker;
 }
 
arch/microblaze/kernel/ftrace.c +1 -1
index 188749d62709..009800d7e54f 100644
@@ -62,7 +62,7 @@ void prepare_ftrace_return(unsigned long *parent, unsigned long self_addr)
 		return;
 	}
 
-	if (function_graph_enter(old, self_addr, 0, NULL))
+	if (function_graph_enter(old, self_addr, 0, NULL, NULL))
 		*parent = old;
 }
 #endif /* CONFIG_FUNCTION_GRAPH_TRACER */
arch/mips/kernel/ftrace.c +1 -1
index 8c401e42301c..65f29de35a59 100644
@@ -362,7 +362,7 @@ void prepare_ftrace_return(unsigned long *parent_ra_addr, unsigned long self_ra,
 	insns = core_kernel_text(self_ra) ? 2 : MCOUNT_OFFSET_INSNS + 1;
 	self_ra -= (MCOUNT_INSN_SIZE * insns);
 
-	if (function_graph_enter(old_parent_ra, self_ra, fp, NULL))
+	if (function_graph_enter(old_parent_ra, self_ra, fp, NULL, NULL))
 		*parent_ra_addr = old_parent_ra;
 	return;
 out:
arch/parisc/kernel/ftrace.c +1 -1
index c91f9c2e61ed..c8d926f057a6 100644
@@ -45,7 +45,7 @@ static void __hot prepare_ftrace_return(unsigned long *parent,
 
 	old = *parent;
 
-	if (!function_graph_enter(old, self_addr, 0, NULL))
+	if (!function_graph_enter(old, self_addr, 0, NULL, NULL))
 		/* activate parisc_return_to_handler() as return point */
 		*parent = (unsigned long) &parisc_return_to_handler;
 }
arch/powerpc/kernel/trace/ftrace.c +1 -1
index d8d6b4fd9a14..8a24d6eabb64 100644
@@ -434,7 +434,7 @@ void ftrace_graph_func(unsigned long ip, unsigned long parent_ip,
 	if (bit < 0)
 		goto out;
 
-	if (!function_graph_enter(parent_ip, ip, 0, (unsigned long *)sp))
+	if (!function_graph_enter(parent_ip, ip, 0, (unsigned long *)sp, NULL))
 		parent_ip = ppc_function_entry(return_to_handler);
 
 	ftrace_test_recursion_unlock(bit);
arch/riscv/kernel/ftrace.c +1 -1
index 4b95c574fd04..b45985265b29 100644
@@ -205,7 +205,7 @@ void prepare_ftrace_return(unsigned long *parent, unsigned long self_addr,
 	 */
 	old = *parent;
 
-	if (!function_graph_enter(old, self_addr, frame_pointer, parent))
+	if (!function_graph_enter(old, self_addr, frame_pointer, parent, NULL))
 		*parent = return_hooker;
 }
 
arch/s390/kernel/ftrace.c +1 -1
index 0b6e62d1d8b8..cf9ee90ae216 100644
@@ -273,7 +273,7 @@ unsigned long prepare_ftrace_return(unsigned long ra, unsigned long sp,
 	if (unlikely(atomic_read(&current->tracing_graph_pause)))
 		goto out;
 	ip -= MCOUNT_INSN_SIZE;
-	if (!function_graph_enter(ra, ip, 0, (void *) sp))
+	if (!function_graph_enter(ra, ip, 0, (void *) sp, NULL))
 		ra = (unsigned long) return_to_handler;
 out:
 	return ra;
arch/sh/kernel/ftrace.c +1 -1
index 930001bb8c6a..a9a0a1238214 100644
@@ -359,7 +359,7 @@ void prepare_ftrace_return(unsigned long *parent, unsigned long self_addr)
 		return;
 	}
 
-	if (function_graph_enter(old, self_addr, 0, NULL))
+	if (function_graph_enter(old, self_addr, 0, NULL, NULL))
 		__raw_writel(old, parent);
 }
 #endif /* CONFIG_FUNCTION_GRAPH_TRACER */
arch/sparc/kernel/ftrace.c +1 -1
index eaead3da8e03..9ad77a2d9bc4 100644
@@ -125,7 +125,7 @@ unsigned long prepare_ftrace_return(unsigned long parent,
 	if (unlikely(atomic_read(&current->tracing_graph_pause)))
 		return parent + 8UL;
 
-	if (function_graph_enter(parent, self_addr, frame_pointer, NULL))
+	if (function_graph_enter(parent, self_addr, frame_pointer, NULL, NULL))
 		return parent + 8UL;
 
 	return return_hooker;
arch/x86/kernel/ftrace.c +1 -1
index 8da0e66ca22d..b325f7e7e39a 100644
@@ -637,7 +637,7 @@ void prepare_ftrace_return(unsigned long ip, unsigned long *parent,
 	if (bit < 0)
 		return;
 
-	if (!function_graph_enter(*parent, ip, frame_pointer, parent))
+	if (!function_graph_enter(*parent, ip, frame_pointer, parent, NULL))
 		*parent = return_hooker;
 
 	ftrace_test_recursion_unlock(bit);
include/linux/ftrace.h +2 -1
index fd5e84d0ec47..56d91041ecd2 100644
@@ -1083,7 +1083,8 @@ extern void return_to_handler(void);
 
 extern int
 function_graph_enter(unsigned long ret, unsigned long func,
-		     unsigned long frame_pointer, unsigned long *retp);
+		     unsigned long frame_pointer, unsigned long *retp,
+		     struct ftrace_regs *fregs);
 
 struct ftrace_ret_stack *
 ftrace_graph_get_ret_stack(struct task_struct *task, int skip);
kernel/trace/fgraph.c +2 -1
index d1d5ea2d0a1b..fa62ebfa0711 100644
@@ -613,7 +613,8 @@ ftrace_push_return_trace(unsigned long ret, unsigned long func,
 
 /* If the caller does not use ftrace, call this function. */
 int function_graph_enter(unsigned long ret, unsigned long func,
-			 unsigned long frame_pointer, unsigned long *retp)
+			 unsigned long frame_pointer, unsigned long *retp,
+			struct ftrace_regs *fregs)
 {
 	struct ftrace_graph_ent trace;
 	unsigned long bitmap = 0;
Signature · 1 line
2.43.0
author reviewer
#2 lore raw

PATCH 2/7 x86/tracing: pass ftrace_regs to function_graph_enter()

In reply to Sven Schnelle

Will be used later for printing function argument in the function graph tracer.

---
 arch/x86/include/asm/ftrace.h | 2 +-
 arch/x86/kernel/ftrace.c      | 6 +++---
 2 files changed, 4 insertions(+), 4 deletions(-)
arch/x86/include/asm/ftrace.h +1 -1
index 0152a81d9b4a..9843d0c08e61 100644
@@ -105,7 +105,7 @@ struct dyn_arch_ftrace {
 #ifndef __ASSEMBLY__
 
 void prepare_ftrace_return(unsigned long ip, unsigned long *parent,
-			   unsigned long frame_pointer);
+			   unsigned long frame_pointer, struct ftrace_regs *regs);
 
 #if defined(CONFIG_FUNCTION_TRACER) && defined(CONFIG_DYNAMIC_FTRACE)
 extern void set_ftrace_ops_ro(void);
arch/x86/kernel/ftrace.c +3 -3
index b325f7e7e39a..a016b82de5e2 100644
@@ -610,7 +610,7 @@ int ftrace_disable_ftrace_graph_caller(void)
  * in current thread info.
  */
 void prepare_ftrace_return(unsigned long ip, unsigned long *parent,
-			   unsigned long frame_pointer)
+			   unsigned long frame_pointer, struct ftrace_regs *fregs)
 {
 	unsigned long return_hooker = (unsigned long)&return_to_handler;
 	int bit;
@@ -637,7 +637,7 @@ void prepare_ftrace_return(unsigned long ip, unsigned long *parent,
 	if (bit < 0)
 		return;
 
-	if (!function_graph_enter(*parent, ip, frame_pointer, parent, NULL))
+	if (!function_graph_enter(*parent, ip, frame_pointer, parent, fregs))
 		*parent = return_hooker;
 
 	ftrace_test_recursion_unlock(bit);
@@ -650,7 +650,7 @@ void ftrace_graph_func(unsigned long ip, unsigned long parent_ip,
 	struct pt_regs *regs = &fregs->regs;
 	unsigned long *stack = (unsigned long *)kernel_stack_pointer(regs);
 
-	prepare_ftrace_return(ip, (unsigned long *)stack, 0);
+	prepare_ftrace_return(ip, (unsigned long *)stack, 0, fregs);
 }
 #endif
 
Signature · 1 line
2.43.0
#3 lore raw

Re: [PATCH 2/7] x86/tracing: pass ftrace_regs to function_graph_enter()

kernel test robot noticed the following build warnings:

Hi Sven,

kernel test robot noticed the following build warnings:

[auto build test WARNING on s390/features]
[also build test WARNING on tip/x86/core linus/master v6.11-rc6 next-20240904] [cannot apply to rostedt-trace/for-next rostedt-trace/for-next-urgent] [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/Sven-Schnelle/tracing-add-ftrace_regs-to-function_graph_enter/20240904-150232
base:   https://git.kernel.org/pub/scm/linux/kernel/git/s390/linux.git features
patch link:    https://lore.kernel.org/r/20240904065908.1009086-3-svens%40linux.ibm.com
patch subject: [PATCH 2/7] x86/tracing: pass ftrace_regs to function_graph_enter()
config: x86_64-defconfig (https://download.01.org/0day-ci/archive/20240905/[email protected]/config)
compiler: gcc-11 (Debian 11.3.0-12) 11.3.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240905/[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 warnings (new ones prefixed by >>):

In file included from include/linux/ftrace.h:23,

                    from include/linux/kprobes.h:28,
                    from arch/x86/kernel/process_64.c:35:
>> arch/x86/include/asm/ftrace.h:108:64: warning: 'struct ftrace_regs' declared inside parameter list will not be visible outside of this definition or declaration
     108 |                            unsigned long frame_pointer, struct ftrace_regs *regs);
         |                                                                ^~~~~~~~~~~

vim +108 arch/x86/include/asm/ftrace.h

106
107 void prepare_ftrace_return(unsigned long ip, unsigned long *parent,

 > 108				   unsigned long frame_pointer, struct ftrace_regs *regs);

109

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
author reviewer
#4 lore raw

PATCH 3/7 s390/tracing: pass ftrace_regs to function_graph_enter()

In reply to Sven Schnelle

Will be used later to print function arguments in the function graph tracer.

---
 arch/s390/kernel/entry.h  | 4 +++-
 arch/s390/kernel/ftrace.c | 4 ++--
 2 files changed, 5 insertions(+), 3 deletions(-)
arch/s390/kernel/entry.h +3 -1
index 21969520f947..d0a5fbaad987 100644
@@ -5,6 +5,7 @@
 #include <linux/percpu.h>
 #include <linux/types.h>
 #include <linux/signal.h>
+#include <linux/ftrace.h>
 #include <asm/extable.h>
 #include <asm/ptrace.h>
 #include <asm/idle.h>
@@ -41,7 +42,8 @@ void do_restart(void *arg);
 void __init startup_init(void);
 void die(struct pt_regs *regs, const char *str);
 int setup_profiling_timer(unsigned int multiplier);
-unsigned long prepare_ftrace_return(unsigned long parent, unsigned long sp, unsigned long ip);
+unsigned long prepare_ftrace_return(unsigned long parent, unsigned long sp, unsigned long ip,
+				    struct ftrace_regs *regs);
 
 struct s390_mmap_arg_struct;
 struct fadvise64_64_args;
arch/s390/kernel/ftrace.c +2 -2
index cf9ee90ae216..dd77b656d9b9 100644
@@ -266,14 +266,14 @@ void ftrace_arch_code_modify_post_process(void)
  * in current thread info.
  */
 unsigned long prepare_ftrace_return(unsigned long ra, unsigned long sp,
-				    unsigned long ip)
+				    unsigned long ip, struct ftrace_regs *regs)
 {
 	if (unlikely(ftrace_graph_is_dead()))
 		goto out;
 	if (unlikely(atomic_read(&current->tracing_graph_pause)))
 		goto out;
 	ip -= MCOUNT_INSN_SIZE;
-	if (!function_graph_enter(ra, ip, 0, (void *) sp, NULL))
+	if (!function_graph_enter(ra, ip, 0, (void *) sp, regs))
 		ra = (unsigned long) return_to_handler;
 out:
 	return ra;
Signature · 1 line
2.43.0
author reviewer
#5 lore raw

PATCH 4/7 Add print_function_args()

In reply to Sven Schnelle

Add a function to decode argument types with the help of BTF. Will be used to display arguments in the function and function graph tracer.

---
 kernel/trace/trace_output.c | 68 +++++++++++++++++++++++++++++++++++++
 kernel/trace/trace_output.h |  9 +++++
 2 files changed, 77 insertions(+)
kernel/trace/trace_output.c +68 -0
index d8b302d01083..70405c4cceb6 100644
@@ -12,8 +12,11 @@
 #include <linux/sched/clock.h>
 #include <linux/sched/mm.h>
 #include <linux/idr.h>
+#include <linux/btf.h>
+#include <linux/bpf.h>
 
 #include "trace_output.h"
+#include "trace_btf.h"
 
 /* must be a power of 2 */
 #define EVENT_HASHSIZE	128
@@ -669,6 +672,71 @@ int trace_print_lat_context(struct trace_iterator *iter)
 	return !trace_seq_has_overflowed(s);
 }
 
+#ifdef CONFIG_FUNCTION_TRACE_ARGS
+void print_function_args(struct trace_seq *s, struct ftrace_regs *fregs,
+			 unsigned long func)
+{
+	const struct btf_param *param;
+	const struct btf_type *t;
+	const char *param_name;
+	char name[KSYM_NAME_LEN];
+	unsigned long arg;
+	struct btf *btf;
+	s32 tid, nr = 0;
+	int i;
+
+	trace_seq_printf(s, "(");
+
+	if (!ftrace_regs_has_args(fregs))
+		goto out;
+	if (lookup_symbol_name(func, name))
+		goto out;
+
+	btf = bpf_get_btf_vmlinux();
+	if (IS_ERR_OR_NULL(btf))
+		goto out;
+
+	t = btf_find_func_proto(name, &btf);
+	if (IS_ERR_OR_NULL(t))
+		goto out;
+
+	param = btf_get_func_param(t, &nr);
+	if (!param)
+		goto out_put;
+
+	for (i = 0; i < nr; i++) {
+		arg = ftrace_regs_get_argument(fregs, i);
+
+		param_name = btf_name_by_offset(btf, param[i].name_off);
+		if (param_name)
+			trace_seq_printf(s, "%s = ", param_name);
+		t = btf_type_skip_modifiers(btf, param[i].type, &tid);
+		if (!t)
+			continue;
+		switch (BTF_INFO_KIND(t->info)) {
+		case BTF_KIND_PTR:
+			trace_seq_printf(s, "0x%lx", arg);
+			break;
+		case BTF_KIND_INT:
+			trace_seq_printf(s, "%ld", arg);
+			break;
+		case BTF_KIND_ENUM:
+			trace_seq_printf(s, "%ld", arg);
+			break;
+		default:
+			trace_seq_printf(s, "0x%lx (%d)", arg, BTF_INFO_KIND(param[i].type));
+			break;
+		}
+		if (i < nr - 1)
+			trace_seq_printf(s, ", ");
+	}
+out_put:
+	btf_put(btf);
+out:
+	trace_seq_printf(s, ")");
+}
+#endif
+
 /**
  * ftrace_find_event - find a registered event
  * @type: the type of event to look for
kernel/trace/trace_output.h +9 -0
index dca40f1f1da4..a21d8ce606f7 100644
@@ -41,5 +41,14 @@ extern struct rw_semaphore trace_event_sem;
 #define SEQ_PUT_HEX_FIELD(s, x)				\
 	trace_seq_putmem_hex(s, &(x), sizeof(x))
 
+#ifdef CONFIG_FUNCTION_TRACE_ARGS
+void print_function_args(struct trace_seq *s, struct ftrace_regs *fregs,
+			 unsigned long func);
+#else
+static inline void print_function_args(struct trace_seq *s, struct ftrace_regs *fregs,
+				       unsigned long func) {
+	trace_seq_puts(s, "()");
+}
+#endif
 #endif
 
Signature · 1 line
2.43.0
#6 lore raw

Re: [PATCH 4/7] Add print_function_args()

Quoted 67 lines · On Wed, 4 Sep 2024 08:58:58 +0200 Sven Schnelle <[email protected]> wrote:

Add a function to decode argument types with the help of BTF. Will be used to display arguments in the function and function graph tracer.

---
 kernel/trace/trace_output.c | 68 +++++++++++++++++++++++++++++++++++++
 kernel/trace/trace_output.h |  9 +++++
 2 files changed, 77 insertions(+)
kernel/trace/trace_output.c +40 -0
index d8b302d01083..70405c4cceb6 100644
@@ -12,8 +12,11 @@
 #include <linux/sched/clock.h>
 #include <linux/sched/mm.h>
 #include <linux/idr.h>
+#include <linux/btf.h>
+#include <linux/bpf.h>
 
 #include "trace_output.h"
+#include "trace_btf.h"
 
 /* must be a power of 2 */
 #define EVENT_HASHSIZE	128
@@ -669,6 +672,71 @@ int trace_print_lat_context(struct trace_iterator *iter)
 	return !trace_seq_has_overflowed(s);
 }
 
+#ifdef CONFIG_FUNCTION_TRACE_ARGS
+void print_function_args(struct trace_seq *s, struct ftrace_regs *fregs,
+			 unsigned long func)
+{
+	const struct btf_param *param;
+	const struct btf_type *t;
+	const char *param_name;
+	char name[KSYM_NAME_LEN];
+	unsigned long arg;
+	struct btf *btf;
+	s32 tid, nr = 0;
+	int i;
+
+	trace_seq_printf(s, "(");
+
+	if (!ftrace_regs_has_args(fregs))
+		goto out;
+	if (lookup_symbol_name(func, name))
+		goto out;
+
+	btf = bpf_get_btf_vmlinux();
+	if (IS_ERR_OR_NULL(btf))
+		goto out;
+
+	t = btf_find_func_proto(name, &btf);
+	if (IS_ERR_OR_NULL(t))
+		goto out;
+
+	param = btf_get_func_param(t, &nr);
+	if (!param)
+		goto out_put;
+
+	for (i = 0; i < nr; i++) {
+		arg = ftrace_regs_get_argument(fregs, i);
+
+		param_name = btf_name_by_offset(btf, param[i].name_off);
+		if (param_name)

kernel/trace/trace_output.c int trace_print_lat_context(struct trace_iterator *iter) · line 721

Quoted 10 lines
kernel/trace/trace_output.c +10 -0
+			trace_seq_printf(s, "%s = ", param_name);
+		t = btf_type_skip_modifiers(btf, param[i].type, &tid);
+		if (!t)
+			continue;
+		switch (BTF_INFO_KIND(t->info)) {
+		case BTF_KIND_PTR:
+			trace_seq_printf(s, "0x%lx", arg);
+			break;
+		case BTF_KIND_INT:
+			trace_seq_printf(s, "%ld", arg);

Don't we check the size and signed? :)

kernel/trace/trace_output.c int trace_print_lat_context(struct trace_iterator *iter) · line 724

Quoted 3 lines
kernel/trace/trace_output.c +3 -0
+			break;
+		case BTF_KIND_ENUM:
+			trace_seq_printf(s, "%ld", arg);

nit: %d? (enum is equal to the int type)

BTW, this series splits the patches by coding, not functionality. For the first review, it is OK. But eventually those should be merged.

Thank you,

Quoted 40 lines
kernel/trace/trace_output.c +15 -0
+			break;
+		default:
+			trace_seq_printf(s, "0x%lx (%d)", arg, BTF_INFO_KIND(param[i].type));
+			break;
+		}
+		if (i < nr - 1)
+			trace_seq_printf(s, ", ");
+	}
+out_put:
+	btf_put(btf);
+out:
+	trace_seq_printf(s, ")");
+}
+#endif
+
 /**
  * ftrace_find_event - find a registered event
  * @type: the type of event to look for
kernel/trace/trace_output.h +9 -0
index dca40f1f1da4..a21d8ce606f7 100644
@@ -41,5 +41,14 @@ extern struct rw_semaphore trace_event_sem;
 #define SEQ_PUT_HEX_FIELD(s, x)				\
 	trace_seq_putmem_hex(s, &(x), sizeof(x))
 
+#ifdef CONFIG_FUNCTION_TRACE_ARGS
+void print_function_args(struct trace_seq *s, struct ftrace_regs *fregs,
+			 unsigned long func);
+#else
+static inline void print_function_args(struct trace_seq *s, struct ftrace_regs *fregs,
+				       unsigned long func) {
+	trace_seq_puts(s, "()");
+}
+#endif
 #endif
 
Signature · 1 line
2.43.0
Signature · 1 line
Masami Hiramatsu (Google) <[email protected]>
#7 lore raw

Re: [PATCH 4/7] Add print_function_args()

In reply to Sven Schnelle
Quoted 46 lines · Sven Schnelle

Add a function to decode argument types with the help of BTF. Will be used to display arguments in the function and function graph tracer.

---
 kernel/trace/trace_output.c | 68 +++++++++++++++++++++++++++++++++++++
 kernel/trace/trace_output.h |  9 +++++
 2 files changed, 77 insertions(+)
kernel/trace/trace_output.c +18 -0
index d8b302d01083..70405c4cceb6 100644
@@ -12,8 +12,11 @@
 #include <linux/sched/clock.h>
 #include <linux/sched/mm.h>
 #include <linux/idr.h>
+#include <linux/btf.h>
+#include <linux/bpf.h>
 
 #include "trace_output.h"
+#include "trace_btf.h"
 
 /* must be a power of 2 */
 #define EVENT_HASHSIZE 128
@@ -669,6 +672,71 @@ int trace_print_lat_context(struct trace_iterator *iter)
        return !trace_seq_has_overflowed(s);
 }
 
+#ifdef CONFIG_FUNCTION_TRACE_ARGS
+void print_function_args(struct trace_seq *s, struct ftrace_regs *fregs,
+                        unsigned long func)
+{
+       const struct btf_param *param;
+       const struct btf_type *t;
+       const char *param_name;
+       char name[KSYM_NAME_LEN];
+       unsigned long arg;
+       struct btf *btf;
+       s32 tid, nr = 0;
+       int i;
+
+       trace_seq_printf(s, "(");
+

kernel/trace/trace_output.c int trace_print_lat_context(struct trace_iterator *iter) · line 699

Quoted 10 lines
kernel/trace/trace_output.c +10 -0
+       if (!ftrace_regs_has_args(fregs))
+               goto out;
+       if (lookup_symbol_name(func, name))
+               goto out;
+
+       btf = bpf_get_btf_vmlinux();
+       if (IS_ERR_OR_NULL(btf))
+               goto out;
+
+       t = btf_find_func_proto(name, &btf);

This is an excellent feature, and I am crafting a series of patches aimed
at enhancing the search performance for locating the btf by its name.

Quoted 66 lines
kernel/trace/trace_output.c +40 -0
+       if (IS_ERR_OR_NULL(t))
+               goto out;
+
+       param = btf_get_func_param(t, &nr);
+       if (!param)
+               goto out_put;
+
+       for (i = 0; i < nr; i++) {
+               arg = ftrace_regs_get_argument(fregs, i);
+
+               param_name = btf_name_by_offset(btf, param[i].name_off);
+               if (param_name)
+                       trace_seq_printf(s, "%s = ", param_name);
+               t = btf_type_skip_modifiers(btf, param[i].type, &tid);
+               if (!t)
+                       continue;
+               switch (BTF_INFO_KIND(t->info)) {
+               case BTF_KIND_PTR:
+                       trace_seq_printf(s, "0x%lx", arg);
+                       break;
+               case BTF_KIND_INT:
+                       trace_seq_printf(s, "%ld", arg);
+                       break;
+               case BTF_KIND_ENUM:
+                       trace_seq_printf(s, "%ld", arg);
+                       break;
+               default:
+                       trace_seq_printf(s, "0x%lx (%d)", arg, BTF_INFO_KIND(param[i].type));
+                       break;
+               }
+               if (i < nr - 1)
+                       trace_seq_printf(s, ", ");
+       }
+out_put:
+       btf_put(btf);
+out:
+       trace_seq_printf(s, ")");
+}
+#endif
+
 /**
  * ftrace_find_event - find a registered event
  * @type: the type of event to look for
kernel/trace/trace_output.h +9 -1
index dca40f1f1da4..a21d8ce606f7 100644
@@ -41,5 +41,14 @@ extern struct rw_semaphore trace_event_sem;
 #define SEQ_PUT_HEX_FIELD(s, x)                                \
        trace_seq_putmem_hex(s, &(x), sizeof(x))
 
+#ifdef CONFIG_FUNCTION_TRACE_ARGS
+void print_function_args(struct trace_seq *s, struct ftrace_regs *fregs,
+                        unsigned long func);
+#else
+static inline void print_function_args(struct trace_seq *s, struct ftrace_regs *fregs,
+                                      unsigned long func) {
+       trace_seq_puts(s, "()");
+}
+#endif
 #endif
 
--

2.43.0

author reviewer
#8 lore raw

PATCH 5/7 tracing: add config option for print arguments in ftrace

In reply to Sven Schnelle

Add a config option to disable/enable function argument printing support during runtime.

---
 kernel/trace/Kconfig | 12 ++++++++++++
 1 file changed, 12 insertions(+)
kernel/trace/Kconfig +12 -0
index 721c3b221048..8b9b6cdf39ac 100644
@@ -242,6 +242,18 @@ config FUNCTION_GRAPH_RETVAL
 	  enable it via the trace option funcgraph-retval.
 	  See Documentation/trace/ftrace.rst
 
+config FUNCTION_TRACE_ARGS
+	bool "Kernel Function Tracer Arguments"
+	depends on HAVE_FUNCTION_ARG_ACCESS_API
+	depends on DEBUG_INFO_BTF && BPF_SYSCALL
+	default n
+	help
+	  Support recording and printing of function arguments when using
+	  the function tracer or function graph tracer. This feature is off
+	  by default, and can be enabled via the trace option func-args (for
+	  the function tracer) and funcgraph-args (for the function graph
+	  tracer).
+
 config DYNAMIC_FTRACE
 	bool "enable/disable function tracing dynamically"
 	depends on FUNCTION_TRACER
Signature · 1 line
2.43.0
#9 lore raw

Re: [PATCH 5/7] tracing: add config option for print arguments in ftrace

Quoted 13 lines · Sven Schnelle

Add a config option to disable/enable function argument printing support during runtime.

---
  kernel/trace/Kconfig | 12 ++++++++++++
  1 file changed, 12 insertions(+)
kernel/trace/Kconfig +0 -0
index 721c3b221048..8b9b6cdf39ac 100644

kernel/trace/Kconfig config FUNCTION_GRAPH_RETVAL · line 248

Quoted 7 lines
kernel/trace/Kconfig +4 -0
@@ -242,6 +242,18 @@ config FUNCTION_GRAPH_RETVAL
  	  enable it via the trace option funcgraph-retval.
  	  See Documentation/trace/ftrace.rst
 
+config FUNCTION_TRACE_ARGS
+	bool "Kernel Function Tracer Arguments"
+	depends on HAVE_FUNCTION_ARG_ACCESS_API
+	depends on DEBUG_INFO_BTF && BPF_SYSCALL

Nice feature!

Just a nit, DEBUG_INFO_BTF currently depends on BPF_SYSCALL, so BPF_SYSCALL may not be necessary here. This feature also doesn't seem to depend on bpf.

Quoted 11 lines
kernel/trace/Kconfig +8 -0
+	default n
+	help
+	  Support recording and printing of function arguments when using
+	  the function tracer or function graph tracer. This feature is off
+	  by default, and can be enabled via the trace option func-args (for
+	  the function tracer) and funcgraph-args (for the function graph
+	  tracer).
+
  config DYNAMIC_FTRACE
  	bool "enable/disable function tracing dynamically"
  	depends on FUNCTION_TRACER
Signature · 2 lines
Thanks,
Zheng Yejian
#10 lore raw

Re: [PATCH 5/7] tracing: add config option for print arguments in ftrace

Quoted 24 lines · On Fri, 6 Sep 2024 11:36:11 +0800 Zheng Yejian <[email protected]>…
Quoted 13 lines · Sven Schnelle

Add a config option to disable/enable function argument printing support during runtime.

---
  kernel/trace/Kconfig | 12 ++++++++++++
  1 file changed, 12 insertions(+)
kernel/trace/Kconfig +0 -0
index 721c3b221048..8b9b6cdf39ac 100644

kernel/trace/Kconfig config FUNCTION_GRAPH_RETVAL · line 248

Quoted 7 lines
kernel/trace/Kconfig +4 -0
@@ -242,6 +242,18 @@ config FUNCTION_GRAPH_RETVAL
  	  enable it via the trace option funcgraph-retval.
  	  See Documentation/trace/ftrace.rst
 
+config FUNCTION_TRACE_ARGS
+	bool "Kernel Function Tracer Arguments"
+	depends on HAVE_FUNCTION_ARG_ACCESS_API
+	depends on DEBUG_INFO_BTF && BPF_SYSCALL

Nice feature!

Quoted 3 lines

Just a nit, DEBUG_INFO_BTF currently depends on BPF_SYSCALL, so BPF_SYSCALL may not be necessary here. This feature also doesn't seem to depend on bpf.

Indeed. Sven, you can check the PROBE_EVENTS_BTF_ARGS as an example.

config PROBE_EVENTS_BTF_ARGS
depends on HAVE_FUNCTION_ARG_ACCESS_API depends on FPROBE_EVENTS || KPROBE_EVENTS depends on DEBUG_INFO_BTF && BPF_SYSCALL bool "Support BTF function arguments for probe events"

Thank you,

Quoted 18 lines
Quoted 12 lines
kernel/trace/Kconfig +8 -0
+	default n
+	help
+	  Support recording and printing of function arguments when using
+	  the function tracer or function graph tracer. This feature is off
+	  by default, and can be enabled via the trace option func-args (for
+	  the function tracer) and funcgraph-args (for the function graph
+	  tracer).
+
  config DYNAMIC_FTRACE
  	bool "enable/disable function tracing dynamically"
  	depends on FUNCTION_TRACER
Signature · 2 lines
Thanks,
Zheng Yejian
Signature · 1 line
Masami Hiramatsu (Google) <[email protected]>
author reviewer
#11 lore raw

Re: [PATCH 5/7] tracing: add config option for print arguments in ftrace

Quoted 31 lines · Masami Hiramatsu (Google)
Quoted 24 lines · On Fri, 6 Sep 2024 11:36:11 +0800 Zheng Yejian <[email protected]>…
Quoted 13 lines · Sven Schnelle

Add a config option to disable/enable function argument printing support during runtime.

---
  kernel/trace/Kconfig | 12 ++++++++++++
  1 file changed, 12 insertions(+)
kernel/trace/Kconfig +0 -0
index 721c3b221048..8b9b6cdf39ac 100644

kernel/trace/Kconfig config FUNCTION_GRAPH_RETVAL · line 248

Quoted 7 lines
kernel/trace/Kconfig +4 -0
@@ -242,6 +242,18 @@ config FUNCTION_GRAPH_RETVAL
  	  enable it via the trace option funcgraph-retval.
  	  See Documentation/trace/ftrace.rst
 
+config FUNCTION_TRACE_ARGS
+	bool "Kernel Function Tracer Arguments"
+	depends on HAVE_FUNCTION_ARG_ACCESS_API
+	depends on DEBUG_INFO_BTF && BPF_SYSCALL

Nice feature!

Quoted 3 lines

Just a nit, DEBUG_INFO_BTF currently depends on BPF_SYSCALL, so BPF_SYSCALL may not be necessary here. This feature also doesn't seem to depend on bpf.

Quoted 8 lines

Indeed. Sven, you can check the PROBE_EVENTS_BTF_ARGS as an example.

config PROBE_EVENTS_BTF_ARGS
depends on HAVE_FUNCTION_ARG_ACCESS_API depends on FPROBE_EVENTS || KPROBE_EVENTS depends on DEBUG_INFO_BTF && BPF_SYSCALL bool "Support BTF function arguments for probe events"

Now i'm confused - Zheng wrote that DEBUG_INFO_BTF depends on BPF_SYSCALL. I just verified that. So i could just remove BPF_SYSCALL from the dependencies - but your example also has BPF_SYSCALL listed.

Regards
Sven

#12 lore raw

Re: [PATCH 5/7] tracing: add config option for print arguments in ftrace

Quoted 42 lines · On Mon, 09 Sep 2024 10:16:55 +0200 Sven Schnelle <[email protected]> wrote:
Quoted 31 lines · Masami Hiramatsu (Google)
Quoted 24 lines · On Fri, 6 Sep 2024 11:36:11 +0800 Zheng Yejian <[email protected]>…
Quoted 13 lines · Sven Schnelle

Add a config option to disable/enable function argument printing support during runtime.

---
  kernel/trace/Kconfig | 12 ++++++++++++
  1 file changed, 12 insertions(+)
kernel/trace/Kconfig +0 -0
index 721c3b221048..8b9b6cdf39ac 100644

kernel/trace/Kconfig config FUNCTION_GRAPH_RETVAL · line 248

Quoted 7 lines
kernel/trace/Kconfig +4 -0
@@ -242,6 +242,18 @@ config FUNCTION_GRAPH_RETVAL
  	  enable it via the trace option funcgraph-retval.
  	  See Documentation/trace/ftrace.rst
 
+config FUNCTION_TRACE_ARGS
+	bool "Kernel Function Tracer Arguments"
+	depends on HAVE_FUNCTION_ARG_ACCESS_API
+	depends on DEBUG_INFO_BTF && BPF_SYSCALL

Nice feature!

Quoted 3 lines

Just a nit, DEBUG_INFO_BTF currently depends on BPF_SYSCALL, so BPF_SYSCALL may not be necessary here. This feature also doesn't seem to depend on bpf.

Quoted 8 lines

Indeed. Sven, you can check the PROBE_EVENTS_BTF_ARGS as an example.

config PROBE_EVENTS_BTF_ARGS
depends on HAVE_FUNCTION_ARG_ACCESS_API depends on FPROBE_EVENTS || KPROBE_EVENTS depends on DEBUG_INFO_BTF && BPF_SYSCALL bool "Support BTF function arguments for probe events"

Quoted 3 lines

Now i'm confused - Zheng wrote that DEBUG_INFO_BTF depends on BPF_SYSCALL. I just verified that. So i could just remove BPF_SYSCALL from the dependencies - but your example also has BPF_SYSCALL listed.

Ah, sorry for confusion. In this case, just need DEBUG_INFO_BTF. Hmm, I think I also need to remove BPF_SYSCALL.

Thanks,

Quoted 3 lines

Regards
Sven

Signature · 1 line
Masami Hiramatsu (Google) <[email protected]>
author reviewer
#13 lore raw

PATCH 6/7 tracing: add support for function argument to graph tracer

In reply to Sven Schnelle

Wire up the code to print function arguments in the function graph tracer. This functionality can be enabled/disabled during compile time by setting CONFIG_FUNCTION_TRACE_ARGS and during runtime with options/funcgraph-args.

Example usage:

6)              | dummy_xmit [dummy](skb = 0x8887c100, dev = 0x872ca000) {
6)              |   consume_skb(skb = 0x8887c100) {
6)              |     skb_release_head_state(skb = 0x8887c100) {
6)  0.178 us    |       sock_wfree(skb = 0x8887c100)
6)  0.627 us    |     }
---
 include/linux/ftrace.h               |  1 +
 kernel/trace/fgraph.c                |  6 ++-
 kernel/trace/trace_functions_graph.c | 74 ++++++++++++++--------------
 3 files changed, 44 insertions(+), 37 deletions(-)
include/linux/ftrace.h +1 -0
index 56d91041ecd2..5d0ff66f8a70 100644
@@ -1010,6 +1010,7 @@ static inline void ftrace_init(void) { }
  * to remove extra padding at the end.
  */
 struct ftrace_graph_ent {
+	struct ftrace_regs regs;
 	unsigned long func; /* Current function */
 	int depth;
 } __packed;
kernel/trace/fgraph.c +5 -1
index fa62ebfa0711..f4bb10c0aa52 100644
@@ -614,7 +614,7 @@ ftrace_push_return_trace(unsigned long ret, unsigned long func,
 /* If the caller does not use ftrace, call this function. */
 int function_graph_enter(unsigned long ret, unsigned long func,
 			 unsigned long frame_pointer, unsigned long *retp,
-			struct ftrace_regs *fregs)
+			 struct ftrace_regs *fregs)
 {
 	struct ftrace_graph_ent trace;
 	unsigned long bitmap = 0;
@@ -623,6 +623,10 @@ int function_graph_enter(unsigned long ret, unsigned long func,
 
 	trace.func = func;
 	trace.depth = ++current->curr_ret_depth;
+	if (IS_ENABLED(CONFIG_FUNCTION_TRACE_ARGS) && fregs)
+		trace.regs = *fregs;
+	else
+		memset(&trace.regs, 0, sizeof(struct ftrace_regs));
 
 	offset = ftrace_push_return_trace(ret, func, frame_pointer, retp, 0);
 	if (offset < 0)
kernel/trace/trace_functions_graph.c +38 -36

135 lines not on this page · raw message

Signature · 1 line
2.43.0
#14 lore raw

Re: [PATCH 6/7] tracing: add support for function argument to graph tracer

kernel test robot noticed the following build errors:

Hi Sven,

kernel test robot noticed the following build errors:

[auto build test ERROR on s390/features]
[also build test ERROR on tip/x86/core linus/master v6.11-rc6]
[cannot apply to rostedt-trace/for-next rostedt-trace/for-next-urgent next-20240904] [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/Sven-Schnelle/tracing-add-ftrace_regs-to-function_graph_enter/20240904-150232
base:   https://git.kernel.org/pub/scm/linux/kernel/git/s390/linux.git features
patch link:    https://lore.kernel.org/r/20240904065908.1009086-7-svens%40linux.ibm.com
patch subject: [PATCH 6/7] tracing: add support for function argument to graph tracer
config: openrisc-allnoconfig (https://download.01.org/0day-ci/archive/20240905/[email protected]/config)
compiler: or1k-linux-gcc (GCC) 14.1.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240905/[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 include/linux/perf_event.h:52,

                    from include/linux/trace_events.h:10,
                    from include/trace/syscall.h:7,
                    from include/linux/syscalls.h:93,
                    from kernel/time/time.c:33:
>> include/linux/ftrace.h:1013:28: error: field 'regs' has incomplete type
    1013 |         struct ftrace_regs regs;
         |                            ^~~~

--
In file included from include/linux/perf_event.h:52,
from include/linux/trace_events.h:10, from include/trace/syscall.h:7, from include/linux/syscalls.h:93, from kernel/time/hrtimer.c:30:

>> include/linux/ftrace.h:1013:28: error: field 'regs' has incomplete type
    1013 |         struct ftrace_regs regs;
         |                            ^~~~

kernel/time/hrtimer.c:121:35: warning: initialized field overwritten [-Woverride-init]
121 | [CLOCK_REALTIME] = HRTIMER_BASE_REALTIME,
| ^~~~~~~~~~~~~~~~~~~~~
kernel/time/hrtimer.c:121:35: note: (near initialization for 'hrtimer_clock_to_base_table[0]') kernel/time/hrtimer.c:122:35: warning: initialized field overwritten [-Woverride-init]
122 | [CLOCK_MONOTONIC] = HRTIMER_BASE_MONOTONIC,
| ^~~~~~~~~~~~~~~~~~~~~~
kernel/time/hrtimer.c:122:35: note: (near initialization for 'hrtimer_clock_to_base_table[1]') kernel/time/hrtimer.c:123:35: warning: initialized field overwritten [-Woverride-init]
123 | [CLOCK_BOOTTIME] = HRTIMER_BASE_BOOTTIME,
| ^~~~~~~~~~~~~~~~~~~~~
kernel/time/hrtimer.c:123:35: note: (near initialization for 'hrtimer_clock_to_base_table[7]') kernel/time/hrtimer.c:124:35: warning: initialized field overwritten [-Woverride-init]
124 | [CLOCK_TAI] = HRTIMER_BASE_TAI,
| ^~~~~~~~~~~~~~~~
kernel/time/hrtimer.c:124:35: note: (near initialization for 'hrtimer_clock_to_base_table[11]')

vim +/regs +1013 include/linux/ftrace.h

1006
1007 /*
1008 * Structure that defines an entry function trace.
1009 * It's already packed but the attribute "packed" is needed
1010 * to remove extra padding at the end.
1011 */
1012 struct ftrace_graph_ent {

> 1013		struct ftrace_regs regs;

1014 unsigned long func; /* Current function */
1015 int depth;
1016 } __packed;
1017

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#15 lore raw

Re: [PATCH 6/7] tracing: add support for function argument to graph tracer

In reply to Sven Schnelle
kernel test robot noticed the following build errors:

Hi Sven,

kernel test robot noticed the following build errors:

[auto build test ERROR on s390/features]
[also build test ERROR on tip/x86/core linus/master v6.11-rc6]
[cannot apply to rostedt-trace/for-next rostedt-trace/for-next-urgent next-20240904] [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/Sven-Schnelle/tracing-add-ftrace_regs-to-function_graph_enter/20240904-150232
base:   https://git.kernel.org/pub/scm/linux/kernel/git/s390/linux.git features
patch link:    https://lore.kernel.org/r/20240904065908.1009086-7-svens%40linux.ibm.com
patch subject: [PATCH 6/7] tracing: add support for function argument to graph tracer
config: um-allnoconfig (https://download.01.org/0day-ci/archive/20240905/[email protected]/config)
compiler: clang version 17.0.6 (https://github.com/llvm/llvm-project 6009708b4367171ccdbf4b5905cb6a803753fe18)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240905/[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/fork.c:34:
In file included from include/linux/mempolicy.h:15:
In file included from include/linux/pagemap.h:11:
In file included from include/linux/highmem.h:12:
In file included from include/linux/hardirq.h:11:
In file included from arch/um/include/asm/hardirq.h:5:
In file included from include/asm-generic/hardirq.h:17:
In file included from include/linux/irq.h:20:
In file included from include/linux/io.h:14:
In file included from arch/um/include/asm/io.h:24:
include/asm-generic/io.h:548:31: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]

     548 |         val = __raw_readb(PCI_IOBASE + addr);
         |                           ~~~~~~~~~~ ^
   include/asm-generic/io.h:561:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     561 |         val = __le16_to_cpu((__le16 __force)__raw_readw(PCI_IOBASE + addr));
         |                                                         ~~~~~~~~~~ ^
   include/uapi/linux/byteorder/little_endian.h:37:51: note: expanded from macro '__le16_to_cpu'
      37 | #define __le16_to_cpu(x) ((__force __u16)(__le16)(x))
         |                                                   ^
   In file included from kernel/fork.c:34:
   In file included from include/linux/mempolicy.h:15:
   In file included from include/linux/pagemap.h:11:
   In file included from include/linux/highmem.h:12:
   In file included from include/linux/hardirq.h:11:
   In file included from arch/um/include/asm/hardirq.h:5:
   In file included from include/asm-generic/hardirq.h:17:
   In file included from include/linux/irq.h:20:
   In file included from include/linux/io.h:14:
   In file included from arch/um/include/asm/io.h:24:
   include/asm-generic/io.h:574:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     574 |         val = __le32_to_cpu((__le32 __force)__raw_readl(PCI_IOBASE + addr));
         |                                                         ~~~~~~~~~~ ^
   include/uapi/linux/byteorder/little_endian.h:35:51: note: expanded from macro '__le32_to_cpu'
      35 | #define __le32_to_cpu(x) ((__force __u32)(__le32)(x))
         |                                                   ^
   In file included from kernel/fork.c:34:
   In file included from include/linux/mempolicy.h:15:
   In file included from include/linux/pagemap.h:11:
   In file included from include/linux/highmem.h:12:
   In file included from include/linux/hardirq.h:11:
   In file included from arch/um/include/asm/hardirq.h:5:
   In file included from include/asm-generic/hardirq.h:17:
   In file included from include/linux/irq.h:20:
   In file included from include/linux/io.h:14:
   In file included from arch/um/include/asm/io.h:24:
   include/asm-generic/io.h:585:33: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     585 |         __raw_writeb(value, PCI_IOBASE + addr);
         |                             ~~~~~~~~~~ ^
   include/asm-generic/io.h:595:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     595 |         __raw_writew((u16 __force)cpu_to_le16(value), PCI_IOBASE + addr);
         |                                                       ~~~~~~~~~~ ^
   include/asm-generic/io.h:605:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     605 |         __raw_writel((u32 __force)cpu_to_le32(value), PCI_IOBASE + addr);
         |                                                       ~~~~~~~~~~ ^
   include/asm-generic/io.h:693:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     693 |         readsb(PCI_IOBASE + addr, buffer, count);
         |                ~~~~~~~~~~ ^
   include/asm-generic/io.h:701:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     701 |         readsw(PCI_IOBASE + addr, buffer, count);
         |                ~~~~~~~~~~ ^
   include/asm-generic/io.h:709:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     709 |         readsl(PCI_IOBASE + addr, buffer, count);
         |                ~~~~~~~~~~ ^
   include/asm-generic/io.h:718:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     718 |         writesb(PCI_IOBASE + addr, buffer, count);
         |                 ~~~~~~~~~~ ^
   include/asm-generic/io.h:727:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     727 |         writesw(PCI_IOBASE + addr, buffer, count);
         |                 ~~~~~~~~~~ ^
   include/asm-generic/io.h:736:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     736 |         writesl(PCI_IOBASE + addr, buffer, count);
         |                 ~~~~~~~~~~ ^
   In file included from kernel/fork.c:56:
   In file included from include/linux/syscalls.h:93:
   In file included from include/trace/syscall.h:7:
   In file included from include/linux/trace_events.h:10:
   In file included from include/linux/perf_event.h:52:
>> include/linux/ftrace.h:1013:21: error: field has incomplete type 'struct ftrace_regs'
    1013 |         struct ftrace_regs regs;
         |                            ^
   include/linux/ftrace.h:41:8: note: forward declaration of 'struct ftrace_regs'
      41 | struct ftrace_regs;
         |        ^

12 warnings and 1 error generated.
--
In file included from kernel/signal.c:27:
In file included from include/linux/tty.h:11:
In file included from include/linux/tty_port.h:5:
In file included from include/linux/kfifo.h:40:
In file included from include/linux/dma-mapping.h:11:
In file included from include/linux/scatterlist.h:9:
In file included from arch/um/include/asm/io.h:24:
include/asm-generic/io.h:548:31: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]

     548 |         val = __raw_readb(PCI_IOBASE + addr);
         |                           ~~~~~~~~~~ ^
   include/asm-generic/io.h:561:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     561 |         val = __le16_to_cpu((__le16 __force)__raw_readw(PCI_IOBASE + addr));
         |                                                         ~~~~~~~~~~ ^
   include/uapi/linux/byteorder/little_endian.h:37:51: note: expanded from macro '__le16_to_cpu'
      37 | #define __le16_to_cpu(x) ((__force __u16)(__le16)(x))
         |                                                   ^
   In file included from kernel/signal.c:27:
   In file included from include/linux/tty.h:11:
   In file included from include/linux/tty_port.h:5:
   In file included from include/linux/kfifo.h:40:
   In file included from include/linux/dma-mapping.h:11:
   In file included from include/linux/scatterlist.h:9:
   In file included from arch/um/include/asm/io.h:24:
   include/asm-generic/io.h:574:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     574 |         val = __le32_to_cpu((__le32 __force)__raw_readl(PCI_IOBASE + addr));
         |                                                         ~~~~~~~~~~ ^
   include/uapi/linux/byteorder/little_endian.h:35:51: note: expanded from macro '__le32_to_cpu'
      35 | #define __le32_to_cpu(x) ((__force __u32)(__le32)(x))
         |                                                   ^
   In file included from kernel/signal.c:27:
   In file included from include/linux/tty.h:11:
   In file included from include/linux/tty_port.h:5:
   In file included from include/linux/kfifo.h:40:
   In file included from include/linux/dma-mapping.h:11:
   In file included from include/linux/scatterlist.h:9:
   In file included from arch/um/include/asm/io.h:24:
   include/asm-generic/io.h:585:33: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     585 |         __raw_writeb(value, PCI_IOBASE + addr);
         |                             ~~~~~~~~~~ ^
   include/asm-generic/io.h:595:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     595 |         __raw_writew((u16 __force)cpu_to_le16(value), PCI_IOBASE + addr);
         |                                                       ~~~~~~~~~~ ^
   include/asm-generic/io.h:605:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     605 |         __raw_writel((u32 __force)cpu_to_le32(value), PCI_IOBASE + addr);
         |                                                       ~~~~~~~~~~ ^
   include/asm-generic/io.h:693:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     693 |         readsb(PCI_IOBASE + addr, buffer, count);
         |                ~~~~~~~~~~ ^
   include/asm-generic/io.h:701:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     701 |         readsw(PCI_IOBASE + addr, buffer, count);
         |                ~~~~~~~~~~ ^
   include/asm-generic/io.h:709:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     709 |         readsl(PCI_IOBASE + addr, buffer, count);
         |                ~~~~~~~~~~ ^
   include/asm-generic/io.h:718:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     718 |         writesb(PCI_IOBASE + addr, buffer, count);
         |                 ~~~~~~~~~~ ^
   include/asm-generic/io.h:727:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     727 |         writesw(PCI_IOBASE + addr, buffer, count);
         |                 ~~~~~~~~~~ ^
   include/asm-generic/io.h:736:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     736 |         writesl(PCI_IOBASE + addr, buffer, count);
         |                 ~~~~~~~~~~ ^
   In file included from kernel/signal.c:31:
   In file included from include/linux/syscalls.h:93:
   In file included from include/trace/syscall.h:7:
   In file included from include/linux/trace_events.h:10:
   In file included from include/linux/perf_event.h:52:
>> include/linux/ftrace.h:1013:21: error: field has incomplete type 'struct ftrace_regs'
    1013 |         struct ftrace_regs regs;
         |                            ^
   include/linux/ftrace.h:41:8: note: forward declaration of 'struct ftrace_regs'
      41 | struct ftrace_regs;
         |        ^
   kernel/signal.c:140:37: warning: array index 3 is past the end of the array (that has type 'unsigned long[2]') [-Warray-bounds]
     140 |         case 4: ready  = signal->sig[3] &~ blocked->sig[3];
         |                                            ^            ~
   arch/x86/include/asm/signal.h:24:2: note: array 'sig' declared here
      24 |         unsigned long sig[_NSIG_WORDS];
         |         ^
   kernel/signal.c:140:19: warning: array index 3 is past the end of the array (that has type 'unsigned long[2]') [-Warray-bounds]
     140 |         case 4: ready  = signal->sig[3] &~ blocked->sig[3];
         |                          ^           ~
   arch/x86/include/asm/signal.h:24:2: note: array 'sig' declared here
      24 |         unsigned long sig[_NSIG_WORDS];
         |         ^
   kernel/signal.c:141:30: warning: array index 2 is past the end of the array (that has type 'unsigned long[2]') [-Warray-bounds]
     141 |                 ready |= signal->sig[2] &~ blocked->sig[2];
         |                                            ^            ~
   arch/x86/include/asm/signal.h:24:2: note: array 'sig' declared here
      24 |         unsigned long sig[_NSIG_WORDS];
         |         ^
   kernel/signal.c:141:12: warning: array index 2 is past the end of the array (that has type 'unsigned long[2]') [-Warray-bounds]
     141 |                 ready |= signal->sig[2] &~ blocked->sig[2];
         |                          ^           ~
   arch/x86/include/asm/signal.h:24:2: note: array 'sig' declared here
      24 |         unsigned long sig[_NSIG_WORDS];
         |         ^

16 warnings and 1 error generated.
--
In file included from kernel/time/hrtimer.c:30:
In file included from include/linux/syscalls.h:93:
In file included from include/trace/syscall.h:7:
In file included from include/linux/trace_events.h:9:
In file included from include/linux/hardirq.h:11:
In file included from arch/um/include/asm/hardirq.h:5:
In file included from include/asm-generic/hardirq.h:17:
In file included from include/linux/irq.h:20:
In file included from include/linux/io.h:14:
In file included from arch/um/include/asm/io.h:24:
include/asm-generic/io.h:548:31: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]

     548 |         val = __raw_readb(PCI_IOBASE + addr);
         |                           ~~~~~~~~~~ ^
   include/asm-generic/io.h:561:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     561 |         val = __le16_to_cpu((__le16 __force)__raw_readw(PCI_IOBASE + addr));
         |                                                         ~~~~~~~~~~ ^
   include/uapi/linux/byteorder/little_endian.h:37:51: note: expanded from macro '__le16_to_cpu'
      37 | #define __le16_to_cpu(x) ((__force __u16)(__le16)(x))
         |                                                   ^
   In file included from kernel/time/hrtimer.c:30:
   In file included from include/linux/syscalls.h:93:
   In file included from include/trace/syscall.h:7:
   In file included from include/linux/trace_events.h:9:
   In file included from include/linux/hardirq.h:11:
   In file included from arch/um/include/asm/hardirq.h:5:
   In file included from include/asm-generic/hardirq.h:17:
   In file included from include/linux/irq.h:20:
   In file included from include/linux/io.h:14:
   In file included from arch/um/include/asm/io.h:24:
   include/asm-generic/io.h:574:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     574 |         val = __le32_to_cpu((__le32 __force)__raw_readl(PCI_IOBASE + addr));
         |                                                         ~~~~~~~~~~ ^
   include/uapi/linux/byteorder/little_endian.h:35:51: note: expanded from macro '__le32_to_cpu'
      35 | #define __le32_to_cpu(x) ((__force __u32)(__le32)(x))
         |                                                   ^
   In file included from kernel/time/hrtimer.c:30:
   In file included from include/linux/syscalls.h:93:
   In file included from include/trace/syscall.h:7:
   In file included from include/linux/trace_events.h:9:
   In file included from include/linux/hardirq.h:11:
   In file included from arch/um/include/asm/hardirq.h:5:
   In file included from include/asm-generic/hardirq.h:17:
   In file included from include/linux/irq.h:20:
   In file included from include/linux/io.h:14:
   In file included from arch/um/include/asm/io.h:24:
   include/asm-generic/io.h:585:33: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     585 |         __raw_writeb(value, PCI_IOBASE + addr);
         |                             ~~~~~~~~~~ ^
   include/asm-generic/io.h:595:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     595 |         __raw_writew((u16 __force)cpu_to_le16(value), PCI_IOBASE + addr);
         |                                                       ~~~~~~~~~~ ^
   include/asm-generic/io.h:605:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     605 |         __raw_writel((u32 __force)cpu_to_le32(value), PCI_IOBASE + addr);
         |                                                       ~~~~~~~~~~ ^
   include/asm-generic/io.h:693:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     693 |         readsb(PCI_IOBASE + addr, buffer, count);
         |                ~~~~~~~~~~ ^
   include/asm-generic/io.h:701:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     701 |         readsw(PCI_IOBASE + addr, buffer, count);
         |                ~~~~~~~~~~ ^
   include/asm-generic/io.h:709:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     709 |         readsl(PCI_IOBASE + addr, buffer, count);
         |                ~~~~~~~~~~ ^
   include/asm-generic/io.h:718:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     718 |         writesb(PCI_IOBASE + addr, buffer, count);
         |                 ~~~~~~~~~~ ^
   include/asm-generic/io.h:727:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     727 |         writesw(PCI_IOBASE + addr, buffer, count);
         |                 ~~~~~~~~~~ ^
   include/asm-generic/io.h:736:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     736 |         writesl(PCI_IOBASE + addr, buffer, count);
         |                 ~~~~~~~~~~ ^
   In file included from kernel/time/hrtimer.c:30:
   In file included from include/linux/syscalls.h:93:
   In file included from include/trace/syscall.h:7:
   In file included from include/linux/trace_events.h:10:
   In file included from include/linux/perf_event.h:52:
>> include/linux/ftrace.h:1013:21: error: field has incomplete type 'struct ftrace_regs'
    1013 |         struct ftrace_regs regs;
         |                            ^
   include/linux/ftrace.h:41:8: note: forward declaration of 'struct ftrace_regs'
      41 | struct ftrace_regs;
         |        ^
   kernel/time/hrtimer.c:121:21: warning: initializer overrides prior initialization of this subobject [-Winitializer-overrides]
     121 |         [CLOCK_REALTIME]        = HRTIMER_BASE_REALTIME,
         |                                   ^~~~~~~~~~~~~~~~~~~~~
   kernel/time/hrtimer.c:119:27: note: previous initialization is here
     119 |         [0 ... MAX_CLOCKS - 1]  = HRTIMER_MAX_CLOCK_BASES,
         |                                   ^~~~~~~~~~~~~~~~~~~~~~~
   kernel/time/hrtimer.c:122:22: warning: initializer overrides prior initialization of this subobject [-Winitializer-overrides]
     122 |         [CLOCK_MONOTONIC]       = HRTIMER_BASE_MONOTONIC,
         |                                   ^~~~~~~~~~~~~~~~~~~~~~
   kernel/time/hrtimer.c:119:27: note: previous initialization is here
     119 |         [0 ... MAX_CLOCKS - 1]  = HRTIMER_MAX_CLOCK_BASES,
         |                                   ^~~~~~~~~~~~~~~~~~~~~~~
   kernel/time/hrtimer.c:123:21: warning: initializer overrides prior initialization of this subobject [-Winitializer-overrides]
     123 |         [CLOCK_BOOTTIME]        = HRTIMER_BASE_BOOTTIME,
         |                                   ^~~~~~~~~~~~~~~~~~~~~
   kernel/time/hrtimer.c:119:27: note: previous initialization is here
     119 |         [0 ... MAX_CLOCKS - 1]  = HRTIMER_MAX_CLOCK_BASES,
         |                                   ^~~~~~~~~~~~~~~~~~~~~~~
   kernel/time/hrtimer.c:124:17: warning: initializer overrides prior initialization of this subobject [-Winitializer-overrides]
     124 |         [CLOCK_TAI]             = HRTIMER_BASE_TAI,
         |                                   ^~~~~~~~~~~~~~~~
   kernel/time/hrtimer.c:119:27: note: previous initialization is here
     119 |         [0 ... MAX_CLOCKS - 1]  = HRTIMER_MAX_CLOCK_BASES,
         |                                   ^~~~~~~~~~~~~~~~~~~~~~~

16 warnings and 1 error generated.

vim +1013 include/linux/ftrace.h

1006
1007 /*
1008 * Structure that defines an entry function trace.
1009 * It's already packed but the attribute "packed" is needed
1010 * to remove extra padding at the end.
1011 */
1012 struct ftrace_graph_ent {

> 1013		struct ftrace_regs regs;

1014 unsigned long func; /* Current function */
1015 int depth;
1016 } __packed;
1017

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
maintainer
#16 lore raw

Re: [PATCH 6/7] tracing: add support for function argument to graph tracer

In reply to Sven Schnelle
Quoted 4 lines · On Wed, 4 Sep 2024 08:59:00 +0200 Sven Schnelle <[email protected]> wrote:

Wire up the code to print function arguments in the function graph tracer. This functionality can be enabled/disabled during compile time by setting CONFIG_FUNCTION_TRACE_ARGS and during runtime with options/funcgraph-args.

I finally got around to looking at your patches. Do you plan on still working on them? I really like this feature, and I'm willing to do the work too if you have other things on your plate.

Quoted 9 lines

Example usage:

6)              | dummy_xmit [dummy](skb = 0x8887c100, dev = 0x872ca000) {
6)              |   consume_skb(skb = 0x8887c100) {
6)              |     skb_release_head_state(skb = 0x8887c100) {
6)  0.178 us    |       sock_wfree(skb = 0x8887c100)
6)  0.627 us    |     }
Quoted 6 lines
---
 include/linux/ftrace.h               |  1 +
 kernel/trace/fgraph.c                |  6 ++-
 kernel/trace/trace_functions_graph.c | 74 ++++++++++++++--------------
 3 files changed, 44 insertions(+), 37 deletions(-)

BTW, this is missing:

kernel/trace/trace.h +1 -0
index 2f8017f8d34d..8a218b39d11d 100644
@@ -879,6 +879,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_ARGS		0x2000
 #define TRACE_GRAPH_PRINT_FILL_SHIFT	28
 #define TRACE_GRAPH_PRINT_FILL_MASK	(0x3 << TRACE_GRAPH_PRINT_FILL_SHIFT)
 

that you added in patch 7, but is needed for this patch, where it does not build without it.

include/linux/ftrace.h static inline void ftrace_init(void) { } · line 1016

Quoted 13 lines
include/linux/ftrace.h +1 -0
index 56d91041ecd2..5d0ff66f8a70 100644
@@ -1010,6 +1010,7 @@ static inline void ftrace_init(void) { }
  * to remove extra padding at the end.
  */
 struct ftrace_graph_ent {
+	struct ftrace_regs regs;
 	unsigned long func; /* Current function */
 	int depth;
 } __packed;

This should have a different event type, to not waste the ring buffer when not needed.

struct ftrace_graph_ent_args {
	struct ftrace_regs_args fargs;
	unsigned long func; /* Current function */
	int depth;
} __packed;

But also, we need to create a new structure, as nothing should depend on the size of ftrace_regs (we plan on hiding that completely). I can add a "struct ftrace_regs_args" that will hold just the args for each arch. Especially for archs (like x86) where ftrace_regs can be pt_regs in size, where most of the space is just wasted. Then we can do a:

	ftrace_regs_copy_args(fregs, &entry->addr);

And then:

	char buf[ftrace_regs_size()];
	struct ftrace_regs *fregs = &buf;

	ftrace_regs_from_args(fregs, &entry->addr);

to get the arguments.

Quoted 91 lines
kernel/trace/fgraph.c +5 -1
index fa62ebfa0711..f4bb10c0aa52 100644
@@ -614,7 +614,7 @@ ftrace_push_return_trace(unsigned long ret, unsigned long func,
 /* If the caller does not use ftrace, call this function. */
 int function_graph_enter(unsigned long ret, unsigned long func,
 			 unsigned long frame_pointer, unsigned long *retp,
-			struct ftrace_regs *fregs)
+			 struct ftrace_regs *fregs)
 {
 	struct ftrace_graph_ent trace;
 	unsigned long bitmap = 0;
@@ -623,6 +623,10 @@ int function_graph_enter(unsigned long ret, unsigned long func,
 
 	trace.func = func;
 	trace.depth = ++current->curr_ret_depth;
+	if (IS_ENABLED(CONFIG_FUNCTION_TRACE_ARGS) && fregs)
+		trace.regs = *fregs;
+	else
+		memset(&trace.regs, 0, sizeof(struct ftrace_regs));
 
 	offset = ftrace_push_return_trace(ret, func, frame_pointer, retp, 0);
 	if (offset < 0)
kernel/trace/trace_functions_graph.c +11 -17
index 13d0387ac6a6..be0cee52944a 100644
@@ -12,6 +12,8 @@
 #include <linux/interrupt.h>
 #include <linux/slab.h>
 #include <linux/fs.h>
+#include <linux/btf.h>
+#include <linux/bpf.h>
 
 #include "trace.h"
 #include "trace_output.h"
@@ -63,6 +65,9 @@ static struct tracer_opt trace_opts[] = {
 	{ TRACER_OPT(funcgraph-retval, TRACE_GRAPH_PRINT_RETVAL) },
 	/* Display function return value in hexadecimal format ? */
 	{ TRACER_OPT(funcgraph-retval-hex, TRACE_GRAPH_PRINT_RETVAL_HEX) },
+#endif
+#ifdef CONFIG_FUNCTION_TRACE_ARGS
+	{ TRACER_OPT(funcgraph-args, TRACE_GRAPH_ARGS) },
 #endif
 	/* Include sleep time (scheduled out) between entry and return */
 	{ TRACER_OPT(sleep-time, TRACE_GRAPH_SLEEP_TIME) },
@@ -653,7 +658,7 @@ print_graph_duration(struct trace_array *tr, unsigned long long duration,
 #define __TRACE_GRAPH_PRINT_RETVAL TRACE_GRAPH_PRINT_RETVAL
 
 static void print_graph_retval(struct trace_seq *s, unsigned long retval,
-				bool leaf, void *func, bool hex_format)
+			       bool hex_format)
 {
 	unsigned long err_code = 0;
 
@@ -673,28 +678,17 @@ static void print_graph_retval(struct trace_seq *s, unsigned long retval,
 		err_code = 0;
 
 done:
-	if (leaf) {
-		if (hex_format || (err_code == 0))
-			trace_seq_printf(s, "%ps(); /* = 0x%lx */\n",
-					func, retval);
-		else
-			trace_seq_printf(s, "%ps(); /* = %ld */\n",
-					func, err_code);
-	} else {
-		if (hex_format || (err_code == 0))
-			trace_seq_printf(s, "} /* %ps = 0x%lx */\n",
-					func, retval);
-		else
-			trace_seq_printf(s, "} /* %ps = %ld */\n",
-					func, err_code);
-	}
+	if (hex_format || (err_code == 0))
+		trace_seq_printf(s, " /* = 0x%lx */", retval);
+	else
+		trace_seq_printf(s, " /* = %ld */", err_code);
 }
 
 #else
 
 #define __TRACE_GRAPH_PRINT_RETVAL 0
 
-#define print_graph_retval(_seq, _retval, _leaf, _func, _format) do {} while (0)
+#define print_graph_retval(_seq, _retval, _format) do {} while (0)
 
 #endif
 

kernel/trace/trace_functions_graph.c print_graph_entry_leaf(struct trace_iterator *iter, · line 740

Quoted 6 lines
kernel/trace/trace_functions_graph.c +3 -0
@@ -741,16 +735,20 @@ print_graph_entry_leaf(struct trace_iterator *iter,
 	/* Function */
 	for (i = 0; i < call->depth * TRACE_GRAPH_INDENT; i++)
 		trace_seq_putc(s, ' ');
+	trace_seq_printf(s, "%ps", (void *)graph_ret->func);
+	if (flags & TRACE_GRAPH_ARGS)
+		print_function_args(s, &call->regs, graph_ret->func);

Ideally, the flag is going to be set when args is recorded and not used for printing. If the event is the ftrace_ent_args() this will print the arguments, otherwise it does not.

To simplify these functions, we probably need to have a:

union fgraph_entry {
	struct ftrace_graph_ent		*normal;
	struct ftrace_graph_ent_args	*args;
};

And switch depending which is which (the header of both is the same as is for all entries).

-- Steve

Quoted 73 lines
kernel/trace/trace_functions_graph.c +24 -19
+	else
+		trace_seq_puts(s, "();");
 
 	/*
 	 * Write out the function return value if the option function-retval is
 	 * enabled.
 	 */
 	if (flags & __TRACE_GRAPH_PRINT_RETVAL)
-		print_graph_retval(s, graph_ret->retval, true, (void *)call->func,
-				!!(flags & TRACE_GRAPH_PRINT_RETVAL_HEX));
-	else
-		trace_seq_printf(s, "%ps();\n", (void *)call->func);
+		print_graph_retval(s, graph_ret->retval,
+				   !!(flags & TRACE_GRAPH_PRINT_RETVAL_HEX));
+	trace_seq_printf(s, "\n");
 
 	print_graph_irq(iter, graph_ret->func, TRACE_GRAPH_RET,
 			cpu, iter->ent->pid, flags);
@@ -788,7 +786,12 @@ print_graph_entry_nested(struct trace_iterator *iter,
 	for (i = 0; i < call->depth * TRACE_GRAPH_INDENT; i++)
 		trace_seq_putc(s, ' ');
 
-	trace_seq_printf(s, "%ps() {\n", (void *)call->func);
+	trace_seq_printf(s, "%ps", (void *)call->func);
+	if (flags & TRACE_GRAPH_ARGS)
+		print_function_args(s, &call->regs, call->func);
+	else
+		trace_seq_puts(s, "()");
+	trace_seq_printf(s, " {\n");
 
 	if (trace_seq_has_overflowed(s))
 		return TRACE_TYPE_PARTIAL_LINE;
@@ -1028,27 +1031,26 @@ print_graph_return(struct ftrace_graph_ret *trace, struct trace_seq *s,
 	for (i = 0; i < trace->depth * TRACE_GRAPH_INDENT; i++)
 		trace_seq_putc(s, ' ');
 
+	/*
+	 * If the return function does not have a matching entry,
+	 * then the entry was lost. Instead of just printing
+	 * the '}' and letting the user guess what function this
+	 * belongs to, write out the function name. Always do
+	 * that if the funcgraph-tail option is enabled.
+	 */
+	if (func_match && !(flags & TRACE_GRAPH_PRINT_TAIL))
+		trace_seq_puts(s, "}");
+	else
+		trace_seq_printf(s, "} /* %ps */", (void *)trace->func);
 	/*
 	 * Always write out the function name and its return value if the
 	 * function-retval option is enabled.
 	 */
 	if (flags & __TRACE_GRAPH_PRINT_RETVAL) {
-		print_graph_retval(s, trace->retval, false, (void *)trace->func,
+		print_graph_retval(s, trace->retval,
 			!!(flags & TRACE_GRAPH_PRINT_RETVAL_HEX));
-	} else {
-		/*
-		 * If the return function does not have a matching entry,
-		 * then the entry was lost. Instead of just printing
-		 * the '}' and letting the user guess what function this
-		 * belongs to, write out the function name. Always do
-		 * that if the funcgraph-tail option is enabled.
-		 */
-		if (func_match && !(flags & TRACE_GRAPH_PRINT_TAIL))
-			trace_seq_puts(s, "}\n");
-		else
-			trace_seq_printf(s, "} /* %ps */\n", (void *)trace->func);
 	}
-
+	trace_seq_printf(s, "\n");
 	/* Overrun */
 	if (flags & TRACE_GRAPH_PRINT_OVERRUN)
 		trace_seq_printf(s, " (Overruns: %u)\n",
author reviewer
#17 lore raw

Re: [PATCH 6/7] tracing: add support for function argument to graph tracer

Quoted 11 lines · Steven Rostedt
Quoted 4 lines · On Wed, 4 Sep 2024 08:59:00 +0200 Sven Schnelle <[email protected]> wrote:

Wire up the code to print function arguments in the function graph tracer. This functionality can be enabled/disabled during compile time by setting CONFIG_FUNCTION_TRACE_ARGS and during runtime with options/funcgraph-args.

I finally got around to looking at your patches. Do you plan on still working on them? I really like this feature, and I'm willing to do the work too if you have other things on your plate.

Yes, working on other things, so feel free to take over.

author reviewer
#18 lore raw

PATCH 7/7 tracing: add arguments to function tracer

In reply to Sven Schnelle

Wire up the code to print function arguments in the function tracer. This functionality can be enabled/disabled during compile time by setting CONFIG_FUNCTION_TRACE_ARGS and during runtime with options/func-args.

        ping-689     [004] b....    77.170220: dummy_xmit(skb = 0x82904800, dev = 0x882d0000) <-dev_hard_start_xmit
---
 kernel/trace/trace.c              |  8 +++++-
 kernel/trace/trace.h              |  4 ++-
 kernel/trace/trace_entries.h      |  7 +++--
 kernel/trace/trace_functions.c    | 46 +++++++++++++++++++++++++++----
 kernel/trace/trace_irqsoff.c      |  4 +--
 kernel/trace/trace_output.c       | 14 ++++++++--
 kernel/trace/trace_sched_wakeup.c |  4 +--
 7 files changed, 71 insertions(+), 16 deletions(-)
kernel/trace/trace.c +7 -1
index ebe7ce2f5f4a..8118e4c8c649 100644
@@ -2864,7 +2864,7 @@ trace_buffer_unlock_commit_nostack(struct trace_buffer *buffer,
 
 void
 trace_function(struct trace_array *tr, unsigned long ip, unsigned long
-	       parent_ip, unsigned int trace_ctx)
+	       parent_ip, unsigned int trace_ctx, struct ftrace_regs *regs)
 {
 	struct trace_event_call *call = &event_function;
 	struct trace_buffer *buffer = tr->array_buffer.buffer;
@@ -2878,6 +2878,12 @@ trace_function(struct trace_array *tr, unsigned long ip, unsigned long
 	entry	= ring_buffer_event_data(event);
 	entry->ip			= ip;
 	entry->parent_ip		= parent_ip;
+#ifdef CONFIG_FUNCTION_TRACE_ARGS
+	if (regs)
+		entry->regs		= *regs;
+	else
+		memset(&entry->regs, 0, sizeof(struct ftrace_regs));
+#endif
 
 	if (!call_filter_check_discard(call, entry, buffer, event)) {
 		if (static_branch_unlikely(&trace_function_exports_enabled))
kernel/trace/trace.h +3 -1
index bd3e3069300e..13cf6f97f7e0 100644
@@ -673,7 +673,8 @@ unsigned long trace_total_entries(struct trace_array *tr);
 void trace_function(struct trace_array *tr,
 		    unsigned long ip,
 		    unsigned long parent_ip,
-		    unsigned int trace_ctx);
+		    unsigned int trace_ctx,
+		    struct ftrace_regs *regs);
 void trace_graph_function(struct trace_array *tr,
 		    unsigned long ip,
 		    unsigned long parent_ip,
@@ -870,6 +871,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_ARGS		0x2000
 #define TRACE_GRAPH_PRINT_FILL_SHIFT	28
 #define TRACE_GRAPH_PRINT_FILL_MASK	(0x3 << TRACE_GRAPH_PRINT_FILL_SHIFT)
 
kernel/trace/trace_entries.h +5 -2
index c47422b20908..f2021ab52da2 100644
@@ -61,8 +61,11 @@ FTRACE_ENTRY_REG(function, ftrace_entry,
 	TRACE_FN,
 
 	F_STRUCT(
-		__field_fn(	unsigned long,	ip		)
-		__field_fn(	unsigned long,	parent_ip	)
+		__field_fn(	unsigned long,		ip		)
+		__field_fn(	unsigned long,		parent_ip	)
+#ifdef CONFIG_FUNCTION_TRACE_ARGS
+		__field_struct( struct ftrace_regs,	regs		)
+#endif
 	),
 
 	F_printk(" %ps <-- %ps",
kernel/trace/trace_functions.c +41 -5

96 lines not on this page · raw message

kernel/trace/trace_irqsoff.c +2 -2
index fce064e20570..096002c99d70 100644
@@ -150,7 +150,7 @@ irqsoff_tracer_call(unsigned long ip, unsigned long parent_ip,
 
 	trace_ctx = tracing_gen_ctx_flags(flags);
 
-	trace_function(tr, ip, parent_ip, trace_ctx);
+	trace_function(tr, ip, parent_ip, trace_ctx, fregs);
 
 	atomic_dec(&data->disabled);
 }
@@ -278,7 +278,7 @@ __trace_function(struct trace_array *tr,
 	if (is_graph(tr))
 		trace_graph_function(tr, ip, parent_ip, trace_ctx);
 	else
-		trace_function(tr, ip, parent_ip, trace_ctx);
+		trace_function(tr, ip, parent_ip, trace_ctx, NULL);
 }
 
 #else
kernel/trace/trace_output.c +11 -3
index 70405c4cceb6..8fdee7b9cdba 100644
@@ -1058,9 +1058,13 @@ enum print_line_t trace_nop_print(struct trace_iterator *iter, int flags,
 }
 
 static void print_fn_trace(struct trace_seq *s, unsigned long ip,
-			   unsigned long parent_ip, int flags)
+			   unsigned long parent_ip,
+			   struct ftrace_regs *fregs,
+			   int flags)
 {
 	seq_print_ip_sym(s, ip, flags);
+	if (fregs)
+		print_function_args(s, fregs, ip);
 
 	if ((flags & TRACE_ITER_PRINT_PARENT) && parent_ip) {
 		trace_seq_puts(s, " <-");
@@ -1074,10 +1078,14 @@ static enum print_line_t trace_fn_trace(struct trace_iterator *iter, int flags,
 {
 	struct ftrace_entry *field;
 	struct trace_seq *s = &iter->seq;
+	struct ftrace_regs *fregs = NULL;
 
 	trace_assign_type(field, iter->ent);
 
-	print_fn_trace(s, field->ip, field->parent_ip, flags);
+#if IS_ENABLED(CONFIG_FUNCTION_TRACE_ARGS)
+	fregs = &field->regs;
+#endif
+	print_fn_trace(s, field->ip, field->parent_ip, fregs, flags);
 	trace_seq_putc(s, '\n');
 
 	return trace_handle_return(s);
@@ -1742,7 +1750,7 @@ trace_func_repeats_print(struct trace_iterator *iter, int flags,
 
 	trace_assign_type(field, iter->ent);
 
-	print_fn_trace(s, field->ip, field->parent_ip, flags);
+	print_fn_trace(s, field->ip, field->parent_ip, NULL, flags);
 	trace_seq_printf(s, " (repeats: %u, last_ts:", field->count);
 	trace_print_time(s, iter,
 			 iter->ts - FUNC_REPEATS_GET_DELTA_TS(field));
kernel/trace/trace_sched_wakeup.c +2 -2
index 130ca7e7787e..39043c955761 100644
@@ -224,7 +224,7 @@ wakeup_tracer_call(unsigned long ip, unsigned long parent_ip,
 		return;
 
 	local_irq_save(flags);
-	trace_function(tr, ip, parent_ip, trace_ctx);
+	trace_function(tr, ip, parent_ip, trace_ctx, fregs);
 	local_irq_restore(flags);
 
 	atomic_dec(&data->disabled);
@@ -309,7 +309,7 @@ __trace_function(struct trace_array *tr,
 	if (is_graph(tr))
 		trace_graph_function(tr, ip, parent_ip, trace_ctx);
 	else
-		trace_function(tr, ip, parent_ip, trace_ctx);
+		trace_function(tr, ip, parent_ip, trace_ctx, NULL);
 }
 
 static int wakeup_flag_changed(struct trace_array *tr, u32 mask, int set)
Signature · 1 line
2.43.0
#19 lore raw

Re: [PATCH 7/7] tracing: add arguments to function tracer

Quoted 71 lines · Sven Schnelle

Wire up the code to print function arguments in the function tracer. This functionality can be enabled/disabled during compile time by setting CONFIG_FUNCTION_TRACE_ARGS and during runtime with options/func-args.

         ping-689     [004] b....    77.170220: dummy_xmit(skb = 0x82904800, dev = 0x882d0000) <-dev_hard_start_xmit
---
  kernel/trace/trace.c              |  8 +++++-
  kernel/trace/trace.h              |  4 ++-
  kernel/trace/trace_entries.h      |  7 +++--
  kernel/trace/trace_functions.c    | 46 +++++++++++++++++++++++++++----
  kernel/trace/trace_irqsoff.c      |  4 +--
  kernel/trace/trace_output.c       | 14 ++++++++--
  kernel/trace/trace_sched_wakeup.c |  4 +--
  7 files changed, 71 insertions(+), 16 deletions(-)
kernel/trace/trace.c +7 -1
index ebe7ce2f5f4a..8118e4c8c649 100644
@@ -2864,7 +2864,7 @@ trace_buffer_unlock_commit_nostack(struct trace_buffer *buffer,
 
  void
  trace_function(struct trace_array *tr, unsigned long ip, unsigned long
-	       parent_ip, unsigned int trace_ctx)
+	       parent_ip, unsigned int trace_ctx, struct ftrace_regs *regs)
  {
  	struct trace_event_call *call = &event_function;
  	struct trace_buffer *buffer = tr->array_buffer.buffer;
@@ -2878,6 +2878,12 @@ trace_function(struct trace_array *tr, unsigned long ip, unsigned long
  	entry	= ring_buffer_event_data(event);
  	entry->ip			= ip;
  	entry->parent_ip		= parent_ip;
+#ifdef CONFIG_FUNCTION_TRACE_ARGS
+	if (regs)
+		entry->regs		= *regs;
+	else
+		memset(&entry->regs, 0, sizeof(struct ftrace_regs));
+#endif
 
  	if (!call_filter_check_discard(call, entry, buffer, event)) {
  		if (static_branch_unlikely(&trace_function_exports_enabled))
kernel/trace/trace.h +3 -1
index bd3e3069300e..13cf6f97f7e0 100644
@@ -673,7 +673,8 @@ unsigned long trace_total_entries(struct trace_array *tr);
  void trace_function(struct trace_array *tr,
  		    unsigned long ip,
  		    unsigned long parent_ip,
-		    unsigned int trace_ctx);
+		    unsigned int trace_ctx,
+		    struct ftrace_regs *regs);
  void trace_graph_function(struct trace_array *tr,
  		    unsigned long ip,
  		    unsigned long parent_ip,
@@ -870,6 +871,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_ARGS		0x2000
  #define TRACE_GRAPH_PRINT_FILL_SHIFT	28
  #define TRACE_GRAPH_PRINT_FILL_MASK	(0x3 << TRACE_GRAPH_PRINT_FILL_SHIFT)
 
kernel/trace/trace_entries.h +0 -0
index c47422b20908..f2021ab52da2 100644

kernel/trace/trace_entries.h FTRACE_ENTRY_REG(function, ftrace_entry, · line 67

Quoted 9 lines
kernel/trace/trace_entries.h +4 -2
@@ -61,8 +61,11 @@ FTRACE_ENTRY_REG(function, ftrace_entry,
  	TRACE_FN,
 
  	F_STRUCT(
-		__field_fn(	unsigned long,	ip		)
-		__field_fn(	unsigned long,	parent_ip	)
+		__field_fn(	unsigned long,		ip		)
+		__field_fn(	unsigned long,		parent_ip	)
+#ifdef CONFIG_FUNCTION_TRACE_ARGS
+		__field_struct( struct ftrace_regs,	regs		)

Only function arguments are printed, they are several registers in ftrace_regs, would it be better to store what are needed?
Although different archs save function arguments in different registers, store the entire ftrace_regs are much more simple..

kernel/trace/trace_entries.h FTRACE_ENTRY_REG(function, ftrace_entry, · line 71

Quoted 4 lines
kernel/trace/trace_entries.h +1 -0
+#endif
  	),
 
  	F_printk(" %ps <-- %ps",

F_printk should also match F_STRUCT, otherwise 'format' info may be incorrect, it may confuse data parsing in user tools.

Quoted 196 lines
kernel/trace/trace_functions.c +41 -5
index 3b0cea37e029..7ff651a0b45a 100644
@@ -25,6 +25,9 @@ static void
  function_trace_call(unsigned long ip, unsigned long parent_ip,
  		    struct ftrace_ops *op, struct ftrace_regs *fregs);
  static void
+function_args_trace_call(unsigned long ip, unsigned long parent_ip,
+			 struct ftrace_ops *op, struct ftrace_regs *fregs);
+static void
  function_stack_trace_call(unsigned long ip, unsigned long parent_ip,
  			  struct ftrace_ops *op, struct ftrace_regs *fregs);
  static void
@@ -42,9 +45,10 @@ enum {
  	TRACE_FUNC_NO_OPTS		= 0x0, /* No flags set. */
  	TRACE_FUNC_OPT_STACK		= 0x1,
  	TRACE_FUNC_OPT_NO_REPEATS	= 0x2,
+	TRACE_FUNC_OPT_ARGS		= 0x4,
 
  	/* Update this to next highest bit. */
-	TRACE_FUNC_OPT_HIGHEST_BIT	= 0x4
+	TRACE_FUNC_OPT_HIGHEST_BIT	= 0x8
  };
 
  #define TRACE_FUNC_OPT_MASK	(TRACE_FUNC_OPT_HIGHEST_BIT - 1)
@@ -114,6 +118,8 @@ static ftrace_func_t select_trace_function(u32 flags_val)
  	switch (flags_val & TRACE_FUNC_OPT_MASK) {
  	case TRACE_FUNC_NO_OPTS:
  		return function_trace_call;
+	case TRACE_FUNC_OPT_ARGS:
+		return function_args_trace_call;
  	case TRACE_FUNC_OPT_STACK:
  		return function_stack_trace_call;
  	case TRACE_FUNC_OPT_NO_REPEATS:
@@ -198,7 +204,34 @@ function_trace_call(unsigned long ip, unsigned long parent_ip,
  	cpu = smp_processor_id();
  	data = per_cpu_ptr(tr->array_buffer.data, cpu);
  	if (!atomic_read(&data->disabled))
-		trace_function(tr, ip, parent_ip, trace_ctx);
+		trace_function(tr, ip, parent_ip, trace_ctx, NULL);
+
+	ftrace_test_recursion_unlock(bit);
+}
+
+static void
+function_args_trace_call(unsigned long ip, unsigned long parent_ip,
+			 struct ftrace_ops *op, struct ftrace_regs *fregs)
+{
+	struct trace_array *tr = op->private;
+	struct trace_array_cpu *data;
+	unsigned int trace_ctx;
+	int bit;
+	int cpu;
+
+	if (unlikely(!tr->function_enabled))
+		return;
+
+	bit = ftrace_test_recursion_trylock(ip, parent_ip);
+	if (bit < 0)
+		return;
+
+	trace_ctx = tracing_gen_ctx();
+
+	cpu = smp_processor_id();
+	data = per_cpu_ptr(tr->array_buffer.data, cpu);
+	if (!atomic_read(&data->disabled))
+		trace_function(tr, ip, parent_ip, trace_ctx, fregs);
 
  	ftrace_test_recursion_unlock(bit);
  }
@@ -247,7 +280,7 @@ function_stack_trace_call(unsigned long ip, unsigned long parent_ip,
 
  	if (likely(disabled == 1)) {
  		trace_ctx = tracing_gen_ctx_flags(flags);
-		trace_function(tr, ip, parent_ip, trace_ctx);
+		trace_function(tr, ip, parent_ip, trace_ctx, NULL);
  #ifdef CONFIG_UNWINDER_FRAME_POINTER
  		if (ftrace_pids_enabled(op))
  			skip++;
@@ -329,7 +362,7 @@ function_no_repeats_trace_call(unsigned long ip, unsigned long parent_ip,
  	trace_ctx = tracing_gen_ctx_flags(flags);
  	process_repeats(tr, ip, parent_ip, last_info, trace_ctx);
 
-	trace_function(tr, ip, parent_ip, trace_ctx);
+	trace_function(tr, ip, parent_ip, trace_ctx, NULL);
 
  out:
  	ftrace_test_recursion_unlock(bit);
@@ -368,7 +401,7 @@ function_stack_no_repeats_trace_call(unsigned long ip, unsigned long parent_ip,
  		trace_ctx = tracing_gen_ctx_flags(flags);
  		process_repeats(tr, ip, parent_ip, last_info, trace_ctx);
 
-		trace_function(tr, ip, parent_ip, trace_ctx);
+		trace_function(tr, ip, parent_ip, trace_ctx, NULL);
  		__trace_stack(tr, trace_ctx, STACK_SKIP);
  	}
 
@@ -382,6 +415,9 @@ static struct tracer_opt func_opts[] = {
  	{ TRACER_OPT(func_stack_trace, TRACE_FUNC_OPT_STACK) },
  #endif
  	{ TRACER_OPT(func-no-repeats, TRACE_FUNC_OPT_NO_REPEATS) },
+#ifdef CONFIG_FUNCTION_TRACE_ARGS
+	{ TRACER_OPT(func-args, TRACE_FUNC_OPT_ARGS) },
+#endif
  	{ } /* Always set a last empty entry */
  };
 
kernel/trace/trace_irqsoff.c +2 -2
index fce064e20570..096002c99d70 100644
@@ -150,7 +150,7 @@ irqsoff_tracer_call(unsigned long ip, unsigned long parent_ip,
 
  	trace_ctx = tracing_gen_ctx_flags(flags);
 
-	trace_function(tr, ip, parent_ip, trace_ctx);
+	trace_function(tr, ip, parent_ip, trace_ctx, fregs);
 
  	atomic_dec(&data->disabled);
  }
@@ -278,7 +278,7 @@ __trace_function(struct trace_array *tr,
  	if (is_graph(tr))
  		trace_graph_function(tr, ip, parent_ip, trace_ctx);
  	else
-		trace_function(tr, ip, parent_ip, trace_ctx);
+		trace_function(tr, ip, parent_ip, trace_ctx, NULL);
  }
 
  #else
kernel/trace/trace_output.c +11 -3
index 70405c4cceb6..8fdee7b9cdba 100644
@@ -1058,9 +1058,13 @@ enum print_line_t trace_nop_print(struct trace_iterator *iter, int flags,
  }
 
  static void print_fn_trace(struct trace_seq *s, unsigned long ip,
-			   unsigned long parent_ip, int flags)
+			   unsigned long parent_ip,
+			   struct ftrace_regs *fregs,
+			   int flags)
  {
  	seq_print_ip_sym(s, ip, flags);
+	if (fregs)
+		print_function_args(s, fregs, ip);
 
  	if ((flags & TRACE_ITER_PRINT_PARENT) && parent_ip) {
  		trace_seq_puts(s, " <-");
@@ -1074,10 +1078,14 @@ static enum print_line_t trace_fn_trace(struct trace_iterator *iter, int flags,
  {
  	struct ftrace_entry *field;
  	struct trace_seq *s = &iter->seq;
+	struct ftrace_regs *fregs = NULL;
 
  	trace_assign_type(field, iter->ent);
 
-	print_fn_trace(s, field->ip, field->parent_ip, flags);
+#if IS_ENABLED(CONFIG_FUNCTION_TRACE_ARGS)
+	fregs = &field->regs;
+#endif
+	print_fn_trace(s, field->ip, field->parent_ip, fregs, flags);
  	trace_seq_putc(s, '\n');
 
  	return trace_handle_return(s);
@@ -1742,7 +1750,7 @@ trace_func_repeats_print(struct trace_iterator *iter, int flags,
 
  	trace_assign_type(field, iter->ent);
 
-	print_fn_trace(s, field->ip, field->parent_ip, flags);
+	print_fn_trace(s, field->ip, field->parent_ip, NULL, flags);
  	trace_seq_printf(s, " (repeats: %u, last_ts:", field->count);
  	trace_print_time(s, iter,
  			 iter->ts - FUNC_REPEATS_GET_DELTA_TS(field));
kernel/trace/trace_sched_wakeup.c +2 -2
index 130ca7e7787e..39043c955761 100644
@@ -224,7 +224,7 @@ wakeup_tracer_call(unsigned long ip, unsigned long parent_ip,
  		return;
 
  	local_irq_save(flags);
-	trace_function(tr, ip, parent_ip, trace_ctx);
+	trace_function(tr, ip, parent_ip, trace_ctx, fregs);
  	local_irq_restore(flags);
 
  	atomic_dec(&data->disabled);
@@ -309,7 +309,7 @@ __trace_function(struct trace_array *tr,
  	if (is_graph(tr))
  		trace_graph_function(tr, ip, parent_ip, trace_ctx);
  	else
-		trace_function(tr, ip, parent_ip, trace_ctx);
+		trace_function(tr, ip, parent_ip, trace_ctx, NULL);
  }
 
  static int wakeup_flag_changed(struct trace_array *tr, u32 mask, int set)
Signature · 2 lines
Thanks,
Zheng Yejian
maintainer
#20 lore raw

Re: [PATCH 7/7] tracing: add arguments to function tracer

Quoted 7 lines · On Fri, 6 Sep 2024 11:49:10 +0800 Zheng Yejian <[email protected]>…
Quoted 7 lines
kernel/trace/trace_entries.h +0 -0
index c47422b20908..f2021ab52da2 100644
@@ -61,8 +61,11 @@ FTRACE_ENTRY_REG(function, ftrace_entry,
  	TRACE_FN,
 
Quoted 12 lines

kernel/trace/trace_entries.h FTRACE_ENTRY_REG(function, ftrace_entry, · line 67

Quoted 7 lines
kernel/trace/trace_entries.h +4 -2
  	F_STRUCT(
-		__field_fn(	unsigned long,	ip		)
-		__field_fn(	unsigned long,	parent_ip	)
+		__field_fn(	unsigned long,		ip		)
+		__field_fn(	unsigned long,		parent_ip	)
+#ifdef CONFIG_FUNCTION_TRACE_ARGS
+		__field_struct( struct ftrace_regs,	regs		)  

Only function arguments are printed, they are several registers in ftrace_regs, would it be better to store what are needed?
Although different archs save function arguments in different registers, store the entire ftrace_regs are much more simple..

Agreed, and I stated as much in my reply to patch 6.

This too will need two versions of the event. One will be function the other will be function_args. And it will only record the necessary arguments not the full ftrace_regs structure, as I plan on making that structure have "zero size".

Quoted 8 lines

kernel/trace/trace_entries.h FTRACE_ENTRY_REG(function, ftrace_entry, · line 71

Quoted 5 lines
kernel/trace/trace_entries.h +1 -0
+#endif
  	),
 
  	F_printk(" %ps <-- %ps",  

F_printk should also match F_STRUCT, otherwise 'format' info may be incorrect, it may confuse data parsing in user tools.

Well, it will just ignore the struct part, as its not listed.

-- Steve

Quoted 11 lines
Quoted 11 lines
kernel/trace/trace_functions.c +2 -0
index 3b0cea37e029..7ff651a0b45a 100644
@@ -25,6 +25,9 @@ static void
  function_trace_call(unsigned long ip, unsigned long parent_ip,
  		    struct ftrace_ops *op, struct ftrace_regs *fregs);
  static void
+function_args_trace_call(unsigned long ip, unsigned long parent_ip,
+			 struct ftrace_ops *op, struct ftrace_regs *fregs);
maintainer
#21 lore raw
In reply to Sven Schnelle
Quoted 44 lines · On Wed, 4 Sep 2024 08:58:54 +0200 Sven Schnelle <[email protected]> wrote:

These patches add support for printing function arguments in ftrace.

Example usage:

function tracer:

cd /sys/kernel/tracing/
echo icmp_rcv >set_ftrace_filter
echo function >current_tracer
echo 1 >options/func-args
ping -c 10 127.0.0.1
[..]
cat trace
[..]

            ping-1277    [030] ..s1.    39.120939: icmp_rcv(skb = 0xa0ecab00) <-ip_protocol_deliver_rcu
            ping-1277    [030] ..s1.    39.120946: icmp_rcv(skb = 0xa0ecac00) <-ip_protocol_deliver_rcu
            ping-1277    [030] ..s1.    40.179724: icmp_rcv(skb = 0xa0ecab00) <-ip_protocol_deliver_rcu
            ping-1277    [030] ..s1.    40.179730: icmp_rcv(skb = 0xa0ecac00) <-ip_protocol_deliver_rcu
            ping-1277    [030] ..s1.    41.219700: icmp_rcv(skb = 0xa0ecab00) <-ip_protocol_deliver_rcu
            ping-1277    [030] ..s1.    41.219706: icmp_rcv(skb = 0xa0ecac00) <-ip_protocol_deliver_rcu
            ping-1277    [030] ..s1.    42.259717: icmp_rcv(skb = 0xa0ecab00) <-ip_protocol_deliver_rcu
            ping-1277    [030] ..s1.    42.259725: icmp_rcv(skb = 0xa0ecac00) <-ip_protocol_deliver_rcu
            ping-1277    [030] ..s1.    43.299735: icmp_rcv(skb = 0xa0ecab00) <-ip_protocol_deliver_rcu
            ping-1277    [030] ..s1.    43.299742: icmp_rcv(skb = 0xa0ecac00) <-ip_protocol_deliver_rcu

function graph:

cd /sys/kernel/tracing
echo icmp_rcv >set_graph_function
echo function_graph >current_tracer
echo 1 >options/funcgraph-args

ping -c 1 127.0.0.1

cat trace

 30)               |  icmp_rcv(skb = 0xa0ecab00) {
 30)               |    __skb_checksum_complete(skb = 0xa0ecab00) {
 30)               |      skb_checksum(skb = 0xa0ecab00, offset = 0, len = 64, csum = 0) {
 30)               |        __skb_checksum(skb = 0xa0ecab00, offset = 0, len = 64, csum = 0, ops = 0x232e0327a88) {
 30)   0.418 us    |          csum_partial(buff = 0xa0d20924, len = 64, sum = 0)
 30)   0.985 us    |        }
 30)   1.463 us    |      }
 30)   2.039 us    |    }
Quoted 2 lines

[..]

First I want to say THANK YOU!!!!

This has been on my TODO list for far too long. I never got the time to work on it :-p

Anyway, this is something I definitely want added. But I'm going to guess that there is going to be issues with it and I doubt it will be ready for the next merge window. I'm currently focused on some other things and also have to get ready for next weeks travels (I'll be in Prague for GNU Cauldron, then Vienna for Plumbers and OSS EU, then to Paris for Kernel Recipes!).

But I most definitely want this in. Hopefully by 6.13. This may be something I can review on the plane (if I get my slides done).

Again, thanks for doing this!

-- Steve

Quoted 42 lines

Sven Schnelle (7):
tracing: add ftrace_regs to function_graph_enter() x86/tracing: pass ftrace_regs to function_graph_enter() s390/tracing: pass ftrace_regs to function_graph_enter() Add print_function_args()
tracing: add config option for print arguments in ftrace
tracing: add support for function argument to graph tracer
tracing: add arguments to function tracer

 arch/arm/kernel/ftrace.c             |  2 +-
 arch/arm64/kernel/ftrace.c           |  2 +-
 arch/csky/kernel/ftrace.c            |  2 +-
 arch/loongarch/kernel/ftrace.c       |  2 +-
 arch/loongarch/kernel/ftrace_dyn.c   |  2 +-
 arch/microblaze/kernel/ftrace.c      |  2 +-
 arch/mips/kernel/ftrace.c            |  2 +-
 arch/parisc/kernel/ftrace.c          |  2 +-
 arch/powerpc/kernel/trace/ftrace.c   |  2 +-
 arch/riscv/kernel/ftrace.c           |  2 +-
 arch/s390/kernel/entry.h             |  4 +-
 arch/s390/kernel/ftrace.c            |  4 +-
 arch/sh/kernel/ftrace.c              |  2 +-
 arch/sparc/kernel/ftrace.c           |  2 +-
 arch/x86/include/asm/ftrace.h        |  2 +-
 arch/x86/kernel/ftrace.c             |  6 +-
 include/linux/ftrace.h               |  4 +-
 kernel/trace/Kconfig                 | 12 ++++
 kernel/trace/fgraph.c                |  7 ++-
 kernel/trace/trace.c                 |  8 ++-
 kernel/trace/trace.h                 |  4 +-
 kernel/trace/trace_entries.h         |  7 ++-
 kernel/trace/trace_functions.c       | 46 ++++++++++++++--
 kernel/trace/trace_functions_graph.c | 74 +++++++++++++------------
 kernel/trace/trace_irqsoff.c         |  4 +-
 kernel/trace/trace_output.c          | 82 +++++++++++++++++++++++++++-
 kernel/trace/trace_output.h          |  9 +++
 kernel/trace/trace_sched_wakeup.c    |  4 +-
 28 files changed, 228 insertions(+), 73 deletions(-)

--
2.43.0

author reviewer
#22 lore raw
Quoted 9 lines · Steven Rostedt
Quoted 1 line · On Wed, 4 Sep 2024 08:58:54 +0200 Sven Schnelle <[email protected]> wrote:

These patches add support for printing function arguments in ftrace.

First I want to say THANK YOU!!!!

This has been on my TODO list for far too long. I never got the time to work on it :-p

Quoted 8 lines

Anyway, this is something I definitely want added. But I'm going to guess that there is going to be issues with it and I doubt it will be ready for the next merge window. I'm currently focused on some other things and also have to get ready for next weeks travels (I'll be in Prague for GNU Cauldron, then Vienna for Plumbers and OSS EU, then to Paris for Kernel Recipes!).

But I most definitely want this in. Hopefully by 6.13. This may be something I can review on the plane (if I get my slides done).

Thanks! It's been hanging in my git repo for quite a while, so no need to rush.

One thing i learned after submitting the series is that struct ftrace_regs depends on CONFIG_FUNCTION_TRACER, so it cannot be used with the graph tracer. So either we make it available unconditionally, or use some other data structure. Would like to hear your opinion on that, but i'll wait for the review after your travel because there are likely other issues that needs to be fixed as well.

Thanks,
Sven

maintainer
#23 lore raw
Quoted 6 lines · On Fri, 06 Sep 2024 08:18:02 +0200 Sven Schnelle <[email protected]> wrote:

One thing i learned after submitting the series is that struct ftrace_regs depends on CONFIG_FUNCTION_TRACER, so it cannot be used with the graph tracer. So either we make it available unconditionally, or use some other data structure. Would like to hear your opinion on that, but i'll wait for the review after your travel because there are likely other issues that needs to be fixed as well.

Hmm, I thought the graph tracer depends on function tracer? Anyway, the configs should be cleaned up. I would like to make CONFIG_FTRACE just mean the function hook mechanism (mcount,fentry,etc) and not be used for the tracing system.

Anyway, we can just make ftrace_regs defined outside any config for now.

-- Steve

#24 lore raw
Quoted 7 lines · On Fri, 6 Sep 2024 10:07:38 -0400 Steven Rostedt <[email protected]> wrote:
Quoted 3 lines · On Fri, 06 Sep 2024 08:18:02 +0200 Sven Schnelle <[email protected]> wrote:

One thing i learned after submitting the series is that struct ftrace_regs depends on CONFIG_FUNCTION_TRACER, so it cannot be used with the graph tracer.

Yeah, this is solved by my series [1].

[1] https://patchwork.kernel.org/project/linux-trace-kernel/patch/172398532480.293426.13232399076477198126.stgit@devnote2/

So I think this series is easier to apply after my series, which passes fgraph_regs in return handler.

Thanks,

Quoted 13 lines
Quoted 4 lines

So either we make it available unconditionally,
or use some other data structure. Would like to hear your opinion on that, but i'll wait for the review after your travel because there are likely other issues that needs to be fixed as well.

Hmm, I thought the graph tracer depends on function tracer? Anyway, the configs should be cleaned up. I would like to make CONFIG_FTRACE just mean the function hook mechanism (mcount,fentry,etc) and not be used for the tracing system.

Anyway, we can just make ftrace_regs defined outside any config for now.

-- Steve

Signature · 1 line
Masami Hiramatsu (Google) <[email protected]>
author reviewer
#25 lore raw
Quoted 11 lines · Masami Hiramatsu (Google)
Quoted 7 lines · On Fri, 6 Sep 2024 10:07:38 -0400 Steven Rostedt <[email protected]> wrote:
Quoted 3 lines · On Fri, 06 Sep 2024 08:18:02 +0200 Sven Schnelle <[email protected]> wrote:

One thing i learned after submitting the series is that struct ftrace_regs depends on CONFIG_FUNCTION_TRACER, so it cannot be used with the graph tracer.

Quoted 6 lines

Yeah, this is solved by my series [1].

[1] https://patchwork.kernel.org/project/linux-trace-kernel/patch/172398532480.293426.13232399076477198126.stgit@devnote2/

So I think this series is easier to apply after my series, which passes fgraph_regs in return handler.

Thanks, i'll rebase my changes on top of your patches then.

Regards
Sven

author reviewer
#26 lore raw
Quoted 13 lines · Sven Schnelle
Quoted 11 lines · Masami Hiramatsu (Google)
Quoted 7 lines · On Fri, 6 Sep 2024 10:07:38 -0400 Steven Rostedt <[email protected]> wrote:
Quoted 3 lines · On Fri, 06 Sep 2024 08:18:02 +0200 Sven Schnelle <[email protected]> wrote:

One thing i learned after submitting the series is that struct ftrace_regs depends on CONFIG_FUNCTION_TRACER, so it cannot be used with the graph tracer.

Quoted 8 lines
Quoted 6 lines

Yeah, this is solved by my series [1].

[1] https://patchwork.kernel.org/project/linux-trace-kernel/patch/172398532480.293426.13232399076477198126.stgit@devnote2/

So I think this series is easier to apply after my series, which passes fgraph_regs in return handler.

Thanks, i'll rebase my changes on top of your patches then.

While doing so i noticed that i completely forgot about arguments located on the stack. The current patchset tries to read from the current kernel stack, which is obviously wrong. So either the tracer needs to save the stack frame in the ringbuffer (which would be quite a lot of data), or ftrace only prints arguments located in registers. Also not nice. Opinions?

Thanks
Sven

#27 lore raw
Quoted 22 lines · On Fri, 13 Sep 2024 08:03:51 +0200 Sven Schnelle <[email protected]> wrote:
Quoted 20 lines · Sven Schnelle
Quoted 17 lines · Masami Hiramatsu (Google)
Quoted 7 lines · On Fri, 6 Sep 2024 10:07:38 -0400 Steven Rostedt <[email protected]> wrote:
Quoted 3 lines · On Fri, 06 Sep 2024 08:18:02 +0200 Sven Schnelle <[email protected]> wrote:

One thing i learned after submitting the series is that struct ftrace_regs depends on CONFIG_FUNCTION_TRACER, so it cannot be used with the graph tracer.

Yeah, this is solved by my series [1].

[1] https://patchwork.kernel.org/project/linux-trace-kernel/patch/172398532480.293426.13232399076477198126.stgit@devnote2/

So I think this series is easier to apply after my series, which passes fgraph_regs in return handler.

Quoted 8 lines
Quoted 1 line

Thanks, i'll rebase my changes on top of your patches then.

While doing so i noticed that i completely forgot about arguments located on the stack. The current patchset tries to read from the current kernel stack, which is obviously wrong. So either the tracer needs to save the stack frame in the ringbuffer (which would be quite a lot of data), or ftrace only prints arguments located in registers. Also not nice. Opinions?

We can limit it to first 6 arguments in the ftrace_regs by default, no need to save all of them. We can add an option to specify how many stack entries (but it is set 0 by default).

Thank you,

Quoted 3 lines

Thanks
Sven

Signature · 1 line
Masami Hiramatsu (Google) <[email protected]>