Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Documentation: probes: Update fprobe on function-graph tracer

Update fprobe documentation for the new fprobe on function-graph
tracer. This includes some bahvior changes and pt_regs to
ftrace_regs interface change.

Cc: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Cc: Florent Revest <revest@chromium.org>
Cc: Martin KaFai Lau <martin.lau@linux.dev>
Cc: bpf <bpf@vger.kernel.org>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Alan Maguire <alan.maguire@oracle.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Link: https://lore.kernel.org/173519010442.391279.10732749889346824783.stgit@devnote2
Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>

authored by

Masami Hiramatsu (Google) and committed by
Steven Rostedt (Google)
54b6b4a3 0c2dd44d

+27 -15
+27 -15
Documentation/trace/fprobe.rst
··· 9 9 Introduction 10 10 ============ 11 11 12 - Fprobe is a function entry/exit probe mechanism based on ftrace. 13 - Instead of using ftrace full feature, if you only want to attach callbacks 14 - on function entry and exit, similar to the kprobes and kretprobes, you can 12 + Fprobe is a function entry/exit probe based on the function-graph tracing 13 + feature in ftrace. 14 + Instead of tracing all functions, if you want to attach callbacks on specific 15 + function entry and exit, similar to the kprobes and kretprobes, you can 15 16 use fprobe. Compared with kprobes and kretprobes, fprobe gives faster 16 17 instrumentation for multiple functions with single handler. This document 17 18 describes how to use fprobe. ··· 92 91 93 92 .. code-block:: c 94 93 95 - int entry_callback(struct fprobe *fp, unsigned long entry_ip, unsigned long ret_ip, struct pt_regs *regs, void *entry_data); 94 + int entry_callback(struct fprobe *fp, unsigned long entry_ip, unsigned long ret_ip, struct ftrace_regs *fregs, void *entry_data); 96 95 97 - void exit_callback(struct fprobe *fp, unsigned long entry_ip, unsigned long ret_ip, struct pt_regs *regs, void *entry_data); 96 + void exit_callback(struct fprobe *fp, unsigned long entry_ip, unsigned long ret_ip, struct ftrace_regs *fregs, void *entry_data); 98 97 99 - Note that the @entry_ip is saved at function entry and passed to exit handler. 100 - If the entry callback function returns !0, the corresponding exit callback will be cancelled. 98 + Note that the @entry_ip is saved at function entry and passed to exit 99 + handler. 100 + If the entry callback function returns !0, the corresponding exit callback 101 + will be cancelled. 101 102 102 103 @fp 103 104 This is the address of `fprobe` data structure related to this handler. ··· 115 112 This is the return address that the traced function will return to, 116 113 somewhere in the caller. This can be used at both entry and exit. 117 114 118 - @regs 119 - This is the `pt_regs` data structure at the entry and exit. Note that 120 - the instruction pointer of @regs may be different from the @entry_ip 121 - in the entry_handler. If you need traced instruction pointer, you need 122 - to use @entry_ip. On the other hand, in the exit_handler, the instruction 123 - pointer of @regs is set to the current return address. 115 + @fregs 116 + This is the `ftrace_regs` data structure at the entry and exit. This 117 + includes the function parameters, or the return values. So user can 118 + access thos values via appropriate `ftrace_regs_*` APIs. 124 119 125 120 @entry_data 126 121 This is a local storage to share the data between entry and exit handlers. 127 122 This storage is NULL by default. If the user specify `exit_handler` field 128 123 and `entry_data_size` field when registering the fprobe, the storage is 129 124 allocated and passed to both `entry_handler` and `exit_handler`. 125 + 126 + Entry data size and exit handlers on the same function 127 + ====================================================== 128 + 129 + Since the entry data is passed via per-task stack and it has limited size, 130 + the entry data size per probe is limited to `15 * sizeof(long)`. You also need 131 + to take care that the different fprobes are probing on the same function, this 132 + limit becomes smaller. The entry data size is aligned to `sizeof(long)` and 133 + each fprobe which has exit handler uses a `sizeof(long)` space on the stack, 134 + you should keep the number of fprobes on the same function as small as 135 + possible. 130 136 131 137 Share the callbacks with kprobes 132 138 ================================ ··· 177 165 - fprobe fails to take ftrace_recursion lock. This usually means that a function 178 166 which is traced by other ftrace users is called from the entry_handler. 179 167 180 - - fprobe fails to setup the function exit because of the shortage of rethook 181 - (the shadow stack for hooking the function return.) 168 + - fprobe fails to setup the function exit because of failing to allocate the 169 + data buffer from the per-task shadow stack. 182 170 183 171 The `fprobe::nmissed` field counts up in both cases. Therefore, the former 184 172 skips both of entry and exit callback and the latter skips the exit