xref: /linux/kernel/trace/trace_probe.h (revision 7d8d6ad659c02ed5d2387777194c22e8e81dbb2b)
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		63
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 
70 static nokprobe_inline void *get_loc_data(u32 *dl, void *ent)
71 {
72 	return (u8 *)ent + get_loc_offs(*dl);
73 }
74 
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 #define MAX_ARRAY_LEN	64
223 
224 #ifdef CONFIG_KPROBE_EVENTS
225 bool trace_kprobe_on_func_entry(struct trace_event_call *call);
226 bool trace_kprobe_error_injectable(struct trace_event_call *call);
227 #else
228 static inline bool trace_kprobe_on_func_entry(struct trace_event_call *call)
229 {
230 	return false;
231 }
232 
233 static inline bool trace_kprobe_error_injectable(struct trace_event_call *call)
234 {
235 	return false;
236 }
237 #endif /* CONFIG_KPROBE_EVENTS */
238 
239 struct probe_arg {
240 	struct fetch_insn	*code;
241 	bool			dynamic;/* Dynamic array (string) is used */
242 	unsigned int		offset;	/* Offset from argument entry */
243 	unsigned int		count;	/* Array count */
244 	const char		*name;	/* Name of this argument */
245 	const char		*comm;	/* Command of this argument */
246 	char			*fmt;	/* Format string if needed */
247 	const struct fetch_type	*type;	/* Type of this argument */
248 };
249 
250 struct probe_entry_arg {
251 	unsigned int		size;	/* The entry data size */
252 	struct fetch_insn	code[] __counted_by(size);
253 };
254 
255 struct trace_uprobe_filter {
256 	rwlock_t		rwlock;
257 	int			nr_systemwide;
258 	struct list_head	perf_events;
259 };
260 
261 /* Event call and class holder */
262 struct trace_probe_event {
263 	unsigned int			flags;	/* For TP_FLAG_* */
264 	struct trace_event_class	class;
265 	struct trace_event_call		call;
266 	struct list_head 		files;
267 	struct list_head		probes;
268 	struct trace_uprobe_filter	filter[];
269 };
270 
271 struct trace_probe {
272 	struct list_head		list;
273 	struct trace_probe_event	*event;
274 	ssize_t				size;	/* trace entry size */
275 	unsigned int			nr_args;
276 	struct probe_entry_arg		*entry_arg;	/* This is only for return probe */
277 	struct probe_arg		args[];
278 };
279 
280 struct event_file_link {
281 	struct trace_event_file		*file;
282 	struct list_head		list;
283 };
284 
285 static inline unsigned int trace_probe_load_flag(struct trace_probe *tp)
286 {
287 	return smp_load_acquire(&tp->event->flags);
288 }
289 
290 static inline bool trace_probe_test_flag(struct trace_probe *tp,
291 					 unsigned int flag)
292 {
293 	return !!(trace_probe_load_flag(tp) & flag);
294 }
295 
296 static inline void trace_probe_set_flag(struct trace_probe *tp,
297 					unsigned int flag)
298 {
299 	smp_store_release(&tp->event->flags, tp->event->flags | flag);
300 }
301 
302 static inline void trace_probe_clear_flag(struct trace_probe *tp,
303 					  unsigned int flag)
304 {
305 	tp->event->flags &= ~flag;
306 }
307 
308 static inline bool trace_probe_is_enabled(struct trace_probe *tp)
309 {
310 	return trace_probe_test_flag(tp, TP_FLAG_TRACE | TP_FLAG_PROFILE);
311 }
312 
313 static inline const char *trace_probe_name(struct trace_probe *tp)
314 {
315 	return trace_event_name(&tp->event->call);
316 }
317 
318 static inline const char *trace_probe_group_name(struct trace_probe *tp)
319 {
320 	return tp->event->call.class->system;
321 }
322 
323 static inline struct trace_event_call *
324 	trace_probe_event_call(struct trace_probe *tp)
325 {
326 	return &tp->event->call;
327 }
328 
329 static inline struct trace_probe_event *
330 trace_probe_event_from_call(struct trace_event_call *event_call)
331 {
332 	return container_of(event_call, struct trace_probe_event, call);
333 }
334 
335 static inline struct trace_probe *
336 trace_probe_primary_from_call(struct trace_event_call *call)
337 {
338 	struct trace_probe_event *tpe = trace_probe_event_from_call(call);
339 
340 	return list_first_entry_or_null(&tpe->probes, struct trace_probe, list);
341 }
342 
343 static inline struct list_head *trace_probe_probe_list(struct trace_probe *tp)
344 {
345 	return &tp->event->probes;
346 }
347 
348 static inline bool trace_probe_has_sibling(struct trace_probe *tp)
349 {
350 	struct list_head *list = trace_probe_probe_list(tp);
351 
352 	return !list_empty(list) && !list_is_singular(list);
353 }
354 
355 static inline int trace_probe_unregister_event_call(struct trace_probe *tp)
356 {
357 	/* tp->event is unregistered in trace_remove_event_call() */
358 	return trace_remove_event_call(&tp->event->call);
359 }
360 
361 static inline bool trace_probe_has_single_file(struct trace_probe *tp)
362 {
363 	return !!list_is_singular(&tp->event->files);
364 }
365 
366 int trace_probe_init(struct trace_probe *tp, const char *event,
367 		     const char *group, bool alloc_filter, int nargs);
368 void trace_probe_cleanup(struct trace_probe *tp);
369 int trace_probe_append(struct trace_probe *tp, struct trace_probe *to);
370 void trace_probe_unlink(struct trace_probe *tp);
371 int trace_probe_register_event_call(struct trace_probe *tp);
372 int trace_probe_add_file(struct trace_probe *tp, struct trace_event_file *file);
373 int trace_probe_remove_file(struct trace_probe *tp,
374 			    struct trace_event_file *file);
375 struct event_file_link *trace_probe_get_file_link(struct trace_probe *tp,
376 						struct trace_event_file *file);
377 int trace_probe_compare_arg_type(struct trace_probe *a, struct trace_probe *b);
378 bool trace_probe_match_command_args(struct trace_probe *tp,
379 				    int argc, const char **argv);
380 int trace_probe_create(const char *raw_command, int (*createfn)(int, const char **));
381 int trace_probe_print_args(struct trace_seq *s, struct probe_arg *args, int nr_args,
382 		 u8 *data, void *field);
383 #ifdef CONFIG_PROBE_EVENTS_DUMP_FETCHARG
384 void trace_probe_dump_args(struct seq_file *m, struct trace_probe *tp);
385 #else
386 static inline void trace_probe_dump_args(struct seq_file *m, struct trace_probe *tp)
387 {
388 }
389 #endif
390 
391 #ifdef CONFIG_HAVE_FUNCTION_ARG_ACCESS_API
392 int traceprobe_get_entry_data_size(struct trace_probe *tp);
393 /* This is a runtime function to store entry data */
394 void store_trace_entry_data(void *edata, struct trace_probe *tp, struct pt_regs *regs);
395 #else /* !CONFIG_HAVE_FUNCTION_ARG_ACCESS_API */
396 static inline int traceprobe_get_entry_data_size(struct trace_probe *tp)
397 {
398 	return 0;
399 }
400 #define store_trace_entry_data(edata, tp, regs) do { } while (0)
401 #endif
402 
403 #define trace_probe_for_each_link(pos, tp)	\
404 	list_for_each_entry(pos, &(tp)->event->files, list)
405 #define trace_probe_for_each_link_rcu(pos, tp)	\
406 	list_for_each_entry_rcu(pos, &(tp)->event->files, list)
407 
408 /*
409  * The flags used for parsing trace_probe arguments.
410  * TPARG_FL_RETURN, TPARG_FL_FENTRY and TPARG_FL_TEVENT are mutually exclusive.
411  * TPARG_FL_KERNEL and TPARG_FL_USER are also mutually exclusive.
412  * TPARG_FL_FPROBE and TPARG_FL_TPOINT are optional but it should be with
413  * TPARG_FL_KERNEL.
414  */
415 #define TPARG_FL_RETURN BIT(0)
416 #define TPARG_FL_KERNEL BIT(1)
417 #define TPARG_FL_FENTRY BIT(2)
418 #define TPARG_FL_TEVENT BIT(3)
419 #define TPARG_FL_USER   BIT(4)
420 #define TPARG_FL_FPROBE BIT(5)
421 #define TPARG_FL_TPOINT BIT(6)
422 #define TPARG_FL_LOC_MASK	GENMASK(4, 0)
423 
424 static inline bool tparg_is_function_entry(unsigned int flags)
425 {
426 	return (flags & TPARG_FL_LOC_MASK) == (TPARG_FL_KERNEL | TPARG_FL_FENTRY);
427 }
428 
429 static inline bool tparg_is_function_return(unsigned int flags)
430 {
431 	return (flags & TPARG_FL_LOC_MASK) == (TPARG_FL_KERNEL | TPARG_FL_RETURN);
432 }
433 
434 static inline bool tparg_is_event_probe(unsigned int flags)
435 {
436 	return !!(flags & TPARG_FL_TEVENT);
437 }
438 
439 struct traceprobe_parse_context {
440 	struct trace_event_call *event;
441 	/* BTF related parameters */
442 	const char *funcname;		/* Function name in BTF */
443 	const struct btf_type  *proto;	/* Prototype of the function */
444 	const struct btf_param *params;	/* Parameter of the function */
445 	s32 nr_params;			/* The number of the parameters */
446 	struct btf *btf;		/* The BTF to be used */
447 	struct btf *struct_btf;		/* The BTF to be used for structs */
448 	const struct btf_type *last_type;	/* Saved type */
449 	const struct btf_type *last_struct;	/* Saved structure */
450 	u32 last_bitoffs;		/* Saved bitoffs */
451 	u32 last_bitsize;		/* Saved bitsize */
452 	struct trace_probe *tp;
453 	unsigned int flags;
454 	int offset;
455 	int nested_level;
456 	int prefix_byteoffs;	/* The byte offset of the prefix field of typecast */
457 };
458 
459 /* Each typecast consumes nested level. So the max number of typecast is 3. */
460 #define TRACEPROBE_MAX_NESTED_LEVEL 3
461 
462 extern int traceprobe_parse_probe_arg(struct trace_probe *tp, int i,
463 				      const char *argv,
464 				      struct traceprobe_parse_context *ctx);
465 const char **traceprobe_expand_meta_args(int argc, const char *argv[],
466 					 int *new_argc, char *buf, int bufsize,
467 					 struct traceprobe_parse_context *ctx);
468 extern int traceprobe_expand_dentry_args(int argc, const char *argv[], char **buf);
469 
470 extern int traceprobe_update_arg(struct probe_arg *arg);
471 extern void traceprobe_free_probe_arg(struct probe_arg *arg);
472 
473 /*
474  * If either traceprobe_parse_probe_arg() or traceprobe_expand_meta_args() is called,
475  * this MUST be called for clean up the context and return a resource.
476  */
477 void traceprobe_finish_parse(struct traceprobe_parse_context *ctx);
478 static inline void traceprobe_free_parse_ctx(struct traceprobe_parse_context *ctx)
479 {
480 	traceprobe_finish_parse(ctx);
481 	kfree(ctx);
482 }
483 
484 DEFINE_FREE(traceprobe_parse_context, struct traceprobe_parse_context *,
485 	if (_T) traceprobe_free_parse_ctx(_T))
486 
487 extern int traceprobe_split_symbol_offset(char *symbol, long *offset);
488 int traceprobe_parse_event_name(const char **pevent, const char **pgroup,
489 				char *buf, int offset);
490 
491 enum probe_print_type {
492 	PROBE_PRINT_NORMAL,
493 	PROBE_PRINT_RETURN,
494 	PROBE_PRINT_EVENT,
495 };
496 
497 extern int traceprobe_set_print_fmt(struct trace_probe *tp, enum probe_print_type ptype);
498 
499 #ifdef CONFIG_PERF_EVENTS
500 extern struct trace_event_call *
501 create_local_trace_kprobe(char *func, void *addr, unsigned long offs,
502 			  bool is_return);
503 extern void destroy_local_trace_kprobe(struct trace_event_call *event_call);
504 
505 extern struct trace_event_call *
506 create_local_trace_uprobe(char *name, unsigned long offs,
507 			  unsigned long ref_ctr_offset, bool is_return);
508 extern void destroy_local_trace_uprobe(struct trace_event_call *event_call);
509 #endif
510 extern int traceprobe_define_arg_fields(struct trace_event_call *event_call,
511 					size_t offset, struct trace_probe *tp);
512 
513 #undef ERRORS
514 #define ERRORS	\
515 	C(FILE_NOT_FOUND,	"Failed to find the given file"),	\
516 	C(NO_REGULAR_FILE,	"Not a regular file"),			\
517 	C(BAD_REFCNT,		"Invalid reference counter offset"),	\
518 	C(REFCNT_OPEN_BRACE,	"Reference counter brace is not closed"), \
519 	C(BAD_REFCNT_SUFFIX,	"Reference counter has wrong suffix"),	\
520 	C(BAD_UPROBE_OFFS,	"Invalid uprobe offset"),		\
521 	C(BAD_MAXACT_TYPE,	"Maxactive is only for function exit"),	\
522 	C(BAD_MAXACT,		"Invalid maxactive number"),		\
523 	C(MAXACT_TOO_BIG,	"Maxactive is too big"),		\
524 	C(BAD_PROBE_ADDR,	"Invalid probed address or symbol"),	\
525 	C(NON_UNIQ_SYMBOL,	"The symbol is not unique"),		\
526 	C(BAD_RETPROBE,		"Retprobe address must be an function entry"), \
527 	C(NO_TRACEPOINT,	"Tracepoint is not found"),		\
528 	C(BAD_TP_NAME,		"Invalid character in tracepoint name"),\
529 	C(BAD_ADDR_SUFFIX,	"Invalid probed address suffix"), \
530 	C(NO_GROUP_NAME,	"Group name is not specified"),		\
531 	C(GROUP_TOO_LONG,	"Group name is too long"),		\
532 	C(BAD_GROUP_NAME,	"Group name must follow the same rules as C identifiers"), \
533 	C(NO_EVENT_NAME,	"Event name is not specified"),		\
534 	C(EVENT_TOO_LONG,	"Event name is too long"),		\
535 	C(BAD_EVENT_NAME,	"Event name must follow the same rules as C identifiers"), \
536 	C(EVENT_EXIST,		"Given group/event name is already used by another event"), \
537 	C(RETVAL_ON_PROBE,	"$retval is not available on probe"),	\
538 	C(NO_RETVAL,		"This function returns 'void' type"),	\
539 	C(BAD_STACK_NUM,	"Invalid stack number"),		\
540 	C(BAD_ARG_NUM,		"Invalid argument number"),		\
541 	C(BAD_VAR,		"Invalid $-variable specified"),	\
542 	C(BAD_REG_NAME,		"Invalid register name"),		\
543 	C(BAD_MEM_ADDR,		"Invalid memory address"),		\
544 	C(BAD_IMM,		"Invalid immediate value"),		\
545 	C(IMMSTR_NO_CLOSE,	"String is not closed with '\"'"),	\
546 	C(FILE_ON_KPROBE,	"File offset is not available for kernel probes"), \
547 	C(BAD_FILE_OFFS,	"Invalid file offset value"),		\
548 	C(SYM_ON_UPROBE,	"Symbol is not available with uprobe"),	\
549 	C(TOO_MANY_OPS,		"Dereference is too much nested"), 	\
550 	C(DEREF_NEED_BRACE,	"Dereference needs a brace"),		\
551 	C(BAD_DEREF_OFFS,	"Invalid dereference offset"),		\
552 	C(DEREF_OPEN_BRACE,	"Dereference brace is not closed"),	\
553 	C(COMM_CANT_DEREF,	"$comm can not be dereferenced"),	\
554 	C(BAD_FETCH_ARG,	"Invalid fetch argument"),		\
555 	C(ARRAY_NO_CLOSE,	"Array is not closed"),			\
556 	C(BAD_ARRAY_SUFFIX,	"Array has wrong suffix"),		\
557 	C(BAD_ARRAY_NUM,	"Invalid array size"),			\
558 	C(ARRAY_TOO_BIG,	"Array number is too big"),		\
559 	C(BAD_TYPE,		"Unknown type is specified"),		\
560 	C(BAD_STRING,		"String accepts only memory argument"),	\
561 	C(BAD_SYMSTRING,	"Symbol String doesn't accept data/userdata"),	\
562 	C(BAD_BITFIELD,		"Invalid bitfield"),			\
563 	C(ARG_NAME_TOO_LONG,	"Argument name is too long"),		\
564 	C(NO_ARG_NAME,		"Argument name is not specified"),	\
565 	C(BAD_ARG_NAME,		"Argument name must follow the same rules as C identifiers"), \
566 	C(USED_ARG_NAME,	"This argument name is already used"),	\
567 	C(ARG_TOO_LONG,		"Argument expression is too long"),	\
568 	C(NO_ARG_BODY,		"No argument expression"),		\
569 	C(BAD_INSN_BNDRY,	"Probe point is not an instruction boundary"),\
570 	C(FAIL_REG_PROBE,	"Failed to register probe event"),\
571 	C(DIFF_PROBE_TYPE,	"Probe type is different from existing probe"),\
572 	C(DIFF_ARG_TYPE,	"Argument type or name is different from existing probe"),\
573 	C(SAME_PROBE,		"There is already the exact same probe event"),\
574 	C(NO_EVENT_INFO,	"This requires both group and event name to attach"),\
575 	C(BAD_ATTACH_EVENT,	"Attached event does not exist"),\
576 	C(BAD_ATTACH_ARG,	"Attached event does not have this field"),\
577 	C(NO_EP_FILTER,		"No filter rule after 'if'"),		\
578 	C(NOSUP_BTFARG,		"BTF is not available or not supported"),	\
579 	C(NO_BTFARG,		"This variable is not found at this probe point"),\
580 	C(NO_BTF_ENTRY,		"No BTF entry for this probe point"),	\
581 	C(BAD_VAR_ARGS,		"$arg* must be an independent parameter without name etc."),\
582 	C(NOFENTRY_ARGS,	"$arg* can be used only on function entry or exit"),	\
583 	C(DOUBLE_ARGS,		"$arg* can be used only once in the parameters"),	\
584 	C(ARGS_2LONG,		"$arg* failed because the argument list is too long"),	\
585 	C(ARGIDX_2BIG,		"$argN index is too big"),		\
586 	C(NO_PTR_STRCT,		"This is not a pointer to union/structure."),	\
587 	C(NOSUP_DAT_ARG,	"Non pointer structure/union argument is not supported."),\
588 	C(BAD_HYPHEN,		"Failed to parse single hyphen. Forgot '>'?"),	\
589 	C(NO_EVENT_FIELD,	"This event field is not found."),	\
590 	C(NO_BTF_FIELD,		"This field is not found."),	\
591 	C(BAD_BTF_TID,		"Failed to get BTF type info."),\
592 	C(BAD_TYPE4STR,		"This type does not fit for string."),\
593 	C(NEED_STRING_TYPE,	"$comm and immediate-string only accepts string type"),\
594 	C(TOO_MANY_ARGS,	"Too many arguments are specified"),	\
595 	C(TOO_MANY_EARGS,	"Too many entry arguments specified"),	\
596 	C(EVENT_TOO_BIG,	"Event too big (too many fields?)"),  \
597 	C(TYPECAST_NOT_EVENT,	"Typecasts are only for eprobe fields"), \
598 	C(TYPECAST_REQ_FIELD,	"Typecast requires a field access"),	\
599 	C(TOO_MANY_NESTED,	"Too many nested typecasts/dereferences"), \
600 	C(TYPECAST_SYM_OFFSET,	"@SYM+/-OFFSET with typecast needs parentheses"), \
601 	C(TYPECAST_NOT_ALIGNED,	"Typecast field option is not byte-aligned"), \
602 	C(TYPECAST_BAD_ARROW,	"Typecast field option does not support -> operator"), \
603 	C(NOSUP_PERCPU,		"Per-cpu variable access is only for kernel probes"),
604 
605 #undef C
606 #define C(a, b)		TP_ERR_##a
607 
608 /* Define TP_ERR_ */
609 enum { ERRORS };
610 
611 /* Error text is defined in trace_probe.c */
612 
613 struct trace_probe_log {
614 	const char	*subsystem;
615 	const char	**argv;
616 	int		argc;
617 	int		index;
618 };
619 
620 const char *trace_probe_log_init(const char *subsystem, int argc, const char **argv);
621 void trace_probe_log_set_index(int index);
622 void trace_probe_log_clear(void);
623 void __trace_probe_log_err(int offset, int err);
624 
625 DEFINE_FREE(trace_probe_log_clear, const char *, if (_T) trace_probe_log_clear())
626 
627 #define trace_probe_log_err(offs, err)	\
628 	__trace_probe_log_err(offs, TP_ERR_##err)
629 
630 struct uprobe_dispatch_data {
631 	struct trace_uprobe	*tu;
632 	unsigned long		bp_addr;
633 };
634