@@ -9,9 +9,10 @@ Fprobe - Function entry/exit probe
99 Introduction
1010============
1111
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
1516use fprobe. Compared with kprobes and kretprobes, fprobe gives faster
1617instrumentation for multiple functions with single handler. This document
1718describes how to use fprobe.
@@ -91,12 +92,14 @@ The prototype of the entry/exit callback function are as follows:
9192
9293.. code-block :: c
9394
94- int entry_callback(struct fprobe *fp, unsigned long entry_ip, unsigned long ret_ip, struct pt_regs *regs , void *entry_data);
95+ int entry_callback(struct fprobe *fp, unsigned long entry_ip, unsigned long ret_ip, struct ftrace_regs *fregs , void *entry_data);
9596
96- void exit_callback(struct fprobe *fp, unsigned long entry_ip, unsigned long ret_ip, struct pt_regs *regs , void *entry_data);
97+ void exit_callback(struct fprobe *fp, unsigned long entry_ip, unsigned long ret_ip, struct ftrace_regs *fregs , void *entry_data);
9798
98- Note that the @entry_ip is saved at function entry and passed to exit handler.
99- If the entry callback function returns !0, the corresponding exit callback will be cancelled.
99+ Note that the @entry_ip is saved at function entry and passed to exit
100+ handler.
101+ If the entry callback function returns !0, the corresponding exit callback
102+ will be cancelled.
100103
101104@fp
102105 This is the address of `fprobe ` data structure related to this handler.
@@ -112,19 +115,28 @@ If the entry callback function returns !0, the corresponding exit callback will
112115 This is the return address that the traced function will return to,
113116 somewhere in the caller. This can be used at both entry and exit.
114117
115- @regs
116- This is the `pt_regs ` data structure at the entry and exit. Note that
117- the instruction pointer of @regs may be different from the @entry_ip
118- in the entry_handler. If you need traced instruction pointer, you need
119- to use @entry_ip. On the other hand, in the exit_handler, the instruction
120- pointer of @regs is set to the current return address.
118+ @fregs
119+ This is the `ftrace_regs ` data structure at the entry and exit. This
120+ includes the function parameters, or the return values. So user can
121+ access thos values via appropriate `ftrace_regs_* ` APIs.
121122
122123@entry_data
123124 This is a local storage to share the data between entry and exit handlers.
124125 This storage is NULL by default. If the user specify `exit_handler ` field
125126 and `entry_data_size ` field when registering the fprobe, the storage is
126127 allocated and passed to both `entry_handler ` and `exit_handler `.
127128
129+ Entry data size and exit handlers on the same function
130+ ======================================================
131+
132+ Since the entry data is passed via per-task stack and it has limited size,
133+ the entry data size per probe is limited to `15 * sizeof(long) `. You also need
134+ to take care that the different fprobes are probing on the same function, this
135+ limit becomes smaller. The entry data size is aligned to `sizeof(long) ` and
136+ each fprobe which has exit handler uses a `sizeof(long) ` space on the stack,
137+ you should keep the number of fprobes on the same function as small as
138+ possible.
139+
128140Share the callbacks with kprobes
129141================================
130142
@@ -165,8 +177,8 @@ This counter counts up when;
165177 - fprobe fails to take ftrace_recursion lock. This usually means that a function
166178 which is traced by other ftrace users is called from the entry_handler.
167179
168- - fprobe fails to setup the function exit because of the shortage of rethook
169- (the shadow stack for hooking the function return.)
180+ - fprobe fails to setup the function exit because of failing to allocate the
181+ data buffer from the per-task shadow stack.
170182
171183The `fprobe::nmissed ` field counts up in both cases. Therefore, the former
172184skips both of entry and exit callback and the latter skips the exit
0 commit comments