Skip to content

Commit f451bc8

Browse files
mhiramatrostedt
authored andcommitted
tracing: probeevent: Unify fetch type tables
Unify {k,u}probe_fetch_type_table to probe_fetch_type_table because the main difference of those type tables (fetcharg methods) are gone. Now we can consolidate it. Link: http://lkml.kernel.org/r/152465871274.26224.13999436317830479698.stgit@devbox Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org> Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
1 parent 5330592 commit f451bc8

File tree

4 files changed

+39
-75
lines changed

4 files changed

+39
-75
lines changed

kernel/trace/trace_kprobe.c

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -121,30 +121,6 @@ static int kprobe_dispatcher(struct kprobe *kp, struct pt_regs *regs);
121121
static int kretprobe_dispatcher(struct kretprobe_instance *ri,
122122
struct pt_regs *regs);
123123

124-
/* Fetch type information table */
125-
static const struct fetch_type kprobes_fetch_type_table[] = {
126-
/* Special types */
127-
[FETCH_TYPE_STRING] = __ASSIGN_FETCH_TYPE("string", string, string,
128-
sizeof(u32), 1, "__data_loc char[]"),
129-
[FETCH_TYPE_STRSIZE] = __ASSIGN_FETCH_TYPE("string_size", u32,
130-
string_size, sizeof(u32), 0, "u32"),
131-
/* Basic types */
132-
ASSIGN_FETCH_TYPE(u8, u8, 0),
133-
ASSIGN_FETCH_TYPE(u16, u16, 0),
134-
ASSIGN_FETCH_TYPE(u32, u32, 0),
135-
ASSIGN_FETCH_TYPE(u64, u64, 0),
136-
ASSIGN_FETCH_TYPE(s8, u8, 1),
137-
ASSIGN_FETCH_TYPE(s16, u16, 1),
138-
ASSIGN_FETCH_TYPE(s32, u32, 1),
139-
ASSIGN_FETCH_TYPE(s64, u64, 1),
140-
ASSIGN_FETCH_TYPE_ALIAS(x8, u8, u8, 0),
141-
ASSIGN_FETCH_TYPE_ALIAS(x16, u16, u16, 0),
142-
ASSIGN_FETCH_TYPE_ALIAS(x32, u32, u32, 0),
143-
ASSIGN_FETCH_TYPE_ALIAS(x64, u64, u64, 0),
144-
145-
ASSIGN_FETCH_TYPE_END
146-
};
147-
148124
/*
149125
* Allocate new trace_probe and initialize it (including kprobes).
150126
*/
@@ -720,8 +696,7 @@ static int create_trace_kprobe(int argc, char **argv)
720696

721697
/* Parse fetch argument */
722698
ret = traceprobe_parse_probe_arg(arg, &tk->tp.size, parg,
723-
is_return, true,
724-
kprobes_fetch_type_table);
699+
is_return, true);
725700
if (ret) {
726701
pr_info("Parse error at argument[%d]. (%d)\n", i, ret);
727702
goto error;

kernel/trace/trace_probe.c

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,29 @@ int PRINT_TYPE_FUNC_NAME(string)(struct trace_seq *s, void *data, void *ent)
6161

6262
const char PRINT_TYPE_FMT_NAME(string)[] = "\\\"%s\\\"";
6363

64-
static const struct fetch_type *find_fetch_type(const char *type,
65-
const struct fetch_type *ftbl)
64+
/* Fetch type information table */
65+
static const struct fetch_type probe_fetch_types[] = {
66+
/* Special types */
67+
__ASSIGN_FETCH_TYPE("string", string, string, sizeof(u32), 1,
68+
"__data_loc char[]"),
69+
/* Basic types */
70+
ASSIGN_FETCH_TYPE(u8, u8, 0),
71+
ASSIGN_FETCH_TYPE(u16, u16, 0),
72+
ASSIGN_FETCH_TYPE(u32, u32, 0),
73+
ASSIGN_FETCH_TYPE(u64, u64, 0),
74+
ASSIGN_FETCH_TYPE(s8, u8, 1),
75+
ASSIGN_FETCH_TYPE(s16, u16, 1),
76+
ASSIGN_FETCH_TYPE(s32, u32, 1),
77+
ASSIGN_FETCH_TYPE(s64, u64, 1),
78+
ASSIGN_FETCH_TYPE_ALIAS(x8, u8, u8, 0),
79+
ASSIGN_FETCH_TYPE_ALIAS(x16, u16, u16, 0),
80+
ASSIGN_FETCH_TYPE_ALIAS(x32, u32, u32, 0),
81+
ASSIGN_FETCH_TYPE_ALIAS(x64, u64, u64, 0),
82+
83+
ASSIGN_FETCH_TYPE_END
84+
};
85+
86+
static const struct fetch_type *find_fetch_type(const char *type)
6687
{
6788
int i;
6889

@@ -83,21 +104,21 @@ static const struct fetch_type *find_fetch_type(const char *type,
83104

84105
switch (bs) {
85106
case 8:
86-
return find_fetch_type("u8", ftbl);
107+
return find_fetch_type("u8");
87108
case 16:
88-
return find_fetch_type("u16", ftbl);
109+
return find_fetch_type("u16");
89110
case 32:
90-
return find_fetch_type("u32", ftbl);
111+
return find_fetch_type("u32");
91112
case 64:
92-
return find_fetch_type("u64", ftbl);
113+
return find_fetch_type("u64");
93114
default:
94115
goto fail;
95116
}
96117
}
97118

98-
for (i = 0; ftbl[i].name; i++) {
99-
if (strcmp(type, ftbl[i].name) == 0)
100-
return &ftbl[i];
119+
for (i = 0; probe_fetch_types[i].name; i++) {
120+
if (strcmp(type, probe_fetch_types[i].name) == 0)
121+
return &probe_fetch_types[i];
101122
}
102123

103124
fail:
@@ -164,8 +185,7 @@ static int parse_probe_vars(char *arg, const struct fetch_type *t,
164185
static int
165186
parse_probe_arg(char *arg, const struct fetch_type *type,
166187
struct fetch_insn **pcode, struct fetch_insn *end,
167-
bool is_return, bool is_kprobe,
168-
const struct fetch_type *ftbl)
188+
bool is_return, bool is_kprobe)
169189
{
170190
struct fetch_insn *code = *pcode;
171191
unsigned long param;
@@ -247,12 +267,11 @@ parse_probe_arg(char *arg, const struct fetch_type *type,
247267
tmp = strrchr(arg, ')');
248268

249269
if (tmp) {
250-
const struct fetch_type *t2;
270+
const struct fetch_type *t2 = find_fetch_type(NULL);
251271

252-
t2 = find_fetch_type(NULL, ftbl);
253272
*tmp = '\0';
254273
ret = parse_probe_arg(arg, t2, &code, end, is_return,
255-
is_kprobe, ftbl);
274+
is_kprobe);
256275
if (ret)
257276
break;
258277
if (code->op == FETCH_OP_COMM)
@@ -312,8 +331,7 @@ static int __parse_bitfield_probe_arg(const char *bf,
312331

313332
/* String length checking wrapper */
314333
int traceprobe_parse_probe_arg(char *arg, ssize_t *size,
315-
struct probe_arg *parg, bool is_return, bool is_kprobe,
316-
const struct fetch_type *ftbl)
334+
struct probe_arg *parg, bool is_return, bool is_kprobe)
317335
{
318336
struct fetch_insn *code, *tmp = NULL;
319337
const char *t;
@@ -339,7 +357,7 @@ int traceprobe_parse_probe_arg(char *arg, ssize_t *size,
339357
*/
340358
if (!t && strcmp(arg, "$comm") == 0)
341359
t = "string";
342-
parg->type = find_fetch_type(t, ftbl);
360+
parg->type = find_fetch_type(t);
343361
if (!parg->type) {
344362
pr_info("Unsupported type: %s\n", t);
345363
return -EINVAL;
@@ -353,7 +371,7 @@ int traceprobe_parse_probe_arg(char *arg, ssize_t *size,
353371
code[FETCH_INSN_MAX - 1].op = FETCH_OP_END;
354372

355373
ret = parse_probe_arg(arg, parg->type, &code, &code[FETCH_INSN_MAX - 1],
356-
is_return, is_kprobe, ftbl);
374+
is_return, is_kprobe);
357375
if (ret)
358376
goto fail;
359377

kernel/trace/trace_probe.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,6 @@ DECLARE_BASIC_PRINT_TYPE_FUNC(string);
184184

185185
#define ASSIGN_FETCH_TYPE_END {}
186186

187-
#define FETCH_TYPE_STRING 0
188-
#define FETCH_TYPE_STRSIZE 1
189-
190187
#ifdef CONFIG_KPROBE_EVENTS
191188
bool trace_kprobe_on_func_entry(struct trace_event_call *call);
192189
bool trace_kprobe_error_injectable(struct trace_event_call *call);
@@ -261,8 +258,7 @@ find_event_file_link(struct trace_probe *tp, struct trace_event_file *file)
261258
}
262259

263260
extern int traceprobe_parse_probe_arg(char *arg, ssize_t *size,
264-
struct probe_arg *parg, bool is_return, bool is_kprobe,
265-
const struct fetch_type *ftbl);
261+
struct probe_arg *parg, bool is_return, bool is_kprobe);
266262

267263
extern int traceprobe_conflict_field_name(const char *name,
268264
struct probe_arg *args, int narg);

kernel/trace/trace_uprobe.c

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -161,30 +161,6 @@ static unsigned long translate_user_vaddr(unsigned long file_offset)
161161
return base_addr + file_offset;
162162
}
163163

164-
/* Fetch type information table */
165-
static const struct fetch_type uprobes_fetch_type_table[] = {
166-
/* Special types */
167-
[FETCH_TYPE_STRING] = __ASSIGN_FETCH_TYPE("string", string, string,
168-
sizeof(u32), 1, "__data_loc char[]"),
169-
[FETCH_TYPE_STRSIZE] = __ASSIGN_FETCH_TYPE("string_size", u32,
170-
string_size, sizeof(u32), 0, "u32"),
171-
/* Basic types */
172-
ASSIGN_FETCH_TYPE(u8, u8, 0),
173-
ASSIGN_FETCH_TYPE(u16, u16, 0),
174-
ASSIGN_FETCH_TYPE(u32, u32, 0),
175-
ASSIGN_FETCH_TYPE(u64, u64, 0),
176-
ASSIGN_FETCH_TYPE(s8, u8, 1),
177-
ASSIGN_FETCH_TYPE(s16, u16, 1),
178-
ASSIGN_FETCH_TYPE(s32, u32, 1),
179-
ASSIGN_FETCH_TYPE(s64, u64, 1),
180-
ASSIGN_FETCH_TYPE_ALIAS(x8, u8, u8, 0),
181-
ASSIGN_FETCH_TYPE_ALIAS(x16, u16, u16, 0),
182-
ASSIGN_FETCH_TYPE_ALIAS(x32, u32, u32, 0),
183-
ASSIGN_FETCH_TYPE_ALIAS(x64, u64, u64, 0),
184-
185-
ASSIGN_FETCH_TYPE_END
186-
};
187-
188164
/* Note that we don't verify it, since the code does not come from user space */
189165
static int
190166
process_fetch_insn(struct fetch_insn *code, struct pt_regs *regs, void *dest,
@@ -621,8 +597,7 @@ static int create_trace_uprobe(int argc, char **argv)
621597

622598
/* Parse fetch argument */
623599
ret = traceprobe_parse_probe_arg(arg, &tu->tp.size, parg,
624-
is_return, false,
625-
uprobes_fetch_type_table);
600+
is_return, false);
626601
if (ret) {
627602
pr_info("Parse error at argument[%d]. (%d)\n", i, ret);
628603
goto error;

0 commit comments

Comments
 (0)