11a59d1b8SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-or-later */ 21da177e4SLinus Torvalds #ifndef _LINUX_KPROBES_H 31da177e4SLinus Torvalds #define _LINUX_KPROBES_H 41da177e4SLinus Torvalds /* 51da177e4SLinus Torvalds * Kernel Probes (KProbes) 61da177e4SLinus Torvalds * include/linux/kprobes.h 71da177e4SLinus Torvalds * 81da177e4SLinus Torvalds * Copyright (C) IBM Corporation, 2002, 2004 91da177e4SLinus Torvalds * 101da177e4SLinus Torvalds * 2002-Oct Created by Vamsi Krishna S <vamsi_krishna@in.ibm.com> Kernel 111da177e4SLinus Torvalds * Probes initial implementation ( includes suggestions from 121da177e4SLinus Torvalds * Rusty Russell). 131da177e4SLinus Torvalds * 2004-July Suparna Bhattacharya <suparna@in.ibm.com> added jumper probes 141da177e4SLinus Torvalds * interface to access function arguments. 15b94cce92SHien Nguyen * 2005-May Hien Nguyen <hien@us.ibm.com> and Jim Keniston 16b94cce92SHien Nguyen * <jkenisto@us.ibm.com> and Prasanna S Panchamukhi 17b94cce92SHien Nguyen * <prasanna@in.ibm.com> added function-return probes. 181da177e4SLinus Torvalds */ 197d134b2cSLuis R. Rodriguez #include <linux/compiler.h> 2036dcd67aSIngo Molnar #include <linux/linkage.h> 211da177e4SLinus Torvalds #include <linux/list.h> 221da177e4SLinus Torvalds #include <linux/notifier.h> 231da177e4SLinus Torvalds #include <linux/smp.h> 24187f1882SPaul Gortmaker #include <linux/bug.h> 25e6584523SAnanth N Mavinakayanahalli #include <linux/percpu.h> 263516a460SAnanth N Mavinakayanahalli #include <linux/spinlock.h> 273516a460SAnanth N Mavinakayanahalli #include <linux/rcupdate.h> 287a7d1cf9SIngo Molnar #include <linux/mutex.h> 29ae6aa16fSMasami Hiramatsu #include <linux/ftrace.h> 307d134b2cSLuis R. Rodriguez #include <asm/kprobes.h> 31b94cce92SHien Nguyen 3200d7c05aSKeshavamurthy Anil S #ifdef CONFIG_KPROBES 331da177e4SLinus Torvalds 34ea32c65cSPrasanna S Panchamukhi /* kprobe_status settings */ 35ea32c65cSPrasanna S Panchamukhi #define KPROBE_HIT_ACTIVE 0x00000001 36ea32c65cSPrasanna S Panchamukhi #define KPROBE_HIT_SS 0x00000002 37ea32c65cSPrasanna S Panchamukhi #define KPROBE_REENTER 0x00000004 38ea32c65cSPrasanna S Panchamukhi #define KPROBE_HIT_SSDONE 0x00000008 39ea32c65cSPrasanna S Panchamukhi 40dc19835dSMasami Hiramatsu #else /* CONFIG_KPROBES */ 417d134b2cSLuis R. Rodriguez #include <asm-generic/kprobes.h> 42dc19835dSMasami Hiramatsu typedef int kprobe_opcode_t; 43dc19835dSMasami Hiramatsu struct arch_specific_insn { 44dc19835dSMasami Hiramatsu int dummy; 45dc19835dSMasami Hiramatsu }; 46dc19835dSMasami Hiramatsu #endif /* CONFIG_KPROBES */ 47d0aaff97SPrasanna S Panchamukhi 481da177e4SLinus Torvalds struct kprobe; 491da177e4SLinus Torvalds struct pt_regs; 50b94cce92SHien Nguyen struct kretprobe; 51b94cce92SHien Nguyen struct kretprobe_instance; 521da177e4SLinus Torvalds typedef int (*kprobe_pre_handler_t) (struct kprobe *, struct pt_regs *); 531da177e4SLinus Torvalds typedef void (*kprobe_post_handler_t) (struct kprobe *, struct pt_regs *, 541da177e4SLinus Torvalds unsigned long flags); 551da177e4SLinus Torvalds typedef int (*kprobe_fault_handler_t) (struct kprobe *, struct pt_regs *, 561da177e4SLinus Torvalds int trapnr); 57b94cce92SHien Nguyen typedef int (*kretprobe_handler_t) (struct kretprobe_instance *, 58b94cce92SHien Nguyen struct pt_regs *); 59b94cce92SHien Nguyen 601da177e4SLinus Torvalds struct kprobe { 611da177e4SLinus Torvalds struct hlist_node hlist; 621da177e4SLinus Torvalds 6364f562c6SAnanth N Mavinakayanahalli /* list of kprobes for multi-handler support */ 6464f562c6SAnanth N Mavinakayanahalli struct list_head list; 6564f562c6SAnanth N Mavinakayanahalli 66ea32c65cSPrasanna S Panchamukhi /*count the number of times this probe was temporarily disarmed */ 67ea32c65cSPrasanna S Panchamukhi unsigned long nmissed; 68ea32c65cSPrasanna S Panchamukhi 691da177e4SLinus Torvalds /* location of the probe point */ 701da177e4SLinus Torvalds kprobe_opcode_t *addr; 711da177e4SLinus Torvalds 723a872d89SAnanth N Mavinakayanahalli /* Allow user to indicate symbol name of the probe point */ 739b3af29bSAnanth N Mavinakayanahalli const char *symbol_name; 743a872d89SAnanth N Mavinakayanahalli 753a872d89SAnanth N Mavinakayanahalli /* Offset into the symbol */ 763a872d89SAnanth N Mavinakayanahalli unsigned int offset; 773a872d89SAnanth N Mavinakayanahalli 781da177e4SLinus Torvalds /* Called before addr is executed. */ 791da177e4SLinus Torvalds kprobe_pre_handler_t pre_handler; 801da177e4SLinus Torvalds 811da177e4SLinus Torvalds /* Called after addr is executed, unless... */ 821da177e4SLinus Torvalds kprobe_post_handler_t post_handler; 831da177e4SLinus Torvalds 84cc00e9cfSMasami Hiramatsu /* 85cc00e9cfSMasami Hiramatsu * ... called if executing addr causes a fault (eg. page fault). 86cc00e9cfSMasami Hiramatsu * Return 1 if it handled fault, otherwise kernel will see it. 87cc00e9cfSMasami Hiramatsu */ 881da177e4SLinus Torvalds kprobe_fault_handler_t fault_handler; 891da177e4SLinus Torvalds 901da177e4SLinus Torvalds /* Saved opcode (which has been replaced with breakpoint) */ 911da177e4SLinus Torvalds kprobe_opcode_t opcode; 921da177e4SLinus Torvalds 931da177e4SLinus Torvalds /* copy of the original instruction */ 941da177e4SLinus Torvalds struct arch_specific_insn ainsn; 95e8386a0cSMasami Hiramatsu 96de5bd88dSMasami Hiramatsu /* 97de5bd88dSMasami Hiramatsu * Indicates various status flags. 98de5bd88dSMasami Hiramatsu * Protected by kprobe_mutex after this kprobe is registered. 99de5bd88dSMasami Hiramatsu */ 100e8386a0cSMasami Hiramatsu u32 flags; 1011da177e4SLinus Torvalds }; 1021da177e4SLinus Torvalds 103e8386a0cSMasami Hiramatsu /* Kprobe status flags */ 104e8386a0cSMasami Hiramatsu #define KPROBE_FLAG_GONE 1 /* breakpoint has already gone */ 105de5bd88dSMasami Hiramatsu #define KPROBE_FLAG_DISABLED 2 /* probe is temporarily disabled */ 106afd66255SMasami Hiramatsu #define KPROBE_FLAG_OPTIMIZED 4 /* 107afd66255SMasami Hiramatsu * probe is really optimized. 108afd66255SMasami Hiramatsu * NOTE: 109afd66255SMasami Hiramatsu * this flag is only for optimized_kprobe. 110afd66255SMasami Hiramatsu */ 111ae6aa16fSMasami Hiramatsu #define KPROBE_FLAG_FTRACE 8 /* probe is using ftrace */ 112e8386a0cSMasami Hiramatsu 113de5bd88dSMasami Hiramatsu /* Has this kprobe gone ? */ 114e8386a0cSMasami Hiramatsu static inline int kprobe_gone(struct kprobe *p) 115e8386a0cSMasami Hiramatsu { 116e8386a0cSMasami Hiramatsu return p->flags & KPROBE_FLAG_GONE; 117e8386a0cSMasami Hiramatsu } 118e8386a0cSMasami Hiramatsu 119de5bd88dSMasami Hiramatsu /* Is this kprobe disabled ? */ 120de5bd88dSMasami Hiramatsu static inline int kprobe_disabled(struct kprobe *p) 121de5bd88dSMasami Hiramatsu { 122de5bd88dSMasami Hiramatsu return p->flags & (KPROBE_FLAG_DISABLED | KPROBE_FLAG_GONE); 123de5bd88dSMasami Hiramatsu } 124afd66255SMasami Hiramatsu 125afd66255SMasami Hiramatsu /* Is this kprobe really running optimized path ? */ 126afd66255SMasami Hiramatsu static inline int kprobe_optimized(struct kprobe *p) 127afd66255SMasami Hiramatsu { 128afd66255SMasami Hiramatsu return p->flags & KPROBE_FLAG_OPTIMIZED; 129afd66255SMasami Hiramatsu } 130ae6aa16fSMasami Hiramatsu 131ae6aa16fSMasami Hiramatsu /* Is this kprobe uses ftrace ? */ 132ae6aa16fSMasami Hiramatsu static inline int kprobe_ftrace(struct kprobe *p) 133ae6aa16fSMasami Hiramatsu { 134ae6aa16fSMasami Hiramatsu return p->flags & KPROBE_FLAG_FTRACE; 135ae6aa16fSMasami Hiramatsu } 136ae6aa16fSMasami Hiramatsu 1371da177e4SLinus Torvalds /* 138b94cce92SHien Nguyen * Function-return probe - 139b94cce92SHien Nguyen * Note: 140b94cce92SHien Nguyen * User needs to provide a handler function, and initialize maxactive. 141b94cce92SHien Nguyen * maxactive - The maximum number of instances of the probed function that 142b94cce92SHien Nguyen * can be active concurrently. 143b94cce92SHien Nguyen * nmissed - tracks the number of times the probed function's return was 144b94cce92SHien Nguyen * ignored, due to maxactive being too low. 145b94cce92SHien Nguyen * 146b94cce92SHien Nguyen */ 147b94cce92SHien Nguyen struct kretprobe { 148b94cce92SHien Nguyen struct kprobe kp; 149b94cce92SHien Nguyen kretprobe_handler_t handler; 150f47cd9b5SAbhishek Sagar kretprobe_handler_t entry_handler; 151b94cce92SHien Nguyen int maxactive; 152b94cce92SHien Nguyen int nmissed; 153f47cd9b5SAbhishek Sagar size_t data_size; 154b94cce92SHien Nguyen struct hlist_head free_instances; 155ec484608SThomas Gleixner raw_spinlock_t lock; 156b94cce92SHien Nguyen }; 157b94cce92SHien Nguyen 158b94cce92SHien Nguyen struct kretprobe_instance { 159b94cce92SHien Nguyen struct hlist_node hlist; 160b94cce92SHien Nguyen struct kretprobe *rp; 161802eae7cSRusty Lynch kprobe_opcode_t *ret_addr; 162802eae7cSRusty Lynch struct task_struct *task; 1633ff9c075SMasami Hiramatsu void *fp; 164f47cd9b5SAbhishek Sagar char data[0]; 165b94cce92SHien Nguyen }; 166b94cce92SHien Nguyen 167f438d914SMasami Hiramatsu struct kretprobe_blackpoint { 168f438d914SMasami Hiramatsu const char *name; 169f438d914SMasami Hiramatsu void *addr; 170f438d914SMasami Hiramatsu }; 1713d8d996eSSrinivasa Ds 172376e2424SMasami Hiramatsu struct kprobe_blacklist_entry { 173376e2424SMasami Hiramatsu struct list_head list; 1743d8d996eSSrinivasa Ds unsigned long start_addr; 175376e2424SMasami Hiramatsu unsigned long end_addr; 1763d8d996eSSrinivasa Ds }; 1773d8d996eSSrinivasa Ds 178dc19835dSMasami Hiramatsu #ifdef CONFIG_KPROBES 179dc19835dSMasami Hiramatsu DECLARE_PER_CPU(struct kprobe *, current_kprobe); 180dc19835dSMasami Hiramatsu DECLARE_PER_CPU(struct kprobe_ctlblk, kprobe_ctlblk); 181dc19835dSMasami Hiramatsu 182b1801812SIngo Molnar /* 183b1801812SIngo Molnar * For #ifdef avoidance: 184b1801812SIngo Molnar */ 185b1801812SIngo Molnar static inline int kprobes_built_in(void) 186b1801812SIngo Molnar { 187b1801812SIngo Molnar return 1; 188b1801812SIngo Molnar } 189b1801812SIngo Molnar 190dc19835dSMasami Hiramatsu #ifdef CONFIG_KRETPROBES 191dc19835dSMasami Hiramatsu extern void arch_prepare_kretprobe(struct kretprobe_instance *ri, 192dc19835dSMasami Hiramatsu struct pt_regs *regs); 193dc19835dSMasami Hiramatsu extern int arch_trampoline_kprobe(struct kprobe *p); 194dc19835dSMasami Hiramatsu #else /* CONFIG_KRETPROBES */ 195dc19835dSMasami Hiramatsu static inline void arch_prepare_kretprobe(struct kretprobe *rp, 196dc19835dSMasami Hiramatsu struct pt_regs *regs) 197dc19835dSMasami Hiramatsu { 198dc19835dSMasami Hiramatsu } 199dc19835dSMasami Hiramatsu static inline int arch_trampoline_kprobe(struct kprobe *p) 200dc19835dSMasami Hiramatsu { 201dc19835dSMasami Hiramatsu return 0; 202dc19835dSMasami Hiramatsu } 203dc19835dSMasami Hiramatsu #endif /* CONFIG_KRETPROBES */ 204dc19835dSMasami Hiramatsu 205f438d914SMasami Hiramatsu extern struct kretprobe_blackpoint kretprobe_blacklist[]; 206f438d914SMasami Hiramatsu 2070f95b7fcSAnanth N Mavinakayanahalli static inline void kretprobe_assert(struct kretprobe_instance *ri, 2080f95b7fcSAnanth N Mavinakayanahalli unsigned long orig_ret_address, unsigned long trampoline_address) 2090f95b7fcSAnanth N Mavinakayanahalli { 2100f95b7fcSAnanth N Mavinakayanahalli if (!orig_ret_address || (orig_ret_address == trampoline_address)) { 2110f95b7fcSAnanth N Mavinakayanahalli printk("kretprobe BUG!: Processing kretprobe %p @ %p\n", 2120f95b7fcSAnanth N Mavinakayanahalli ri->rp, ri->rp->kp.addr); 2130f95b7fcSAnanth N Mavinakayanahalli BUG(); 2140f95b7fcSAnanth N Mavinakayanahalli } 2150f95b7fcSAnanth N Mavinakayanahalli } 2160f95b7fcSAnanth N Mavinakayanahalli 2178c1c9356SAnanth N Mavinakayanahalli #ifdef CONFIG_KPROBES_SANITY_TEST 2188c1c9356SAnanth N Mavinakayanahalli extern int init_test_probes(void); 2198c1c9356SAnanth N Mavinakayanahalli #else 2208c1c9356SAnanth N Mavinakayanahalli static inline int init_test_probes(void) 2218c1c9356SAnanth N Mavinakayanahalli { 2228c1c9356SAnanth N Mavinakayanahalli return 0; 2238c1c9356SAnanth N Mavinakayanahalli } 2248c1c9356SAnanth N Mavinakayanahalli #endif /* CONFIG_KPROBES_SANITY_TEST */ 2258c1c9356SAnanth N Mavinakayanahalli 2261da177e4SLinus Torvalds extern int arch_prepare_kprobe(struct kprobe *p); 2277e1048b1SRusty Lynch extern void arch_arm_kprobe(struct kprobe *p); 2287e1048b1SRusty Lynch extern void arch_disarm_kprobe(struct kprobe *p); 2296772926bSRusty Lynch extern int arch_init_kprobes(void); 2301da177e4SLinus Torvalds extern void show_registers(struct pt_regs *regs); 231bf8d5c52SKeshavamurthy Anil S extern void kprobes_inc_nmissed_count(struct kprobe *p); 232be8f2743SMasami Hiramatsu extern bool arch_within_kprobe_blacklist(unsigned long addr); 233fb1a59faSMasami Hiramatsu extern int arch_populate_kprobe_blacklist(void); 234659b957fSNaveen N. Rao extern bool arch_kprobe_on_func_entry(unsigned long offset); 235659b957fSNaveen N. Rao extern bool kprobe_on_func_entry(kprobe_opcode_t *addr, const char *sym, unsigned long offset); 2361da177e4SLinus Torvalds 237e5779e8eSAndy Lutomirski extern bool within_kprobe_blacklist(unsigned long addr); 238fb1a59faSMasami Hiramatsu extern int kprobe_add_ksym_blacklist(unsigned long entry); 239fb1a59faSMasami Hiramatsu extern int kprobe_add_area_blacklist(unsigned long start, unsigned long end); 240e5779e8eSAndy Lutomirski 241c802d64aSHeiko Carstens struct kprobe_insn_cache { 242c802d64aSHeiko Carstens struct mutex mutex; 243af96397dSHeiko Carstens void *(*alloc)(void); /* allocate insn page */ 244af96397dSHeiko Carstens void (*free)(void *); /* free insn page */ 245c802d64aSHeiko Carstens struct list_head pages; /* list of kprobe_insn_page */ 246c802d64aSHeiko Carstens size_t insn_size; /* size of instruction slot */ 247c802d64aSHeiko Carstens int nr_garbage; 248c802d64aSHeiko Carstens }; 249c802d64aSHeiko Carstens 2505b485629SMasami Hiramatsu #ifdef __ARCH_WANT_KPROBES_INSN_SLOT 251c802d64aSHeiko Carstens extern kprobe_opcode_t *__get_insn_slot(struct kprobe_insn_cache *c); 252c802d64aSHeiko Carstens extern void __free_insn_slot(struct kprobe_insn_cache *c, 253c802d64aSHeiko Carstens kprobe_opcode_t *slot, int dirty); 2545b485629SMasami Hiramatsu /* sleep-less address checking routine */ 2555b485629SMasami Hiramatsu extern bool __is_insn_slot_addr(struct kprobe_insn_cache *c, 2565b485629SMasami Hiramatsu unsigned long addr); 257c802d64aSHeiko Carstens 258c802d64aSHeiko Carstens #define DEFINE_INSN_CACHE_OPS(__name) \ 259c802d64aSHeiko Carstens extern struct kprobe_insn_cache kprobe_##__name##_slots; \ 260c802d64aSHeiko Carstens \ 261c802d64aSHeiko Carstens static inline kprobe_opcode_t *get_##__name##_slot(void) \ 262c802d64aSHeiko Carstens { \ 263c802d64aSHeiko Carstens return __get_insn_slot(&kprobe_##__name##_slots); \ 264c802d64aSHeiko Carstens } \ 265c802d64aSHeiko Carstens \ 266c802d64aSHeiko Carstens static inline void free_##__name##_slot(kprobe_opcode_t *slot, int dirty)\ 267c802d64aSHeiko Carstens { \ 268c802d64aSHeiko Carstens __free_insn_slot(&kprobe_##__name##_slots, slot, dirty); \ 269c802d64aSHeiko Carstens } \ 2705b485629SMasami Hiramatsu \ 2715b485629SMasami Hiramatsu static inline bool is_kprobe_##__name##_slot(unsigned long addr) \ 2725b485629SMasami Hiramatsu { \ 2735b485629SMasami Hiramatsu return __is_insn_slot_addr(&kprobe_##__name##_slots, addr); \ 2745b485629SMasami Hiramatsu } 2755b485629SMasami Hiramatsu #else /* __ARCH_WANT_KPROBES_INSN_SLOT */ 2765b485629SMasami Hiramatsu #define DEFINE_INSN_CACHE_OPS(__name) \ 2775b485629SMasami Hiramatsu static inline bool is_kprobe_##__name##_slot(unsigned long addr) \ 2785b485629SMasami Hiramatsu { \ 2795b485629SMasami Hiramatsu return 0; \ 2805b485629SMasami Hiramatsu } 2815b485629SMasami Hiramatsu #endif 282c802d64aSHeiko Carstens 283c802d64aSHeiko Carstens DEFINE_INSN_CACHE_OPS(insn); 284c802d64aSHeiko Carstens 285afd66255SMasami Hiramatsu #ifdef CONFIG_OPTPROBES 286afd66255SMasami Hiramatsu /* 287afd66255SMasami Hiramatsu * Internal structure for direct jump optimized probe 288afd66255SMasami Hiramatsu */ 289afd66255SMasami Hiramatsu struct optimized_kprobe { 290afd66255SMasami Hiramatsu struct kprobe kp; 291afd66255SMasami Hiramatsu struct list_head list; /* list for optimizing queue */ 292afd66255SMasami Hiramatsu struct arch_optimized_insn optinsn; 293afd66255SMasami Hiramatsu }; 294afd66255SMasami Hiramatsu 295afd66255SMasami Hiramatsu /* Architecture dependent functions for direct jump optimization */ 296afd66255SMasami Hiramatsu extern int arch_prepared_optinsn(struct arch_optimized_insn *optinsn); 297afd66255SMasami Hiramatsu extern int arch_check_optimized_kprobe(struct optimized_kprobe *op); 298cbf6ab52SMasami Hiramatsu extern int arch_prepare_optimized_kprobe(struct optimized_kprobe *op, 299cbf6ab52SMasami Hiramatsu struct kprobe *orig); 300afd66255SMasami Hiramatsu extern void arch_remove_optimized_kprobe(struct optimized_kprobe *op); 301cd7ebe22SMasami Hiramatsu extern void arch_optimize_kprobes(struct list_head *oplist); 302f984ba4eSMasami Hiramatsu extern void arch_unoptimize_kprobes(struct list_head *oplist, 303f984ba4eSMasami Hiramatsu struct list_head *done_list); 304afd66255SMasami Hiramatsu extern void arch_unoptimize_kprobe(struct optimized_kprobe *op); 305afd66255SMasami Hiramatsu extern int arch_within_optimized_kprobe(struct optimized_kprobe *op, 306afd66255SMasami Hiramatsu unsigned long addr); 307afd66255SMasami Hiramatsu 308afd66255SMasami Hiramatsu extern void opt_pre_handler(struct kprobe *p, struct pt_regs *regs); 309b2be84dfSMasami Hiramatsu 310c802d64aSHeiko Carstens DEFINE_INSN_CACHE_OPS(optinsn); 311c802d64aSHeiko Carstens 312b2be84dfSMasami Hiramatsu #ifdef CONFIG_SYSCTL 313b2be84dfSMasami Hiramatsu extern int sysctl_kprobes_optimization; 314b2be84dfSMasami Hiramatsu extern int proc_kprobes_optimization_handler(struct ctl_table *table, 315b2be84dfSMasami Hiramatsu int write, void __user *buffer, 316b2be84dfSMasami Hiramatsu size_t *length, loff_t *ppos); 317b2be84dfSMasami Hiramatsu #endif 31830e7d894SThomas Gleixner extern void wait_for_kprobe_optimizer(void); 31930e7d894SThomas Gleixner #else 32030e7d894SThomas Gleixner static inline void wait_for_kprobe_optimizer(void) { } 321afd66255SMasami Hiramatsu #endif /* CONFIG_OPTPROBES */ 322e7dbfe34SMasami Hiramatsu #ifdef CONFIG_KPROBES_ON_FTRACE 323ae6aa16fSMasami Hiramatsu extern void kprobe_ftrace_handler(unsigned long ip, unsigned long parent_ip, 324e5253896SMasami Hiramatsu struct ftrace_ops *ops, struct pt_regs *regs); 325ae6aa16fSMasami Hiramatsu extern int arch_prepare_kprobe_ftrace(struct kprobe *p); 326ae6aa16fSMasami Hiramatsu #endif 327ae6aa16fSMasami Hiramatsu 328f7f242ffSHeiko Carstens int arch_check_ftrace_location(struct kprobe *p); 329afd66255SMasami Hiramatsu 330d217d545SAnanth N Mavinakayanahalli /* Get the kprobe at this addr (if any) - called with preemption disabled */ 3311da177e4SLinus Torvalds struct kprobe *get_kprobe(void *addr); 332ef53d9c5SSrinivasa D S void kretprobe_hash_lock(struct task_struct *tsk, 333ef53d9c5SSrinivasa D S struct hlist_head **head, unsigned long *flags); 334ef53d9c5SSrinivasa D S void kretprobe_hash_unlock(struct task_struct *tsk, unsigned long *flags); 335b94cce92SHien Nguyen struct hlist_head * kretprobe_inst_table_head(struct task_struct *tsk); 3361da177e4SLinus Torvalds 337e6584523SAnanth N Mavinakayanahalli /* kprobe_running() will just return the current_kprobe on this CPU */ 338e6584523SAnanth N Mavinakayanahalli static inline struct kprobe *kprobe_running(void) 339e6584523SAnanth N Mavinakayanahalli { 340b76834bcSChristoph Lameter return (__this_cpu_read(current_kprobe)); 341e6584523SAnanth N Mavinakayanahalli } 342e6584523SAnanth N Mavinakayanahalli 343e6584523SAnanth N Mavinakayanahalli static inline void reset_current_kprobe(void) 344e6584523SAnanth N Mavinakayanahalli { 345b76834bcSChristoph Lameter __this_cpu_write(current_kprobe, NULL); 346e6584523SAnanth N Mavinakayanahalli } 347e6584523SAnanth N Mavinakayanahalli 348e6584523SAnanth N Mavinakayanahalli static inline struct kprobe_ctlblk *get_kprobe_ctlblk(void) 349e6584523SAnanth N Mavinakayanahalli { 350bdffd893SChristoph Lameter return this_cpu_ptr(&kprobe_ctlblk); 351e6584523SAnanth N Mavinakayanahalli } 352e6584523SAnanth N Mavinakayanahalli 353290e3070SNaveen N. Rao kprobe_opcode_t *kprobe_lookup_name(const char *name, unsigned int offset); 3541da177e4SLinus Torvalds int register_kprobe(struct kprobe *p); 3551da177e4SLinus Torvalds void unregister_kprobe(struct kprobe *p); 3569861668fSMasami Hiramatsu int register_kprobes(struct kprobe **kps, int num); 3579861668fSMasami Hiramatsu void unregister_kprobes(struct kprobe **kps, int num); 3583d7e3382SMichael Ellerman unsigned long arch_deref_entry_point(void *); 3591da177e4SLinus Torvalds 360b94cce92SHien Nguyen int register_kretprobe(struct kretprobe *rp); 361b94cce92SHien Nguyen void unregister_kretprobe(struct kretprobe *rp); 3624a296e07SMasami Hiramatsu int register_kretprobes(struct kretprobe **rps, int num); 3634a296e07SMasami Hiramatsu void unregister_kretprobes(struct kretprobe **rps, int num); 364b94cce92SHien Nguyen 365b94cce92SHien Nguyen void kprobe_flush_task(struct task_struct *tk); 36699219a3fSbibo,mao void recycle_rp_inst(struct kretprobe_instance *ri, struct hlist_head *head); 3678c1c9356SAnanth N Mavinakayanahalli 368de5bd88dSMasami Hiramatsu int disable_kprobe(struct kprobe *kp); 369de5bd88dSMasami Hiramatsu int enable_kprobe(struct kprobe *kp); 370de5bd88dSMasami Hiramatsu 37124851d24SFrederic Weisbecker void dump_kprobe(struct kprobe *kp); 37224851d24SFrederic Weisbecker 373ad3bc25aSBorislav Petkov void *alloc_insn_page(void); 374ad3bc25aSBorislav Petkov void free_insn_page(void *page); 375ad3bc25aSBorislav Petkov 376b1801812SIngo Molnar #else /* !CONFIG_KPROBES: */ 37700d7c05aSKeshavamurthy Anil S 378b1801812SIngo Molnar static inline int kprobes_built_in(void) 379b1801812SIngo Molnar { 380b1801812SIngo Molnar return 0; 381b1801812SIngo Molnar } 382b1801812SIngo Molnar static inline int kprobe_fault_handler(struct pt_regs *regs, int trapnr) 383b1801812SIngo Molnar { 384b1801812SIngo Molnar return 0; 385b1801812SIngo Molnar } 386785656a4SAbhishek Sagar static inline struct kprobe *get_kprobe(void *addr) 387785656a4SAbhishek Sagar { 388785656a4SAbhishek Sagar return NULL; 389785656a4SAbhishek Sagar } 390e6584523SAnanth N Mavinakayanahalli static inline struct kprobe *kprobe_running(void) 3911da177e4SLinus Torvalds { 392e6584523SAnanth N Mavinakayanahalli return NULL; 3931da177e4SLinus Torvalds } 3941da177e4SLinus Torvalds static inline int register_kprobe(struct kprobe *p) 3951da177e4SLinus Torvalds { 3961da177e4SLinus Torvalds return -ENOSYS; 3971da177e4SLinus Torvalds } 3989861668fSMasami Hiramatsu static inline int register_kprobes(struct kprobe **kps, int num) 3999861668fSMasami Hiramatsu { 4009861668fSMasami Hiramatsu return -ENOSYS; 4019861668fSMasami Hiramatsu } 4021da177e4SLinus Torvalds static inline void unregister_kprobe(struct kprobe *p) 4031da177e4SLinus Torvalds { 4041da177e4SLinus Torvalds } 4059861668fSMasami Hiramatsu static inline void unregister_kprobes(struct kprobe **kps, int num) 4069861668fSMasami Hiramatsu { 4079861668fSMasami Hiramatsu } 408b94cce92SHien Nguyen static inline int register_kretprobe(struct kretprobe *rp) 409b94cce92SHien Nguyen { 410b94cce92SHien Nguyen return -ENOSYS; 411b94cce92SHien Nguyen } 4124a296e07SMasami Hiramatsu static inline int register_kretprobes(struct kretprobe **rps, int num) 4134a296e07SMasami Hiramatsu { 4144a296e07SMasami Hiramatsu return -ENOSYS; 4154a296e07SMasami Hiramatsu } 416b94cce92SHien Nguyen static inline void unregister_kretprobe(struct kretprobe *rp) 417b94cce92SHien Nguyen { 418b94cce92SHien Nguyen } 4194a296e07SMasami Hiramatsu static inline void unregister_kretprobes(struct kretprobe **rps, int num) 4204a296e07SMasami Hiramatsu { 4214a296e07SMasami Hiramatsu } 422b94cce92SHien Nguyen static inline void kprobe_flush_task(struct task_struct *tk) 423b94cce92SHien Nguyen { 424b94cce92SHien Nguyen } 425de5bd88dSMasami Hiramatsu static inline int disable_kprobe(struct kprobe *kp) 426de5bd88dSMasami Hiramatsu { 427de5bd88dSMasami Hiramatsu return -ENOSYS; 428de5bd88dSMasami Hiramatsu } 429de5bd88dSMasami Hiramatsu static inline int enable_kprobe(struct kprobe *kp) 430de5bd88dSMasami Hiramatsu { 431de5bd88dSMasami Hiramatsu return -ENOSYS; 432de5bd88dSMasami Hiramatsu } 433fab94075SBorislav Petkov 434fab94075SBorislav Petkov static inline bool within_kprobe_blacklist(unsigned long addr) 435fab94075SBorislav Petkov { 436fab94075SBorislav Petkov return true; 437fab94075SBorislav Petkov } 438b94cce92SHien Nguyen #endif /* CONFIG_KPROBES */ 4398f9b1528SMasami Hiramatsu static inline int disable_kretprobe(struct kretprobe *rp) 4408f9b1528SMasami Hiramatsu { 4418f9b1528SMasami Hiramatsu return disable_kprobe(&rp->kp); 4428f9b1528SMasami Hiramatsu } 4438f9b1528SMasami Hiramatsu static inline int enable_kretprobe(struct kretprobe *rp) 4448f9b1528SMasami Hiramatsu { 4458f9b1528SMasami Hiramatsu return enable_kprobe(&rp->kp); 4468f9b1528SMasami Hiramatsu } 4478f9b1528SMasami Hiramatsu 4485b485629SMasami Hiramatsu #ifndef CONFIG_KPROBES 4495b485629SMasami Hiramatsu static inline bool is_kprobe_insn_slot(unsigned long addr) 4505b485629SMasami Hiramatsu { 4515b485629SMasami Hiramatsu return false; 4525b485629SMasami Hiramatsu } 4535b485629SMasami Hiramatsu #endif 4545b485629SMasami Hiramatsu #ifndef CONFIG_OPTPROBES 4555b485629SMasami Hiramatsu static inline bool is_kprobe_optinsn_slot(unsigned long addr) 4565b485629SMasami Hiramatsu { 4575b485629SMasami Hiramatsu return false; 4585b485629SMasami Hiramatsu } 4595b485629SMasami Hiramatsu #endif 4605b485629SMasami Hiramatsu 461*b98cca44SAnshuman Khandual /* Returns true if kprobes handled the fault */ 462*b98cca44SAnshuman Khandual static nokprobe_inline bool kprobe_page_fault(struct pt_regs *regs, 463*b98cca44SAnshuman Khandual unsigned int trap) 464*b98cca44SAnshuman Khandual { 465*b98cca44SAnshuman Khandual if (!kprobes_built_in()) 466*b98cca44SAnshuman Khandual return false; 467*b98cca44SAnshuman Khandual if (user_mode(regs)) 468*b98cca44SAnshuman Khandual return false; 469*b98cca44SAnshuman Khandual /* 470*b98cca44SAnshuman Khandual * To be potentially processing a kprobe fault and to be allowed 471*b98cca44SAnshuman Khandual * to call kprobe_running(), we have to be non-preemptible. 472*b98cca44SAnshuman Khandual */ 473*b98cca44SAnshuman Khandual if (preemptible()) 474*b98cca44SAnshuman Khandual return false; 475*b98cca44SAnshuman Khandual if (!kprobe_running()) 476*b98cca44SAnshuman Khandual return false; 477*b98cca44SAnshuman Khandual return kprobe_fault_handler(regs, trap); 478*b98cca44SAnshuman Khandual } 479*b98cca44SAnshuman Khandual 4801da177e4SLinus Torvalds #endif /* _LINUX_KPROBES_H */ 481