Merge tag 'trace-v6.4' of git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux...
[linux-block.git] / include / linux / fprobe.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* Simple ftrace probe wrapper */
3 #ifndef _LINUX_FPROBE_H
4 #define _LINUX_FPROBE_H
5
6 #include <linux/compiler.h>
7 #include <linux/ftrace.h>
8 #include <linux/rethook.h>
9
10 /**
11  * struct fprobe - ftrace based probe.
12  * @ops: The ftrace_ops.
13  * @nmissed: The counter for missing events.
14  * @flags: The status flag.
15  * @rethook: The rethook data structure. (internal data)
16  * @entry_data_size: The private data storage size.
17  * @nr_maxactive: The max number of active functions.
18  * @entry_handler: The callback function for function entry.
19  * @exit_handler: The callback function for function exit.
20  */
21 struct fprobe {
22 #ifdef CONFIG_FUNCTION_TRACER
23         /*
24          * If CONFIG_FUNCTION_TRACER is not set, CONFIG_FPROBE is disabled too.
25          * But user of fprobe may keep embedding the struct fprobe on their own
26          * code. To avoid build error, this will keep the fprobe data structure
27          * defined here, but remove ftrace_ops data structure.
28          */
29         struct ftrace_ops       ops;
30 #endif
31         unsigned long           nmissed;
32         unsigned int            flags;
33         struct rethook          *rethook;
34         size_t                  entry_data_size;
35         int                     nr_maxactive;
36
37         int (*entry_handler)(struct fprobe *fp, unsigned long entry_ip,
38                              struct pt_regs *regs, void *entry_data);
39         void (*exit_handler)(struct fprobe *fp, unsigned long entry_ip,
40                              struct pt_regs *regs, void *entry_data);
41 };
42
43 /* This fprobe is soft-disabled. */
44 #define FPROBE_FL_DISABLED      1
45
46 /*
47  * This fprobe handler will be shared with kprobes.
48  * This flag must be set before registering.
49  */
50 #define FPROBE_FL_KPROBE_SHARED 2
51
52 static inline bool fprobe_disabled(struct fprobe *fp)
53 {
54         return (fp) ? fp->flags & FPROBE_FL_DISABLED : false;
55 }
56
57 static inline bool fprobe_shared_with_kprobes(struct fprobe *fp)
58 {
59         return (fp) ? fp->flags & FPROBE_FL_KPROBE_SHARED : false;
60 }
61
62 #ifdef CONFIG_FPROBE
63 int register_fprobe(struct fprobe *fp, const char *filter, const char *notfilter);
64 int register_fprobe_ips(struct fprobe *fp, unsigned long *addrs, int num);
65 int register_fprobe_syms(struct fprobe *fp, const char **syms, int num);
66 int unregister_fprobe(struct fprobe *fp);
67 #else
68 static inline int register_fprobe(struct fprobe *fp, const char *filter, const char *notfilter)
69 {
70         return -EOPNOTSUPP;
71 }
72 static inline int register_fprobe_ips(struct fprobe *fp, unsigned long *addrs, int num)
73 {
74         return -EOPNOTSUPP;
75 }
76 static inline int register_fprobe_syms(struct fprobe *fp, const char **syms, int num)
77 {
78         return -EOPNOTSUPP;
79 }
80 static inline int unregister_fprobe(struct fprobe *fp)
81 {
82         return -EOPNOTSUPP;
83 }
84 #endif
85
86 /**
87  * disable_fprobe() - Disable fprobe
88  * @fp: The fprobe to be disabled.
89  *
90  * This will soft-disable @fp. Note that this doesn't remove the ftrace
91  * hooks from the function entry.
92  */
93 static inline void disable_fprobe(struct fprobe *fp)
94 {
95         if (fp)
96                 fp->flags |= FPROBE_FL_DISABLED;
97 }
98
99 /**
100  * enable_fprobe() - Enable fprobe
101  * @fp: The fprobe to be enabled.
102  *
103  * This will soft-enable @fp.
104  */
105 static inline void enable_fprobe(struct fprobe *fp)
106 {
107         if (fp)
108                 fp->flags &= ~FPROBE_FL_DISABLED;
109 }
110
111 #endif