Commit | Line | Data |
---|---|---|
bcea3f96 | 1 | // SPDX-License-Identifier: GPL-2.0 |
8ab83f56 SD |
2 | /* |
3 | * Common code for probe-based Dynamic events. | |
4 | * | |
8ab83f56 SD |
5 | * This code was copied from kernel/trace/trace_kprobe.c 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 | */ | |
72576341 | 12 | #define pr_fmt(fmt) "trace_probe: " fmt |
8ab83f56 | 13 | |
b576e097 MHG |
14 | #include <linux/bpf.h> |
15 | ||
8ab83f56 SD |
16 | #include "trace_probe.h" |
17 | ||
ab105a4f MH |
18 | #undef C |
19 | #define C(a, b) b | |
20 | ||
21 | static const char *trace_probe_err_text[] = { ERRORS }; | |
22 | ||
08416252 | 23 | static const char *reserved_field_names[] = { |
8ab83f56 SD |
24 | "common_type", |
25 | "common_flags", | |
26 | "common_preempt_count", | |
27 | "common_pid", | |
28 | "common_tgid", | |
29 | FIELD_STRING_IP, | |
30 | FIELD_STRING_RETIP, | |
31 | FIELD_STRING_FUNC, | |
32 | }; | |
33 | ||
8ab83f56 | 34 | /* Printing in basic type function template */ |
17ce3dc7 | 35 | #define DEFINE_BASIC_PRINT_TYPE_FUNC(tname, type, fmt) \ |
56de7630 | 36 | int PRINT_TYPE_FUNC_NAME(tname)(struct trace_seq *s, void *data, void *ent)\ |
8ab83f56 | 37 | { \ |
56de7630 | 38 | trace_seq_printf(s, fmt, *(type *)data); \ |
d2b0191a | 39 | return !trace_seq_has_overflowed(s); \ |
8ab83f56 | 40 | } \ |
7bfbc63e | 41 | const char PRINT_TYPE_FMT_NAME(tname)[] = fmt; |
8ab83f56 | 42 | |
bdca79c2 MH |
43 | DEFINE_BASIC_PRINT_TYPE_FUNC(u8, u8, "%u") |
44 | DEFINE_BASIC_PRINT_TYPE_FUNC(u16, u16, "%u") | |
45 | DEFINE_BASIC_PRINT_TYPE_FUNC(u32, u32, "%u") | |
46 | DEFINE_BASIC_PRINT_TYPE_FUNC(u64, u64, "%Lu") | |
17ce3dc7 MH |
47 | DEFINE_BASIC_PRINT_TYPE_FUNC(s8, s8, "%d") |
48 | DEFINE_BASIC_PRINT_TYPE_FUNC(s16, s16, "%d") | |
49 | DEFINE_BASIC_PRINT_TYPE_FUNC(s32, s32, "%d") | |
50 | DEFINE_BASIC_PRINT_TYPE_FUNC(s64, s64, "%Ld") | |
51 | DEFINE_BASIC_PRINT_TYPE_FUNC(x8, u8, "0x%x") | |
52 | DEFINE_BASIC_PRINT_TYPE_FUNC(x16, u16, "0x%x") | |
53 | DEFINE_BASIC_PRINT_TYPE_FUNC(x32, u32, "0x%x") | |
54 | DEFINE_BASIC_PRINT_TYPE_FUNC(x64, u64, "0x%Lx") | |
8478cca1 | 55 | DEFINE_BASIC_PRINT_TYPE_FUNC(char, u8, "'%c'") |
8ab83f56 | 56 | |
60c2e0ce MH |
57 | int PRINT_TYPE_FUNC_NAME(symbol)(struct trace_seq *s, void *data, void *ent) |
58 | { | |
59 | trace_seq_printf(s, "%pS", (void *)*(unsigned long *)data); | |
60 | return !trace_seq_has_overflowed(s); | |
61 | } | |
62 | const char PRINT_TYPE_FMT_NAME(symbol)[] = "%pS"; | |
63 | ||
8ab83f56 | 64 | /* Print type function for string type */ |
56de7630 | 65 | int PRINT_TYPE_FUNC_NAME(string)(struct trace_seq *s, void *data, void *ent) |
8ab83f56 SD |
66 | { |
67 | int len = *(u32 *)data >> 16; | |
68 | ||
69 | if (!len) | |
56de7630 | 70 | trace_seq_puts(s, "(fault)"); |
8ab83f56 | 71 | else |
56de7630 | 72 | trace_seq_printf(s, "\"%s\"", |
d2b0191a SRRH |
73 | (const char *)get_loc_data(data, ent)); |
74 | return !trace_seq_has_overflowed(s); | |
8ab83f56 SD |
75 | } |
76 | ||
b26c74e1 | 77 | const char PRINT_TYPE_FMT_NAME(string)[] = "\\\"%s\\\""; |
8ab83f56 | 78 | |
f451bc89 MH |
79 | /* Fetch type information table */ |
80 | static const struct fetch_type probe_fetch_types[] = { | |
81 | /* Special types */ | |
b26a124c | 82 | __ASSIGN_FETCH_TYPE("string", string, string, sizeof(u32), 1, 1, |
f451bc89 | 83 | "__data_loc char[]"), |
b26a124c MHG |
84 | __ASSIGN_FETCH_TYPE("ustring", string, string, sizeof(u32), 1, 1, |
85 | "__data_loc char[]"), | |
86 | __ASSIGN_FETCH_TYPE("symstr", string, string, sizeof(u32), 1, 1, | |
88903c46 | 87 | "__data_loc char[]"), |
f451bc89 MH |
88 | /* Basic types */ |
89 | ASSIGN_FETCH_TYPE(u8, u8, 0), | |
90 | ASSIGN_FETCH_TYPE(u16, u16, 0), | |
91 | ASSIGN_FETCH_TYPE(u32, u32, 0), | |
92 | ASSIGN_FETCH_TYPE(u64, u64, 0), | |
93 | ASSIGN_FETCH_TYPE(s8, u8, 1), | |
94 | ASSIGN_FETCH_TYPE(s16, u16, 1), | |
95 | ASSIGN_FETCH_TYPE(s32, u32, 1), | |
96 | ASSIGN_FETCH_TYPE(s64, u64, 1), | |
97 | ASSIGN_FETCH_TYPE_ALIAS(x8, u8, u8, 0), | |
98 | ASSIGN_FETCH_TYPE_ALIAS(x16, u16, u16, 0), | |
99 | ASSIGN_FETCH_TYPE_ALIAS(x32, u32, u32, 0), | |
100 | ASSIGN_FETCH_TYPE_ALIAS(x64, u64, u64, 0), | |
8478cca1 | 101 | ASSIGN_FETCH_TYPE_ALIAS(char, u8, u8, 0), |
60c2e0ce | 102 | ASSIGN_FETCH_TYPE_ALIAS(symbol, ADDR_FETCH_TYPE, ADDR_FETCH_TYPE, 0), |
f451bc89 MH |
103 | |
104 | ASSIGN_FETCH_TYPE_END | |
105 | }; | |
106 | ||
d4505aa6 | 107 | static const struct fetch_type *find_fetch_type(const char *type, unsigned long flags) |
8ab83f56 SD |
108 | { |
109 | int i; | |
110 | ||
d4505aa6 MHG |
111 | /* Reject the symbol/symstr for uprobes */ |
112 | if (type && (flags & TPARG_FL_USER) && | |
113 | (!strcmp(type, "symbol") || !strcmp(type, "symstr"))) | |
114 | return NULL; | |
115 | ||
8ab83f56 SD |
116 | if (!type) |
117 | type = DEFAULT_FETCH_TYPE_STR; | |
118 | ||
119 | /* Special case: bitfield */ | |
120 | if (*type == 'b') { | |
121 | unsigned long bs; | |
122 | ||
123 | type = strchr(type, '/'); | |
124 | if (!type) | |
125 | goto fail; | |
126 | ||
127 | type++; | |
bcd83ea6 | 128 | if (kstrtoul(type, 0, &bs)) |
8ab83f56 SD |
129 | goto fail; |
130 | ||
131 | switch (bs) { | |
132 | case 8: | |
d4505aa6 | 133 | return find_fetch_type("u8", flags); |
8ab83f56 | 134 | case 16: |
d4505aa6 | 135 | return find_fetch_type("u16", flags); |
8ab83f56 | 136 | case 32: |
d4505aa6 | 137 | return find_fetch_type("u32", flags); |
8ab83f56 | 138 | case 64: |
d4505aa6 | 139 | return find_fetch_type("u64", flags); |
8ab83f56 SD |
140 | default: |
141 | goto fail; | |
142 | } | |
143 | } | |
144 | ||
f451bc89 MH |
145 | for (i = 0; probe_fetch_types[i].name; i++) { |
146 | if (strcmp(type, probe_fetch_types[i].name) == 0) | |
147 | return &probe_fetch_types[i]; | |
34fee3a1 | 148 | } |
8ab83f56 SD |
149 | |
150 | fail: | |
151 | return NULL; | |
152 | } | |
153 | ||
ab105a4f MH |
154 | static struct trace_probe_log trace_probe_log; |
155 | ||
156 | void trace_probe_log_init(const char *subsystem, int argc, const char **argv) | |
157 | { | |
158 | trace_probe_log.subsystem = subsystem; | |
159 | trace_probe_log.argc = argc; | |
160 | trace_probe_log.argv = argv; | |
161 | trace_probe_log.index = 0; | |
162 | } | |
163 | ||
164 | void trace_probe_log_clear(void) | |
165 | { | |
166 | memset(&trace_probe_log, 0, sizeof(trace_probe_log)); | |
167 | } | |
168 | ||
169 | void trace_probe_log_set_index(int index) | |
170 | { | |
171 | trace_probe_log.index = index; | |
172 | } | |
173 | ||
174 | void __trace_probe_log_err(int offset, int err_type) | |
175 | { | |
176 | char *command, *p; | |
177 | int i, len = 0, pos = 0; | |
178 | ||
179 | if (!trace_probe_log.argv) | |
180 | return; | |
181 | ||
f2cc020d | 182 | /* Recalculate the length and allocate buffer */ |
ab105a4f MH |
183 | for (i = 0; i < trace_probe_log.argc; i++) { |
184 | if (i == trace_probe_log.index) | |
185 | pos = len; | |
186 | len += strlen(trace_probe_log.argv[i]) + 1; | |
187 | } | |
188 | command = kzalloc(len, GFP_KERNEL); | |
189 | if (!command) | |
190 | return; | |
191 | ||
d2aea95a MH |
192 | if (trace_probe_log.index >= trace_probe_log.argc) { |
193 | /** | |
194 | * Set the error position is next to the last arg + space. | |
195 | * Note that len includes the terminal null and the cursor | |
f2cc020d | 196 | * appears at pos + 1. |
d2aea95a MH |
197 | */ |
198 | pos = len; | |
199 | offset = 0; | |
200 | } | |
201 | ||
ab105a4f MH |
202 | /* And make a command string from argv array */ |
203 | p = command; | |
204 | for (i = 0; i < trace_probe_log.argc; i++) { | |
205 | len = strlen(trace_probe_log.argv[i]); | |
206 | strcpy(p, trace_probe_log.argv[i]); | |
207 | p[len] = ' '; | |
208 | p += len + 1; | |
209 | } | |
210 | *(p - 1) = '\0'; | |
211 | ||
2f754e77 | 212 | tracing_log_err(NULL, trace_probe_log.subsystem, command, |
ab105a4f MH |
213 | trace_probe_err_text, err_type, pos + offset); |
214 | ||
215 | kfree(command); | |
216 | } | |
217 | ||
8ab83f56 | 218 | /* Split symbol and offset. */ |
c5d343b6 | 219 | int traceprobe_split_symbol_offset(char *symbol, long *offset) |
8ab83f56 SD |
220 | { |
221 | char *tmp; | |
222 | int ret; | |
223 | ||
224 | if (!offset) | |
225 | return -EINVAL; | |
226 | ||
c5d343b6 | 227 | tmp = strpbrk(symbol, "+-"); |
8ab83f56 | 228 | if (tmp) { |
c5d343b6 | 229 | ret = kstrtol(tmp, 0, offset); |
8ab83f56 SD |
230 | if (ret) |
231 | return ret; | |
8ab83f56 SD |
232 | *tmp = '\0'; |
233 | } else | |
234 | *offset = 0; | |
235 | ||
236 | return 0; | |
237 | } | |
238 | ||
6212dd29 MH |
239 | /* @buf must has MAX_EVENT_NAME_LEN size */ |
240 | int traceprobe_parse_event_name(const char **pevent, const char **pgroup, | |
ab105a4f | 241 | char *buf, int offset) |
6212dd29 MH |
242 | { |
243 | const char *slash, *event = *pevent; | |
dec65d79 | 244 | int len; |
6212dd29 MH |
245 | |
246 | slash = strchr(event, '/'); | |
bc1b9734 SRV |
247 | if (!slash) |
248 | slash = strchr(event, '.'); | |
249 | ||
6212dd29 MH |
250 | if (slash) { |
251 | if (slash == event) { | |
ab105a4f | 252 | trace_probe_log_err(offset, NO_GROUP_NAME); |
6212dd29 MH |
253 | return -EINVAL; |
254 | } | |
255 | if (slash - event + 1 > MAX_EVENT_NAME_LEN) { | |
ab105a4f MH |
256 | trace_probe_log_err(offset, GROUP_TOO_LONG); |
257 | return -EINVAL; | |
6212dd29 MH |
258 | } |
259 | strlcpy(buf, event, slash - event + 1); | |
575b76cb | 260 | if (!is_good_system_name(buf)) { |
ab105a4f | 261 | trace_probe_log_err(offset, BAD_GROUP_NAME); |
5b7a9622 MH |
262 | return -EINVAL; |
263 | } | |
6212dd29 MH |
264 | *pgroup = buf; |
265 | *pevent = slash + 1; | |
ab105a4f | 266 | offset += slash - event + 1; |
dec65d79 | 267 | event = *pevent; |
6212dd29 | 268 | } |
dec65d79 MH |
269 | len = strlen(event); |
270 | if (len == 0) { | |
95c104c3 LY |
271 | if (slash) { |
272 | *pevent = NULL; | |
273 | return 0; | |
274 | } | |
ab105a4f | 275 | trace_probe_log_err(offset, NO_EVENT_NAME); |
6212dd29 | 276 | return -EINVAL; |
dec65d79 | 277 | } else if (len > MAX_EVENT_NAME_LEN) { |
ab105a4f MH |
278 | trace_probe_log_err(offset, EVENT_TOO_LONG); |
279 | return -EINVAL; | |
6212dd29 | 280 | } |
5b7a9622 | 281 | if (!is_good_name(event)) { |
ab105a4f | 282 | trace_probe_log_err(offset, BAD_EVENT_NAME); |
5b7a9622 MH |
283 | return -EINVAL; |
284 | } | |
6212dd29 MH |
285 | return 0; |
286 | } | |
287 | ||
1b8b0cd7 MHG |
288 | static int parse_trace_event_arg(char *arg, struct fetch_insn *code, |
289 | struct traceprobe_parse_context *ctx) | |
290 | { | |
291 | struct ftrace_event_field *field; | |
292 | struct list_head *head; | |
293 | ||
294 | head = trace_get_fields(ctx->event); | |
295 | list_for_each_entry(field, head, link) { | |
296 | if (!strcmp(arg, field->name)) { | |
297 | code->op = FETCH_OP_TP_ARG; | |
298 | code->data = field; | |
299 | return 0; | |
300 | } | |
301 | } | |
302 | return -ENOENT; | |
303 | } | |
304 | ||
b576e097 MHG |
305 | #ifdef CONFIG_PROBE_EVENTS_BTF_ARGS |
306 | ||
307 | static struct btf *traceprobe_get_btf(void) | |
308 | { | |
309 | struct btf *btf = bpf_get_btf_vmlinux(); | |
310 | ||
311 | if (IS_ERR_OR_NULL(btf)) | |
312 | return NULL; | |
313 | ||
314 | return btf; | |
315 | } | |
316 | ||
317 | static u32 btf_type_int(const struct btf_type *t) | |
318 | { | |
319 | return *(u32 *)(t + 1); | |
320 | } | |
321 | ||
322 | static const char *type_from_btf_id(struct btf *btf, s32 id) | |
323 | { | |
324 | const struct btf_type *t; | |
325 | u32 intdata; | |
326 | s32 tid; | |
327 | ||
328 | /* TODO: const char * could be converted as a string */ | |
329 | t = btf_type_skip_modifiers(btf, id, &tid); | |
330 | ||
331 | switch (BTF_INFO_KIND(t->info)) { | |
332 | case BTF_KIND_ENUM: | |
333 | /* enum is "int", so convert to "s32" */ | |
334 | return "s32"; | |
335 | case BTF_KIND_ENUM64: | |
336 | return "s64"; | |
337 | case BTF_KIND_PTR: | |
338 | /* pointer will be converted to "x??" */ | |
339 | if (IS_ENABLED(CONFIG_64BIT)) | |
340 | return "x64"; | |
341 | else | |
342 | return "x32"; | |
343 | case BTF_KIND_INT: | |
344 | intdata = btf_type_int(t); | |
345 | if (BTF_INT_ENCODING(intdata) & BTF_INT_SIGNED) { | |
346 | switch (BTF_INT_BITS(intdata)) { | |
347 | case 8: | |
348 | return "s8"; | |
349 | case 16: | |
350 | return "s16"; | |
351 | case 32: | |
352 | return "s32"; | |
353 | case 64: | |
354 | return "s64"; | |
355 | } | |
356 | } else { /* unsigned */ | |
357 | switch (BTF_INT_BITS(intdata)) { | |
358 | case 8: | |
359 | return "u8"; | |
360 | case 16: | |
361 | return "u16"; | |
362 | case 32: | |
363 | return "u32"; | |
364 | case 64: | |
365 | return "u64"; | |
366 | } | |
367 | } | |
368 | } | |
369 | /* TODO: support other types */ | |
370 | ||
371 | return NULL; | |
372 | } | |
373 | ||
374 | static const struct btf_param *find_btf_func_param(const char *funcname, s32 *nr) | |
375 | { | |
376 | struct btf *btf = traceprobe_get_btf(); | |
377 | const struct btf_type *t; | |
378 | s32 id; | |
379 | ||
380 | if (!btf || !funcname || !nr) | |
381 | return ERR_PTR(-EINVAL); | |
382 | ||
383 | id = btf_find_by_name_kind(btf, funcname, BTF_KIND_FUNC); | |
384 | if (id <= 0) | |
385 | return ERR_PTR(-ENOENT); | |
386 | ||
387 | /* Get BTF_KIND_FUNC type */ | |
388 | t = btf_type_by_id(btf, id); | |
389 | if (!btf_type_is_func(t)) | |
390 | return ERR_PTR(-ENOENT); | |
391 | ||
392 | /* The type of BTF_KIND_FUNC is BTF_KIND_FUNC_PROTO */ | |
393 | t = btf_type_by_id(btf, t->type); | |
394 | if (!btf_type_is_func_proto(t)) | |
395 | return ERR_PTR(-ENOENT); | |
396 | ||
397 | *nr = btf_type_vlen(t); | |
398 | ||
399 | if (*nr) | |
400 | return (const struct btf_param *)(t + 1); | |
401 | else | |
402 | return NULL; | |
403 | } | |
404 | ||
405 | static int parse_btf_arg(const char *varname, struct fetch_insn *code, | |
406 | struct traceprobe_parse_context *ctx) | |
407 | { | |
408 | struct btf *btf = traceprobe_get_btf(); | |
409 | const struct btf_param *params; | |
410 | int i; | |
411 | ||
412 | if (!btf) { | |
413 | trace_probe_log_err(ctx->offset, NOSUP_BTFARG); | |
414 | return -EOPNOTSUPP; | |
415 | } | |
416 | ||
417 | if (WARN_ON_ONCE(!ctx->funcname)) | |
418 | return -EINVAL; | |
419 | ||
420 | if (!ctx->params) { | |
421 | params = find_btf_func_param(ctx->funcname, &ctx->nr_params); | |
422 | if (IS_ERR(params)) { | |
423 | trace_probe_log_err(ctx->offset, NO_BTF_ENTRY); | |
424 | return PTR_ERR(params); | |
425 | } | |
426 | ctx->params = params; | |
427 | } else | |
428 | params = ctx->params; | |
429 | ||
430 | for (i = 0; i < ctx->nr_params; i++) { | |
431 | const char *name = btf_name_by_offset(btf, params[i].name_off); | |
432 | ||
433 | if (name && !strcmp(name, varname)) { | |
434 | code->op = FETCH_OP_ARG; | |
435 | code->param = i; | |
436 | return 0; | |
437 | } | |
438 | } | |
439 | trace_probe_log_err(ctx->offset, NO_BTFARG); | |
440 | return -ENOENT; | |
441 | } | |
442 | ||
443 | static const struct fetch_type *parse_btf_arg_type(int arg_idx, | |
444 | struct traceprobe_parse_context *ctx) | |
445 | { | |
446 | struct btf *btf = traceprobe_get_btf(); | |
447 | const char *typestr = NULL; | |
448 | ||
449 | if (btf && ctx->params) | |
450 | typestr = type_from_btf_id(btf, ctx->params[arg_idx].type); | |
451 | ||
452 | return find_fetch_type(typestr, ctx->flags); | |
453 | } | |
454 | #else | |
455 | static struct btf *traceprobe_get_btf(void) | |
456 | { | |
457 | return NULL; | |
458 | } | |
459 | ||
460 | static int parse_btf_arg(const char *varname, struct fetch_insn *code, | |
461 | struct traceprobe_parse_context *ctx) | |
462 | { | |
463 | trace_probe_log_err(ctx->offset, NOSUP_BTFARG); | |
464 | return -EOPNOTSUPP; | |
465 | } | |
466 | #define parse_btf_arg_type(idx, ctx) \ | |
467 | find_fetch_type(NULL, ctx->flags) | |
468 | #endif | |
469 | ||
8ab83f56 SD |
470 | #define PARAM_MAX_STACK (THREAD_SIZE / sizeof(unsigned long)) |
471 | ||
472 | static int parse_probe_vars(char *arg, const struct fetch_type *t, | |
1b8b0cd7 MHG |
473 | struct fetch_insn *code, |
474 | struct traceprobe_parse_context *ctx) | |
8ab83f56 | 475 | { |
8ab83f56 | 476 | unsigned long param; |
1b8b0cd7 | 477 | int err = TP_ERR_BAD_VAR; |
3d739c1f SRV |
478 | int ret = 0; |
479 | int len; | |
8ab83f56 | 480 | |
1b8b0cd7 | 481 | if (ctx->flags & TPARG_FL_TEVENT) { |
2673c60e SRG |
482 | if (code->data) |
483 | return -EFAULT; | |
1b8b0cd7 MHG |
484 | ret = parse_trace_event_arg(arg, code, ctx); |
485 | if (!ret) | |
486 | return 0; | |
487 | if (strcmp(arg, "comm") == 0 || strcmp(arg, "COMM") == 0) { | |
488 | code->op = FETCH_OP_COMM; | |
489 | return 0; | |
490 | } | |
491 | /* backward compatibility */ | |
492 | ctx->offset = 0; | |
493 | goto inval; | |
494 | } | |
495 | ||
496 | if (strcmp(arg, "retval") == 0) { | |
497 | if (ctx->flags & TPARG_FL_RETURN) { | |
53305928 | 498 | code->op = FETCH_OP_RETVAL; |
1b8b0cd7 | 499 | return 0; |
ab105a4f | 500 | } |
1b8b0cd7 MHG |
501 | err = TP_ERR_RETVAL_ON_PROBE; |
502 | goto inval; | |
503 | } | |
504 | ||
505 | len = str_has_prefix(arg, "stack"); | |
506 | if (len) { | |
507 | ||
3d739c1f | 508 | if (arg[len] == '\0') { |
53305928 | 509 | code->op = FETCH_OP_STACKP; |
1b8b0cd7 MHG |
510 | return 0; |
511 | } | |
512 | ||
513 | if (isdigit(arg[len])) { | |
3d739c1f | 514 | ret = kstrtoul(arg + len, 10, ¶m); |
1b8b0cd7 MHG |
515 | if (ret) |
516 | goto inval; | |
517 | ||
518 | if ((ctx->flags & TPARG_FL_KERNEL) && | |
519 | param > PARAM_MAX_STACK) { | |
520 | err = TP_ERR_BAD_STACK_NUM; | |
521 | goto inval; | |
8ab83f56 | 522 | } |
1b8b0cd7 MHG |
523 | code->op = FETCH_OP_STACK; |
524 | code->param = (unsigned int)param; | |
525 | return 0; | |
526 | } | |
527 | goto inval; | |
528 | } | |
529 | ||
530 | if (strcmp(arg, "comm") == 0 || strcmp(arg, "COMM") == 0) { | |
53305928 | 531 | code->op = FETCH_OP_COMM; |
1b8b0cd7 MHG |
532 | return 0; |
533 | } | |
534 | ||
a1303af5 | 535 | #ifdef CONFIG_HAVE_FUNCTION_ARG_ACCESS_API |
1b8b0cd7 MHG |
536 | len = str_has_prefix(arg, "arg"); |
537 | if (len && tparg_is_function_entry(ctx->flags)) { | |
3d739c1f | 538 | ret = kstrtoul(arg + len, 10, ¶m); |
1b8b0cd7 MHG |
539 | if (ret) |
540 | goto inval; | |
541 | ||
542 | if (!param || param > PARAM_MAX_STACK) { | |
543 | err = TP_ERR_BAD_ARG_NUM; | |
544 | goto inval; | |
ab105a4f | 545 | } |
1b8b0cd7 | 546 | |
a1303af5 MH |
547 | code->op = FETCH_OP_ARG; |
548 | code->param = (unsigned int)param - 1; | |
e2d0d7b2 MHG |
549 | /* |
550 | * The tracepoint probe will probe a stub function, and the | |
551 | * first parameter of the stub is a dummy and should be ignored. | |
552 | */ | |
1b8b0cd7 | 553 | if (ctx->flags & TPARG_FL_TPOINT) |
e2d0d7b2 | 554 | code->param++; |
1b8b0cd7 MHG |
555 | return 0; |
556 | } | |
a1303af5 | 557 | #endif |
8ab83f56 | 558 | |
1b8b0cd7 MHG |
559 | inval: |
560 | __trace_probe_log_err(ctx->offset, err); | |
ab105a4f | 561 | return -EINVAL; |
8ab83f56 SD |
562 | } |
563 | ||
6218bf9f MH |
564 | static int str_to_immediate(char *str, unsigned long *imm) |
565 | { | |
566 | if (isdigit(str[0])) | |
567 | return kstrtoul(str, 0, imm); | |
568 | else if (str[0] == '-') | |
569 | return kstrtol(str, 0, (long *)imm); | |
570 | else if (str[0] == '+') | |
571 | return kstrtol(str + 1, 0, (long *)imm); | |
572 | return -EINVAL; | |
573 | } | |
574 | ||
a42e3c4d MH |
575 | static int __parse_imm_string(char *str, char **pbuf, int offs) |
576 | { | |
577 | size_t len = strlen(str); | |
578 | ||
579 | if (str[len - 1] != '"') { | |
580 | trace_probe_log_err(offs + len, IMMSTR_NO_CLOSE); | |
581 | return -EINVAL; | |
582 | } | |
583 | *pbuf = kstrndup(str, len - 1, GFP_KERNEL); | |
1c1857d4 XW |
584 | if (!*pbuf) |
585 | return -ENOMEM; | |
a42e3c4d MH |
586 | return 0; |
587 | } | |
588 | ||
8ab83f56 | 589 | /* Recursive argument parser */ |
53305928 MH |
590 | static int |
591 | parse_probe_arg(char *arg, const struct fetch_type *type, | |
592 | struct fetch_insn **pcode, struct fetch_insn *end, | |
1b8b0cd7 | 593 | struct traceprobe_parse_context *ctx) |
8ab83f56 | 594 | { |
53305928 | 595 | struct fetch_insn *code = *pcode; |
8ab83f56 | 596 | unsigned long param; |
e65f7ae7 | 597 | int deref = FETCH_OP_DEREF; |
bf173ca9 | 598 | long offset = 0; |
8ab83f56 | 599 | char *tmp; |
34fee3a1 | 600 | int ret = 0; |
8ab83f56 | 601 | |
8ab83f56 SD |
602 | switch (arg[0]) { |
603 | case '$': | |
1b8b0cd7 | 604 | ret = parse_probe_vars(arg + 1, type, code, ctx); |
8ab83f56 SD |
605 | break; |
606 | ||
607 | case '%': /* named register */ | |
1b8b0cd7 | 608 | if (ctx->flags & (TPARG_FL_TEVENT | TPARG_FL_FPROBE)) { |
334e5519 | 609 | /* eprobe and fprobe do not handle registers */ |
1b8b0cd7 | 610 | trace_probe_log_err(ctx->offset, BAD_VAR); |
2673c60e SRG |
611 | break; |
612 | } | |
8ab83f56 SD |
613 | ret = regs_query_register_offset(arg + 1); |
614 | if (ret >= 0) { | |
53305928 MH |
615 | code->op = FETCH_OP_REG; |
616 | code->param = (unsigned int)ret; | |
8ab83f56 | 617 | ret = 0; |
ab105a4f | 618 | } else |
1b8b0cd7 | 619 | trace_probe_log_err(ctx->offset, BAD_REG_NAME); |
8ab83f56 SD |
620 | break; |
621 | ||
b7e0bf34 | 622 | case '@': /* memory, file-offset or symbol */ |
8ab83f56 | 623 | if (isdigit(arg[1])) { |
bcd83ea6 | 624 | ret = kstrtoul(arg + 1, 0, ¶m); |
ab105a4f | 625 | if (ret) { |
1b8b0cd7 | 626 | trace_probe_log_err(ctx->offset, BAD_MEM_ADDR); |
8ab83f56 | 627 | break; |
ab105a4f | 628 | } |
53305928 MH |
629 | /* load address */ |
630 | code->op = FETCH_OP_IMM; | |
631 | code->immediate = param; | |
b7e0bf34 NK |
632 | } else if (arg[1] == '+') { |
633 | /* kprobes don't support file offsets */ | |
1b8b0cd7 MHG |
634 | if (ctx->flags & TPARG_FL_KERNEL) { |
635 | trace_probe_log_err(ctx->offset, FILE_ON_KPROBE); | |
b7e0bf34 | 636 | return -EINVAL; |
ab105a4f | 637 | } |
b7e0bf34 | 638 | ret = kstrtol(arg + 2, 0, &offset); |
ab105a4f | 639 | if (ret) { |
1b8b0cd7 | 640 | trace_probe_log_err(ctx->offset, BAD_FILE_OFFS); |
b7e0bf34 | 641 | break; |
ab105a4f | 642 | } |
b7e0bf34 | 643 | |
53305928 MH |
644 | code->op = FETCH_OP_FOFFS; |
645 | code->immediate = (unsigned long)offset; // imm64? | |
8ab83f56 | 646 | } else { |
b079d374 | 647 | /* uprobes don't support symbols */ |
1b8b0cd7 MHG |
648 | if (!(ctx->flags & TPARG_FL_KERNEL)) { |
649 | trace_probe_log_err(ctx->offset, SYM_ON_UPROBE); | |
b079d374 | 650 | return -EINVAL; |
ab105a4f | 651 | } |
a6682814 MH |
652 | /* Preserve symbol for updating */ |
653 | code->op = FETCH_NOP_SYMBOL; | |
654 | code->data = kstrdup(arg + 1, GFP_KERNEL); | |
655 | if (!code->data) | |
656 | return -ENOMEM; | |
ab105a4f | 657 | if (++code == end) { |
1b8b0cd7 | 658 | trace_probe_log_err(ctx->offset, TOO_MANY_OPS); |
ab105a4f MH |
659 | return -EINVAL; |
660 | } | |
53305928 | 661 | code->op = FETCH_OP_IMM; |
a6682814 | 662 | code->immediate = 0; |
8ab83f56 | 663 | } |
53305928 | 664 | /* These are fetching from memory */ |
ab105a4f | 665 | if (++code == end) { |
1b8b0cd7 | 666 | trace_probe_log_err(ctx->offset, TOO_MANY_OPS); |
ab105a4f MH |
667 | return -EINVAL; |
668 | } | |
53305928 MH |
669 | *pcode = code; |
670 | code->op = FETCH_OP_DEREF; | |
671 | code->offset = offset; | |
8ab83f56 SD |
672 | break; |
673 | ||
674 | case '+': /* deref memory */ | |
8ab83f56 | 675 | case '-': |
e65f7ae7 MH |
676 | if (arg[1] == 'u') { |
677 | deref = FETCH_OP_UDEREF; | |
678 | arg[1] = arg[0]; | |
679 | arg++; | |
680 | } | |
681 | if (arg[0] == '+') | |
682 | arg++; /* Skip '+', because kstrtol() rejects it. */ | |
8ab83f56 | 683 | tmp = strchr(arg, '('); |
ab105a4f | 684 | if (!tmp) { |
1b8b0cd7 | 685 | trace_probe_log_err(ctx->offset, DEREF_NEED_BRACE); |
53305928 | 686 | return -EINVAL; |
ab105a4f | 687 | } |
8ab83f56 | 688 | *tmp = '\0'; |
bcd83ea6 | 689 | ret = kstrtol(arg, 0, &offset); |
ab105a4f | 690 | if (ret) { |
1b8b0cd7 | 691 | trace_probe_log_err(ctx->offset, BAD_DEREF_OFFS); |
8ab83f56 | 692 | break; |
ab105a4f | 693 | } |
1b8b0cd7 | 694 | ctx->offset += (tmp + 1 - arg) + (arg[0] != '-' ? 1 : 0); |
8ab83f56 SD |
695 | arg = tmp + 1; |
696 | tmp = strrchr(arg, ')'); | |
ab105a4f | 697 | if (!tmp) { |
1b8b0cd7 | 698 | trace_probe_log_err(ctx->offset + strlen(arg), |
ab105a4f MH |
699 | DEREF_OPEN_BRACE); |
700 | return -EINVAL; | |
701 | } else { | |
1b8b0cd7 MHG |
702 | const struct fetch_type *t2 = find_fetch_type(NULL, ctx->flags); |
703 | int cur_offs = ctx->offset; | |
8ab83f56 | 704 | |
8ab83f56 | 705 | *tmp = '\0'; |
1b8b0cd7 | 706 | ret = parse_probe_arg(arg, t2, &code, end, ctx); |
8ab83f56 | 707 | if (ret) |
53305928 | 708 | break; |
1b8b0cd7 | 709 | ctx->offset = cur_offs; |
a42e3c4d MH |
710 | if (code->op == FETCH_OP_COMM || |
711 | code->op == FETCH_OP_DATA) { | |
1b8b0cd7 | 712 | trace_probe_log_err(ctx->offset, COMM_CANT_DEREF); |
ab105a4f MH |
713 | return -EINVAL; |
714 | } | |
715 | if (++code == end) { | |
1b8b0cd7 | 716 | trace_probe_log_err(ctx->offset, TOO_MANY_OPS); |
53305928 | 717 | return -EINVAL; |
ab105a4f | 718 | } |
53305928 MH |
719 | *pcode = code; |
720 | ||
e65f7ae7 | 721 | code->op = deref; |
53305928 | 722 | code->offset = offset; |
8ab83f56 SD |
723 | } |
724 | break; | |
6218bf9f | 725 | case '\\': /* Immediate value */ |
a42e3c4d | 726 | if (arg[1] == '"') { /* Immediate string */ |
1b8b0cd7 | 727 | ret = __parse_imm_string(arg + 2, &tmp, ctx->offset + 2); |
a42e3c4d MH |
728 | if (ret) |
729 | break; | |
730 | code->op = FETCH_OP_DATA; | |
731 | code->data = tmp; | |
732 | } else { | |
733 | ret = str_to_immediate(arg + 1, &code->immediate); | |
734 | if (ret) | |
1b8b0cd7 | 735 | trace_probe_log_err(ctx->offset + 1, BAD_IMM); |
a42e3c4d MH |
736 | else |
737 | code->op = FETCH_OP_IMM; | |
738 | } | |
6218bf9f | 739 | break; |
b576e097 MHG |
740 | default: |
741 | if (isalpha(arg[0]) || arg[0] == '_') { /* BTF variable */ | |
742 | if (!tparg_is_function_entry(ctx->flags)) { | |
743 | trace_probe_log_err(ctx->offset, NOSUP_BTFARG); | |
744 | return -EINVAL; | |
745 | } | |
746 | ret = parse_btf_arg(arg, code, ctx); | |
747 | break; | |
748 | } | |
8ab83f56 | 749 | } |
53305928 MH |
750 | if (!ret && code->op == FETCH_OP_NOP) { |
751 | /* Parsed, but do not find fetch method */ | |
1b8b0cd7 | 752 | trace_probe_log_err(ctx->offset, BAD_FETCH_ARG); |
8ab83f56 SD |
753 | ret = -EINVAL; |
754 | } | |
8ab83f56 SD |
755 | return ret; |
756 | } | |
757 | ||
758 | #define BYTES_TO_BITS(nb) ((BITS_PER_LONG * (nb)) / sizeof(long)) | |
759 | ||
760 | /* Bitfield type needs to be parsed into a fetch function */ | |
761 | static int __parse_bitfield_probe_arg(const char *bf, | |
762 | const struct fetch_type *t, | |
53305928 | 763 | struct fetch_insn **pcode) |
8ab83f56 | 764 | { |
53305928 | 765 | struct fetch_insn *code = *pcode; |
8ab83f56 SD |
766 | unsigned long bw, bo; |
767 | char *tail; | |
768 | ||
769 | if (*bf != 'b') | |
770 | return 0; | |
771 | ||
8ab83f56 SD |
772 | bw = simple_strtoul(bf + 1, &tail, 0); /* Use simple one */ |
773 | ||
774 | if (bw == 0 || *tail != '@') | |
775 | return -EINVAL; | |
776 | ||
777 | bf = tail + 1; | |
778 | bo = simple_strtoul(bf, &tail, 0); | |
779 | ||
780 | if (tail == bf || *tail != '/') | |
781 | return -EINVAL; | |
53305928 MH |
782 | code++; |
783 | if (code->op != FETCH_OP_NOP) | |
ab105a4f | 784 | return -EINVAL; |
53305928 | 785 | *pcode = code; |
8ab83f56 | 786 | |
53305928 MH |
787 | code->op = FETCH_OP_MOD_BF; |
788 | code->lshift = BYTES_TO_BITS(t->size) - (bw + bo); | |
789 | code->rshift = BYTES_TO_BITS(t->size) - bw; | |
790 | code->basesize = t->size; | |
8ab83f56 SD |
791 | |
792 | return (BYTES_TO_BITS(t->size) < (bw + bo)) ? -EINVAL : 0; | |
793 | } | |
794 | ||
795 | /* String length checking wrapper */ | |
fcd9db51 | 796 | static int traceprobe_parse_probe_arg_body(const char *argv, ssize_t *size, |
1b8b0cd7 MHG |
797 | struct probe_arg *parg, |
798 | struct traceprobe_parse_context *ctx) | |
8ab83f56 | 799 | { |
40b53b77 | 800 | struct fetch_insn *code, *scode, *tmp = NULL; |
ab105a4f | 801 | char *t, *t2, *t3; |
40b53b77 | 802 | int ret, len; |
1b8b0cd7 | 803 | char *arg; |
8ab83f56 | 804 | |
fcd9db51 SRV |
805 | arg = kstrdup(argv, GFP_KERNEL); |
806 | if (!arg) | |
807 | return -ENOMEM; | |
808 | ||
809 | ret = -EINVAL; | |
ab105a4f MH |
810 | len = strlen(arg); |
811 | if (len > MAX_ARGSTR_LEN) { | |
1b8b0cd7 | 812 | trace_probe_log_err(ctx->offset, ARG_TOO_LONG); |
fcd9db51 | 813 | goto out; |
ab105a4f | 814 | } else if (len == 0) { |
1b8b0cd7 | 815 | trace_probe_log_err(ctx->offset, NO_ARG_BODY); |
fcd9db51 | 816 | goto out; |
8ab83f56 | 817 | } |
ab105a4f | 818 | |
fcd9db51 | 819 | ret = -ENOMEM; |
8ab83f56 | 820 | parg->comm = kstrdup(arg, GFP_KERNEL); |
ab105a4f | 821 | if (!parg->comm) |
fcd9db51 | 822 | goto out; |
ab105a4f | 823 | |
fcd9db51 | 824 | ret = -EINVAL; |
40b53b77 | 825 | t = strchr(arg, ':'); |
8ab83f56 | 826 | if (t) { |
40b53b77 MH |
827 | *t = '\0'; |
828 | t2 = strchr(++t, '['); | |
829 | if (t2) { | |
ab105a4f MH |
830 | *t2++ = '\0'; |
831 | t3 = strchr(t2, ']'); | |
832 | if (!t3) { | |
1b8b0cd7 MHG |
833 | int offs = t2 + strlen(t2) - arg; |
834 | ||
835 | trace_probe_log_err(ctx->offset + offs, | |
ab105a4f | 836 | ARRAY_NO_CLOSE); |
fcd9db51 | 837 | goto out; |
ab105a4f | 838 | } else if (t3[1] != '\0') { |
1b8b0cd7 | 839 | trace_probe_log_err(ctx->offset + t3 + 1 - arg, |
ab105a4f | 840 | BAD_ARRAY_SUFFIX); |
fcd9db51 | 841 | goto out; |
ab105a4f MH |
842 | } |
843 | *t3 = '\0'; | |
844 | if (kstrtouint(t2, 0, &parg->count) || !parg->count) { | |
1b8b0cd7 | 845 | trace_probe_log_err(ctx->offset + t2 - arg, |
ab105a4f | 846 | BAD_ARRAY_NUM); |
fcd9db51 | 847 | goto out; |
ab105a4f MH |
848 | } |
849 | if (parg->count > MAX_ARRAY_LEN) { | |
1b8b0cd7 | 850 | trace_probe_log_err(ctx->offset + t2 - arg, |
ab105a4f | 851 | ARRAY_TOO_BIG); |
fcd9db51 | 852 | goto out; |
ab105a4f | 853 | } |
40b53b77 | 854 | } |
8ab83f56 | 855 | } |
3dd1f7f2 | 856 | |
a42e3c4d | 857 | /* |
f2cc020d | 858 | * Since $comm and immediate string can not be dereferenced, |
02333de9 | 859 | * we can find those by strcmp. But ignore for eprobes. |
a42e3c4d | 860 | */ |
1b8b0cd7 | 861 | if (!(ctx->flags & TPARG_FL_TEVENT) && |
ab838444 SRG |
862 | (strcmp(arg, "$comm") == 0 || strcmp(arg, "$COMM") == 0 || |
863 | strncmp(arg, "\\\"", 2) == 0)) { | |
3dd1f7f2 MH |
864 | /* The type of $comm must be "string", and not an array. */ |
865 | if (parg->count || (t && strcmp(t, "string"))) | |
fcd9db51 | 866 | goto out; |
1b8b0cd7 | 867 | parg->type = find_fetch_type("string", ctx->flags); |
3dd1f7f2 | 868 | } else |
1b8b0cd7 | 869 | parg->type = find_fetch_type(t, ctx->flags); |
8ab83f56 | 870 | if (!parg->type) { |
1b8b0cd7 | 871 | trace_probe_log_err(ctx->offset + (t ? (t - arg) : 0), BAD_TYPE); |
fcd9db51 | 872 | goto out; |
8ab83f56 SD |
873 | } |
874 | parg->offset = *size; | |
40b53b77 MH |
875 | *size += parg->type->size * (parg->count ?: 1); |
876 | ||
fcd9db51 | 877 | ret = -ENOMEM; |
40b53b77 MH |
878 | if (parg->count) { |
879 | len = strlen(parg->type->fmttype) + 6; | |
880 | parg->fmt = kmalloc(len, GFP_KERNEL); | |
881 | if (!parg->fmt) | |
fcd9db51 | 882 | goto out; |
40b53b77 MH |
883 | snprintf(parg->fmt, len, "%s[%d]", parg->type->fmttype, |
884 | parg->count); | |
885 | } | |
8ab83f56 | 886 | |
8623b006 | 887 | code = tmp = kcalloc(FETCH_INSN_MAX, sizeof(*code), GFP_KERNEL); |
53305928 | 888 | if (!code) |
fcd9db51 | 889 | goto out; |
53305928 MH |
890 | code[FETCH_INSN_MAX - 1].op = FETCH_OP_END; |
891 | ||
892 | ret = parse_probe_arg(arg, parg->type, &code, &code[FETCH_INSN_MAX - 1], | |
1b8b0cd7 | 893 | ctx); |
53305928 MH |
894 | if (ret) |
895 | goto fail; | |
896 | ||
b576e097 MHG |
897 | /* Update storing type if BTF is available */ |
898 | if (IS_ENABLED(CONFIG_PROBE_EVENTS_BTF_ARGS) && | |
899 | !t && code->op == FETCH_OP_ARG) | |
900 | parg->type = parse_btf_arg_type(code->param, ctx); | |
901 | ||
fcd9db51 | 902 | ret = -EINVAL; |
53305928 | 903 | /* Store operation */ |
b26a124c MHG |
904 | if (parg->type->is_string) { |
905 | if (!strcmp(parg->type->name, "symstr")) { | |
906 | if (code->op != FETCH_OP_REG && code->op != FETCH_OP_STACK && | |
907 | code->op != FETCH_OP_RETVAL && code->op != FETCH_OP_ARG && | |
908 | code->op != FETCH_OP_DEREF && code->op != FETCH_OP_TP_ARG) { | |
1b8b0cd7 | 909 | trace_probe_log_err(ctx->offset + (t ? (t - arg) : 0), |
b26a124c MHG |
910 | BAD_SYMSTRING); |
911 | goto fail; | |
912 | } | |
913 | } else { | |
914 | if (code->op != FETCH_OP_DEREF && code->op != FETCH_OP_UDEREF && | |
915 | code->op != FETCH_OP_IMM && code->op != FETCH_OP_COMM && | |
916 | code->op != FETCH_OP_DATA && code->op != FETCH_OP_TP_ARG) { | |
1b8b0cd7 | 917 | trace_probe_log_err(ctx->offset + (t ? (t - arg) : 0), |
b26a124c MHG |
918 | BAD_STRING); |
919 | goto fail; | |
920 | } | |
53305928 | 921 | } |
b26a124c MHG |
922 | if (!strcmp(parg->type->name, "symstr") || |
923 | (code->op == FETCH_OP_IMM || code->op == FETCH_OP_COMM || | |
7491e2c4 TSV |
924 | code->op == FETCH_OP_DATA) || code->op == FETCH_OP_TP_ARG || |
925 | parg->count) { | |
40b53b77 | 926 | /* |
a42e3c4d MH |
927 | * IMM, DATA and COMM is pointing actual address, those |
928 | * must be kept, and if parg->count != 0, this is an | |
929 | * array of string pointers instead of string address | |
930 | * itself. | |
b26a124c MHG |
931 | * For the symstr, it doesn't need to dereference, thus |
932 | * it just get the value. | |
40b53b77 | 933 | */ |
53305928 | 934 | code++; |
40b53b77 | 935 | if (code->op != FETCH_OP_NOP) { |
1b8b0cd7 | 936 | trace_probe_log_err(ctx->offset, TOO_MANY_OPS); |
40b53b77 MH |
937 | goto fail; |
938 | } | |
939 | } | |
88903c46 | 940 | /* If op == DEREF, replace it with STRING */ |
e65f7ae7 MH |
941 | if (!strcmp(parg->type->name, "ustring") || |
942 | code->op == FETCH_OP_UDEREF) | |
88903c46 | 943 | code->op = FETCH_OP_ST_USTRING; |
b26a124c MHG |
944 | else if (!strcmp(parg->type->name, "symstr")) |
945 | code->op = FETCH_OP_ST_SYMSTR; | |
88903c46 MH |
946 | else |
947 | code->op = FETCH_OP_ST_STRING; | |
40b53b77 | 948 | code->size = parg->type->size; |
53305928 MH |
949 | parg->dynamic = true; |
950 | } else if (code->op == FETCH_OP_DEREF) { | |
951 | code->op = FETCH_OP_ST_MEM; | |
952 | code->size = parg->type->size; | |
e65f7ae7 MH |
953 | } else if (code->op == FETCH_OP_UDEREF) { |
954 | code->op = FETCH_OP_ST_UMEM; | |
955 | code->size = parg->type->size; | |
53305928 MH |
956 | } else { |
957 | code++; | |
958 | if (code->op != FETCH_OP_NOP) { | |
1b8b0cd7 | 959 | trace_probe_log_err(ctx->offset, TOO_MANY_OPS); |
53305928 MH |
960 | goto fail; |
961 | } | |
962 | code->op = FETCH_OP_ST_RAW; | |
963 | code->size = parg->type->size; | |
964 | } | |
40b53b77 | 965 | scode = code; |
53305928 MH |
966 | /* Modify operation */ |
967 | if (t != NULL) { | |
968 | ret = __parse_bitfield_probe_arg(t, parg->type, &code); | |
ab105a4f | 969 | if (ret) { |
1b8b0cd7 | 970 | trace_probe_log_err(ctx->offset + t - arg, BAD_BITFIELD); |
53305928 | 971 | goto fail; |
ab105a4f | 972 | } |
8ab83f56 | 973 | } |
fcd9db51 | 974 | ret = -EINVAL; |
40b53b77 MH |
975 | /* Loop(Array) operation */ |
976 | if (parg->count) { | |
977 | if (scode->op != FETCH_OP_ST_MEM && | |
88903c46 MH |
978 | scode->op != FETCH_OP_ST_STRING && |
979 | scode->op != FETCH_OP_ST_USTRING) { | |
1b8b0cd7 | 980 | trace_probe_log_err(ctx->offset + (t ? (t - arg) : 0), |
ab105a4f | 981 | BAD_STRING); |
40b53b77 MH |
982 | goto fail; |
983 | } | |
984 | code++; | |
985 | if (code->op != FETCH_OP_NOP) { | |
1b8b0cd7 | 986 | trace_probe_log_err(ctx->offset, TOO_MANY_OPS); |
40b53b77 MH |
987 | goto fail; |
988 | } | |
989 | code->op = FETCH_OP_LP_ARRAY; | |
990 | code->param = parg->count; | |
991 | } | |
53305928 MH |
992 | code++; |
993 | code->op = FETCH_OP_END; | |
994 | ||
fcd9db51 | 995 | ret = 0; |
53305928 | 996 | /* Shrink down the code buffer */ |
8623b006 | 997 | parg->code = kcalloc(code - tmp + 1, sizeof(*code), GFP_KERNEL); |
53305928 MH |
998 | if (!parg->code) |
999 | ret = -ENOMEM; | |
1000 | else | |
1001 | memcpy(parg->code, tmp, sizeof(*code) * (code - tmp + 1)); | |
1002 | ||
1003 | fail: | |
a6682814 MH |
1004 | if (ret) { |
1005 | for (code = tmp; code < tmp + FETCH_INSN_MAX; code++) | |
a42e3c4d MH |
1006 | if (code->op == FETCH_NOP_SYMBOL || |
1007 | code->op == FETCH_OP_DATA) | |
a6682814 MH |
1008 | kfree(code->data); |
1009 | } | |
53305928 | 1010 | kfree(tmp); |
fcd9db51 SRV |
1011 | out: |
1012 | kfree(arg); | |
8ab83f56 SD |
1013 | |
1014 | return ret; | |
1015 | } | |
1016 | ||
1017 | /* Return 1 if name is reserved or already used by another argument */ | |
d00bbea9 MH |
1018 | static int traceprobe_conflict_field_name(const char *name, |
1019 | struct probe_arg *args, int narg) | |
8ab83f56 SD |
1020 | { |
1021 | int i; | |
1022 | ||
1023 | for (i = 0; i < ARRAY_SIZE(reserved_field_names); i++) | |
1024 | if (strcmp(reserved_field_names[i], name) == 0) | |
1025 | return 1; | |
1026 | ||
1027 | for (i = 0; i < narg; i++) | |
1028 | if (strcmp(args[i].name, name) == 0) | |
1029 | return 1; | |
1030 | ||
1031 | return 0; | |
1032 | } | |
1033 | ||
b576e097 MHG |
1034 | static char *generate_probe_arg_name(const char *arg, int idx) |
1035 | { | |
1036 | char *name = NULL; | |
1037 | const char *end; | |
1038 | ||
1039 | /* | |
1040 | * If argument name is omitted, try arg as a name (BTF variable) | |
1041 | * or "argN". | |
1042 | */ | |
1043 | if (IS_ENABLED(CONFIG_PROBE_EVENTS_BTF_ARGS)) { | |
1044 | end = strchr(arg, ':'); | |
1045 | if (!end) | |
1046 | end = arg + strlen(arg); | |
1047 | ||
1048 | name = kmemdup_nul(arg, end - arg, GFP_KERNEL); | |
1049 | if (!name || !is_good_name(name)) { | |
1050 | kfree(name); | |
1051 | name = NULL; | |
1052 | } | |
1053 | } | |
1054 | ||
1055 | if (!name) | |
1056 | name = kasprintf(GFP_KERNEL, "arg%d", idx + 1); | |
1057 | ||
1058 | return name; | |
1059 | } | |
1060 | ||
fcd9db51 | 1061 | int traceprobe_parse_probe_arg(struct trace_probe *tp, int i, const char *arg, |
1b8b0cd7 | 1062 | struct traceprobe_parse_context *ctx) |
d00bbea9 MH |
1063 | { |
1064 | struct probe_arg *parg = &tp->args[i]; | |
fcd9db51 | 1065 | const char *body; |
d00bbea9 MH |
1066 | |
1067 | /* Increment count for freeing args in error case */ | |
1068 | tp->nr_args++; | |
1069 | ||
1070 | body = strchr(arg, '='); | |
1071 | if (body) { | |
ab105a4f MH |
1072 | if (body - arg > MAX_ARG_NAME_LEN) { |
1073 | trace_probe_log_err(0, ARG_NAME_TOO_LONG); | |
1074 | return -EINVAL; | |
1075 | } else if (body == arg) { | |
1076 | trace_probe_log_err(0, NO_ARG_NAME); | |
b4443c17 | 1077 | return -EINVAL; |
ab105a4f | 1078 | } |
d00bbea9 MH |
1079 | parg->name = kmemdup_nul(arg, body - arg, GFP_KERNEL); |
1080 | body++; | |
1081 | } else { | |
b576e097 | 1082 | parg->name = generate_probe_arg_name(arg, i); |
d00bbea9 MH |
1083 | body = arg; |
1084 | } | |
1085 | if (!parg->name) | |
1086 | return -ENOMEM; | |
1087 | ||
1088 | if (!is_good_name(parg->name)) { | |
ab105a4f | 1089 | trace_probe_log_err(0, BAD_ARG_NAME); |
d00bbea9 MH |
1090 | return -EINVAL; |
1091 | } | |
d00bbea9 | 1092 | if (traceprobe_conflict_field_name(parg->name, tp->args, i)) { |
ab105a4f | 1093 | trace_probe_log_err(0, USED_ARG_NAME); |
d00bbea9 MH |
1094 | return -EINVAL; |
1095 | } | |
1b8b0cd7 | 1096 | ctx->offset = body - arg; |
d00bbea9 | 1097 | /* Parse fetch argument */ |
1b8b0cd7 | 1098 | return traceprobe_parse_probe_arg_body(body, &tp->size, parg, ctx); |
d00bbea9 MH |
1099 | } |
1100 | ||
8ab83f56 SD |
1101 | void traceprobe_free_probe_arg(struct probe_arg *arg) |
1102 | { | |
a6682814 MH |
1103 | struct fetch_insn *code = arg->code; |
1104 | ||
1105 | while (code && code->op != FETCH_OP_END) { | |
a42e3c4d MH |
1106 | if (code->op == FETCH_NOP_SYMBOL || |
1107 | code->op == FETCH_OP_DATA) | |
a6682814 MH |
1108 | kfree(code->data); |
1109 | code++; | |
1110 | } | |
53305928 | 1111 | kfree(arg->code); |
8ab83f56 SD |
1112 | kfree(arg->name); |
1113 | kfree(arg->comm); | |
40b53b77 | 1114 | kfree(arg->fmt); |
8ab83f56 SD |
1115 | } |
1116 | ||
a6682814 MH |
1117 | int traceprobe_update_arg(struct probe_arg *arg) |
1118 | { | |
1119 | struct fetch_insn *code = arg->code; | |
1120 | long offset; | |
1121 | char *tmp; | |
1122 | char c; | |
1123 | int ret = 0; | |
1124 | ||
1125 | while (code && code->op != FETCH_OP_END) { | |
1126 | if (code->op == FETCH_NOP_SYMBOL) { | |
1127 | if (code[1].op != FETCH_OP_IMM) | |
1128 | return -EINVAL; | |
1129 | ||
ee474b81 | 1130 | tmp = strpbrk(code->data, "+-"); |
a6682814 MH |
1131 | if (tmp) |
1132 | c = *tmp; | |
1133 | ret = traceprobe_split_symbol_offset(code->data, | |
1134 | &offset); | |
1135 | if (ret) | |
1136 | return ret; | |
1137 | ||
1138 | code[1].immediate = | |
1139 | (unsigned long)kallsyms_lookup_name(code->data); | |
1140 | if (tmp) | |
1141 | *tmp = c; | |
1142 | if (!code[1].immediate) | |
1143 | return -ENOENT; | |
1144 | code[1].immediate += offset; | |
1145 | } | |
1146 | code++; | |
1147 | } | |
1148 | return 0; | |
1149 | } | |
1150 | ||
40b53b77 MH |
1151 | /* When len=0, we just calculate the needed length */ |
1152 | #define LEN_OR_ZERO (len ? len - pos : 0) | |
5bf652aa | 1153 | static int __set_print_fmt(struct trace_probe *tp, char *buf, int len, |
007517a0 | 1154 | enum probe_print_type ptype) |
5bf652aa | 1155 | { |
40b53b77 MH |
1156 | struct probe_arg *parg; |
1157 | int i, j; | |
5bf652aa | 1158 | int pos = 0; |
5bf652aa NK |
1159 | const char *fmt, *arg; |
1160 | ||
007517a0 SRV |
1161 | switch (ptype) { |
1162 | case PROBE_PRINT_NORMAL: | |
5bf652aa | 1163 | fmt = "(%lx)"; |
b61edd57 | 1164 | arg = ", REC->" FIELD_STRING_IP; |
007517a0 SRV |
1165 | break; |
1166 | case PROBE_PRINT_RETURN: | |
5bf652aa | 1167 | fmt = "(%lx <- %lx)"; |
b61edd57 | 1168 | arg = ", REC->" FIELD_STRING_FUNC ", REC->" FIELD_STRING_RETIP; |
007517a0 | 1169 | break; |
7491e2c4 | 1170 | case PROBE_PRINT_EVENT: |
b61edd57 SRG |
1171 | fmt = ""; |
1172 | arg = ""; | |
7491e2c4 | 1173 | break; |
007517a0 SRV |
1174 | default: |
1175 | WARN_ON_ONCE(1); | |
1176 | return 0; | |
5bf652aa NK |
1177 | } |
1178 | ||
5bf652aa NK |
1179 | pos += snprintf(buf + pos, LEN_OR_ZERO, "\"%s", fmt); |
1180 | ||
1181 | for (i = 0; i < tp->nr_args; i++) { | |
40b53b77 MH |
1182 | parg = tp->args + i; |
1183 | pos += snprintf(buf + pos, LEN_OR_ZERO, " %s=", parg->name); | |
1184 | if (parg->count) { | |
1185 | pos += snprintf(buf + pos, LEN_OR_ZERO, "{%s", | |
1186 | parg->type->fmt); | |
1187 | for (j = 1; j < parg->count; j++) | |
1188 | pos += snprintf(buf + pos, LEN_OR_ZERO, ",%s", | |
1189 | parg->type->fmt); | |
1190 | pos += snprintf(buf + pos, LEN_OR_ZERO, "}"); | |
1191 | } else | |
1192 | pos += snprintf(buf + pos, LEN_OR_ZERO, "%s", | |
1193 | parg->type->fmt); | |
5bf652aa NK |
1194 | } |
1195 | ||
b61edd57 | 1196 | pos += snprintf(buf + pos, LEN_OR_ZERO, "\"%s", arg); |
5bf652aa NK |
1197 | |
1198 | for (i = 0; i < tp->nr_args; i++) { | |
40b53b77 MH |
1199 | parg = tp->args + i; |
1200 | if (parg->count) { | |
b26a124c | 1201 | if (parg->type->is_string) |
40b53b77 MH |
1202 | fmt = ", __get_str(%s[%d])"; |
1203 | else | |
1204 | fmt = ", REC->%s[%d]"; | |
1205 | for (j = 0; j < parg->count; j++) | |
1206 | pos += snprintf(buf + pos, LEN_OR_ZERO, | |
1207 | fmt, parg->name, j); | |
1208 | } else { | |
b26a124c | 1209 | if (parg->type->is_string) |
40b53b77 MH |
1210 | fmt = ", __get_str(%s)"; |
1211 | else | |
1212 | fmt = ", REC->%s"; | |
5bf652aa | 1213 | pos += snprintf(buf + pos, LEN_OR_ZERO, |
40b53b77 MH |
1214 | fmt, parg->name); |
1215 | } | |
5bf652aa NK |
1216 | } |
1217 | ||
5bf652aa NK |
1218 | /* return the length of print_fmt */ |
1219 | return pos; | |
1220 | } | |
40b53b77 | 1221 | #undef LEN_OR_ZERO |
5bf652aa | 1222 | |
007517a0 | 1223 | int traceprobe_set_print_fmt(struct trace_probe *tp, enum probe_print_type ptype) |
5bf652aa | 1224 | { |
e3dc9f89 | 1225 | struct trace_event_call *call = trace_probe_event_call(tp); |
5bf652aa NK |
1226 | int len; |
1227 | char *print_fmt; | |
1228 | ||
1229 | /* First: called with 0 length to calculate the needed length */ | |
007517a0 | 1230 | len = __set_print_fmt(tp, NULL, 0, ptype); |
5bf652aa NK |
1231 | print_fmt = kmalloc(len + 1, GFP_KERNEL); |
1232 | if (!print_fmt) | |
1233 | return -ENOMEM; | |
1234 | ||
1235 | /* Second: actually write the @print_fmt */ | |
007517a0 | 1236 | __set_print_fmt(tp, print_fmt, len + 1, ptype); |
e3dc9f89 | 1237 | call->print_fmt = print_fmt; |
5bf652aa NK |
1238 | |
1239 | return 0; | |
1240 | } | |
eeb07b06 MH |
1241 | |
1242 | int traceprobe_define_arg_fields(struct trace_event_call *event_call, | |
1243 | size_t offset, struct trace_probe *tp) | |
1244 | { | |
1245 | int ret, i; | |
1246 | ||
1247 | /* Set argument names as fields */ | |
1248 | for (i = 0; i < tp->nr_args; i++) { | |
1249 | struct probe_arg *parg = &tp->args[i]; | |
40b53b77 MH |
1250 | const char *fmt = parg->type->fmttype; |
1251 | int size = parg->type->size; | |
1252 | ||
1253 | if (parg->fmt) | |
1254 | fmt = parg->fmt; | |
1255 | if (parg->count) | |
1256 | size *= parg->count; | |
1257 | ret = trace_define_field(event_call, fmt, parg->name, | |
1258 | offset + parg->offset, size, | |
eeb07b06 MH |
1259 | parg->type->is_signed, |
1260 | FILTER_OTHER); | |
1261 | if (ret) | |
1262 | return ret; | |
1263 | } | |
1264 | return 0; | |
1265 | } | |
455b2899 | 1266 | |
ca89bc07 MH |
1267 | static void trace_probe_event_free(struct trace_probe_event *tpe) |
1268 | { | |
1269 | kfree(tpe->class.system); | |
1270 | kfree(tpe->call.name); | |
1271 | kfree(tpe->call.print_fmt); | |
1272 | kfree(tpe); | |
1273 | } | |
1274 | ||
1275 | int trace_probe_append(struct trace_probe *tp, struct trace_probe *to) | |
1276 | { | |
1277 | if (trace_probe_has_sibling(tp)) | |
1278 | return -EBUSY; | |
1279 | ||
1280 | list_del_init(&tp->list); | |
1281 | trace_probe_event_free(tp->event); | |
1282 | ||
1283 | tp->event = to->event; | |
1284 | list_add_tail(&tp->list, trace_probe_probe_list(to)); | |
1285 | ||
1286 | return 0; | |
1287 | } | |
1288 | ||
1289 | void trace_probe_unlink(struct trace_probe *tp) | |
1290 | { | |
1291 | list_del_init(&tp->list); | |
1292 | if (list_empty(trace_probe_probe_list(tp))) | |
1293 | trace_probe_event_free(tp->event); | |
1294 | tp->event = NULL; | |
1295 | } | |
455b2899 MH |
1296 | |
1297 | void trace_probe_cleanup(struct trace_probe *tp) | |
1298 | { | |
1299 | int i; | |
1300 | ||
1301 | for (i = 0; i < tp->nr_args; i++) | |
1302 | traceprobe_free_probe_arg(&tp->args[i]); | |
1303 | ||
ca89bc07 MH |
1304 | if (tp->event) |
1305 | trace_probe_unlink(tp); | |
455b2899 MH |
1306 | } |
1307 | ||
1308 | int trace_probe_init(struct trace_probe *tp, const char *event, | |
b61387cb | 1309 | const char *group, bool alloc_filter) |
455b2899 | 1310 | { |
60d53e2c | 1311 | struct trace_event_call *call; |
b61387cb | 1312 | size_t size = sizeof(struct trace_probe_event); |
60d53e2c | 1313 | int ret = 0; |
e3dc9f89 | 1314 | |
455b2899 MH |
1315 | if (!event || !group) |
1316 | return -EINVAL; | |
1317 | ||
b61387cb MH |
1318 | if (alloc_filter) |
1319 | size += sizeof(struct trace_uprobe_filter); | |
1320 | ||
1321 | tp->event = kzalloc(size, GFP_KERNEL); | |
60d53e2c | 1322 | if (!tp->event) |
455b2899 MH |
1323 | return -ENOMEM; |
1324 | ||
d59fae6f MH |
1325 | INIT_LIST_HEAD(&tp->event->files); |
1326 | INIT_LIST_HEAD(&tp->event->class.fields); | |
1327 | INIT_LIST_HEAD(&tp->event->probes); | |
1328 | INIT_LIST_HEAD(&tp->list); | |
fc9d276f | 1329 | list_add(&tp->list, &tp->event->probes); |
d59fae6f | 1330 | |
60d53e2c MH |
1331 | call = trace_probe_event_call(tp); |
1332 | call->class = &tp->event->class; | |
1333 | call->name = kstrdup(event, GFP_KERNEL); | |
1334 | if (!call->name) { | |
1335 | ret = -ENOMEM; | |
1336 | goto error; | |
1337 | } | |
1338 | ||
1339 | tp->event->class.system = kstrdup(group, GFP_KERNEL); | |
1340 | if (!tp->event->class.system) { | |
1341 | ret = -ENOMEM; | |
1342 | goto error; | |
455b2899 | 1343 | } |
455b2899 MH |
1344 | |
1345 | return 0; | |
60d53e2c MH |
1346 | |
1347 | error: | |
1348 | trace_probe_cleanup(tp); | |
1349 | return ret; | |
455b2899 | 1350 | } |
46e5376d | 1351 | |
8e242060 MH |
1352 | static struct trace_event_call * |
1353 | find_trace_event_call(const char *system, const char *event_name) | |
1354 | { | |
1355 | struct trace_event_call *tp_event; | |
1356 | const char *name; | |
1357 | ||
1358 | list_for_each_entry(tp_event, &ftrace_events, list) { | |
1359 | if (!tp_event->class->system || | |
1360 | strcmp(system, tp_event->class->system)) | |
1361 | continue; | |
1362 | name = trace_event_name(tp_event); | |
1363 | if (!name || strcmp(event_name, name)) | |
1364 | continue; | |
1365 | return tp_event; | |
1366 | } | |
1367 | ||
1368 | return NULL; | |
1369 | } | |
1370 | ||
46e5376d MH |
1371 | int trace_probe_register_event_call(struct trace_probe *tp) |
1372 | { | |
e3dc9f89 | 1373 | struct trace_event_call *call = trace_probe_event_call(tp); |
46e5376d MH |
1374 | int ret; |
1375 | ||
8e242060 MH |
1376 | lockdep_assert_held(&event_mutex); |
1377 | ||
1378 | if (find_trace_event_call(trace_probe_group_name(tp), | |
1379 | trace_probe_name(tp))) | |
1380 | return -EEXIST; | |
1381 | ||
46e5376d MH |
1382 | ret = register_trace_event(&call->event); |
1383 | if (!ret) | |
1384 | return -ENODEV; | |
1385 | ||
1386 | ret = trace_add_event_call(call); | |
1387 | if (ret) | |
1388 | unregister_trace_event(&call->event); | |
1389 | ||
1390 | return ret; | |
1391 | } | |
b5f935ee MH |
1392 | |
1393 | int trace_probe_add_file(struct trace_probe *tp, struct trace_event_file *file) | |
1394 | { | |
1395 | struct event_file_link *link; | |
1396 | ||
1397 | link = kmalloc(sizeof(*link), GFP_KERNEL); | |
1398 | if (!link) | |
1399 | return -ENOMEM; | |
1400 | ||
1401 | link->file = file; | |
1402 | INIT_LIST_HEAD(&link->list); | |
60d53e2c | 1403 | list_add_tail_rcu(&link->list, &tp->event->files); |
747774d6 | 1404 | trace_probe_set_flag(tp, TP_FLAG_TRACE); |
b5f935ee MH |
1405 | return 0; |
1406 | } | |
1407 | ||
1408 | struct event_file_link *trace_probe_get_file_link(struct trace_probe *tp, | |
1409 | struct trace_event_file *file) | |
1410 | { | |
1411 | struct event_file_link *link; | |
1412 | ||
1413 | trace_probe_for_each_link(link, tp) { | |
1414 | if (link->file == file) | |
1415 | return link; | |
1416 | } | |
1417 | ||
1418 | return NULL; | |
1419 | } | |
1420 | ||
1421 | int trace_probe_remove_file(struct trace_probe *tp, | |
1422 | struct trace_event_file *file) | |
1423 | { | |
1424 | struct event_file_link *link; | |
1425 | ||
1426 | link = trace_probe_get_file_link(tp, file); | |
1427 | if (!link) | |
1428 | return -ENOENT; | |
1429 | ||
1430 | list_del_rcu(&link->list); | |
cae16f2c | 1431 | kvfree_rcu_mightsleep(link); |
b5f935ee | 1432 | |
60d53e2c | 1433 | if (list_empty(&tp->event->files)) |
747774d6 | 1434 | trace_probe_clear_flag(tp, TP_FLAG_TRACE); |
b5f935ee MH |
1435 | |
1436 | return 0; | |
1437 | } | |
ca89bc07 MH |
1438 | |
1439 | /* | |
1440 | * Return the smallest index of different type argument (start from 1). | |
1441 | * If all argument types and name are same, return 0. | |
1442 | */ | |
1443 | int trace_probe_compare_arg_type(struct trace_probe *a, struct trace_probe *b) | |
1444 | { | |
1445 | int i; | |
1446 | ||
d2aea95a MH |
1447 | /* In case of more arguments */ |
1448 | if (a->nr_args < b->nr_args) | |
1449 | return a->nr_args + 1; | |
1450 | if (a->nr_args > b->nr_args) | |
1451 | return b->nr_args + 1; | |
1452 | ||
ca89bc07 MH |
1453 | for (i = 0; i < a->nr_args; i++) { |
1454 | if ((b->nr_args <= i) || | |
1455 | ((a->args[i].type != b->args[i].type) || | |
1456 | (a->args[i].count != b->args[i].count) || | |
1457 | strcmp(a->args[i].name, b->args[i].name))) | |
1458 | return i + 1; | |
1459 | } | |
1460 | ||
1461 | return 0; | |
1462 | } | |
eb5bf813 MH |
1463 | |
1464 | bool trace_probe_match_command_args(struct trace_probe *tp, | |
1465 | int argc, const char **argv) | |
1466 | { | |
1467 | char buf[MAX_ARGSTR_LEN + 1]; | |
1468 | int i; | |
1469 | ||
1470 | if (tp->nr_args < argc) | |
1471 | return false; | |
1472 | ||
1473 | for (i = 0; i < argc; i++) { | |
1474 | snprintf(buf, sizeof(buf), "%s=%s", | |
1475 | tp->args[i].name, tp->args[i].comm); | |
1476 | if (strcmp(buf, argv[i])) | |
1477 | return false; | |
1478 | } | |
1479 | return true; | |
1480 | } | |
d262271d MH |
1481 | |
1482 | int trace_probe_create(const char *raw_command, int (*createfn)(int, const char **)) | |
1483 | { | |
1484 | int argc = 0, ret = 0; | |
1485 | char **argv; | |
1486 | ||
1487 | argv = argv_split(GFP_KERNEL, raw_command, &argc); | |
1488 | if (!argv) | |
1489 | return -ENOMEM; | |
1490 | ||
1491 | if (argc) | |
1492 | ret = createfn(argc, (const char **)argv); | |
1493 | ||
1494 | argv_free(argv); | |
1495 | ||
1496 | return ret; | |
1497 | } | |
196b6389 SC |
1498 | |
1499 | int trace_probe_print_args(struct trace_seq *s, struct probe_arg *args, int nr_args, | |
1500 | u8 *data, void *field) | |
1501 | { | |
1502 | void *p; | |
1503 | int i, j; | |
1504 | ||
1505 | for (i = 0; i < nr_args; i++) { | |
1506 | struct probe_arg *a = args + i; | |
1507 | ||
1508 | trace_seq_printf(s, " %s=", a->name); | |
1509 | if (likely(!a->count)) { | |
1510 | if (!a->type->print(s, data + a->offset, field)) | |
1511 | return -ENOMEM; | |
1512 | continue; | |
1513 | } | |
1514 | trace_seq_putc(s, '{'); | |
1515 | p = data + a->offset; | |
1516 | for (j = 0; j < a->count; j++) { | |
1517 | if (!a->type->print(s, p, field)) | |
1518 | return -ENOMEM; | |
1519 | trace_seq_putc(s, j == a->count - 1 ? '}' : ','); | |
1520 | p += a->type->size; | |
1521 | } | |
1522 | } | |
1523 | return 0; | |
1524 | } |