Merge tag 'io_uring-6.16-20250630' of git://git.kernel.dk/linux
[linux-2.6-block.git] / include / linux / fprobe.h
CommitLineData
cad9931f
MH
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>
4346ba16
MHG
8#include <linux/rcupdate.h>
9#include <linux/refcount.h>
10#include <linux/slab.h>
cad9931f 11
73142cab 12struct fprobe;
73142cab 13typedef int (*fprobe_entry_cb)(struct fprobe *fp, unsigned long entry_ip,
46bc0823 14 unsigned long ret_ip, struct ftrace_regs *regs,
73142cab
JO
15 void *entry_data);
16
17typedef void (*fprobe_exit_cb)(struct fprobe *fp, unsigned long entry_ip,
762abbc0 18 unsigned long ret_ip, struct ftrace_regs *regs,
73142cab
JO
19 void *entry_data);
20
4346ba16
MHG
21/**
22 * struct fprobe_hlist_node - address based hash list node for fprobe.
23 *
24 * @hlist: The hlist node for address search hash table.
25 * @addr: One of the probing address of @fp.
26 * @fp: The fprobe which owns this.
27 */
28struct fprobe_hlist_node {
29 struct hlist_node hlist;
30 unsigned long addr;
31 struct fprobe *fp;
32};
33
34/**
35 * struct fprobe_hlist - hash list nodes for fprobe.
36 *
37 * @hlist: The hlist node for existence checking hash table.
38 * @rcu: rcu_head for RCU deferred release.
39 * @fp: The fprobe which owns this fprobe_hlist.
40 * @size: The size of @array.
41 * @array: The fprobe_hlist_node for each address to probe.
42 */
43struct fprobe_hlist {
44 struct hlist_node hlist;
45 struct rcu_head rcu;
46 struct fprobe *fp;
47 int size;
48 struct fprobe_hlist_node array[] __counted_by(size);
49};
50
cad9931f
MH
51/**
52 * struct fprobe - ftrace based probe.
4346ba16 53 *
cad9931f
MH
54 * @nmissed: The counter for missing events.
55 * @flags: The status flag.
76d0de57 56 * @entry_data_size: The private data storage size.
cad9931f 57 * @entry_handler: The callback function for function entry.
5b0ab789 58 * @exit_handler: The callback function for function exit.
4346ba16 59 * @hlist_array: The fprobe_hlist for fprobe search from IP hash table.
cad9931f
MH
60 */
61struct fprobe {
cad9931f
MH
62 unsigned long nmissed;
63 unsigned int flags;
76d0de57 64 size_t entry_data_size;
5b0ab789 65
73142cab
JO
66 fprobe_entry_cb entry_handler;
67 fprobe_exit_cb exit_handler;
4346ba16
MHG
68
69 struct fprobe_hlist *hlist_array;
cad9931f
MH
70};
71
ab51e15d 72/* This fprobe is soft-disabled. */
cad9931f
MH
73#define FPROBE_FL_DISABLED 1
74
ab51e15d
MH
75/*
76 * This fprobe handler will be shared with kprobes.
77 * This flag must be set before registering.
78 */
79#define FPROBE_FL_KPROBE_SHARED 2
80
cad9931f
MH
81static inline bool fprobe_disabled(struct fprobe *fp)
82{
83 return (fp) ? fp->flags & FPROBE_FL_DISABLED : false;
84}
85
ab51e15d
MH
86static inline bool fprobe_shared_with_kprobes(struct fprobe *fp)
87{
88 return (fp) ? fp->flags & FPROBE_FL_KPROBE_SHARED : false;
89}
90
cad9931f
MH
91#ifdef CONFIG_FPROBE
92int register_fprobe(struct fprobe *fp, const char *filter, const char *notfilter);
93int register_fprobe_ips(struct fprobe *fp, unsigned long *addrs, int num);
94int register_fprobe_syms(struct fprobe *fp, const char **syms, int num);
95int unregister_fprobe(struct fprobe *fp);
334e5519 96bool fprobe_is_registered(struct fprobe *fp);
cad9931f
MH
97#else
98static inline int register_fprobe(struct fprobe *fp, const char *filter, const char *notfilter)
99{
100 return -EOPNOTSUPP;
101}
102static inline int register_fprobe_ips(struct fprobe *fp, unsigned long *addrs, int num)
103{
104 return -EOPNOTSUPP;
105}
106static inline int register_fprobe_syms(struct fprobe *fp, const char **syms, int num)
107{
108 return -EOPNOTSUPP;
109}
110static inline int unregister_fprobe(struct fprobe *fp)
111{
112 return -EOPNOTSUPP;
113}
334e5519
MHG
114static inline bool fprobe_is_registered(struct fprobe *fp)
115{
116 return false;
117}
cad9931f
MH
118#endif
119
120/**
121 * disable_fprobe() - Disable fprobe
122 * @fp: The fprobe to be disabled.
123 *
124 * This will soft-disable @fp. Note that this doesn't remove the ftrace
125 * hooks from the function entry.
126 */
127static inline void disable_fprobe(struct fprobe *fp)
128{
129 if (fp)
130 fp->flags |= FPROBE_FL_DISABLED;
131}
132
133/**
134 * enable_fprobe() - Enable fprobe
135 * @fp: The fprobe to be enabled.
136 *
137 * This will soft-enable @fp.
138 */
139static inline void enable_fprobe(struct fprobe *fp)
140{
141 if (fp)
142 fp->flags &= ~FPROBE_FL_DISABLED;
143}
144
4346ba16
MHG
145/* The entry data size is 4 bits (=16) * sizeof(long) in maximum */
146#define FPROBE_DATA_SIZE_BITS 4
147#define MAX_FPROBE_DATA_SIZE_WORD ((1L << FPROBE_DATA_SIZE_BITS) - 1)
148#define MAX_FPROBE_DATA_SIZE (MAX_FPROBE_DATA_SIZE_WORD * sizeof(long))
149
cad9931f 150#endif