Steven Rostedt (VMware) | bcea3f9 | 2018-08-16 11:23:53 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 2 | /* |
| 3 | * Common code for probe-based Dynamic events. |
| 4 | * |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 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 | */ |
Masami Hiramatsu | 7257634 | 2017-02-07 20:21:28 +0900 | [diff] [blame] | 12 | #define pr_fmt(fmt) "trace_probe: " fmt |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 13 | |
| 14 | #include "trace_probe.h" |
| 15 | |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 16 | #undef C |
| 17 | #define C(a, b) b |
| 18 | |
| 19 | static const char *trace_probe_err_text[] = { ERRORS }; |
| 20 | |
Valdis Klētnieks | 0841625 | 2019-03-12 04:52:58 -0400 | [diff] [blame] | 21 | static const char *reserved_field_names[] = { |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 22 | "common_type", |
| 23 | "common_flags", |
| 24 | "common_preempt_count", |
| 25 | "common_pid", |
| 26 | "common_tgid", |
| 27 | FIELD_STRING_IP, |
| 28 | FIELD_STRING_RETIP, |
| 29 | FIELD_STRING_FUNC, |
| 30 | }; |
| 31 | |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 32 | /* Printing in basic type function template */ |
Masami Hiramatsu | 17ce3dc | 2016-08-18 17:57:50 +0900 | [diff] [blame] | 33 | #define DEFINE_BASIC_PRINT_TYPE_FUNC(tname, type, fmt) \ |
Masami Hiramatsu | 56de763 | 2018-04-25 21:16:36 +0900 | [diff] [blame] | 34 | int PRINT_TYPE_FUNC_NAME(tname)(struct trace_seq *s, void *data, void *ent)\ |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 35 | { \ |
Masami Hiramatsu | 56de763 | 2018-04-25 21:16:36 +0900 | [diff] [blame] | 36 | trace_seq_printf(s, fmt, *(type *)data); \ |
Steven Rostedt (Red Hat) | d2b0191 | 2014-11-12 17:19:51 -0500 | [diff] [blame] | 37 | return !trace_seq_has_overflowed(s); \ |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 38 | } \ |
Masami Hiramatsu | 7bfbc63 | 2018-04-25 21:17:34 +0900 | [diff] [blame] | 39 | const char PRINT_TYPE_FMT_NAME(tname)[] = fmt; |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 40 | |
Masami Hiramatsu | bdca79c2 | 2016-08-18 17:59:21 +0900 | [diff] [blame] | 41 | DEFINE_BASIC_PRINT_TYPE_FUNC(u8, u8, "%u") |
| 42 | DEFINE_BASIC_PRINT_TYPE_FUNC(u16, u16, "%u") |
| 43 | DEFINE_BASIC_PRINT_TYPE_FUNC(u32, u32, "%u") |
| 44 | DEFINE_BASIC_PRINT_TYPE_FUNC(u64, u64, "%Lu") |
Masami Hiramatsu | 17ce3dc | 2016-08-18 17:57:50 +0900 | [diff] [blame] | 45 | DEFINE_BASIC_PRINT_TYPE_FUNC(s8, s8, "%d") |
| 46 | DEFINE_BASIC_PRINT_TYPE_FUNC(s16, s16, "%d") |
| 47 | DEFINE_BASIC_PRINT_TYPE_FUNC(s32, s32, "%d") |
| 48 | DEFINE_BASIC_PRINT_TYPE_FUNC(s64, s64, "%Ld") |
| 49 | DEFINE_BASIC_PRINT_TYPE_FUNC(x8, u8, "0x%x") |
| 50 | DEFINE_BASIC_PRINT_TYPE_FUNC(x16, u16, "0x%x") |
| 51 | DEFINE_BASIC_PRINT_TYPE_FUNC(x32, u32, "0x%x") |
| 52 | DEFINE_BASIC_PRINT_TYPE_FUNC(x64, u64, "0x%Lx") |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 53 | |
Masami Hiramatsu | 60c2e0c | 2018-04-25 21:20:28 +0900 | [diff] [blame] | 54 | int PRINT_TYPE_FUNC_NAME(symbol)(struct trace_seq *s, void *data, void *ent) |
| 55 | { |
| 56 | trace_seq_printf(s, "%pS", (void *)*(unsigned long *)data); |
| 57 | return !trace_seq_has_overflowed(s); |
| 58 | } |
| 59 | const char PRINT_TYPE_FMT_NAME(symbol)[] = "%pS"; |
| 60 | |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 61 | /* Print type function for string type */ |
Masami Hiramatsu | 56de763 | 2018-04-25 21:16:36 +0900 | [diff] [blame] | 62 | int PRINT_TYPE_FUNC_NAME(string)(struct trace_seq *s, void *data, void *ent) |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 63 | { |
| 64 | int len = *(u32 *)data >> 16; |
| 65 | |
| 66 | if (!len) |
Masami Hiramatsu | 56de763 | 2018-04-25 21:16:36 +0900 | [diff] [blame] | 67 | trace_seq_puts(s, "(fault)"); |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 68 | else |
Masami Hiramatsu | 56de763 | 2018-04-25 21:16:36 +0900 | [diff] [blame] | 69 | trace_seq_printf(s, "\"%s\"", |
Steven Rostedt (Red Hat) | d2b0191 | 2014-11-12 17:19:51 -0500 | [diff] [blame] | 70 | (const char *)get_loc_data(data, ent)); |
| 71 | return !trace_seq_has_overflowed(s); |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 72 | } |
| 73 | |
Namhyung Kim | b26c74e | 2013-11-26 14:19:59 +0900 | [diff] [blame] | 74 | const char PRINT_TYPE_FMT_NAME(string)[] = "\\\"%s\\\""; |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 75 | |
Masami Hiramatsu | f451bc8 | 2018-04-25 21:18:32 +0900 | [diff] [blame] | 76 | /* Fetch type information table */ |
| 77 | static const struct fetch_type probe_fetch_types[] = { |
| 78 | /* Special types */ |
| 79 | __ASSIGN_FETCH_TYPE("string", string, string, sizeof(u32), 1, |
| 80 | "__data_loc char[]"), |
Masami Hiramatsu | 88903c4 | 2019-05-15 14:38:30 +0900 | [diff] [blame] | 81 | __ASSIGN_FETCH_TYPE("ustring", string, string, sizeof(u32), 1, |
| 82 | "__data_loc char[]"), |
Masami Hiramatsu | f451bc8 | 2018-04-25 21:18:32 +0900 | [diff] [blame] | 83 | /* Basic types */ |
| 84 | ASSIGN_FETCH_TYPE(u8, u8, 0), |
| 85 | ASSIGN_FETCH_TYPE(u16, u16, 0), |
| 86 | ASSIGN_FETCH_TYPE(u32, u32, 0), |
| 87 | ASSIGN_FETCH_TYPE(u64, u64, 0), |
| 88 | ASSIGN_FETCH_TYPE(s8, u8, 1), |
| 89 | ASSIGN_FETCH_TYPE(s16, u16, 1), |
| 90 | ASSIGN_FETCH_TYPE(s32, u32, 1), |
| 91 | ASSIGN_FETCH_TYPE(s64, u64, 1), |
| 92 | ASSIGN_FETCH_TYPE_ALIAS(x8, u8, u8, 0), |
| 93 | ASSIGN_FETCH_TYPE_ALIAS(x16, u16, u16, 0), |
| 94 | ASSIGN_FETCH_TYPE_ALIAS(x32, u32, u32, 0), |
| 95 | ASSIGN_FETCH_TYPE_ALIAS(x64, u64, u64, 0), |
Masami Hiramatsu | 60c2e0c | 2018-04-25 21:20:28 +0900 | [diff] [blame] | 96 | ASSIGN_FETCH_TYPE_ALIAS(symbol, ADDR_FETCH_TYPE, ADDR_FETCH_TYPE, 0), |
Masami Hiramatsu | f451bc8 | 2018-04-25 21:18:32 +0900 | [diff] [blame] | 97 | |
| 98 | ASSIGN_FETCH_TYPE_END |
| 99 | }; |
| 100 | |
| 101 | static const struct fetch_type *find_fetch_type(const char *type) |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 102 | { |
| 103 | int i; |
| 104 | |
| 105 | if (!type) |
| 106 | type = DEFAULT_FETCH_TYPE_STR; |
| 107 | |
| 108 | /* Special case: bitfield */ |
| 109 | if (*type == 'b') { |
| 110 | unsigned long bs; |
| 111 | |
| 112 | type = strchr(type, '/'); |
| 113 | if (!type) |
| 114 | goto fail; |
| 115 | |
| 116 | type++; |
Daniel Walter | bcd83ea | 2012-09-26 22:08:38 +0200 | [diff] [blame] | 117 | if (kstrtoul(type, 0, &bs)) |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 118 | goto fail; |
| 119 | |
| 120 | switch (bs) { |
| 121 | case 8: |
Masami Hiramatsu | f451bc8 | 2018-04-25 21:18:32 +0900 | [diff] [blame] | 122 | return find_fetch_type("u8"); |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 123 | case 16: |
Masami Hiramatsu | f451bc8 | 2018-04-25 21:18:32 +0900 | [diff] [blame] | 124 | return find_fetch_type("u16"); |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 125 | case 32: |
Masami Hiramatsu | f451bc8 | 2018-04-25 21:18:32 +0900 | [diff] [blame] | 126 | return find_fetch_type("u32"); |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 127 | case 64: |
Masami Hiramatsu | f451bc8 | 2018-04-25 21:18:32 +0900 | [diff] [blame] | 128 | return find_fetch_type("u64"); |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 129 | default: |
| 130 | goto fail; |
| 131 | } |
| 132 | } |
| 133 | |
Masami Hiramatsu | f451bc8 | 2018-04-25 21:18:32 +0900 | [diff] [blame] | 134 | for (i = 0; probe_fetch_types[i].name; i++) { |
| 135 | if (strcmp(type, probe_fetch_types[i].name) == 0) |
| 136 | return &probe_fetch_types[i]; |
Namhyung Kim | 34fee3a | 2013-11-26 14:56:28 +0900 | [diff] [blame] | 137 | } |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 138 | |
| 139 | fail: |
| 140 | return NULL; |
| 141 | } |
| 142 | |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 143 | static struct trace_probe_log trace_probe_log; |
| 144 | |
| 145 | void trace_probe_log_init(const char *subsystem, int argc, const char **argv) |
| 146 | { |
| 147 | trace_probe_log.subsystem = subsystem; |
| 148 | trace_probe_log.argc = argc; |
| 149 | trace_probe_log.argv = argv; |
| 150 | trace_probe_log.index = 0; |
| 151 | } |
| 152 | |
| 153 | void trace_probe_log_clear(void) |
| 154 | { |
| 155 | memset(&trace_probe_log, 0, sizeof(trace_probe_log)); |
| 156 | } |
| 157 | |
| 158 | void trace_probe_log_set_index(int index) |
| 159 | { |
| 160 | trace_probe_log.index = index; |
| 161 | } |
| 162 | |
| 163 | void __trace_probe_log_err(int offset, int err_type) |
| 164 | { |
| 165 | char *command, *p; |
| 166 | int i, len = 0, pos = 0; |
| 167 | |
| 168 | if (!trace_probe_log.argv) |
| 169 | return; |
| 170 | |
Ingo Molnar | f2cc020 | 2021-03-23 18:49:35 +0100 | [diff] [blame] | 171 | /* Recalculate the length and allocate buffer */ |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 172 | for (i = 0; i < trace_probe_log.argc; i++) { |
| 173 | if (i == trace_probe_log.index) |
| 174 | pos = len; |
| 175 | len += strlen(trace_probe_log.argv[i]) + 1; |
| 176 | } |
| 177 | command = kzalloc(len, GFP_KERNEL); |
| 178 | if (!command) |
| 179 | return; |
| 180 | |
Masami Hiramatsu | d2aea95 | 2019-09-28 05:53:29 -0400 | [diff] [blame] | 181 | if (trace_probe_log.index >= trace_probe_log.argc) { |
| 182 | /** |
| 183 | * Set the error position is next to the last arg + space. |
| 184 | * Note that len includes the terminal null and the cursor |
Ingo Molnar | f2cc020 | 2021-03-23 18:49:35 +0100 | [diff] [blame] | 185 | * appears at pos + 1. |
Masami Hiramatsu | d2aea95 | 2019-09-28 05:53:29 -0400 | [diff] [blame] | 186 | */ |
| 187 | pos = len; |
| 188 | offset = 0; |
| 189 | } |
| 190 | |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 191 | /* And make a command string from argv array */ |
| 192 | p = command; |
| 193 | for (i = 0; i < trace_probe_log.argc; i++) { |
| 194 | len = strlen(trace_probe_log.argv[i]); |
| 195 | strcpy(p, trace_probe_log.argv[i]); |
| 196 | p[len] = ' '; |
| 197 | p += len + 1; |
| 198 | } |
| 199 | *(p - 1) = '\0'; |
| 200 | |
Steven Rostedt (VMware) | 2f754e7 | 2019-04-01 22:52:21 -0400 | [diff] [blame] | 201 | tracing_log_err(NULL, trace_probe_log.subsystem, command, |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 202 | trace_probe_err_text, err_type, pos + offset); |
| 203 | |
| 204 | kfree(command); |
| 205 | } |
| 206 | |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 207 | /* Split symbol and offset. */ |
Masami Hiramatsu | c5d343b | 2018-03-17 21:38:10 +0900 | [diff] [blame] | 208 | int traceprobe_split_symbol_offset(char *symbol, long *offset) |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 209 | { |
| 210 | char *tmp; |
| 211 | int ret; |
| 212 | |
| 213 | if (!offset) |
| 214 | return -EINVAL; |
| 215 | |
Masami Hiramatsu | c5d343b | 2018-03-17 21:38:10 +0900 | [diff] [blame] | 216 | tmp = strpbrk(symbol, "+-"); |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 217 | if (tmp) { |
Masami Hiramatsu | c5d343b | 2018-03-17 21:38:10 +0900 | [diff] [blame] | 218 | ret = kstrtol(tmp, 0, offset); |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 219 | if (ret) |
| 220 | return ret; |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 221 | *tmp = '\0'; |
| 222 | } else |
| 223 | *offset = 0; |
| 224 | |
| 225 | return 0; |
| 226 | } |
| 227 | |
Masami Hiramatsu | 6212dd2 | 2018-11-05 18:02:36 +0900 | [diff] [blame] | 228 | /* @buf must has MAX_EVENT_NAME_LEN size */ |
| 229 | int traceprobe_parse_event_name(const char **pevent, const char **pgroup, |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 230 | char *buf, int offset) |
Masami Hiramatsu | 6212dd2 | 2018-11-05 18:02:36 +0900 | [diff] [blame] | 231 | { |
| 232 | const char *slash, *event = *pevent; |
Masami Hiramatsu | dec65d79 | 2019-03-14 13:30:20 +0900 | [diff] [blame] | 233 | int len; |
Masami Hiramatsu | 6212dd2 | 2018-11-05 18:02:36 +0900 | [diff] [blame] | 234 | |
| 235 | slash = strchr(event, '/'); |
Steven Rostedt (VMware) | bc1b973 | 2021-08-16 23:42:59 -0400 | [diff] [blame^] | 236 | if (!slash) |
| 237 | slash = strchr(event, '.'); |
| 238 | |
Masami Hiramatsu | 6212dd2 | 2018-11-05 18:02:36 +0900 | [diff] [blame] | 239 | if (slash) { |
| 240 | if (slash == event) { |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 241 | trace_probe_log_err(offset, NO_GROUP_NAME); |
Masami Hiramatsu | 6212dd2 | 2018-11-05 18:02:36 +0900 | [diff] [blame] | 242 | return -EINVAL; |
| 243 | } |
| 244 | if (slash - event + 1 > MAX_EVENT_NAME_LEN) { |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 245 | trace_probe_log_err(offset, GROUP_TOO_LONG); |
| 246 | return -EINVAL; |
Masami Hiramatsu | 6212dd2 | 2018-11-05 18:02:36 +0900 | [diff] [blame] | 247 | } |
| 248 | strlcpy(buf, event, slash - event + 1); |
Masami Hiramatsu | 5b7a962 | 2019-03-14 13:30:40 +0900 | [diff] [blame] | 249 | if (!is_good_name(buf)) { |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 250 | trace_probe_log_err(offset, BAD_GROUP_NAME); |
Masami Hiramatsu | 5b7a962 | 2019-03-14 13:30:40 +0900 | [diff] [blame] | 251 | return -EINVAL; |
| 252 | } |
Masami Hiramatsu | 6212dd2 | 2018-11-05 18:02:36 +0900 | [diff] [blame] | 253 | *pgroup = buf; |
| 254 | *pevent = slash + 1; |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 255 | offset += slash - event + 1; |
Masami Hiramatsu | dec65d79 | 2019-03-14 13:30:20 +0900 | [diff] [blame] | 256 | event = *pevent; |
Masami Hiramatsu | 6212dd2 | 2018-11-05 18:02:36 +0900 | [diff] [blame] | 257 | } |
Masami Hiramatsu | dec65d79 | 2019-03-14 13:30:20 +0900 | [diff] [blame] | 258 | len = strlen(event); |
| 259 | if (len == 0) { |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 260 | trace_probe_log_err(offset, NO_EVENT_NAME); |
Masami Hiramatsu | 6212dd2 | 2018-11-05 18:02:36 +0900 | [diff] [blame] | 261 | return -EINVAL; |
Masami Hiramatsu | dec65d79 | 2019-03-14 13:30:20 +0900 | [diff] [blame] | 262 | } else if (len > MAX_EVENT_NAME_LEN) { |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 263 | trace_probe_log_err(offset, EVENT_TOO_LONG); |
| 264 | return -EINVAL; |
Masami Hiramatsu | 6212dd2 | 2018-11-05 18:02:36 +0900 | [diff] [blame] | 265 | } |
Masami Hiramatsu | 5b7a962 | 2019-03-14 13:30:40 +0900 | [diff] [blame] | 266 | if (!is_good_name(event)) { |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 267 | trace_probe_log_err(offset, BAD_EVENT_NAME); |
Masami Hiramatsu | 5b7a962 | 2019-03-14 13:30:40 +0900 | [diff] [blame] | 268 | return -EINVAL; |
| 269 | } |
Masami Hiramatsu | 6212dd2 | 2018-11-05 18:02:36 +0900 | [diff] [blame] | 270 | return 0; |
| 271 | } |
| 272 | |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 273 | #define PARAM_MAX_STACK (THREAD_SIZE / sizeof(unsigned long)) |
| 274 | |
| 275 | static int parse_probe_vars(char *arg, const struct fetch_type *t, |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 276 | struct fetch_insn *code, unsigned int flags, int offs) |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 277 | { |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 278 | unsigned long param; |
Steven Rostedt (VMware) | 3d739c1 | 2018-12-21 23:10:26 -0500 | [diff] [blame] | 279 | int ret = 0; |
| 280 | int len; |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 281 | |
| 282 | if (strcmp(arg, "retval") == 0) { |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 283 | if (flags & TPARG_FL_RETURN) { |
Masami Hiramatsu | 5330592 | 2018-04-25 21:18:03 +0900 | [diff] [blame] | 284 | code->op = FETCH_OP_RETVAL; |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 285 | } else { |
| 286 | trace_probe_log_err(offs, RETVAL_ON_PROBE); |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 287 | ret = -EINVAL; |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 288 | } |
Steven Rostedt (VMware) | 3d739c1 | 2018-12-21 23:10:26 -0500 | [diff] [blame] | 289 | } else if ((len = str_has_prefix(arg, "stack"))) { |
| 290 | if (arg[len] == '\0') { |
Masami Hiramatsu | 5330592 | 2018-04-25 21:18:03 +0900 | [diff] [blame] | 291 | code->op = FETCH_OP_STACKP; |
Steven Rostedt (VMware) | 3d739c1 | 2018-12-21 23:10:26 -0500 | [diff] [blame] | 292 | } else if (isdigit(arg[len])) { |
| 293 | ret = kstrtoul(arg + len, 10, ¶m); |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 294 | if (ret) { |
| 295 | goto inval_var; |
| 296 | } else if ((flags & TPARG_FL_KERNEL) && |
| 297 | param > PARAM_MAX_STACK) { |
| 298 | trace_probe_log_err(offs, BAD_STACK_NUM); |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 299 | ret = -EINVAL; |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 300 | } else { |
Masami Hiramatsu | 5330592 | 2018-04-25 21:18:03 +0900 | [diff] [blame] | 301 | code->op = FETCH_OP_STACK; |
| 302 | code->param = (unsigned int)param; |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 303 | } |
| 304 | } else |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 305 | goto inval_var; |
Omar Sandoval | 35abb67 | 2016-06-08 18:38:02 -0700 | [diff] [blame] | 306 | } else if (strcmp(arg, "comm") == 0) { |
Masami Hiramatsu | 5330592 | 2018-04-25 21:18:03 +0900 | [diff] [blame] | 307 | code->op = FETCH_OP_COMM; |
Masami Hiramatsu | a1303af | 2018-04-25 21:21:26 +0900 | [diff] [blame] | 308 | #ifdef CONFIG_HAVE_FUNCTION_ARG_ACCESS_API |
| 309 | } else if (((flags & TPARG_FL_MASK) == |
| 310 | (TPARG_FL_KERNEL | TPARG_FL_FENTRY)) && |
Steven Rostedt (VMware) | 3d739c1 | 2018-12-21 23:10:26 -0500 | [diff] [blame] | 311 | (len = str_has_prefix(arg, "arg"))) { |
Steven Rostedt (VMware) | 3d739c1 | 2018-12-21 23:10:26 -0500 | [diff] [blame] | 312 | ret = kstrtoul(arg + len, 10, ¶m); |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 313 | if (ret) { |
| 314 | goto inval_var; |
| 315 | } else if (!param || param > PARAM_MAX_STACK) { |
| 316 | trace_probe_log_err(offs, BAD_ARG_NUM); |
Masami Hiramatsu | a1303af | 2018-04-25 21:21:26 +0900 | [diff] [blame] | 317 | return -EINVAL; |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 318 | } |
Masami Hiramatsu | a1303af | 2018-04-25 21:21:26 +0900 | [diff] [blame] | 319 | code->op = FETCH_OP_ARG; |
| 320 | code->param = (unsigned int)param - 1; |
| 321 | #endif |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 322 | } else |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 323 | goto inval_var; |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 324 | |
| 325 | return ret; |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 326 | |
| 327 | inval_var: |
| 328 | trace_probe_log_err(offs, BAD_VAR); |
| 329 | return -EINVAL; |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 330 | } |
| 331 | |
Masami Hiramatsu | 6218bf9 | 2019-06-20 00:08:27 +0900 | [diff] [blame] | 332 | static int str_to_immediate(char *str, unsigned long *imm) |
| 333 | { |
| 334 | if (isdigit(str[0])) |
| 335 | return kstrtoul(str, 0, imm); |
| 336 | else if (str[0] == '-') |
| 337 | return kstrtol(str, 0, (long *)imm); |
| 338 | else if (str[0] == '+') |
| 339 | return kstrtol(str + 1, 0, (long *)imm); |
| 340 | return -EINVAL; |
| 341 | } |
| 342 | |
Masami Hiramatsu | a42e3c4 | 2019-06-20 00:08:37 +0900 | [diff] [blame] | 343 | static int __parse_imm_string(char *str, char **pbuf, int offs) |
| 344 | { |
| 345 | size_t len = strlen(str); |
| 346 | |
| 347 | if (str[len - 1] != '"') { |
| 348 | trace_probe_log_err(offs + len, IMMSTR_NO_CLOSE); |
| 349 | return -EINVAL; |
| 350 | } |
| 351 | *pbuf = kstrndup(str, len - 1, GFP_KERNEL); |
| 352 | return 0; |
| 353 | } |
| 354 | |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 355 | /* Recursive argument parser */ |
Masami Hiramatsu | 5330592 | 2018-04-25 21:18:03 +0900 | [diff] [blame] | 356 | static int |
| 357 | parse_probe_arg(char *arg, const struct fetch_type *type, |
| 358 | struct fetch_insn **pcode, struct fetch_insn *end, |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 359 | unsigned int flags, int offs) |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 360 | { |
Masami Hiramatsu | 5330592 | 2018-04-25 21:18:03 +0900 | [diff] [blame] | 361 | struct fetch_insn *code = *pcode; |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 362 | unsigned long param; |
Masami Hiramatsu | e65f7ae | 2019-05-15 14:38:42 +0900 | [diff] [blame] | 363 | int deref = FETCH_OP_DEREF; |
Steven Rostedt (VMware) | bf173ca | 2018-10-12 12:50:22 -0400 | [diff] [blame] | 364 | long offset = 0; |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 365 | char *tmp; |
Namhyung Kim | 34fee3a | 2013-11-26 14:56:28 +0900 | [diff] [blame] | 366 | int ret = 0; |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 367 | |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 368 | switch (arg[0]) { |
| 369 | case '$': |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 370 | ret = parse_probe_vars(arg + 1, type, code, flags, offs); |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 371 | break; |
| 372 | |
| 373 | case '%': /* named register */ |
| 374 | ret = regs_query_register_offset(arg + 1); |
| 375 | if (ret >= 0) { |
Masami Hiramatsu | 5330592 | 2018-04-25 21:18:03 +0900 | [diff] [blame] | 376 | code->op = FETCH_OP_REG; |
| 377 | code->param = (unsigned int)ret; |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 378 | ret = 0; |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 379 | } else |
| 380 | trace_probe_log_err(offs, BAD_REG_NAME); |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 381 | break; |
| 382 | |
Namhyung Kim | b7e0bf3 | 2013-11-25 13:42:47 +0900 | [diff] [blame] | 383 | case '@': /* memory, file-offset or symbol */ |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 384 | if (isdigit(arg[1])) { |
Daniel Walter | bcd83ea | 2012-09-26 22:08:38 +0200 | [diff] [blame] | 385 | ret = kstrtoul(arg + 1, 0, ¶m); |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 386 | if (ret) { |
| 387 | trace_probe_log_err(offs, BAD_MEM_ADDR); |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 388 | break; |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 389 | } |
Masami Hiramatsu | 5330592 | 2018-04-25 21:18:03 +0900 | [diff] [blame] | 390 | /* load address */ |
| 391 | code->op = FETCH_OP_IMM; |
| 392 | code->immediate = param; |
Namhyung Kim | b7e0bf3 | 2013-11-25 13:42:47 +0900 | [diff] [blame] | 393 | } else if (arg[1] == '+') { |
| 394 | /* kprobes don't support file offsets */ |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 395 | if (flags & TPARG_FL_KERNEL) { |
| 396 | trace_probe_log_err(offs, FILE_ON_KPROBE); |
Namhyung Kim | b7e0bf3 | 2013-11-25 13:42:47 +0900 | [diff] [blame] | 397 | return -EINVAL; |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 398 | } |
Namhyung Kim | b7e0bf3 | 2013-11-25 13:42:47 +0900 | [diff] [blame] | 399 | ret = kstrtol(arg + 2, 0, &offset); |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 400 | if (ret) { |
| 401 | trace_probe_log_err(offs, BAD_FILE_OFFS); |
Namhyung Kim | b7e0bf3 | 2013-11-25 13:42:47 +0900 | [diff] [blame] | 402 | break; |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 403 | } |
Namhyung Kim | b7e0bf3 | 2013-11-25 13:42:47 +0900 | [diff] [blame] | 404 | |
Masami Hiramatsu | 5330592 | 2018-04-25 21:18:03 +0900 | [diff] [blame] | 405 | code->op = FETCH_OP_FOFFS; |
| 406 | code->immediate = (unsigned long)offset; // imm64? |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 407 | } else { |
Namhyung Kim | b079d37 | 2013-07-03 18:34:23 +0900 | [diff] [blame] | 408 | /* uprobes don't support symbols */ |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 409 | if (!(flags & TPARG_FL_KERNEL)) { |
| 410 | trace_probe_log_err(offs, SYM_ON_UPROBE); |
Namhyung Kim | b079d37 | 2013-07-03 18:34:23 +0900 | [diff] [blame] | 411 | return -EINVAL; |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 412 | } |
Masami Hiramatsu | a668281 | 2018-08-29 01:18:43 +0900 | [diff] [blame] | 413 | /* Preserve symbol for updating */ |
| 414 | code->op = FETCH_NOP_SYMBOL; |
| 415 | code->data = kstrdup(arg + 1, GFP_KERNEL); |
| 416 | if (!code->data) |
| 417 | return -ENOMEM; |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 418 | if (++code == end) { |
| 419 | trace_probe_log_err(offs, TOO_MANY_OPS); |
| 420 | return -EINVAL; |
| 421 | } |
Masami Hiramatsu | 5330592 | 2018-04-25 21:18:03 +0900 | [diff] [blame] | 422 | code->op = FETCH_OP_IMM; |
Masami Hiramatsu | a668281 | 2018-08-29 01:18:43 +0900 | [diff] [blame] | 423 | code->immediate = 0; |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 424 | } |
Masami Hiramatsu | 5330592 | 2018-04-25 21:18:03 +0900 | [diff] [blame] | 425 | /* These are fetching from memory */ |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 426 | if (++code == end) { |
| 427 | trace_probe_log_err(offs, TOO_MANY_OPS); |
| 428 | return -EINVAL; |
| 429 | } |
Masami Hiramatsu | 5330592 | 2018-04-25 21:18:03 +0900 | [diff] [blame] | 430 | *pcode = code; |
| 431 | code->op = FETCH_OP_DEREF; |
| 432 | code->offset = offset; |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 433 | break; |
| 434 | |
| 435 | case '+': /* deref memory */ |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 436 | case '-': |
Masami Hiramatsu | e65f7ae | 2019-05-15 14:38:42 +0900 | [diff] [blame] | 437 | if (arg[1] == 'u') { |
| 438 | deref = FETCH_OP_UDEREF; |
| 439 | arg[1] = arg[0]; |
| 440 | arg++; |
| 441 | } |
| 442 | if (arg[0] == '+') |
| 443 | arg++; /* Skip '+', because kstrtol() rejects it. */ |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 444 | tmp = strchr(arg, '('); |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 445 | if (!tmp) { |
| 446 | trace_probe_log_err(offs, DEREF_NEED_BRACE); |
Masami Hiramatsu | 5330592 | 2018-04-25 21:18:03 +0900 | [diff] [blame] | 447 | return -EINVAL; |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 448 | } |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 449 | *tmp = '\0'; |
Daniel Walter | bcd83ea | 2012-09-26 22:08:38 +0200 | [diff] [blame] | 450 | ret = kstrtol(arg, 0, &offset); |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 451 | if (ret) { |
| 452 | trace_probe_log_err(offs, BAD_DEREF_OFFS); |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 453 | break; |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 454 | } |
| 455 | offs += (tmp + 1 - arg) + (arg[0] != '-' ? 1 : 0); |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 456 | arg = tmp + 1; |
| 457 | tmp = strrchr(arg, ')'); |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 458 | if (!tmp) { |
| 459 | trace_probe_log_err(offs + strlen(arg), |
| 460 | DEREF_OPEN_BRACE); |
| 461 | return -EINVAL; |
| 462 | } else { |
Masami Hiramatsu | f451bc8 | 2018-04-25 21:18:32 +0900 | [diff] [blame] | 463 | const struct fetch_type *t2 = find_fetch_type(NULL); |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 464 | |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 465 | *tmp = '\0'; |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 466 | ret = parse_probe_arg(arg, t2, &code, end, flags, offs); |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 467 | if (ret) |
Masami Hiramatsu | 5330592 | 2018-04-25 21:18:03 +0900 | [diff] [blame] | 468 | break; |
Masami Hiramatsu | a42e3c4 | 2019-06-20 00:08:37 +0900 | [diff] [blame] | 469 | if (code->op == FETCH_OP_COMM || |
| 470 | code->op == FETCH_OP_DATA) { |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 471 | trace_probe_log_err(offs, COMM_CANT_DEREF); |
Masami Hiramatsu | 5330592 | 2018-04-25 21:18:03 +0900 | [diff] [blame] | 472 | return -EINVAL; |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 473 | } |
| 474 | if (++code == end) { |
| 475 | trace_probe_log_err(offs, TOO_MANY_OPS); |
| 476 | return -EINVAL; |
| 477 | } |
Masami Hiramatsu | 5330592 | 2018-04-25 21:18:03 +0900 | [diff] [blame] | 478 | *pcode = code; |
| 479 | |
Masami Hiramatsu | e65f7ae | 2019-05-15 14:38:42 +0900 | [diff] [blame] | 480 | code->op = deref; |
Masami Hiramatsu | 5330592 | 2018-04-25 21:18:03 +0900 | [diff] [blame] | 481 | code->offset = offset; |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 482 | } |
| 483 | break; |
Masami Hiramatsu | 6218bf9 | 2019-06-20 00:08:27 +0900 | [diff] [blame] | 484 | case '\\': /* Immediate value */ |
Masami Hiramatsu | a42e3c4 | 2019-06-20 00:08:37 +0900 | [diff] [blame] | 485 | if (arg[1] == '"') { /* Immediate string */ |
| 486 | ret = __parse_imm_string(arg + 2, &tmp, offs + 2); |
| 487 | if (ret) |
| 488 | break; |
| 489 | code->op = FETCH_OP_DATA; |
| 490 | code->data = tmp; |
| 491 | } else { |
| 492 | ret = str_to_immediate(arg + 1, &code->immediate); |
| 493 | if (ret) |
| 494 | trace_probe_log_err(offs + 1, BAD_IMM); |
| 495 | else |
| 496 | code->op = FETCH_OP_IMM; |
| 497 | } |
Masami Hiramatsu | 6218bf9 | 2019-06-20 00:08:27 +0900 | [diff] [blame] | 498 | break; |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 499 | } |
Masami Hiramatsu | 5330592 | 2018-04-25 21:18:03 +0900 | [diff] [blame] | 500 | if (!ret && code->op == FETCH_OP_NOP) { |
| 501 | /* Parsed, but do not find fetch method */ |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 502 | trace_probe_log_err(offs, BAD_FETCH_ARG); |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 503 | ret = -EINVAL; |
| 504 | } |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 505 | return ret; |
| 506 | } |
| 507 | |
| 508 | #define BYTES_TO_BITS(nb) ((BITS_PER_LONG * (nb)) / sizeof(long)) |
| 509 | |
| 510 | /* Bitfield type needs to be parsed into a fetch function */ |
| 511 | static int __parse_bitfield_probe_arg(const char *bf, |
| 512 | const struct fetch_type *t, |
Masami Hiramatsu | 5330592 | 2018-04-25 21:18:03 +0900 | [diff] [blame] | 513 | struct fetch_insn **pcode) |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 514 | { |
Masami Hiramatsu | 5330592 | 2018-04-25 21:18:03 +0900 | [diff] [blame] | 515 | struct fetch_insn *code = *pcode; |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 516 | unsigned long bw, bo; |
| 517 | char *tail; |
| 518 | |
| 519 | if (*bf != 'b') |
| 520 | return 0; |
| 521 | |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 522 | bw = simple_strtoul(bf + 1, &tail, 0); /* Use simple one */ |
| 523 | |
| 524 | if (bw == 0 || *tail != '@') |
| 525 | return -EINVAL; |
| 526 | |
| 527 | bf = tail + 1; |
| 528 | bo = simple_strtoul(bf, &tail, 0); |
| 529 | |
| 530 | if (tail == bf || *tail != '/') |
| 531 | return -EINVAL; |
Masami Hiramatsu | 5330592 | 2018-04-25 21:18:03 +0900 | [diff] [blame] | 532 | code++; |
| 533 | if (code->op != FETCH_OP_NOP) |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 534 | return -EINVAL; |
Masami Hiramatsu | 5330592 | 2018-04-25 21:18:03 +0900 | [diff] [blame] | 535 | *pcode = code; |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 536 | |
Masami Hiramatsu | 5330592 | 2018-04-25 21:18:03 +0900 | [diff] [blame] | 537 | code->op = FETCH_OP_MOD_BF; |
| 538 | code->lshift = BYTES_TO_BITS(t->size) - (bw + bo); |
| 539 | code->rshift = BYTES_TO_BITS(t->size) - bw; |
| 540 | code->basesize = t->size; |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 541 | |
| 542 | return (BYTES_TO_BITS(t->size) < (bw + bo)) ? -EINVAL : 0; |
| 543 | } |
| 544 | |
| 545 | /* String length checking wrapper */ |
Steven Rostedt (VMware) | fcd9db5 | 2021-08-16 23:42:58 -0400 | [diff] [blame] | 546 | static int traceprobe_parse_probe_arg_body(const char *argv, ssize_t *size, |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 547 | struct probe_arg *parg, unsigned int flags, int offset) |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 548 | { |
Masami Hiramatsu | 40b53b7 | 2018-04-25 21:21:55 +0900 | [diff] [blame] | 549 | struct fetch_insn *code, *scode, *tmp = NULL; |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 550 | char *t, *t2, *t3; |
Steven Rostedt (VMware) | fcd9db5 | 2021-08-16 23:42:58 -0400 | [diff] [blame] | 551 | char *arg; |
Masami Hiramatsu | 40b53b7 | 2018-04-25 21:21:55 +0900 | [diff] [blame] | 552 | int ret, len; |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 553 | |
Steven Rostedt (VMware) | fcd9db5 | 2021-08-16 23:42:58 -0400 | [diff] [blame] | 554 | arg = kstrdup(argv, GFP_KERNEL); |
| 555 | if (!arg) |
| 556 | return -ENOMEM; |
| 557 | |
| 558 | ret = -EINVAL; |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 559 | len = strlen(arg); |
| 560 | if (len > MAX_ARGSTR_LEN) { |
| 561 | trace_probe_log_err(offset, ARG_TOO_LONG); |
Steven Rostedt (VMware) | fcd9db5 | 2021-08-16 23:42:58 -0400 | [diff] [blame] | 562 | goto out; |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 563 | } else if (len == 0) { |
| 564 | trace_probe_log_err(offset, NO_ARG_BODY); |
Steven Rostedt (VMware) | fcd9db5 | 2021-08-16 23:42:58 -0400 | [diff] [blame] | 565 | goto out; |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 566 | } |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 567 | |
Steven Rostedt (VMware) | fcd9db5 | 2021-08-16 23:42:58 -0400 | [diff] [blame] | 568 | ret = -ENOMEM; |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 569 | parg->comm = kstrdup(arg, GFP_KERNEL); |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 570 | if (!parg->comm) |
Steven Rostedt (VMware) | fcd9db5 | 2021-08-16 23:42:58 -0400 | [diff] [blame] | 571 | goto out; |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 572 | |
Steven Rostedt (VMware) | fcd9db5 | 2021-08-16 23:42:58 -0400 | [diff] [blame] | 573 | ret = -EINVAL; |
Masami Hiramatsu | 40b53b7 | 2018-04-25 21:21:55 +0900 | [diff] [blame] | 574 | t = strchr(arg, ':'); |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 575 | if (t) { |
Masami Hiramatsu | 40b53b7 | 2018-04-25 21:21:55 +0900 | [diff] [blame] | 576 | *t = '\0'; |
| 577 | t2 = strchr(++t, '['); |
| 578 | if (t2) { |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 579 | *t2++ = '\0'; |
| 580 | t3 = strchr(t2, ']'); |
| 581 | if (!t3) { |
| 582 | offset += t2 + strlen(t2) - arg; |
| 583 | trace_probe_log_err(offset, |
| 584 | ARRAY_NO_CLOSE); |
Steven Rostedt (VMware) | fcd9db5 | 2021-08-16 23:42:58 -0400 | [diff] [blame] | 585 | goto out; |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 586 | } else if (t3[1] != '\0') { |
| 587 | trace_probe_log_err(offset + t3 + 1 - arg, |
| 588 | BAD_ARRAY_SUFFIX); |
Steven Rostedt (VMware) | fcd9db5 | 2021-08-16 23:42:58 -0400 | [diff] [blame] | 589 | goto out; |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 590 | } |
| 591 | *t3 = '\0'; |
| 592 | if (kstrtouint(t2, 0, &parg->count) || !parg->count) { |
| 593 | trace_probe_log_err(offset + t2 - arg, |
| 594 | BAD_ARRAY_NUM); |
Steven Rostedt (VMware) | fcd9db5 | 2021-08-16 23:42:58 -0400 | [diff] [blame] | 595 | goto out; |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 596 | } |
| 597 | if (parg->count > MAX_ARRAY_LEN) { |
| 598 | trace_probe_log_err(offset + t2 - arg, |
| 599 | ARRAY_TOO_BIG); |
Steven Rostedt (VMware) | fcd9db5 | 2021-08-16 23:42:58 -0400 | [diff] [blame] | 600 | goto out; |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 601 | } |
Masami Hiramatsu | 40b53b7 | 2018-04-25 21:21:55 +0900 | [diff] [blame] | 602 | } |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 603 | } |
Masami Hiramatsu | 3dd1f7f | 2019-05-07 22:56:02 +0900 | [diff] [blame] | 604 | |
Masami Hiramatsu | a42e3c4 | 2019-06-20 00:08:37 +0900 | [diff] [blame] | 605 | /* |
Ingo Molnar | f2cc020 | 2021-03-23 18:49:35 +0100 | [diff] [blame] | 606 | * Since $comm and immediate string can not be dereferenced, |
Masami Hiramatsu | a42e3c4 | 2019-06-20 00:08:37 +0900 | [diff] [blame] | 607 | * we can find those by strcmp. |
| 608 | */ |
| 609 | if (strcmp(arg, "$comm") == 0 || strncmp(arg, "\\\"", 2) == 0) { |
Masami Hiramatsu | 3dd1f7f | 2019-05-07 22:56:02 +0900 | [diff] [blame] | 610 | /* The type of $comm must be "string", and not an array. */ |
| 611 | if (parg->count || (t && strcmp(t, "string"))) |
Steven Rostedt (VMware) | fcd9db5 | 2021-08-16 23:42:58 -0400 | [diff] [blame] | 612 | goto out; |
Masami Hiramatsu | 40b53b7 | 2018-04-25 21:21:55 +0900 | [diff] [blame] | 613 | parg->type = find_fetch_type("string"); |
Masami Hiramatsu | 3dd1f7f | 2019-05-07 22:56:02 +0900 | [diff] [blame] | 614 | } else |
Masami Hiramatsu | 40b53b7 | 2018-04-25 21:21:55 +0900 | [diff] [blame] | 615 | parg->type = find_fetch_type(t); |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 616 | if (!parg->type) { |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 617 | trace_probe_log_err(offset + (t ? (t - arg) : 0), BAD_TYPE); |
Steven Rostedt (VMware) | fcd9db5 | 2021-08-16 23:42:58 -0400 | [diff] [blame] | 618 | goto out; |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 619 | } |
| 620 | parg->offset = *size; |
Masami Hiramatsu | 40b53b7 | 2018-04-25 21:21:55 +0900 | [diff] [blame] | 621 | *size += parg->type->size * (parg->count ?: 1); |
| 622 | |
Steven Rostedt (VMware) | fcd9db5 | 2021-08-16 23:42:58 -0400 | [diff] [blame] | 623 | ret = -ENOMEM; |
Masami Hiramatsu | 40b53b7 | 2018-04-25 21:21:55 +0900 | [diff] [blame] | 624 | if (parg->count) { |
| 625 | len = strlen(parg->type->fmttype) + 6; |
| 626 | parg->fmt = kmalloc(len, GFP_KERNEL); |
| 627 | if (!parg->fmt) |
Steven Rostedt (VMware) | fcd9db5 | 2021-08-16 23:42:58 -0400 | [diff] [blame] | 628 | goto out; |
Masami Hiramatsu | 40b53b7 | 2018-04-25 21:21:55 +0900 | [diff] [blame] | 629 | snprintf(parg->fmt, len, "%s[%d]", parg->type->fmttype, |
| 630 | parg->count); |
| 631 | } |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 632 | |
Gustavo A. R. Silva | 8623b00 | 2019-01-14 22:34:08 -0600 | [diff] [blame] | 633 | code = tmp = kcalloc(FETCH_INSN_MAX, sizeof(*code), GFP_KERNEL); |
Masami Hiramatsu | 5330592 | 2018-04-25 21:18:03 +0900 | [diff] [blame] | 634 | if (!code) |
Steven Rostedt (VMware) | fcd9db5 | 2021-08-16 23:42:58 -0400 | [diff] [blame] | 635 | goto out; |
Masami Hiramatsu | 5330592 | 2018-04-25 21:18:03 +0900 | [diff] [blame] | 636 | code[FETCH_INSN_MAX - 1].op = FETCH_OP_END; |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 637 | |
Masami Hiramatsu | 5330592 | 2018-04-25 21:18:03 +0900 | [diff] [blame] | 638 | ret = parse_probe_arg(arg, parg->type, &code, &code[FETCH_INSN_MAX - 1], |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 639 | flags, offset); |
Masami Hiramatsu | 5330592 | 2018-04-25 21:18:03 +0900 | [diff] [blame] | 640 | if (ret) |
| 641 | goto fail; |
| 642 | |
Steven Rostedt (VMware) | fcd9db5 | 2021-08-16 23:42:58 -0400 | [diff] [blame] | 643 | ret = -EINVAL; |
Masami Hiramatsu | 5330592 | 2018-04-25 21:18:03 +0900 | [diff] [blame] | 644 | /* Store operation */ |
Masami Hiramatsu | 88903c4 | 2019-05-15 14:38:30 +0900 | [diff] [blame] | 645 | if (!strcmp(parg->type->name, "string") || |
| 646 | !strcmp(parg->type->name, "ustring")) { |
Masami Hiramatsu | e65f7ae | 2019-05-15 14:38:42 +0900 | [diff] [blame] | 647 | if (code->op != FETCH_OP_DEREF && code->op != FETCH_OP_UDEREF && |
Masami Hiramatsu | a42e3c4 | 2019-06-20 00:08:37 +0900 | [diff] [blame] | 648 | code->op != FETCH_OP_IMM && code->op != FETCH_OP_COMM && |
| 649 | code->op != FETCH_OP_DATA) { |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 650 | trace_probe_log_err(offset + (t ? (t - arg) : 0), |
| 651 | BAD_STRING); |
Masami Hiramatsu | 5330592 | 2018-04-25 21:18:03 +0900 | [diff] [blame] | 652 | goto fail; |
| 653 | } |
Vamshi K Sthambamkadi | 3aa8fdc | 2020-06-15 20:00:38 +0530 | [diff] [blame] | 654 | if ((code->op == FETCH_OP_IMM || code->op == FETCH_OP_COMM || |
| 655 | code->op == FETCH_OP_DATA) || parg->count) { |
Masami Hiramatsu | 40b53b7 | 2018-04-25 21:21:55 +0900 | [diff] [blame] | 656 | /* |
Masami Hiramatsu | a42e3c4 | 2019-06-20 00:08:37 +0900 | [diff] [blame] | 657 | * IMM, DATA and COMM is pointing actual address, those |
| 658 | * must be kept, and if parg->count != 0, this is an |
| 659 | * array of string pointers instead of string address |
| 660 | * itself. |
Masami Hiramatsu | 40b53b7 | 2018-04-25 21:21:55 +0900 | [diff] [blame] | 661 | */ |
Masami Hiramatsu | 5330592 | 2018-04-25 21:18:03 +0900 | [diff] [blame] | 662 | code++; |
Masami Hiramatsu | 40b53b7 | 2018-04-25 21:21:55 +0900 | [diff] [blame] | 663 | if (code->op != FETCH_OP_NOP) { |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 664 | trace_probe_log_err(offset, TOO_MANY_OPS); |
Masami Hiramatsu | 40b53b7 | 2018-04-25 21:21:55 +0900 | [diff] [blame] | 665 | goto fail; |
| 666 | } |
| 667 | } |
Masami Hiramatsu | 88903c4 | 2019-05-15 14:38:30 +0900 | [diff] [blame] | 668 | /* If op == DEREF, replace it with STRING */ |
Masami Hiramatsu | e65f7ae | 2019-05-15 14:38:42 +0900 | [diff] [blame] | 669 | if (!strcmp(parg->type->name, "ustring") || |
| 670 | code->op == FETCH_OP_UDEREF) |
Masami Hiramatsu | 88903c4 | 2019-05-15 14:38:30 +0900 | [diff] [blame] | 671 | code->op = FETCH_OP_ST_USTRING; |
| 672 | else |
| 673 | code->op = FETCH_OP_ST_STRING; |
Masami Hiramatsu | 40b53b7 | 2018-04-25 21:21:55 +0900 | [diff] [blame] | 674 | code->size = parg->type->size; |
Masami Hiramatsu | 5330592 | 2018-04-25 21:18:03 +0900 | [diff] [blame] | 675 | parg->dynamic = true; |
| 676 | } else if (code->op == FETCH_OP_DEREF) { |
| 677 | code->op = FETCH_OP_ST_MEM; |
| 678 | code->size = parg->type->size; |
Masami Hiramatsu | e65f7ae | 2019-05-15 14:38:42 +0900 | [diff] [blame] | 679 | } else if (code->op == FETCH_OP_UDEREF) { |
| 680 | code->op = FETCH_OP_ST_UMEM; |
| 681 | code->size = parg->type->size; |
Masami Hiramatsu | 5330592 | 2018-04-25 21:18:03 +0900 | [diff] [blame] | 682 | } else { |
| 683 | code++; |
| 684 | if (code->op != FETCH_OP_NOP) { |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 685 | trace_probe_log_err(offset, TOO_MANY_OPS); |
Masami Hiramatsu | 5330592 | 2018-04-25 21:18:03 +0900 | [diff] [blame] | 686 | goto fail; |
| 687 | } |
| 688 | code->op = FETCH_OP_ST_RAW; |
| 689 | code->size = parg->type->size; |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 690 | } |
Masami Hiramatsu | 40b53b7 | 2018-04-25 21:21:55 +0900 | [diff] [blame] | 691 | scode = code; |
Masami Hiramatsu | 5330592 | 2018-04-25 21:18:03 +0900 | [diff] [blame] | 692 | /* Modify operation */ |
| 693 | if (t != NULL) { |
| 694 | ret = __parse_bitfield_probe_arg(t, parg->type, &code); |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 695 | if (ret) { |
| 696 | trace_probe_log_err(offset + t - arg, BAD_BITFIELD); |
Masami Hiramatsu | 5330592 | 2018-04-25 21:18:03 +0900 | [diff] [blame] | 697 | goto fail; |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 698 | } |
Masami Hiramatsu | 5330592 | 2018-04-25 21:18:03 +0900 | [diff] [blame] | 699 | } |
Steven Rostedt (VMware) | fcd9db5 | 2021-08-16 23:42:58 -0400 | [diff] [blame] | 700 | ret = -EINVAL; |
Masami Hiramatsu | 40b53b7 | 2018-04-25 21:21:55 +0900 | [diff] [blame] | 701 | /* Loop(Array) operation */ |
| 702 | if (parg->count) { |
| 703 | if (scode->op != FETCH_OP_ST_MEM && |
Masami Hiramatsu | 88903c4 | 2019-05-15 14:38:30 +0900 | [diff] [blame] | 704 | scode->op != FETCH_OP_ST_STRING && |
| 705 | scode->op != FETCH_OP_ST_USTRING) { |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 706 | trace_probe_log_err(offset + (t ? (t - arg) : 0), |
| 707 | BAD_STRING); |
Masami Hiramatsu | 40b53b7 | 2018-04-25 21:21:55 +0900 | [diff] [blame] | 708 | goto fail; |
| 709 | } |
| 710 | code++; |
| 711 | if (code->op != FETCH_OP_NOP) { |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 712 | trace_probe_log_err(offset, TOO_MANY_OPS); |
Masami Hiramatsu | 40b53b7 | 2018-04-25 21:21:55 +0900 | [diff] [blame] | 713 | goto fail; |
| 714 | } |
| 715 | code->op = FETCH_OP_LP_ARRAY; |
| 716 | code->param = parg->count; |
| 717 | } |
Masami Hiramatsu | 5330592 | 2018-04-25 21:18:03 +0900 | [diff] [blame] | 718 | code++; |
| 719 | code->op = FETCH_OP_END; |
| 720 | |
Steven Rostedt (VMware) | fcd9db5 | 2021-08-16 23:42:58 -0400 | [diff] [blame] | 721 | ret = 0; |
Masami Hiramatsu | 5330592 | 2018-04-25 21:18:03 +0900 | [diff] [blame] | 722 | /* Shrink down the code buffer */ |
Gustavo A. R. Silva | 8623b00 | 2019-01-14 22:34:08 -0600 | [diff] [blame] | 723 | parg->code = kcalloc(code - tmp + 1, sizeof(*code), GFP_KERNEL); |
Masami Hiramatsu | 5330592 | 2018-04-25 21:18:03 +0900 | [diff] [blame] | 724 | if (!parg->code) |
| 725 | ret = -ENOMEM; |
| 726 | else |
| 727 | memcpy(parg->code, tmp, sizeof(*code) * (code - tmp + 1)); |
| 728 | |
| 729 | fail: |
Masami Hiramatsu | a668281 | 2018-08-29 01:18:43 +0900 | [diff] [blame] | 730 | if (ret) { |
| 731 | for (code = tmp; code < tmp + FETCH_INSN_MAX; code++) |
Masami Hiramatsu | a42e3c4 | 2019-06-20 00:08:37 +0900 | [diff] [blame] | 732 | if (code->op == FETCH_NOP_SYMBOL || |
| 733 | code->op == FETCH_OP_DATA) |
Masami Hiramatsu | a668281 | 2018-08-29 01:18:43 +0900 | [diff] [blame] | 734 | kfree(code->data); |
| 735 | } |
Masami Hiramatsu | 5330592 | 2018-04-25 21:18:03 +0900 | [diff] [blame] | 736 | kfree(tmp); |
Steven Rostedt (VMware) | fcd9db5 | 2021-08-16 23:42:58 -0400 | [diff] [blame] | 737 | out: |
| 738 | kfree(arg); |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 739 | |
| 740 | return ret; |
| 741 | } |
| 742 | |
| 743 | /* Return 1 if name is reserved or already used by another argument */ |
Masami Hiramatsu | d00bbea9 | 2018-11-05 18:01:40 +0900 | [diff] [blame] | 744 | static int traceprobe_conflict_field_name(const char *name, |
| 745 | struct probe_arg *args, int narg) |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 746 | { |
| 747 | int i; |
| 748 | |
| 749 | for (i = 0; i < ARRAY_SIZE(reserved_field_names); i++) |
| 750 | if (strcmp(reserved_field_names[i], name) == 0) |
| 751 | return 1; |
| 752 | |
| 753 | for (i = 0; i < narg; i++) |
| 754 | if (strcmp(args[i].name, name) == 0) |
| 755 | return 1; |
| 756 | |
| 757 | return 0; |
| 758 | } |
| 759 | |
Steven Rostedt (VMware) | fcd9db5 | 2021-08-16 23:42:58 -0400 | [diff] [blame] | 760 | int traceprobe_parse_probe_arg(struct trace_probe *tp, int i, const char *arg, |
Masami Hiramatsu | d00bbea9 | 2018-11-05 18:01:40 +0900 | [diff] [blame] | 761 | unsigned int flags) |
| 762 | { |
| 763 | struct probe_arg *parg = &tp->args[i]; |
Steven Rostedt (VMware) | fcd9db5 | 2021-08-16 23:42:58 -0400 | [diff] [blame] | 764 | const char *body; |
Masami Hiramatsu | d00bbea9 | 2018-11-05 18:01:40 +0900 | [diff] [blame] | 765 | |
| 766 | /* Increment count for freeing args in error case */ |
| 767 | tp->nr_args++; |
| 768 | |
| 769 | body = strchr(arg, '='); |
| 770 | if (body) { |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 771 | if (body - arg > MAX_ARG_NAME_LEN) { |
| 772 | trace_probe_log_err(0, ARG_NAME_TOO_LONG); |
Masami Hiramatsu | b4443c1 | 2019-03-14 13:30:30 +0900 | [diff] [blame] | 773 | return -EINVAL; |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 774 | } else if (body == arg) { |
| 775 | trace_probe_log_err(0, NO_ARG_NAME); |
| 776 | return -EINVAL; |
| 777 | } |
Masami Hiramatsu | d00bbea9 | 2018-11-05 18:01:40 +0900 | [diff] [blame] | 778 | parg->name = kmemdup_nul(arg, body - arg, GFP_KERNEL); |
| 779 | body++; |
| 780 | } else { |
| 781 | /* If argument name is omitted, set "argN" */ |
| 782 | parg->name = kasprintf(GFP_KERNEL, "arg%d", i + 1); |
| 783 | body = arg; |
| 784 | } |
| 785 | if (!parg->name) |
| 786 | return -ENOMEM; |
| 787 | |
| 788 | if (!is_good_name(parg->name)) { |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 789 | trace_probe_log_err(0, BAD_ARG_NAME); |
Masami Hiramatsu | d00bbea9 | 2018-11-05 18:01:40 +0900 | [diff] [blame] | 790 | return -EINVAL; |
| 791 | } |
Masami Hiramatsu | d00bbea9 | 2018-11-05 18:01:40 +0900 | [diff] [blame] | 792 | if (traceprobe_conflict_field_name(parg->name, tp->args, i)) { |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 793 | trace_probe_log_err(0, USED_ARG_NAME); |
Masami Hiramatsu | d00bbea9 | 2018-11-05 18:01:40 +0900 | [diff] [blame] | 794 | return -EINVAL; |
| 795 | } |
Masami Hiramatsu | d00bbea9 | 2018-11-05 18:01:40 +0900 | [diff] [blame] | 796 | /* Parse fetch argument */ |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 797 | return traceprobe_parse_probe_arg_body(body, &tp->size, parg, flags, |
| 798 | body - arg); |
Masami Hiramatsu | d00bbea9 | 2018-11-05 18:01:40 +0900 | [diff] [blame] | 799 | } |
| 800 | |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 801 | void traceprobe_free_probe_arg(struct probe_arg *arg) |
| 802 | { |
Masami Hiramatsu | a668281 | 2018-08-29 01:18:43 +0900 | [diff] [blame] | 803 | struct fetch_insn *code = arg->code; |
| 804 | |
| 805 | while (code && code->op != FETCH_OP_END) { |
Masami Hiramatsu | a42e3c4 | 2019-06-20 00:08:37 +0900 | [diff] [blame] | 806 | if (code->op == FETCH_NOP_SYMBOL || |
| 807 | code->op == FETCH_OP_DATA) |
Masami Hiramatsu | a668281 | 2018-08-29 01:18:43 +0900 | [diff] [blame] | 808 | kfree(code->data); |
| 809 | code++; |
| 810 | } |
Masami Hiramatsu | 5330592 | 2018-04-25 21:18:03 +0900 | [diff] [blame] | 811 | kfree(arg->code); |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 812 | kfree(arg->name); |
| 813 | kfree(arg->comm); |
Masami Hiramatsu | 40b53b7 | 2018-04-25 21:21:55 +0900 | [diff] [blame] | 814 | kfree(arg->fmt); |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 815 | } |
| 816 | |
Masami Hiramatsu | a668281 | 2018-08-29 01:18:43 +0900 | [diff] [blame] | 817 | int traceprobe_update_arg(struct probe_arg *arg) |
| 818 | { |
| 819 | struct fetch_insn *code = arg->code; |
| 820 | long offset; |
| 821 | char *tmp; |
| 822 | char c; |
| 823 | int ret = 0; |
| 824 | |
| 825 | while (code && code->op != FETCH_OP_END) { |
| 826 | if (code->op == FETCH_NOP_SYMBOL) { |
| 827 | if (code[1].op != FETCH_OP_IMM) |
| 828 | return -EINVAL; |
| 829 | |
Masami Hiramatsu | ee474b8 | 2018-11-01 23:29:28 +0900 | [diff] [blame] | 830 | tmp = strpbrk(code->data, "+-"); |
Masami Hiramatsu | a668281 | 2018-08-29 01:18:43 +0900 | [diff] [blame] | 831 | if (tmp) |
| 832 | c = *tmp; |
| 833 | ret = traceprobe_split_symbol_offset(code->data, |
| 834 | &offset); |
| 835 | if (ret) |
| 836 | return ret; |
| 837 | |
| 838 | code[1].immediate = |
| 839 | (unsigned long)kallsyms_lookup_name(code->data); |
| 840 | if (tmp) |
| 841 | *tmp = c; |
| 842 | if (!code[1].immediate) |
| 843 | return -ENOENT; |
| 844 | code[1].immediate += offset; |
| 845 | } |
| 846 | code++; |
| 847 | } |
| 848 | return 0; |
| 849 | } |
| 850 | |
Masami Hiramatsu | 40b53b7 | 2018-04-25 21:21:55 +0900 | [diff] [blame] | 851 | /* When len=0, we just calculate the needed length */ |
| 852 | #define LEN_OR_ZERO (len ? len - pos : 0) |
Namhyung Kim | 5bf652a | 2013-07-03 16:09:02 +0900 | [diff] [blame] | 853 | static int __set_print_fmt(struct trace_probe *tp, char *buf, int len, |
| 854 | bool is_return) |
| 855 | { |
Masami Hiramatsu | 40b53b7 | 2018-04-25 21:21:55 +0900 | [diff] [blame] | 856 | struct probe_arg *parg; |
| 857 | int i, j; |
Namhyung Kim | 5bf652a | 2013-07-03 16:09:02 +0900 | [diff] [blame] | 858 | int pos = 0; |
Namhyung Kim | 5bf652a | 2013-07-03 16:09:02 +0900 | [diff] [blame] | 859 | const char *fmt, *arg; |
| 860 | |
| 861 | if (!is_return) { |
| 862 | fmt = "(%lx)"; |
| 863 | arg = "REC->" FIELD_STRING_IP; |
| 864 | } else { |
| 865 | fmt = "(%lx <- %lx)"; |
| 866 | arg = "REC->" FIELD_STRING_FUNC ", REC->" FIELD_STRING_RETIP; |
| 867 | } |
| 868 | |
Namhyung Kim | 5bf652a | 2013-07-03 16:09:02 +0900 | [diff] [blame] | 869 | pos += snprintf(buf + pos, LEN_OR_ZERO, "\"%s", fmt); |
| 870 | |
| 871 | for (i = 0; i < tp->nr_args; i++) { |
Masami Hiramatsu | 40b53b7 | 2018-04-25 21:21:55 +0900 | [diff] [blame] | 872 | parg = tp->args + i; |
| 873 | pos += snprintf(buf + pos, LEN_OR_ZERO, " %s=", parg->name); |
| 874 | if (parg->count) { |
| 875 | pos += snprintf(buf + pos, LEN_OR_ZERO, "{%s", |
| 876 | parg->type->fmt); |
| 877 | for (j = 1; j < parg->count; j++) |
| 878 | pos += snprintf(buf + pos, LEN_OR_ZERO, ",%s", |
| 879 | parg->type->fmt); |
| 880 | pos += snprintf(buf + pos, LEN_OR_ZERO, "}"); |
| 881 | } else |
| 882 | pos += snprintf(buf + pos, LEN_OR_ZERO, "%s", |
| 883 | parg->type->fmt); |
Namhyung Kim | 5bf652a | 2013-07-03 16:09:02 +0900 | [diff] [blame] | 884 | } |
| 885 | |
| 886 | pos += snprintf(buf + pos, LEN_OR_ZERO, "\", %s", arg); |
| 887 | |
| 888 | for (i = 0; i < tp->nr_args; i++) { |
Masami Hiramatsu | 40b53b7 | 2018-04-25 21:21:55 +0900 | [diff] [blame] | 889 | parg = tp->args + i; |
| 890 | if (parg->count) { |
Steven Rostedt (VMware) | 2027942 | 2020-01-24 10:07:42 -0500 | [diff] [blame] | 891 | if ((strcmp(parg->type->name, "string") == 0) || |
| 892 | (strcmp(parg->type->name, "ustring") == 0)) |
Masami Hiramatsu | 40b53b7 | 2018-04-25 21:21:55 +0900 | [diff] [blame] | 893 | fmt = ", __get_str(%s[%d])"; |
| 894 | else |
| 895 | fmt = ", REC->%s[%d]"; |
| 896 | for (j = 0; j < parg->count; j++) |
| 897 | pos += snprintf(buf + pos, LEN_OR_ZERO, |
| 898 | fmt, parg->name, j); |
| 899 | } else { |
Steven Rostedt (VMware) | 2027942 | 2020-01-24 10:07:42 -0500 | [diff] [blame] | 900 | if ((strcmp(parg->type->name, "string") == 0) || |
| 901 | (strcmp(parg->type->name, "ustring") == 0)) |
Masami Hiramatsu | 40b53b7 | 2018-04-25 21:21:55 +0900 | [diff] [blame] | 902 | fmt = ", __get_str(%s)"; |
| 903 | else |
| 904 | fmt = ", REC->%s"; |
Namhyung Kim | 5bf652a | 2013-07-03 16:09:02 +0900 | [diff] [blame] | 905 | pos += snprintf(buf + pos, LEN_OR_ZERO, |
Masami Hiramatsu | 40b53b7 | 2018-04-25 21:21:55 +0900 | [diff] [blame] | 906 | fmt, parg->name); |
| 907 | } |
Namhyung Kim | 5bf652a | 2013-07-03 16:09:02 +0900 | [diff] [blame] | 908 | } |
| 909 | |
Namhyung Kim | 5bf652a | 2013-07-03 16:09:02 +0900 | [diff] [blame] | 910 | /* return the length of print_fmt */ |
| 911 | return pos; |
| 912 | } |
Masami Hiramatsu | 40b53b7 | 2018-04-25 21:21:55 +0900 | [diff] [blame] | 913 | #undef LEN_OR_ZERO |
Namhyung Kim | 5bf652a | 2013-07-03 16:09:02 +0900 | [diff] [blame] | 914 | |
Masami Hiramatsu | 0a46c85 | 2018-04-25 21:19:30 +0900 | [diff] [blame] | 915 | int traceprobe_set_print_fmt(struct trace_probe *tp, bool is_return) |
Namhyung Kim | 5bf652a | 2013-07-03 16:09:02 +0900 | [diff] [blame] | 916 | { |
Masami Hiramatsu | e3dc9f8 | 2019-06-01 00:17:57 +0900 | [diff] [blame] | 917 | struct trace_event_call *call = trace_probe_event_call(tp); |
Namhyung Kim | 5bf652a | 2013-07-03 16:09:02 +0900 | [diff] [blame] | 918 | int len; |
| 919 | char *print_fmt; |
| 920 | |
| 921 | /* First: called with 0 length to calculate the needed length */ |
| 922 | len = __set_print_fmt(tp, NULL, 0, is_return); |
| 923 | print_fmt = kmalloc(len + 1, GFP_KERNEL); |
| 924 | if (!print_fmt) |
| 925 | return -ENOMEM; |
| 926 | |
| 927 | /* Second: actually write the @print_fmt */ |
| 928 | __set_print_fmt(tp, print_fmt, len + 1, is_return); |
Masami Hiramatsu | e3dc9f8 | 2019-06-01 00:17:57 +0900 | [diff] [blame] | 929 | call->print_fmt = print_fmt; |
Namhyung Kim | 5bf652a | 2013-07-03 16:09:02 +0900 | [diff] [blame] | 930 | |
| 931 | return 0; |
| 932 | } |
Masami Hiramatsu | eeb07b0 | 2018-04-25 21:17:05 +0900 | [diff] [blame] | 933 | |
| 934 | int traceprobe_define_arg_fields(struct trace_event_call *event_call, |
| 935 | size_t offset, struct trace_probe *tp) |
| 936 | { |
| 937 | int ret, i; |
| 938 | |
| 939 | /* Set argument names as fields */ |
| 940 | for (i = 0; i < tp->nr_args; i++) { |
| 941 | struct probe_arg *parg = &tp->args[i]; |
Masami Hiramatsu | 40b53b7 | 2018-04-25 21:21:55 +0900 | [diff] [blame] | 942 | const char *fmt = parg->type->fmttype; |
| 943 | int size = parg->type->size; |
Masami Hiramatsu | eeb07b0 | 2018-04-25 21:17:05 +0900 | [diff] [blame] | 944 | |
Masami Hiramatsu | 40b53b7 | 2018-04-25 21:21:55 +0900 | [diff] [blame] | 945 | if (parg->fmt) |
| 946 | fmt = parg->fmt; |
| 947 | if (parg->count) |
| 948 | size *= parg->count; |
| 949 | ret = trace_define_field(event_call, fmt, parg->name, |
| 950 | offset + parg->offset, size, |
Masami Hiramatsu | eeb07b0 | 2018-04-25 21:17:05 +0900 | [diff] [blame] | 951 | parg->type->is_signed, |
| 952 | FILTER_OTHER); |
| 953 | if (ret) |
| 954 | return ret; |
| 955 | } |
| 956 | return 0; |
| 957 | } |
Masami Hiramatsu | 455b289 | 2019-06-01 00:17:06 +0900 | [diff] [blame] | 958 | |
Masami Hiramatsu | ca89bc0 | 2019-06-20 00:07:49 +0900 | [diff] [blame] | 959 | static void trace_probe_event_free(struct trace_probe_event *tpe) |
| 960 | { |
| 961 | kfree(tpe->class.system); |
| 962 | kfree(tpe->call.name); |
| 963 | kfree(tpe->call.print_fmt); |
| 964 | kfree(tpe); |
| 965 | } |
| 966 | |
| 967 | int trace_probe_append(struct trace_probe *tp, struct trace_probe *to) |
| 968 | { |
| 969 | if (trace_probe_has_sibling(tp)) |
| 970 | return -EBUSY; |
| 971 | |
| 972 | list_del_init(&tp->list); |
| 973 | trace_probe_event_free(tp->event); |
| 974 | |
| 975 | tp->event = to->event; |
| 976 | list_add_tail(&tp->list, trace_probe_probe_list(to)); |
| 977 | |
| 978 | return 0; |
| 979 | } |
| 980 | |
| 981 | void trace_probe_unlink(struct trace_probe *tp) |
| 982 | { |
| 983 | list_del_init(&tp->list); |
| 984 | if (list_empty(trace_probe_probe_list(tp))) |
| 985 | trace_probe_event_free(tp->event); |
| 986 | tp->event = NULL; |
| 987 | } |
Masami Hiramatsu | 455b289 | 2019-06-01 00:17:06 +0900 | [diff] [blame] | 988 | |
| 989 | void trace_probe_cleanup(struct trace_probe *tp) |
| 990 | { |
| 991 | int i; |
| 992 | |
| 993 | for (i = 0; i < tp->nr_args; i++) |
| 994 | traceprobe_free_probe_arg(&tp->args[i]); |
| 995 | |
Masami Hiramatsu | ca89bc0 | 2019-06-20 00:07:49 +0900 | [diff] [blame] | 996 | if (tp->event) |
| 997 | trace_probe_unlink(tp); |
Masami Hiramatsu | 455b289 | 2019-06-01 00:17:06 +0900 | [diff] [blame] | 998 | } |
| 999 | |
| 1000 | int trace_probe_init(struct trace_probe *tp, const char *event, |
Masami Hiramatsu | b61387c | 2020-01-22 12:23:25 +0900 | [diff] [blame] | 1001 | const char *group, bool alloc_filter) |
Masami Hiramatsu | 455b289 | 2019-06-01 00:17:06 +0900 | [diff] [blame] | 1002 | { |
Masami Hiramatsu | 60d53e2 | 2019-06-20 00:07:20 +0900 | [diff] [blame] | 1003 | struct trace_event_call *call; |
Masami Hiramatsu | b61387c | 2020-01-22 12:23:25 +0900 | [diff] [blame] | 1004 | size_t size = sizeof(struct trace_probe_event); |
Masami Hiramatsu | 60d53e2 | 2019-06-20 00:07:20 +0900 | [diff] [blame] | 1005 | int ret = 0; |
Masami Hiramatsu | e3dc9f8 | 2019-06-01 00:17:57 +0900 | [diff] [blame] | 1006 | |
Masami Hiramatsu | 455b289 | 2019-06-01 00:17:06 +0900 | [diff] [blame] | 1007 | if (!event || !group) |
| 1008 | return -EINVAL; |
| 1009 | |
Masami Hiramatsu | b61387c | 2020-01-22 12:23:25 +0900 | [diff] [blame] | 1010 | if (alloc_filter) |
| 1011 | size += sizeof(struct trace_uprobe_filter); |
| 1012 | |
| 1013 | tp->event = kzalloc(size, GFP_KERNEL); |
Masami Hiramatsu | 60d53e2 | 2019-06-20 00:07:20 +0900 | [diff] [blame] | 1014 | if (!tp->event) |
Masami Hiramatsu | 455b289 | 2019-06-01 00:17:06 +0900 | [diff] [blame] | 1015 | return -ENOMEM; |
| 1016 | |
Masami Hiramatsu | d59fae6 | 2019-09-17 14:11:37 +0900 | [diff] [blame] | 1017 | INIT_LIST_HEAD(&tp->event->files); |
| 1018 | INIT_LIST_HEAD(&tp->event->class.fields); |
| 1019 | INIT_LIST_HEAD(&tp->event->probes); |
| 1020 | INIT_LIST_HEAD(&tp->list); |
Julia Lawall | fc9d276 | 2020-05-07 21:30:08 +0200 | [diff] [blame] | 1021 | list_add(&tp->list, &tp->event->probes); |
Masami Hiramatsu | d59fae6 | 2019-09-17 14:11:37 +0900 | [diff] [blame] | 1022 | |
Masami Hiramatsu | 60d53e2 | 2019-06-20 00:07:20 +0900 | [diff] [blame] | 1023 | call = trace_probe_event_call(tp); |
| 1024 | call->class = &tp->event->class; |
| 1025 | call->name = kstrdup(event, GFP_KERNEL); |
| 1026 | if (!call->name) { |
| 1027 | ret = -ENOMEM; |
| 1028 | goto error; |
Masami Hiramatsu | 455b289 | 2019-06-01 00:17:06 +0900 | [diff] [blame] | 1029 | } |
Masami Hiramatsu | 60d53e2 | 2019-06-20 00:07:20 +0900 | [diff] [blame] | 1030 | |
| 1031 | tp->event->class.system = kstrdup(group, GFP_KERNEL); |
| 1032 | if (!tp->event->class.system) { |
| 1033 | ret = -ENOMEM; |
| 1034 | goto error; |
| 1035 | } |
Masami Hiramatsu | 455b289 | 2019-06-01 00:17:06 +0900 | [diff] [blame] | 1036 | |
| 1037 | return 0; |
Masami Hiramatsu | 60d53e2 | 2019-06-20 00:07:20 +0900 | [diff] [blame] | 1038 | |
| 1039 | error: |
| 1040 | trace_probe_cleanup(tp); |
| 1041 | return ret; |
Masami Hiramatsu | 455b289 | 2019-06-01 00:17:06 +0900 | [diff] [blame] | 1042 | } |
Masami Hiramatsu | 46e5376 | 2019-06-01 00:17:16 +0900 | [diff] [blame] | 1043 | |
| 1044 | int trace_probe_register_event_call(struct trace_probe *tp) |
| 1045 | { |
Masami Hiramatsu | e3dc9f8 | 2019-06-01 00:17:57 +0900 | [diff] [blame] | 1046 | struct trace_event_call *call = trace_probe_event_call(tp); |
Masami Hiramatsu | 46e5376 | 2019-06-01 00:17:16 +0900 | [diff] [blame] | 1047 | int ret; |
| 1048 | |
| 1049 | ret = register_trace_event(&call->event); |
| 1050 | if (!ret) |
| 1051 | return -ENODEV; |
| 1052 | |
| 1053 | ret = trace_add_event_call(call); |
| 1054 | if (ret) |
| 1055 | unregister_trace_event(&call->event); |
| 1056 | |
| 1057 | return ret; |
| 1058 | } |
Masami Hiramatsu | b5f935e | 2019-06-01 00:17:26 +0900 | [diff] [blame] | 1059 | |
| 1060 | int trace_probe_add_file(struct trace_probe *tp, struct trace_event_file *file) |
| 1061 | { |
| 1062 | struct event_file_link *link; |
| 1063 | |
| 1064 | link = kmalloc(sizeof(*link), GFP_KERNEL); |
| 1065 | if (!link) |
| 1066 | return -ENOMEM; |
| 1067 | |
| 1068 | link->file = file; |
| 1069 | INIT_LIST_HEAD(&link->list); |
Masami Hiramatsu | 60d53e2 | 2019-06-20 00:07:20 +0900 | [diff] [blame] | 1070 | list_add_tail_rcu(&link->list, &tp->event->files); |
Masami Hiramatsu | 747774d | 2019-06-01 00:17:37 +0900 | [diff] [blame] | 1071 | trace_probe_set_flag(tp, TP_FLAG_TRACE); |
Masami Hiramatsu | b5f935e | 2019-06-01 00:17:26 +0900 | [diff] [blame] | 1072 | return 0; |
| 1073 | } |
| 1074 | |
| 1075 | struct event_file_link *trace_probe_get_file_link(struct trace_probe *tp, |
| 1076 | struct trace_event_file *file) |
| 1077 | { |
| 1078 | struct event_file_link *link; |
| 1079 | |
| 1080 | trace_probe_for_each_link(link, tp) { |
| 1081 | if (link->file == file) |
| 1082 | return link; |
| 1083 | } |
| 1084 | |
| 1085 | return NULL; |
| 1086 | } |
| 1087 | |
| 1088 | int trace_probe_remove_file(struct trace_probe *tp, |
| 1089 | struct trace_event_file *file) |
| 1090 | { |
| 1091 | struct event_file_link *link; |
| 1092 | |
| 1093 | link = trace_probe_get_file_link(tp, file); |
| 1094 | if (!link) |
| 1095 | return -ENOENT; |
| 1096 | |
| 1097 | list_del_rcu(&link->list); |
| 1098 | synchronize_rcu(); |
| 1099 | kfree(link); |
| 1100 | |
Masami Hiramatsu | 60d53e2 | 2019-06-20 00:07:20 +0900 | [diff] [blame] | 1101 | if (list_empty(&tp->event->files)) |
Masami Hiramatsu | 747774d | 2019-06-01 00:17:37 +0900 | [diff] [blame] | 1102 | trace_probe_clear_flag(tp, TP_FLAG_TRACE); |
Masami Hiramatsu | b5f935e | 2019-06-01 00:17:26 +0900 | [diff] [blame] | 1103 | |
| 1104 | return 0; |
| 1105 | } |
Masami Hiramatsu | ca89bc0 | 2019-06-20 00:07:49 +0900 | [diff] [blame] | 1106 | |
| 1107 | /* |
| 1108 | * Return the smallest index of different type argument (start from 1). |
| 1109 | * If all argument types and name are same, return 0. |
| 1110 | */ |
| 1111 | int trace_probe_compare_arg_type(struct trace_probe *a, struct trace_probe *b) |
| 1112 | { |
| 1113 | int i; |
| 1114 | |
Masami Hiramatsu | d2aea95 | 2019-09-28 05:53:29 -0400 | [diff] [blame] | 1115 | /* In case of more arguments */ |
| 1116 | if (a->nr_args < b->nr_args) |
| 1117 | return a->nr_args + 1; |
| 1118 | if (a->nr_args > b->nr_args) |
| 1119 | return b->nr_args + 1; |
| 1120 | |
Masami Hiramatsu | ca89bc0 | 2019-06-20 00:07:49 +0900 | [diff] [blame] | 1121 | for (i = 0; i < a->nr_args; i++) { |
| 1122 | if ((b->nr_args <= i) || |
| 1123 | ((a->args[i].type != b->args[i].type) || |
| 1124 | (a->args[i].count != b->args[i].count) || |
| 1125 | strcmp(a->args[i].name, b->args[i].name))) |
| 1126 | return i + 1; |
| 1127 | } |
| 1128 | |
| 1129 | return 0; |
| 1130 | } |
Masami Hiramatsu | eb5bf81 | 2019-06-20 00:08:08 +0900 | [diff] [blame] | 1131 | |
| 1132 | bool trace_probe_match_command_args(struct trace_probe *tp, |
| 1133 | int argc, const char **argv) |
| 1134 | { |
| 1135 | char buf[MAX_ARGSTR_LEN + 1]; |
| 1136 | int i; |
| 1137 | |
| 1138 | if (tp->nr_args < argc) |
| 1139 | return false; |
| 1140 | |
| 1141 | for (i = 0; i < argc; i++) { |
| 1142 | snprintf(buf, sizeof(buf), "%s=%s", |
| 1143 | tp->args[i].name, tp->args[i].comm); |
| 1144 | if (strcmp(buf, argv[i])) |
| 1145 | return false; |
| 1146 | } |
| 1147 | return true; |
| 1148 | } |
Masami Hiramatsu | d262271 | 2021-02-01 13:48:11 -0600 | [diff] [blame] | 1149 | |
| 1150 | int trace_probe_create(const char *raw_command, int (*createfn)(int, const char **)) |
| 1151 | { |
| 1152 | int argc = 0, ret = 0; |
| 1153 | char **argv; |
| 1154 | |
| 1155 | argv = argv_split(GFP_KERNEL, raw_command, &argc); |
| 1156 | if (!argv) |
| 1157 | return -ENOMEM; |
| 1158 | |
| 1159 | if (argc) |
| 1160 | ret = createfn(argc, (const char **)argv); |
| 1161 | |
| 1162 | argv_free(argv); |
| 1163 | |
| 1164 | return ret; |
| 1165 | } |