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