Merge tag 'mm-hotfixes-stable-2025-07-11-16-16' of git://git.kernel.org/pub/scm/linux...
[linux-block.git] / include / linux / kprobes.h
CommitLineData
1a59d1b8 1/* SPDX-License-Identifier: GPL-2.0-or-later */
1da177e4
LT
2#ifndef _LINUX_KPROBES_H
3#define _LINUX_KPROBES_H
4/*
5 * Kernel Probes (KProbes)
1da177e4 6 *
1da177e4
LT
7 * Copyright (C) IBM Corporation, 2002, 2004
8 *
9 * 2002-Oct Created by Vamsi Krishna S <vamsi_krishna@in.ibm.com> Kernel
10 * Probes initial implementation ( includes suggestions from
11 * Rusty Russell).
12 * 2004-July Suparna Bhattacharya <suparna@in.ibm.com> added jumper probes
13 * interface to access function arguments.
b94cce92
HN
14 * 2005-May Hien Nguyen <hien@us.ibm.com> and Jim Keniston
15 * <jkenisto@us.ibm.com> and Prasanna S Panchamukhi
16 * <prasanna@in.ibm.com> added function-return probes.
1da177e4 17 */
7d134b2c 18#include <linux/compiler.h>
36dcd67a 19#include <linux/linkage.h>
1da177e4
LT
20#include <linux/list.h>
21#include <linux/notifier.h>
22#include <linux/smp.h>
187f1882 23#include <linux/bug.h>
e6584523 24#include <linux/percpu.h>
3516a460
AM
25#include <linux/spinlock.h>
26#include <linux/rcupdate.h>
7a7d1cf9 27#include <linux/mutex.h>
ae6aa16f 28#include <linux/ftrace.h>
4bbd9345 29#include <linux/objpool.h>
73f9b911 30#include <linux/rethook.h>
7d134b2c 31#include <asm/kprobes.h>
b94cce92 32
00d7c05a 33#ifdef CONFIG_KPROBES
1da177e4 34
ea32c65c
PP
35/* kprobe_status settings */
36#define KPROBE_HIT_ACTIVE 0x00000001
37#define KPROBE_HIT_SS 0x00000002
38#define KPROBE_REENTER 0x00000004
39#define KPROBE_HIT_SSDONE 0x00000008
40
223a76b2 41#else /* !CONFIG_KPROBES */
7d134b2c 42#include <asm-generic/kprobes.h>
dc19835d
MH
43typedef int kprobe_opcode_t;
44struct arch_specific_insn {
45 int dummy;
46};
dc19835d 47#endif /* CONFIG_KPROBES */
d0aaff97 48
1da177e4
LT
49struct kprobe;
50struct pt_regs;
b94cce92
HN
51struct kretprobe;
52struct kretprobe_instance;
1da177e4 53typedef int (*kprobe_pre_handler_t) (struct kprobe *, struct pt_regs *);
1da177e4
LT
54typedef void (*kprobe_post_handler_t) (struct kprobe *, struct pt_regs *,
55 unsigned long flags);
b94cce92
HN
56typedef int (*kretprobe_handler_t) (struct kretprobe_instance *,
57 struct pt_regs *);
58
1da177e4
LT
59struct kprobe {
60 struct hlist_node hlist;
61
64f562c6
AM
62 /* list of kprobes for multi-handler support */
63 struct list_head list;
64
ea32c65c
PP
65 /*count the number of times this probe was temporarily disarmed */
66 unsigned long nmissed;
67
1da177e4
LT
68 /* location of the probe point */
69 kprobe_opcode_t *addr;
70
3a872d89 71 /* Allow user to indicate symbol name of the probe point */
9b3af29b 72 const char *symbol_name;
3a872d89
AM
73
74 /* Offset into the symbol */
75 unsigned int offset;
76
1da177e4
LT
77 /* Called before addr is executed. */
78 kprobe_pre_handler_t pre_handler;
79
80 /* Called after addr is executed, unless... */
81 kprobe_post_handler_t post_handler;
82
1da177e4
LT
83 /* Saved opcode (which has been replaced with breakpoint) */
84 kprobe_opcode_t opcode;
85
86 /* copy of the original instruction */
87 struct arch_specific_insn ainsn;
e8386a0c 88
de5bd88d
MH
89 /*
90 * Indicates various status flags.
91 * Protected by kprobe_mutex after this kprobe is registered.
92 */
e8386a0c 93 u32 flags;
1da177e4
LT
94};
95
e8386a0c
MH
96/* Kprobe status flags */
97#define KPROBE_FLAG_GONE 1 /* breakpoint has already gone */
de5bd88d 98#define KPROBE_FLAG_DISABLED 2 /* probe is temporarily disabled */
afd66255
MH
99#define KPROBE_FLAG_OPTIMIZED 4 /*
100 * probe is really optimized.
101 * NOTE:
102 * this flag is only for optimized_kprobe.
103 */
ae6aa16f 104#define KPROBE_FLAG_FTRACE 8 /* probe is using ftrace */
bf7a87f1 105#define KPROBE_FLAG_ON_FUNC_ENTRY 16 /* probe is on the function entry */
e8386a0c 106
de5bd88d 107/* Has this kprobe gone ? */
29e8077a 108static inline bool kprobe_gone(struct kprobe *p)
e8386a0c
MH
109{
110 return p->flags & KPROBE_FLAG_GONE;
111}
112
de5bd88d 113/* Is this kprobe disabled ? */
29e8077a 114static inline bool kprobe_disabled(struct kprobe *p)
de5bd88d
MH
115{
116 return p->flags & (KPROBE_FLAG_DISABLED | KPROBE_FLAG_GONE);
117}
afd66255
MH
118
119/* Is this kprobe really running optimized path ? */
29e8077a 120static inline bool kprobe_optimized(struct kprobe *p)
afd66255
MH
121{
122 return p->flags & KPROBE_FLAG_OPTIMIZED;
123}
ae6aa16f
MH
124
125/* Is this kprobe uses ftrace ? */
29e8077a 126static inline bool kprobe_ftrace(struct kprobe *p)
ae6aa16f
MH
127{
128 return p->flags & KPROBE_FLAG_FTRACE;
129}
130
b94cce92
HN
131/*
132 * Function-return probe -
133 * Note:
134 * User needs to provide a handler function, and initialize maxactive.
135 * maxactive - The maximum number of instances of the probed function that
136 * can be active concurrently.
137 * nmissed - tracks the number of times the probed function's return was
138 * ignored, due to maxactive being too low.
139 *
140 */
d741bf41 141struct kretprobe_holder {
d839a656 142 struct kretprobe __rcu *rp;
4bbd9345 143 struct objpool_head pool;
d741bf41
PZ
144};
145
b94cce92
HN
146struct kretprobe {
147 struct kprobe kp;
148 kretprobe_handler_t handler;
f47cd9b5 149 kretprobe_handler_t entry_handler;
b94cce92
HN
150 int maxactive;
151 int nmissed;
f47cd9b5 152 size_t data_size;
73f9b911
MH
153#ifdef CONFIG_KRETPROBE_ON_RETHOOK
154 struct rethook *rh;
155#else
d741bf41 156 struct kretprobe_holder *rph;
73f9b911 157#endif
b94cce92
HN
158};
159
6bbfa441
MH
160#define KRETPROBE_MAX_DATA_SIZE 4096
161
b94cce92 162struct kretprobe_instance {
73f9b911
MH
163#ifdef CONFIG_KRETPROBE_ON_RETHOOK
164 struct rethook_node node;
165#else
4bbd9345 166 struct rcu_head rcu;
6e426e0f 167 struct llist_node llist;
d741bf41 168 struct kretprobe_holder *rph;
802eae7c 169 kprobe_opcode_t *ret_addr;
3ff9c075 170 void *fp;
73f9b911 171#endif
67a862a9 172 char data[];
b94cce92
HN
173};
174
f438d914
MH
175struct kretprobe_blackpoint {
176 const char *name;
177 void *addr;
178};
3d8d996e 179
376e2424
MH
180struct kprobe_blacklist_entry {
181 struct list_head list;
3d8d996e 182 unsigned long start_addr;
376e2424 183 unsigned long end_addr;
3d8d996e
SD
184};
185
dc19835d
MH
186#ifdef CONFIG_KPROBES
187DECLARE_PER_CPU(struct kprobe *, current_kprobe);
188DECLARE_PER_CPU(struct kprobe_ctlblk, kprobe_ctlblk);
189
66ada2cc
MH
190extern void kprobe_busy_begin(void);
191extern void kprobe_busy_end(void);
192
dc19835d 193#ifdef CONFIG_KRETPROBES
73f9b911 194/* Check whether @p is used for implementing a trampoline. */
dc19835d 195extern int arch_trampoline_kprobe(struct kprobe *p);
66ada2cc 196
73f9b911
MH
197#ifdef CONFIG_KRETPROBE_ON_RETHOOK
198static nokprobe_inline struct kretprobe *get_kretprobe(struct kretprobe_instance *ri)
199{
a1461f1f
MHG
200 /* rethook::data is non-changed field, so that you can access it freely. */
201 return (struct kretprobe *)ri->node.rethook->data;
73f9b911
MH
202}
203static nokprobe_inline unsigned long get_kretprobe_retaddr(struct kretprobe_instance *ri)
204{
205 return ri->node.ret_addr;
206}
207#else
208extern void arch_prepare_kretprobe(struct kretprobe_instance *ri,
209 struct pt_regs *regs);
bf094cff
MH
210void arch_kretprobe_fixup_return(struct pt_regs *regs,
211 kprobe_opcode_t *correct_ret_addr);
212
adf8a61a 213void __kretprobe_trampoline(void);
96fed8ac
MH
214/*
215 * Since some architecture uses structured function pointer,
216 * use dereference_function_descriptor() to get real function address.
217 */
218static nokprobe_inline void *kretprobe_trampoline_addr(void)
219{
adf8a61a 220 return dereference_kernel_function_descriptor(__kretprobe_trampoline);
96fed8ac
MH
221}
222
66ada2cc
MH
223/* If the trampoline handler called from a kprobe, use this version */
224unsigned long __kretprobe_trampoline_handler(struct pt_regs *regs,
96fed8ac 225 void *frame_pointer);
66ada2cc
MH
226
227static nokprobe_inline
228unsigned long kretprobe_trampoline_handler(struct pt_regs *regs,
96fed8ac 229 void *frame_pointer)
66ada2cc
MH
230{
231 unsigned long ret;
232 /*
233 * Set a dummy kprobe for avoiding kretprobe recursion.
234 * Since kretprobe never runs in kprobe handler, no kprobe must
235 * be running at this point.
236 */
237 kprobe_busy_begin();
96fed8ac 238 ret = __kretprobe_trampoline_handler(regs, frame_pointer);
66ada2cc
MH
239 kprobe_busy_end();
240
241 return ret;
242}
243
d741bf41
PZ
244static nokprobe_inline struct kretprobe *get_kretprobe(struct kretprobe_instance *ri)
245{
d839a656 246 return rcu_dereference_check(ri->rph->rp, rcu_read_lock_any_held());
d741bf41
PZ
247}
248
73f9b911
MH
249static nokprobe_inline unsigned long get_kretprobe_retaddr(struct kretprobe_instance *ri)
250{
251 return (unsigned long)ri->ret_addr;
252}
253#endif /* CONFIG_KRETPROBE_ON_RETHOOK */
254
223a76b2 255#else /* !CONFIG_KRETPROBES */
dc19835d
MH
256static inline void arch_prepare_kretprobe(struct kretprobe *rp,
257 struct pt_regs *regs)
258{
259}
260static inline int arch_trampoline_kprobe(struct kprobe *p)
261{
262 return 0;
263}
264#endif /* CONFIG_KRETPROBES */
265
223a76b2
MH
266/* Markers of '_kprobe_blacklist' section */
267extern unsigned long __start_kprobe_blacklist[];
268extern unsigned long __stop_kprobe_blacklist[];
269
f438d914
MH
270extern struct kretprobe_blackpoint kretprobe_blacklist[];
271
1da177e4 272extern int arch_prepare_kprobe(struct kprobe *p);
7e1048b1
RL
273extern void arch_arm_kprobe(struct kprobe *p);
274extern void arch_disarm_kprobe(struct kprobe *p);
6772926b 275extern int arch_init_kprobes(void);
bf8d5c52 276extern void kprobes_inc_nmissed_count(struct kprobe *p);
be8f2743 277extern bool arch_within_kprobe_blacklist(unsigned long addr);
fb1a59fa 278extern int arch_populate_kprobe_blacklist(void);
97c753e6 279extern int kprobe_on_func_entry(kprobe_opcode_t *addr, const char *sym, unsigned long offset);
1da177e4 280
e5779e8e 281extern bool within_kprobe_blacklist(unsigned long addr);
fb1a59fa
MH
282extern int kprobe_add_ksym_blacklist(unsigned long entry);
283extern int kprobe_add_area_blacklist(unsigned long start, unsigned long end);
e5779e8e 284
c802d64a
HC
285struct kprobe_insn_cache {
286 struct mutex mutex;
af96397d
HC
287 void *(*alloc)(void); /* allocate insn page */
288 void (*free)(void *); /* free insn page */
d002b8bc 289 const char *sym; /* symbol for insn pages */
c802d64a
HC
290 struct list_head pages; /* list of kprobe_insn_page */
291 size_t insn_size; /* size of instruction slot */
292 int nr_garbage;
293};
294
5b485629 295#ifdef __ARCH_WANT_KPROBES_INSN_SLOT
c802d64a
HC
296extern kprobe_opcode_t *__get_insn_slot(struct kprobe_insn_cache *c);
297extern void __free_insn_slot(struct kprobe_insn_cache *c,
298 kprobe_opcode_t *slot, int dirty);
5b485629
MH
299/* sleep-less address checking routine */
300extern bool __is_insn_slot_addr(struct kprobe_insn_cache *c,
301 unsigned long addr);
c802d64a
HC
302
303#define DEFINE_INSN_CACHE_OPS(__name) \
304extern struct kprobe_insn_cache kprobe_##__name##_slots; \
305 \
306static inline kprobe_opcode_t *get_##__name##_slot(void) \
307{ \
308 return __get_insn_slot(&kprobe_##__name##_slots); \
309} \
310 \
311static inline void free_##__name##_slot(kprobe_opcode_t *slot, int dirty)\
312{ \
313 __free_insn_slot(&kprobe_##__name##_slots, slot, dirty); \
314} \
5b485629
MH
315 \
316static inline bool is_kprobe_##__name##_slot(unsigned long addr) \
317{ \
318 return __is_insn_slot_addr(&kprobe_##__name##_slots, addr); \
319}
d002b8bc
AH
320#define KPROBE_INSN_PAGE_SYM "kprobe_insn_page"
321#define KPROBE_OPTINSN_PAGE_SYM "kprobe_optinsn_page"
322int kprobe_cache_get_kallsym(struct kprobe_insn_cache *c, unsigned int *symnum,
323 unsigned long *value, char *type, char *sym);
223a76b2 324#else /* !__ARCH_WANT_KPROBES_INSN_SLOT */
5b485629
MH
325#define DEFINE_INSN_CACHE_OPS(__name) \
326static inline bool is_kprobe_##__name##_slot(unsigned long addr) \
327{ \
328 return 0; \
329}
330#endif
c802d64a
HC
331
332DEFINE_INSN_CACHE_OPS(insn);
333
afd66255
MH
334#ifdef CONFIG_OPTPROBES
335/*
336 * Internal structure for direct jump optimized probe
337 */
338struct optimized_kprobe {
339 struct kprobe kp;
340 struct list_head list; /* list for optimizing queue */
341 struct arch_optimized_insn optinsn;
342};
343
344/* Architecture dependent functions for direct jump optimization */
345extern int arch_prepared_optinsn(struct arch_optimized_insn *optinsn);
346extern int arch_check_optimized_kprobe(struct optimized_kprobe *op);
cbf6ab52
MH
347extern int arch_prepare_optimized_kprobe(struct optimized_kprobe *op,
348 struct kprobe *orig);
afd66255 349extern void arch_remove_optimized_kprobe(struct optimized_kprobe *op);
cd7ebe22 350extern void arch_optimize_kprobes(struct list_head *oplist);
f984ba4e
MH
351extern void arch_unoptimize_kprobes(struct list_head *oplist,
352 struct list_head *done_list);
afd66255 353extern void arch_unoptimize_kprobe(struct optimized_kprobe *op);
afd66255 354extern int arch_within_optimized_kprobe(struct optimized_kprobe *op,
c42421e2 355 kprobe_opcode_t *addr);
afd66255
MH
356
357extern void opt_pre_handler(struct kprobe *p, struct pt_regs *regs);
b2be84df 358
c802d64a
HC
359DEFINE_INSN_CACHE_OPS(optinsn);
360
30e7d894 361extern void wait_for_kprobe_optimizer(void);
868a6fc0 362bool optprobe_queued_unopt(struct optimized_kprobe *op);
f1c97a1b 363bool kprobe_disarmed(struct kprobe *p);
223a76b2 364#else /* !CONFIG_OPTPROBES */
30e7d894 365static inline void wait_for_kprobe_optimizer(void) { }
afd66255 366#endif /* CONFIG_OPTPROBES */
223a76b2 367
e7dbfe34 368#ifdef CONFIG_KPROBES_ON_FTRACE
ae6aa16f 369extern void kprobe_ftrace_handler(unsigned long ip, unsigned long parent_ip,
d19ad077 370 struct ftrace_ops *ops, struct ftrace_regs *fregs);
ae6aa16f 371extern int arch_prepare_kprobe_ftrace(struct kprobe *p);
1a7d0890
SB
372/* Set when ftrace has been killed: kprobes on ftrace must be disabled for safety */
373extern bool kprobe_ftrace_disabled __read_mostly;
374extern void kprobe_ftrace_kill(void);
02afb8d6
PA
375#else
376static inline int arch_prepare_kprobe_ftrace(struct kprobe *p)
377{
378 return -EINVAL;
379}
1a7d0890 380static inline void kprobe_ftrace_kill(void) {}
223a76b2 381#endif /* CONFIG_KPROBES_ON_FTRACE */
ae6aa16f 382
d217d545 383/* Get the kprobe at this addr (if any) - called with preemption disabled */
1da177e4
LT
384struct kprobe *get_kprobe(void *addr);
385
e6584523
AM
386/* kprobe_running() will just return the current_kprobe on this CPU */
387static inline struct kprobe *kprobe_running(void)
388{
223a76b2 389 return __this_cpu_read(current_kprobe);
e6584523
AM
390}
391
392static inline void reset_current_kprobe(void)
393{
b76834bc 394 __this_cpu_write(current_kprobe, NULL);
e6584523
AM
395}
396
397static inline struct kprobe_ctlblk *get_kprobe_ctlblk(void)
398{
bdffd893 399 return this_cpu_ptr(&kprobe_ctlblk);
e6584523
AM
400}
401
290e3070 402kprobe_opcode_t *kprobe_lookup_name(const char *name, unsigned int offset);
cc66bb91
PZ
403kprobe_opcode_t *arch_adjust_kprobe_addr(unsigned long addr, unsigned long offset, bool *on_func_entry);
404
1da177e4
LT
405int register_kprobe(struct kprobe *p);
406void unregister_kprobe(struct kprobe *p);
9861668f
MH
407int register_kprobes(struct kprobe **kps, int num);
408void unregister_kprobes(struct kprobe **kps, int num);
1da177e4 409
b94cce92
HN
410int register_kretprobe(struct kretprobe *rp);
411void unregister_kretprobe(struct kretprobe *rp);
4a296e07
MH
412int register_kretprobes(struct kretprobe **rps, int num);
413void unregister_kretprobes(struct kretprobe **rps, int num);
b94cce92 414
43994049 415#if defined(CONFIG_KRETPROBE_ON_RETHOOK) || !defined(CONFIG_KRETPROBES)
73f9b911
MH
416#define kprobe_flush_task(tk) do {} while (0)
417#else
b94cce92 418void kprobe_flush_task(struct task_struct *tk);
73f9b911 419#endif
8c1c9356 420
82d083ab
MH
421void kprobe_free_init_mem(void);
422
de5bd88d
MH
423int disable_kprobe(struct kprobe *kp);
424int enable_kprobe(struct kprobe *kp);
425
24851d24
FW
426void dump_kprobe(struct kprobe *kp);
427
ad3bc25a 428void *alloc_insn_page(void);
ad3bc25a 429
7ee3e97e
CL
430void *alloc_optinsn_page(void);
431void free_optinsn_page(void *page);
432
d002b8bc
AH
433int kprobe_get_kallsym(unsigned int symnum, unsigned long *value, char *type,
434 char *sym);
435
436int arch_kprobe_get_kallsym(unsigned int *symnum, unsigned long *value,
437 char *type, char *sym);
abc28463
AB
438
439int kprobe_exceptions_notify(struct notifier_block *self,
440 unsigned long val, void *data);
441
b1801812 442#else /* !CONFIG_KPROBES: */
00d7c05a 443
b1801812
IM
444static inline int kprobe_fault_handler(struct pt_regs *regs, int trapnr)
445{
446 return 0;
447}
785656a4
AS
448static inline struct kprobe *get_kprobe(void *addr)
449{
450 return NULL;
451}
e6584523 452static inline struct kprobe *kprobe_running(void)
1da177e4 453{
e6584523 454 return NULL;
1da177e4 455}
ab51e15d
MH
456#define kprobe_busy_begin() do {} while (0)
457#define kprobe_busy_end() do {} while (0)
458
1da177e4
LT
459static inline int register_kprobe(struct kprobe *p)
460{
223a76b2 461 return -EOPNOTSUPP;
1da177e4 462}
9861668f
MH
463static inline int register_kprobes(struct kprobe **kps, int num)
464{
223a76b2 465 return -EOPNOTSUPP;
9861668f 466}
1da177e4
LT
467static inline void unregister_kprobe(struct kprobe *p)
468{
469}
9861668f
MH
470static inline void unregister_kprobes(struct kprobe **kps, int num)
471{
472}
b94cce92
HN
473static inline int register_kretprobe(struct kretprobe *rp)
474{
223a76b2 475 return -EOPNOTSUPP;
b94cce92 476}
4a296e07
MH
477static inline int register_kretprobes(struct kretprobe **rps, int num)
478{
223a76b2 479 return -EOPNOTSUPP;
4a296e07 480}
b94cce92
HN
481static inline void unregister_kretprobe(struct kretprobe *rp)
482{
483}
4a296e07
MH
484static inline void unregister_kretprobes(struct kretprobe **rps, int num)
485{
486}
b94cce92
HN
487static inline void kprobe_flush_task(struct task_struct *tk)
488{
489}
82d083ab
MH
490static inline void kprobe_free_init_mem(void)
491{
492}
1a7d0890
SB
493static inline void kprobe_ftrace_kill(void)
494{
495}
de5bd88d
MH
496static inline int disable_kprobe(struct kprobe *kp)
497{
223a76b2 498 return -EOPNOTSUPP;
de5bd88d
MH
499}
500static inline int enable_kprobe(struct kprobe *kp)
501{
223a76b2 502 return -EOPNOTSUPP;
de5bd88d 503}
fab94075
BP
504
505static inline bool within_kprobe_blacklist(unsigned long addr)
506{
507 return true;
508}
d002b8bc
AH
509static inline int kprobe_get_kallsym(unsigned int symnum, unsigned long *value,
510 char *type, char *sym)
511{
512 return -ERANGE;
513}
b1801812 514#endif /* CONFIG_KPROBES */
223a76b2 515
8f9b1528
MH
516static inline int disable_kretprobe(struct kretprobe *rp)
517{
518 return disable_kprobe(&rp->kp);
519}
520static inline int enable_kretprobe(struct kretprobe *rp)
521{
522 return enable_kprobe(&rp->kp);
523}
8f9b1528 524
5b485629
MH
525#ifndef CONFIG_KPROBES
526static inline bool is_kprobe_insn_slot(unsigned long addr)
527{
528 return false;
529}
223a76b2
MH
530#endif /* !CONFIG_KPROBES */
531
5b485629
MH
532#ifndef CONFIG_OPTPROBES
533static inline bool is_kprobe_optinsn_slot(unsigned long addr)
534{
535 return false;
536}
223a76b2 537#endif /* !CONFIG_OPTPROBES */
5b485629 538
03bac0df 539#ifdef CONFIG_KRETPROBES
73f9b911
MH
540#ifdef CONFIG_KRETPROBE_ON_RETHOOK
541static nokprobe_inline bool is_kretprobe_trampoline(unsigned long addr)
542{
543 return is_rethook_trampoline(addr);
544}
545
546static nokprobe_inline
547unsigned long kretprobe_find_ret_addr(struct task_struct *tsk, void *fp,
548 struct llist_node **cur)
549{
550 return rethook_find_ret_addr(tsk, (unsigned long)fp, cur);
551}
552#else
03bac0df
MH
553static nokprobe_inline bool is_kretprobe_trampoline(unsigned long addr)
554{
555 return (void *)addr == kretprobe_trampoline_addr();
556}
557
558unsigned long kretprobe_find_ret_addr(struct task_struct *tsk, void *fp,
559 struct llist_node **cur);
73f9b911 560#endif
03bac0df
MH
561#else
562static nokprobe_inline bool is_kretprobe_trampoline(unsigned long addr)
563{
564 return false;
565}
566
567static nokprobe_inline
568unsigned long kretprobe_find_ret_addr(struct task_struct *tsk, void *fp,
569 struct llist_node **cur)
570{
571 return 0;
572}
573#endif
574
b98cca44
AK
575/* Returns true if kprobes handled the fault */
576static nokprobe_inline bool kprobe_page_fault(struct pt_regs *regs,
577 unsigned int trap)
578{
dfc05b55 579 if (!IS_ENABLED(CONFIG_KPROBES))
b98cca44
AK
580 return false;
581 if (user_mode(regs))
582 return false;
583 /*
584 * To be potentially processing a kprobe fault and to be allowed
585 * to call kprobe_running(), we have to be non-preemptible.
586 */
587 if (preemptible())
588 return false;
589 if (!kprobe_running())
590 return false;
591 return kprobe_fault_handler(regs, trap);
592}
593
b1801812 594#endif /* _LINUX_KPROBES_H */