at v6.17 4.2 kB view raw
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/rcupdate.h> 9#include <linux/refcount.h> 10#include <linux/slab.h> 11 12struct fprobe; 13typedef int (*fprobe_entry_cb)(struct fprobe *fp, unsigned long entry_ip, 14 unsigned long ret_ip, struct ftrace_regs *regs, 15 void *entry_data); 16 17typedef void (*fprobe_exit_cb)(struct fprobe *fp, unsigned long entry_ip, 18 unsigned long ret_ip, struct ftrace_regs *regs, 19 void *entry_data); 20 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 51/** 52 * struct fprobe - ftrace based probe. 53 * 54 * @nmissed: The counter for missing events. 55 * @flags: The status flag. 56 * @entry_data_size: The private data storage size. 57 * @entry_handler: The callback function for function entry. 58 * @exit_handler: The callback function for function exit. 59 * @hlist_array: The fprobe_hlist for fprobe search from IP hash table. 60 */ 61struct fprobe { 62 unsigned long nmissed; 63 unsigned int flags; 64 size_t entry_data_size; 65 66 fprobe_entry_cb entry_handler; 67 fprobe_exit_cb exit_handler; 68 69 struct fprobe_hlist *hlist_array; 70}; 71 72/* This fprobe is soft-disabled. */ 73#define FPROBE_FL_DISABLED 1 74 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 81static inline bool fprobe_disabled(struct fprobe *fp) 82{ 83 return (fp) ? fp->flags & FPROBE_FL_DISABLED : false; 84} 85 86static inline bool fprobe_shared_with_kprobes(struct fprobe *fp) 87{ 88 return (fp) ? fp->flags & FPROBE_FL_KPROBE_SHARED : false; 89} 90 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); 96bool fprobe_is_registered(struct fprobe *fp); 97int fprobe_count_ips_from_filter(const char *filter, const char *notfilter); 98#else 99static inline int register_fprobe(struct fprobe *fp, const char *filter, const char *notfilter) 100{ 101 return -EOPNOTSUPP; 102} 103static inline int register_fprobe_ips(struct fprobe *fp, unsigned long *addrs, int num) 104{ 105 return -EOPNOTSUPP; 106} 107static inline int register_fprobe_syms(struct fprobe *fp, const char **syms, int num) 108{ 109 return -EOPNOTSUPP; 110} 111static inline int unregister_fprobe(struct fprobe *fp) 112{ 113 return -EOPNOTSUPP; 114} 115static inline bool fprobe_is_registered(struct fprobe *fp) 116{ 117 return false; 118} 119static inline int fprobe_count_ips_from_filter(const char *filter, const char *notfilter) 120{ 121 return -EOPNOTSUPP; 122} 123#endif 124 125/** 126 * disable_fprobe() - Disable fprobe 127 * @fp: The fprobe to be disabled. 128 * 129 * This will soft-disable @fp. Note that this doesn't remove the ftrace 130 * hooks from the function entry. 131 */ 132static inline void disable_fprobe(struct fprobe *fp) 133{ 134 if (fp) 135 fp->flags |= FPROBE_FL_DISABLED; 136} 137 138/** 139 * enable_fprobe() - Enable fprobe 140 * @fp: The fprobe to be enabled. 141 * 142 * This will soft-enable @fp. 143 */ 144static inline void enable_fprobe(struct fprobe *fp) 145{ 146 if (fp) 147 fp->flags &= ~FPROBE_FL_DISABLED; 148} 149 150/* The entry data size is 4 bits (=16) * sizeof(long) in maximum */ 151#define FPROBE_DATA_SIZE_BITS 4 152#define MAX_FPROBE_DATA_SIZE_WORD ((1L << FPROBE_DATA_SIZE_BITS) - 1) 153#define MAX_FPROBE_DATA_SIZE (MAX_FPROBE_DATA_SIZE_WORD * sizeof(long)) 154 155#endif