xref: /linux/kernel/trace/trace_probe.h (revision 6439079365dcb33c6701f5f0e480ac2c17312b6b)
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Common header file for probe-based Dynamic events.
4  *
5  * This code was copied from kernel/trace/trace_kprobe.h written by
6  * Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
7  *
8  * Updates to make this generic:
9  * Copyright (C) IBM Corporation, 2010-2011
10  * Author:     Srikar Dronamraju
11  */
12 
13 #include <linux/bitops.h>
14 #include <linux/btf.h>
15 #include <linux/cleanup.h>
16 #include <linux/kprobes.h>
17 #include <linux/limits.h>
18 #include <linux/perf_event.h>
19 #include <linux/ptrace.h>
20 #include <linux/seq_file.h>
21 #include <linux/slab.h>
22 #include <linux/smp.h>
23 #include <linux/string.h>
24 #include <linux/stringify.h>
25 #include <linux/tracefs.h>
26 #include <linux/types.h>
27 #include <linux/uaccess.h>
28 
29 #include <asm/bitsperlong.h>
30 
31 #include "trace.h"
32 #include "trace_output.h"
33 
34 #define MAX_TRACE_ARGS		128
35 #define MAX_ARGSTR_LEN		255
36 #define MAX_ARRAY_LEN		64
37 #define MAX_ARG_NAME_LEN	32
38 #define MAX_BTF_ARGS_LEN	128
39 #define MAX_DENTRY_ARGS_LEN	256
40 #define MAX_STRING_SIZE		PATH_MAX
41 #define MAX_PROBE_EVENT_SIZE	3072
42 
43 /* Reserved field names */
44 #define FIELD_STRING_IP		"__probe_ip"
45 #define FIELD_STRING_RETIP	"__probe_ret_ip"
46 #define FIELD_STRING_FUNC	"__probe_func"
47 
48 #undef DEFINE_FIELD
49 #define DEFINE_FIELD(type, item, name, is_signed)			\
50 	do {								\
51 		ret = trace_define_field(event_call, #type, name,	\
52 					 offsetof(typeof(field), item),	\
53 					 sizeof(field.item), is_signed, \
54 					 FILTER_OTHER);			\
55 		if (ret)						\
56 			return ret;					\
57 	} while (0)
58 
59 
60 /* Flags for trace_probe */
61 #define TP_FLAG_TRACE		1
62 #define TP_FLAG_PROFILE		2
63 
64 /* data_loc: data location, compatible with u32 */
65 #define make_data_loc(len, offs)	\
66 	(((u32)(len) << 16) | ((u32)(offs) & 0xffff))
67 #define get_loc_len(dl)		((u32)(dl) >> 16)
68 #define get_loc_offs(dl)	((u32)(dl) & 0xffff)
69 
get_loc_data(u32 * dl,void * ent)70 static nokprobe_inline void *get_loc_data(u32 *dl, void *ent)
71 {
72 	return (u8 *)ent + get_loc_offs(*dl);
73 }
74 
update_data_loc(u32 loc,int consumed)75 static nokprobe_inline u32 update_data_loc(u32 loc, int consumed)
76 {
77 	u32 maxlen = get_loc_len(loc);
78 	u32 offset = get_loc_offs(loc);
79 
80 	return make_data_loc(maxlen - consumed, offset + consumed);
81 }
82 
83 /* Printing function type */
84 typedef int (*print_type_func_t)(struct trace_seq *, void *, void *);
85 
86 #define FETCH_OP_LIST	{						\
87 	/* Stage 1 (load) ops */					\
88 	FETCH_OP(NOP, none),		/* NOP */			\
89 	FETCH_OP(REG, param),		/* Register: .param = offset */	\
90 	FETCH_OP(STACK, param),		/* Stack: .param = index */	\
91 	FETCH_OP(STACKP, none),		/* Stack pointer */		\
92 	FETCH_OP(RETVAL, none),		/* Return value */		\
93 	FETCH_OP(IMM, imm),		/* Immediate: .immediate */	\
94 	FETCH_OP(COMM, none),		/* Current comm */		\
95 	FETCH_OP(CURRENT, none),	/* Current task_struct address */\
96 	FETCH_OP(ARG, param),		/* Argument: .param = index */	\
97 	FETCH_OP(FOFFS, imm),		/* File offset: .immediate */	\
98 	FETCH_OP(IMMSTR, string),	/* Allocated string: .data */	\
99 	FETCH_OP(EDATA, offset),	/* Entry data: .offset */	\
100 	FETCH_OP(TP_ARG, tp_arg),	/* Tracepoint argument: .data */\
101 	/* Stage 2 (dereference) ops */					\
102 	FETCH_OP(DEREF, offset),	/* Dereference: .offset */	\
103 	FETCH_OP(UDEREF, offset),	/* User-space dereference: .offset */\
104 	FETCH_OP(CPU_PTR, none),	/* Per-CPU pointer: .offset */	\
105 	/* Stage 3 (store) ops */					\
106 	FETCH_OP(ST_RAW, store),	/* Raw value: .size */		\
107 	FETCH_OP(ST_MEM, store),	/* Memory: .offset, .size */	\
108 	FETCH_OP(ST_UMEM, store),	/* User memory: .offset, .size */\
109 	FETCH_OP(ST_STRING, store),	/* String: .offset, .size */	\
110 	FETCH_OP(ST_USTRING, store),	/* User string: .offset, .size */\
111 	FETCH_OP(ST_SYMSTR, store),	/* Symbol name: .offset, .size */\
112 	FETCH_OP(ST_EDATA, offset),	/* Entry data: .offset */	\
113 	/* Stage 4 (modify) op */					\
114 	FETCH_OP(MOD_BF, bf),		/* Bitfield: .basesize, .lshift, .rshift*/\
115 	/* Stage 5 (loop) op */						\
116 	FETCH_OP(LP_ARRAY, param),	/* Loop array: .param = count */\
117 	/* End */							\
118 	FETCH_OP(END, none),						\
119 	/* Unresolved Symbol holder */					\
120 	FETCH_OP(NOP_SYMBOL, symbol),	/* Non loaded symbol: .data = symbol name */\
121 }
122 
123 #define FETCH_OP(opname, decode_fn) FETCH_OP_##opname
124 enum fetch_op FETCH_OP_LIST;
125 #undef FETCH_OP
126 
127 #define FETCH_NOP_SYMBOL FETCH_OP_NOP_SYMBOL
128 
129 struct fetch_insn {
130 	enum fetch_op op;
131 	union {
132 		unsigned int param;
133 		struct {
134 			unsigned int size;
135 			int offset;
136 		};
137 		struct {
138 			unsigned char basesize;
139 			unsigned char lshift;
140 			unsigned char rshift;
141 		};
142 		unsigned long immediate;
143 		void *data;
144 	};
145 };
146 
147 /* fetch + deref*N + store + mod + end <= 16, this allows N=12, enough */
148 #define FETCH_INSN_MAX	16
149 #define FETCH_TOKEN_COMM	(-ECOMM)
150 
151 /* Fetch type information table */
152 struct fetch_type {
153 	const char		*name;		/* Name of type */
154 	size_t			size;		/* Byte size of type */
155 	bool			is_signed;	/* Signed flag */
156 	bool			is_string;	/* String flag */
157 	print_type_func_t	print;		/* Print functions */
158 	const char		*fmt;		/* Format string */
159 	const char		*fmttype;	/* Name in format file */
160 };
161 
162 /* For defining macros, define string/string_size types */
163 typedef u32 string;
164 typedef u32 string_size;
165 
166 #define PRINT_TYPE_FUNC_NAME(type)	print_type_##type
167 #define PRINT_TYPE_FMT_NAME(type)	print_type_format_##type
168 
169 /* Printing  in basic type function template */
170 #define DECLARE_BASIC_PRINT_TYPE_FUNC(type)				\
171 int PRINT_TYPE_FUNC_NAME(type)(struct trace_seq *s, void *data, void *ent);\
172 extern const char PRINT_TYPE_FMT_NAME(type)[]
173 
174 DECLARE_BASIC_PRINT_TYPE_FUNC(u8);
175 DECLARE_BASIC_PRINT_TYPE_FUNC(u16);
176 DECLARE_BASIC_PRINT_TYPE_FUNC(u32);
177 DECLARE_BASIC_PRINT_TYPE_FUNC(u64);
178 DECLARE_BASIC_PRINT_TYPE_FUNC(s8);
179 DECLARE_BASIC_PRINT_TYPE_FUNC(s16);
180 DECLARE_BASIC_PRINT_TYPE_FUNC(s32);
181 DECLARE_BASIC_PRINT_TYPE_FUNC(s64);
182 DECLARE_BASIC_PRINT_TYPE_FUNC(x8);
183 DECLARE_BASIC_PRINT_TYPE_FUNC(x16);
184 DECLARE_BASIC_PRINT_TYPE_FUNC(x32);
185 DECLARE_BASIC_PRINT_TYPE_FUNC(x64);
186 
187 DECLARE_BASIC_PRINT_TYPE_FUNC(char);
188 DECLARE_BASIC_PRINT_TYPE_FUNC(string);
189 DECLARE_BASIC_PRINT_TYPE_FUNC(symbol);
190 
191 /* Default (unsigned long) fetch type */
192 #define __DEFAULT_FETCH_TYPE(t) x##t
193 #define _DEFAULT_FETCH_TYPE(t) __DEFAULT_FETCH_TYPE(t)
194 #define DEFAULT_FETCH_TYPE _DEFAULT_FETCH_TYPE(BITS_PER_LONG)
195 #define DEFAULT_FETCH_TYPE_STR __stringify(DEFAULT_FETCH_TYPE)
196 
197 #define __ADDR_FETCH_TYPE(t) u##t
198 #define _ADDR_FETCH_TYPE(t) __ADDR_FETCH_TYPE(t)
199 #define ADDR_FETCH_TYPE _ADDR_FETCH_TYPE(BITS_PER_LONG)
200 
201 #define __ASSIGN_FETCH_TYPE(_name, ptype, ftype, _size, sign, str, _fmttype)	\
202 	{.name = _name,					\
203 	 .size = _size,					\
204 	 .is_signed = (bool)sign,			\
205 	 .is_string = (bool)str,			\
206 	 .print = PRINT_TYPE_FUNC_NAME(ptype),		\
207 	 .fmt = PRINT_TYPE_FMT_NAME(ptype),		\
208 	 .fmttype = _fmttype,				\
209 	}
210 
211 /* Non string types can use these macros */
212 #define _ASSIGN_FETCH_TYPE(_name, ptype, ftype, _size, sign, _fmttype)	\
213 	__ASSIGN_FETCH_TYPE(_name, ptype, ftype, _size, sign, 0, #_fmttype)
214 #define ASSIGN_FETCH_TYPE(ptype, ftype, sign)			\
215 	_ASSIGN_FETCH_TYPE(#ptype, ptype, ftype, sizeof(ftype), sign, ptype)
216 
217 /* If ptype is an alias of atype, use this macro (show atype in format) */
218 #define ASSIGN_FETCH_TYPE_ALIAS(ptype, atype, ftype, sign)		\
219 	_ASSIGN_FETCH_TYPE(#ptype, ptype, ftype, sizeof(ftype), sign, atype)
220 
221 #define ASSIGN_FETCH_TYPE_END {}
222 
223 #ifdef CONFIG_KPROBE_EVENTS
224 bool trace_kprobe_on_func_entry(struct trace_event_call *call);
225 bool trace_kprobe_error_injectable(struct trace_event_call *call);
226 #else
trace_kprobe_on_func_entry(struct trace_event_call * call)227 static inline bool trace_kprobe_on_func_entry(struct trace_event_call *call)
228 {
229 	return false;
230 }
231 
trace_kprobe_error_injectable(struct trace_event_call * call)232 static inline bool trace_kprobe_error_injectable(struct trace_event_call *call)
233 {
234 	return false;
235 }
236 #endif /* CONFIG_KPROBE_EVENTS */
237 
238 struct probe_arg {
239 	struct fetch_insn	*code;
240 	bool			dynamic;/* Dynamic array (string) is used */
241 	unsigned int		offset;	/* Offset from argument entry */
242 	unsigned int		count;	/* Array count */
243 	const char		*name;	/* Name of this argument */
244 	const char		*comm;	/* Command of this argument */
245 	char			*fmt;	/* Format string if needed */
246 	const struct fetch_type	*type;	/* Type of this argument */
247 };
248 
249 struct probe_entry_arg {
250 	unsigned int		size;	/* The entry data size */
251 	struct fetch_insn	code[] __counted_by(size);
252 };
253 
254 struct trace_uprobe_filter {
255 	rwlock_t		rwlock;
256 	int			nr_systemwide;
257 	struct list_head	perf_events;
258 };
259 
260 /* Event call and class holder */
261 struct trace_probe_event {
262 	unsigned int			flags;	/* For TP_FLAG_* */
263 	struct trace_event_class	class;
264 	struct trace_event_call		call;
265 	struct list_head 		files;
266 	struct list_head		probes;
267 	struct trace_uprobe_filter	filter[];
268 };
269 
270 struct trace_probe {
271 	struct list_head		list;
272 	struct trace_probe_event	*event;
273 	ssize_t				size;	/* trace entry size */
274 	unsigned int			nr_args;
275 	struct probe_entry_arg		*entry_arg;	/* This is only for return probe */
276 	struct probe_arg		args[];
277 };
278 
279 struct event_file_link {
280 	struct trace_event_file		*file;
281 	struct list_head		list;
282 };
283 
trace_probe_load_flag(struct trace_probe * tp)284 static inline unsigned int trace_probe_load_flag(struct trace_probe *tp)
285 {
286 	return smp_load_acquire(&tp->event->flags);
287 }
288 
trace_probe_test_flag(struct trace_probe * tp,unsigned int flag)289 static inline bool trace_probe_test_flag(struct trace_probe *tp,
290 					 unsigned int flag)
291 {
292 	return !!(trace_probe_load_flag(tp) & flag);
293 }
294 
trace_probe_set_flag(struct trace_probe * tp,unsigned int flag)295 static inline void trace_probe_set_flag(struct trace_probe *tp,
296 					unsigned int flag)
297 {
298 	smp_store_release(&tp->event->flags, tp->event->flags | flag);
299 }
300 
trace_probe_clear_flag(struct trace_probe * tp,unsigned int flag)301 static inline void trace_probe_clear_flag(struct trace_probe *tp,
302 					  unsigned int flag)
303 {
304 	tp->event->flags &= ~flag;
305 }
306 
trace_probe_is_enabled(struct trace_probe * tp)307 static inline bool trace_probe_is_enabled(struct trace_probe *tp)
308 {
309 	return trace_probe_test_flag(tp, TP_FLAG_TRACE | TP_FLAG_PROFILE);
310 }
311 
trace_probe_name(struct trace_probe * tp)312 static inline const char *trace_probe_name(struct trace_probe *tp)
313 {
314 	return trace_event_name(&tp->event->call);
315 }
316 
trace_probe_group_name(struct trace_probe * tp)317 static inline const char *trace_probe_group_name(struct trace_probe *tp)
318 {
319 	return tp->event->call.class->system;
320 }
321 
322 static inline struct trace_event_call *
trace_probe_event_call(struct trace_probe * tp)323 	trace_probe_event_call(struct trace_probe *tp)
324 {
325 	return &tp->event->call;
326 }
327 
328 static inline struct trace_probe_event *
trace_probe_event_from_call(struct trace_event_call * event_call)329 trace_probe_event_from_call(struct trace_event_call *event_call)
330 {
331 	return container_of(event_call, struct trace_probe_event, call);
332 }
333 
334 static inline struct trace_probe *
trace_probe_primary_from_call(struct trace_event_call * call)335 trace_probe_primary_from_call(struct trace_event_call *call)
336 {
337 	struct trace_probe_event *tpe = trace_probe_event_from_call(call);
338 
339 	return list_first_entry_or_null(&tpe->probes, struct trace_probe, list);
340 }
341 
trace_probe_probe_list(struct trace_probe * tp)342 static inline struct list_head *trace_probe_probe_list(struct trace_probe *tp)
343 {
344 	return &tp->event->probes;
345 }
346 
trace_probe_has_sibling(struct trace_probe * tp)347 static inline bool trace_probe_has_sibling(struct trace_probe *tp)
348 {
349 	struct list_head *list = trace_probe_probe_list(tp);
350 
351 	return !list_empty(list) && !list_is_singular(list);
352 }
353 
trace_probe_unregister_event_call(struct trace_probe * tp)354 static inline int trace_probe_unregister_event_call(struct trace_probe *tp)
355 {
356 	/* tp->event is unregistered in trace_remove_event_call() */
357 	return trace_remove_event_call(&tp->event->call);
358 }
359 
trace_probe_has_single_file(struct trace_probe * tp)360 static inline bool trace_probe_has_single_file(struct trace_probe *tp)
361 {
362 	return list_is_singular(&tp->event->files);
363 }
364 
365 int trace_probe_init(struct trace_probe *tp, const char *event,
366 		     const char *group, bool alloc_filter, int nargs);
367 void trace_probe_cleanup(struct trace_probe *tp);
368 int trace_probe_append(struct trace_probe *tp, struct trace_probe *to);
369 void trace_probe_unlink(struct trace_probe *tp);
370 int trace_probe_register_event_call(struct trace_probe *tp);
371 int trace_probe_add_file(struct trace_probe *tp, struct trace_event_file *file);
372 int trace_probe_remove_file(struct trace_probe *tp,
373 			    struct trace_event_file *file);
374 struct event_file_link *trace_probe_get_file_link(struct trace_probe *tp,
375 						struct trace_event_file *file);
376 int trace_probe_compare_arg_type(struct trace_probe *a, struct trace_probe *b);
377 bool trace_probe_match_command_args(struct trace_probe *tp,
378 				    int argc, const char **argv);
379 int trace_probe_create(const char *raw_command, int (*createfn)(int, const char **));
380 int trace_probe_print_args(struct trace_seq *s, struct probe_arg *args, int nr_args,
381 		 u8 *data, void *field);
382 #ifdef CONFIG_PROBE_EVENTS_DUMP_FETCHARG
383 void trace_probe_dump_args(struct seq_file *m, struct trace_probe *tp);
384 #else
trace_probe_dump_args(struct seq_file * m,struct trace_probe * tp)385 static inline void trace_probe_dump_args(struct seq_file *m, struct trace_probe *tp)
386 {
387 }
388 #endif
389 
390 #ifdef CONFIG_HAVE_FUNCTION_ARG_ACCESS_API
391 int traceprobe_get_entry_data_size(struct trace_probe *tp);
392 /* This is a runtime function to store entry data */
393 void store_trace_entry_data(void *edata, struct trace_probe *tp, struct pt_regs *regs);
394 #else /* !CONFIG_HAVE_FUNCTION_ARG_ACCESS_API */
traceprobe_get_entry_data_size(struct trace_probe * tp)395 static inline int traceprobe_get_entry_data_size(struct trace_probe *tp)
396 {
397 	return 0;
398 }
399 #define store_trace_entry_data(edata, tp, regs) do { } while (0)
400 #endif
401 
402 #define trace_probe_for_each_link(pos, tp)	\
403 	list_for_each_entry(pos, &(tp)->event->files, list)
404 #define trace_probe_for_each_link_rcu(pos, tp)	\
405 	list_for_each_entry_rcu(pos, &(tp)->event->files, list)
406 
407 /*
408  * The flags used for parsing trace_probe arguments.
409  * TPARG_FL_RETURN, TPARG_FL_FENTRY and TPARG_FL_TEVENT are mutually exclusive.
410  * TPARG_FL_KERNEL and TPARG_FL_USER are also mutually exclusive.
411  * TPARG_FL_FPROBE and TPARG_FL_TPOINT are optional but it should be with
412  * TPARG_FL_KERNEL.
413  */
414 #define TPARG_FL_RETURN BIT(0)
415 #define TPARG_FL_KERNEL BIT(1)
416 #define TPARG_FL_FENTRY BIT(2)
417 #define TPARG_FL_TEVENT BIT(3)
418 #define TPARG_FL_USER   BIT(4)
419 #define TPARG_FL_FPROBE BIT(5)
420 #define TPARG_FL_TPOINT BIT(6)
421 #define TPARG_FL_LOC_MASK	GENMASK(4, 0)
422 
tparg_is_function_entry(unsigned int flags)423 static inline bool tparg_is_function_entry(unsigned int flags)
424 {
425 	return (flags & TPARG_FL_LOC_MASK) == (TPARG_FL_KERNEL | TPARG_FL_FENTRY);
426 }
427 
tparg_is_function_return(unsigned int flags)428 static inline bool tparg_is_function_return(unsigned int flags)
429 {
430 	return (flags & TPARG_FL_LOC_MASK) == (TPARG_FL_KERNEL | TPARG_FL_RETURN);
431 }
432 
tparg_is_event_probe(unsigned int flags)433 static inline bool tparg_is_event_probe(unsigned int flags)
434 {
435 	return !!(flags & TPARG_FL_TEVENT);
436 }
437 
438 /* Each typecast consumes nested level. So the max number of typecast is 8. */
439 #define TRACEPROBE_MAX_NESTED_LEVEL 8
440 
441 enum parse_state_type {
442 	STATE_DEREF,
443 	STATE_TYPECAST,
444 };
445 
446 struct parse_state {
447 	int type;
448 	union {
449 		struct {
450 			int deref;
451 			long offset;
452 			int cur_offs;
453 			char *inner_arg;
454 			bool is_cpu_read;
455 		} deref;
456 		struct {
457 			char *casttype;
458 			char *fieldname;
459 			int orig_offset;
460 			int field_offset_diff;
461 			char *inner_arg;
462 		} typecast;
463 	};
464 };
465 
466 struct traceprobe_parse_context {
467 	struct trace_event_call *event;
468 	/* BTF related parameters */
469 	const char *funcname;		/* Function name in BTF */
470 	const struct btf_type  *proto;	/* Prototype of the function */
471 	const struct btf_param *params;	/* Parameter of the function */
472 	s32 nr_params;			/* The number of the parameters */
473 	struct btf *btf;		/* The BTF to be used */
474 	struct btf *struct_btf;		/* The BTF to be used for structs */
475 	const struct btf_type *last_type;	/* Saved type */
476 	const struct btf_type *last_struct;	/* Saved structure */
477 	u32 last_bitoffs;		/* Saved bitoffs */
478 	u32 last_bitsize;		/* Saved bitsize */
479 	struct trace_probe *tp;
480 	unsigned int flags;
481 	int offset;
482 	int prefix_byteoffs;	/* The byte offset of the prefix field of typecast */
483 	struct parse_state stack[TRACEPROBE_MAX_NESTED_LEVEL + 1];
484 	int depth;
485 };
486 
487 
488 extern int traceprobe_parse_probe_arg(struct trace_probe *tp, int i,
489 				      const char *argv,
490 				      struct traceprobe_parse_context *ctx);
491 const char **traceprobe_expand_meta_args(int argc, const char *argv[],
492 					 int *new_argc, char *buf, int bufsize,
493 					 struct traceprobe_parse_context *ctx);
494 extern int traceprobe_expand_dentry_args(int argc, const char *argv[], char **buf);
495 
496 extern int traceprobe_update_arg(struct probe_arg *arg);
497 extern void traceprobe_free_probe_arg(struct probe_arg *arg);
498 
499 /*
500  * If either traceprobe_parse_probe_arg() or traceprobe_expand_meta_args() is called,
501  * this MUST be called for clean up the context and return a resource.
502  */
503 void traceprobe_finish_parse(struct traceprobe_parse_context *ctx);
traceprobe_free_parse_ctx(struct traceprobe_parse_context * ctx)504 static inline void traceprobe_free_parse_ctx(struct traceprobe_parse_context *ctx)
505 {
506 	traceprobe_finish_parse(ctx);
507 	kfree(ctx);
508 }
509 
510 DEFINE_FREE(traceprobe_parse_context, struct traceprobe_parse_context *,
511 	if (_T) traceprobe_free_parse_ctx(_T))
512 
513 extern int traceprobe_split_symbol_offset(char *symbol, long *offset);
514 int traceprobe_parse_event_name(const char **pevent, const char **pgroup,
515 				char *buf, int offset);
516 
517 enum probe_print_type {
518 	PROBE_PRINT_NORMAL,
519 	PROBE_PRINT_RETURN,
520 	PROBE_PRINT_EVENT,
521 };
522 
523 extern int traceprobe_set_print_fmt(struct trace_probe *tp, enum probe_print_type ptype);
524 
525 #ifdef CONFIG_PERF_EVENTS
526 extern struct trace_event_call *
527 create_local_trace_kprobe(char *func, void *addr, unsigned long offs,
528 			  bool is_return);
529 extern void destroy_local_trace_kprobe(struct trace_event_call *event_call);
530 
531 extern struct trace_event_call *
532 create_local_trace_uprobe(char *name, unsigned long offs,
533 			  unsigned long ref_ctr_offset, bool is_return);
534 extern void destroy_local_trace_uprobe(struct trace_event_call *event_call);
535 #endif
536 extern int traceprobe_define_arg_fields(struct trace_event_call *event_call,
537 					size_t offset, struct trace_probe *tp);
538 
539 #undef ERRORS
540 #define ERRORS	\
541 	C(ARGIDX_2BIG,		"$argN index is too big"),		\
542 	C(ARGS_2LONG,		"$arg* failed because the argument list is too long"),	\
543 	C(ARG_NAME_TOO_LONG,	"Argument name is too long"),		\
544 	C(ARG_TOO_LONG,		"Argument expression is too long"),		\
545 	C(ARRAY_NO_CLOSE,	"Array is not closed"),		\
546 	C(ARRAY_TOO_BIG,	"Array number is too big"),		\
547 	C(BAD_ADDR_SUFFIX,	"Invalid probed address suffix"),		\
548 	C(BAD_ARG_NAME,		"Argument name must follow the same rules as C identifiers"),	\
549 	C(BAD_ARG_NUM,		"Invalid argument number"),		\
550 	C(BAD_ARRAY_NUM,	"Invalid array size"),		\
551 	C(BAD_ARRAY_SUFFIX,	"Array has wrong suffix"),		\
552 	C(BAD_ATTACH_ARG,	"Attached event does not have this field"),	\
553 	C(BAD_ATTACH_EVENT,	"Attached event does not exist"),		\
554 	C(BAD_BITFIELD,		"Invalid bitfield"),		\
555 	C(BAD_BTF_TID,		"Failed to get BTF type info."),		\
556 	C(BAD_DEREF_OFFS,	"Invalid dereference offset"),		\
557 	C(BAD_EVENT_NAME,	"Event name must follow the same rules as C identifiers"),	\
558 	C(BAD_FETCH_ARG,	"Invalid fetch argument"),		\
559 	C(BAD_FILE_OFFS,	"Invalid file offset value"),		\
560 	C(BAD_GROUP_NAME,	"Group name must follow the same rules as C identifiers"),	\
561 	C(BAD_HYPHEN,		"Failed to parse single hyphen. Forgot '>'?"),	\
562 	C(BAD_IMM,		"Invalid immediate value"),		\
563 	C(BAD_INSN_BNDRY,	"Probe point is not an instruction boundary"),	\
564 	C(BAD_MAXACT,		"Invalid maxactive number"),		\
565 	C(BAD_MAXACT_TYPE,	"Maxactive is only for function exit"),	\
566 	C(BAD_MEM_ADDR,		"Invalid memory address"),		\
567 	C(BAD_PROBE_ADDR,	"Invalid probed address or symbol"),		\
568 	C(BAD_REFCNT,		"Invalid reference counter offset"),		\
569 	C(BAD_REFCNT_SUFFIX,	"Reference counter has wrong suffix"),	\
570 	C(BAD_REG_NAME,		"Invalid register name"),		\
571 	C(BAD_RETPROBE,		"Retprobe address must be an function entry"),	\
572 	C(BAD_STACK_NUM,	"Invalid stack number"),		\
573 	C(BAD_STRING,		"String accepts only memory argument"),		\
574 	C(BAD_SYMSTRING,	"Symbol String doesn't accept data/userdata"),	\
575 	C(BAD_TP_NAME,		"Invalid character in tracepoint name"),	\
576 	C(BAD_TYPE,		"Unknown type is specified"),		\
577 	C(BAD_TYPE4STR,		"This type does not fit for string."),	\
578 	C(BAD_UPROBE_OFFS,	"Invalid uprobe offset"),		\
579 	C(BAD_VAR,		"Invalid $-variable specified"),		\
580 	C(BAD_VAR_ARGS,		"$arg* must be an independent parameter without name etc."),	\
581 	C(COMM_CANT_DEREF,	"$comm can not be dereferenced"),		\
582 	C(DEREF_NEED_BRACE,	"Dereference needs a brace"),		\
583 	C(DEREF_OPEN_BRACE,	"Dereference brace is not closed"),	\
584 	C(DIFF_ARG_TYPE,	"Argument type or name is different from existing probe"),	\
585 	C(DIFF_PROBE_TYPE,	"Probe type is different from existing probe"),	\
586 	C(DOUBLE_ARGS,		"$arg* can be used only once in the parameters"),	\
587 	C(EVENT_EXIST,		"Given group/event name is already used by another event"),	\
588 	C(EVENT_TOO_BIG,	"Event too big (too many fields?)"),		\
589 	C(EVENT_TOO_LONG,	"Event name is too long"),		\
590 	C(FAIL_REG_PROBE,	"Failed to register probe event"),		\
591 	C(FILE_NOT_FOUND,	"Failed to find the given file"),		\
592 	C(FILE_ON_KPROBE,	"File offset is not available for kernel probes"),	\
593 	C(GROUP_TOO_LONG,	"Group name is too long"),		\
594 	C(IMMSTR_NO_CLOSE,	"String is not closed with '\"'"),		\
595 	C(MAXACT_TOO_BIG,	"Maxactive is too big"),		\
596 	C(NEED_STRING_TYPE,	"$comm and immediate-string only accepts string type"),	\
597 	C(NOFENTRY_ARGS,	"$arg* can be used only on function entry or exit"),	\
598 	C(NON_UNIQ_SYMBOL,	"The symbol is not unique"),		\
599 	C(NOSUP_BTFARG,		"BTF is not available or not supported"),	\
600 	C(NOSUP_DAT_ARG,	"Non pointer structure/union argument is not supported."),	\
601 	C(NOSUP_PERCPU,		"Per-cpu variable access is only for kernel probes"),	\
602 	C(NO_ARG_BODY,		"No argument expression"),		\
603 	C(NO_ARG_NAME,		"Argument name is not specified"),		\
604 	C(NO_BTFARG,		"This variable is not found at this probe point"),	\
605 	C(NO_BTF_ENTRY,		"No BTF entry for this probe point"),		\
606 	C(NO_BTF_FIELD,		"This field is not found."),		\
607 	C(NO_EP_FILTER,		"No filter rule after 'if'"),		\
608 	C(NO_EVENT_FIELD,	"This event field is not found."),		\
609 	C(NO_EVENT_INFO,	"This requires both group and event name to attach"),	\
610 	C(NO_EVENT_NAME,	"Event name is not specified"),		\
611 	C(NO_GROUP_NAME,	"Group name is not specified"),		\
612 	C(NO_PTR_STRCT,		"This is not a pointer to union/structure."),	\
613 	C(NO_REGULAR_FILE,	"Not a regular file"),		\
614 	C(NO_RETVAL,		"This function returns 'void' type"),		\
615 	C(NO_TRACEPOINT,	"Tracepoint is not found"),		\
616 	C(REFCNT_OPEN_BRACE,	"Reference counter brace is not closed"),	\
617 	C(RETVAL_ON_PROBE,	"$retval is not available on probe"),	\
618 	C(SAME_PROBE,		"There is already the exact same probe event"),	\
619 	C(SYM_ON_UPROBE,	"Symbol is not available with uprobe"),	\
620 	C(TOO_MANY_ARGS,	"Too many arguments are specified"),		\
621 	C(TOO_MANY_EARGS,	"Too many entry arguments specified"),	\
622 	C(TOO_MANY_NESTED,	"Too many nested typecasts/dereferences"),	\
623 	C(TOO_MANY_OPS,		"Dereference is too much nested"),		\
624 	C(TYPECAST_BAD_ARROW,	"Typecast field option does not support -> operator"),	\
625 	C(TYPECAST_NOT_ALIGNED,	"Typecast field option is not byte-aligned"),	\
626 	C(TYPECAST_NOT_EVENT,	"Typecasts are only for eprobe fields"),	\
627 	C(TYPECAST_REQ_FIELD,	"Typecast requires a field access"),	\
628 	C(TYPECAST_SYM_OFFSET,	"@SYM+/-OFFSET with typecast needs parentheses"),	\
629 	C(USED_ARG_NAME,	"This argument name is already used"),
630 
631 #undef C
632 #define C(a, b)		TP_ERR_##a
633 
634 /* Define TP_ERR_ */
635 enum { ERRORS };
636 
637 /* Error text is defined in trace_probe.c */
638 
639 struct trace_probe_log {
640 	const char	*subsystem;
641 	const char	**argv;
642 	int		argc;
643 	int		index;
644 };
645 
646 const char *trace_probe_log_init(const char *subsystem, int argc, const char **argv);
647 void trace_probe_log_set_index(int index);
648 void trace_probe_log_clear(void);
649 void __trace_probe_log_err(int offset, int err);
650 
651 DEFINE_FREE(trace_probe_log_clear, const char *, if (_T) trace_probe_log_clear())
652 
653 #define trace_probe_log_err(offs, err)	\
654 	__trace_probe_log_err(offs, TP_ERR_##err)
655 
656 struct uprobe_dispatch_data {
657 	struct trace_uprobe	*tu;
658 	unsigned long		bp_addr;
659 };
660