Skip to content

Commit 116b411

Browse files
committed
Merge tag 'probes-v6.3-2' of git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace
Pull kprobes cleanup updates from Masami Hiramatsu: "These are probe events cleanups, no new features but improve readability: - Rename print_probe_args() to trace_probe_print_args() and un-inline it - Introduce a set of default data fetch functions for dynamic probe events - Extract common code of data fetch process of dynamic probe events" * tag 'probes-v6.3-2' of git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace: kernel/trace: extract common part in process_fetch_insn kernel/trace: Provide default impelentations defined in trace_probe_tmpl.h kernel/trace: Introduce trace_probe_print_args and use it in *probes
2 parents 0447ed0 + bd78acc commit 116b411

File tree

8 files changed

+96
-185
lines changed

8 files changed

+96
-185
lines changed

kernel/trace/trace_eprobe.c

Lines changed: 9 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ print_eprobe_event(struct trace_iterator *iter, int flags,
311311

312312
trace_seq_putc(s, ')');
313313

314-
if (print_probe_args(s, tp->args, tp->nr_args,
314+
if (trace_probe_print_args(s, tp->args, tp->nr_args,
315315
(u8 *)&field[1], field) < 0)
316316
goto out;
317317

@@ -320,7 +320,8 @@ print_eprobe_event(struct trace_iterator *iter, int flags,
320320
return trace_handle_return(s);
321321
}
322322

323-
static unsigned long get_event_field(struct fetch_insn *code, void *rec)
323+
static nokprobe_inline unsigned long
324+
get_event_field(struct fetch_insn *code, void *rec)
324325
{
325326
struct ftrace_event_field *field = code->data;
326327
unsigned long val;
@@ -395,20 +396,12 @@ static int get_eprobe_size(struct trace_probe *tp, void *rec)
395396
case FETCH_OP_TP_ARG:
396397
val = get_event_field(code, rec);
397398
break;
398-
case FETCH_OP_IMM:
399-
val = code->immediate;
400-
break;
401-
case FETCH_OP_COMM:
402-
val = (unsigned long)current->comm;
403-
break;
404-
case FETCH_OP_DATA:
405-
val = (unsigned long)code->data;
406-
break;
407399
case FETCH_NOP_SYMBOL: /* Ignore a place holder */
408400
code++;
409401
goto retry;
410402
default:
411-
continue;
403+
if (process_common_fetch_insn(code, &val) < 0)
404+
continue;
412405
}
413406
code++;
414407
len = process_fetch_insn_bottom(code, val, NULL, NULL);
@@ -428,84 +421,26 @@ process_fetch_insn(struct fetch_insn *code, void *rec, void *dest,
428421
void *base)
429422
{
430423
unsigned long val;
424+
int ret;
431425

432426
retry:
433427
switch (code->op) {
434428
case FETCH_OP_TP_ARG:
435429
val = get_event_field(code, rec);
436430
break;
437-
case FETCH_OP_IMM:
438-
val = code->immediate;
439-
break;
440-
case FETCH_OP_COMM:
441-
val = (unsigned long)current->comm;
442-
break;
443-
case FETCH_OP_DATA:
444-
val = (unsigned long)code->data;
445-
break;
446431
case FETCH_NOP_SYMBOL: /* Ignore a place holder */
447432
code++;
448433
goto retry;
449434
default:
450-
return -EILSEQ;
435+
ret = process_common_fetch_insn(code, &val);
436+
if (ret < 0)
437+
return ret;
451438
}
452439
code++;
453440
return process_fetch_insn_bottom(code, val, dest, base);
454441
}
455442
NOKPROBE_SYMBOL(process_fetch_insn)
456443

457-
/* Return the length of string -- including null terminal byte */
458-
static nokprobe_inline int
459-
fetch_store_strlen_user(unsigned long addr)
460-
{
461-
return kern_fetch_store_strlen_user(addr);
462-
}
463-
464-
/* Return the length of string -- including null terminal byte */
465-
static nokprobe_inline int
466-
fetch_store_strlen(unsigned long addr)
467-
{
468-
return kern_fetch_store_strlen(addr);
469-
}
470-
471-
/*
472-
* Fetch a null-terminated string from user. Caller MUST set *(u32 *)buf
473-
* with max length and relative data location.
474-
*/
475-
static nokprobe_inline int
476-
fetch_store_string_user(unsigned long addr, void *dest, void *base)
477-
{
478-
return kern_fetch_store_string_user(addr, dest, base);
479-
}
480-
481-
/*
482-
* Fetch a null-terminated string. Caller MUST set *(u32 *)buf with max
483-
* length and relative data location.
484-
*/
485-
static nokprobe_inline int
486-
fetch_store_string(unsigned long addr, void *dest, void *base)
487-
{
488-
return kern_fetch_store_string(addr, dest, base);
489-
}
490-
491-
static nokprobe_inline int
492-
probe_mem_read_user(void *dest, void *src, size_t size)
493-
{
494-
const void __user *uaddr = (__force const void __user *)src;
495-
496-
return copy_from_user_nofault(dest, uaddr, size);
497-
}
498-
499-
static nokprobe_inline int
500-
probe_mem_read(void *dest, void *src, size_t size)
501-
{
502-
#ifdef CONFIG_ARCH_HAS_NON_OVERLAPPING_ADDRESS_SPACE
503-
if ((unsigned long)src < TASK_SIZE)
504-
return probe_mem_read_user(dest, src, size);
505-
#endif
506-
return copy_from_kernel_nofault(dest, src, size);
507-
}
508-
509444
/* eprobe handler */
510445
static inline void
511446
__eprobe_trace_func(struct eprobe_data *edata, void *rec)

kernel/trace/trace_events_synth.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -448,12 +448,12 @@ static unsigned int trace_string(struct synth_trace_event *entry,
448448
data_offset = struct_size(entry, fields, event->n_u64);
449449
data_offset += data_size;
450450

451-
len = kern_fetch_store_strlen((unsigned long)str_val);
451+
len = fetch_store_strlen((unsigned long)str_val);
452452

453453
data_offset |= len << 16;
454454
*(u32 *)&entry->fields[*n_u64] = data_offset;
455455

456-
ret = kern_fetch_store_string((unsigned long)str_val, &entry->fields[*n_u64], entry);
456+
ret = fetch_store_string((unsigned long)str_val, &entry->fields[*n_u64], entry);
457457

458458
(*n_u64)++;
459459
} else {
@@ -542,7 +542,7 @@ static notrace void trace_event_raw_event_synth(void *__data,
542542
len = *((unsigned long *)str_val);
543543
len *= sizeof(unsigned long);
544544
} else {
545-
len = kern_fetch_store_strlen((unsigned long)str_val);
545+
len = fetch_store_strlen((unsigned long)str_val);
546546
}
547547

548548
fields_size += len;

kernel/trace/trace_kprobe.c

Lines changed: 6 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1218,67 +1218,14 @@ static const struct file_operations kprobe_profile_ops = {
12181218
.release = seq_release,
12191219
};
12201220

1221-
/* Kprobe specific fetch functions */
1222-
1223-
/* Return the length of string -- including null terminal byte */
1224-
static nokprobe_inline int
1225-
fetch_store_strlen_user(unsigned long addr)
1226-
{
1227-
return kern_fetch_store_strlen_user(addr);
1228-
}
1229-
1230-
/* Return the length of string -- including null terminal byte */
1231-
static nokprobe_inline int
1232-
fetch_store_strlen(unsigned long addr)
1233-
{
1234-
return kern_fetch_store_strlen(addr);
1235-
}
1236-
1237-
/*
1238-
* Fetch a null-terminated string from user. Caller MUST set *(u32 *)buf
1239-
* with max length and relative data location.
1240-
*/
1241-
static nokprobe_inline int
1242-
fetch_store_string_user(unsigned long addr, void *dest, void *base)
1243-
{
1244-
return kern_fetch_store_string_user(addr, dest, base);
1245-
}
1246-
1247-
/*
1248-
* Fetch a null-terminated string. Caller MUST set *(u32 *)buf with max
1249-
* length and relative data location.
1250-
*/
1251-
static nokprobe_inline int
1252-
fetch_store_string(unsigned long addr, void *dest, void *base)
1253-
{
1254-
return kern_fetch_store_string(addr, dest, base);
1255-
}
1256-
1257-
static nokprobe_inline int
1258-
probe_mem_read_user(void *dest, void *src, size_t size)
1259-
{
1260-
const void __user *uaddr = (__force const void __user *)src;
1261-
1262-
return copy_from_user_nofault(dest, uaddr, size);
1263-
}
1264-
1265-
static nokprobe_inline int
1266-
probe_mem_read(void *dest, void *src, size_t size)
1267-
{
1268-
#ifdef CONFIG_ARCH_HAS_NON_OVERLAPPING_ADDRESS_SPACE
1269-
if ((unsigned long)src < TASK_SIZE)
1270-
return probe_mem_read_user(dest, src, size);
1271-
#endif
1272-
return copy_from_kernel_nofault(dest, src, size);
1273-
}
1274-
12751221
/* Note that we don't verify it, since the code does not come from user space */
12761222
static int
12771223
process_fetch_insn(struct fetch_insn *code, void *rec, void *dest,
12781224
void *base)
12791225
{
12801226
struct pt_regs *regs = rec;
12811227
unsigned long val;
1228+
int ret;
12821229

12831230
retry:
12841231
/* 1st stage: get value from context */
@@ -1295,15 +1242,6 @@ process_fetch_insn(struct fetch_insn *code, void *rec, void *dest,
12951242
case FETCH_OP_RETVAL:
12961243
val = regs_return_value(regs);
12971244
break;
1298-
case FETCH_OP_IMM:
1299-
val = code->immediate;
1300-
break;
1301-
case FETCH_OP_COMM:
1302-
val = (unsigned long)current->comm;
1303-
break;
1304-
case FETCH_OP_DATA:
1305-
val = (unsigned long)code->data;
1306-
break;
13071245
#ifdef CONFIG_HAVE_FUNCTION_ARG_ACCESS_API
13081246
case FETCH_OP_ARG:
13091247
val = regs_get_kernel_argument(regs, code->param);
@@ -1313,7 +1251,9 @@ process_fetch_insn(struct fetch_insn *code, void *rec, void *dest,
13131251
code++;
13141252
goto retry;
13151253
default:
1316-
return -EILSEQ;
1254+
ret = process_common_fetch_insn(code, &val);
1255+
if (ret < 0)
1256+
return ret;
13171257
}
13181258
code++;
13191259

@@ -1424,7 +1364,7 @@ print_kprobe_event(struct trace_iterator *iter, int flags,
14241364

14251365
trace_seq_putc(s, ')');
14261366

1427-
if (print_probe_args(s, tp->args, tp->nr_args,
1367+
if (trace_probe_print_args(s, tp->args, tp->nr_args,
14281368
(u8 *)&field[1], field) < 0)
14291369
goto out;
14301370

@@ -1459,7 +1399,7 @@ print_kretprobe_event(struct trace_iterator *iter, int flags,
14591399

14601400
trace_seq_putc(s, ')');
14611401

1462-
if (print_probe_args(s, tp->args, tp->nr_args,
1402+
if (trace_probe_print_args(s, tp->args, tp->nr_args,
14631403
(u8 *)&field[1], field) < 0)
14641404
goto out;
14651405

kernel/trace/trace_probe.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1239,3 +1239,30 @@ int trace_probe_create(const char *raw_command, int (*createfn)(int, const char
12391239

12401240
return ret;
12411241
}
1242+
1243+
int trace_probe_print_args(struct trace_seq *s, struct probe_arg *args, int nr_args,
1244+
u8 *data, void *field)
1245+
{
1246+
void *p;
1247+
int i, j;
1248+
1249+
for (i = 0; i < nr_args; i++) {
1250+
struct probe_arg *a = args + i;
1251+
1252+
trace_seq_printf(s, " %s=", a->name);
1253+
if (likely(!a->count)) {
1254+
if (!a->type->print(s, data + a->offset, field))
1255+
return -ENOMEM;
1256+
continue;
1257+
}
1258+
trace_seq_putc(s, '{');
1259+
p = data + a->offset;
1260+
for (j = 0; j < a->count; j++) {
1261+
if (!a->type->print(s, p, field))
1262+
return -ENOMEM;
1263+
trace_seq_putc(s, j == a->count - 1 ? '}' : ',');
1264+
p += a->type->size;
1265+
}
1266+
}
1267+
return 0;
1268+
}

kernel/trace/trace_probe.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,8 @@ int trace_probe_compare_arg_type(struct trace_probe *a, struct trace_probe *b);
349349
bool trace_probe_match_command_args(struct trace_probe *tp,
350350
int argc, const char **argv);
351351
int trace_probe_create(const char *raw_command, int (*createfn)(int, const char **));
352+
int trace_probe_print_args(struct trace_seq *s, struct probe_arg *args, int nr_args,
353+
u8 *data, void *field);
352354

353355
#define trace_probe_for_each_link(pos, tp) \
354356
list_for_each_entry(pos, &(tp)->event->files, list)

kernel/trace/trace_probe_kernel.h

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*/
1313
/* Return the length of string -- including null terminal byte */
1414
static nokprobe_inline int
15-
kern_fetch_store_strlen_user(unsigned long addr)
15+
fetch_store_strlen_user(unsigned long addr)
1616
{
1717
const void __user *uaddr = (__force const void __user *)addr;
1818
int ret;
@@ -29,14 +29,14 @@ kern_fetch_store_strlen_user(unsigned long addr)
2929

3030
/* Return the length of string -- including null terminal byte */
3131
static nokprobe_inline int
32-
kern_fetch_store_strlen(unsigned long addr)
32+
fetch_store_strlen(unsigned long addr)
3333
{
3434
int ret, len = 0;
3535
u8 c;
3636

3737
#ifdef CONFIG_ARCH_HAS_NON_OVERLAPPING_ADDRESS_SPACE
3838
if (addr < TASK_SIZE)
39-
return kern_fetch_store_strlen_user(addr);
39+
return fetch_store_strlen_user(addr);
4040
#endif
4141

4242
do {
@@ -63,7 +63,7 @@ static nokprobe_inline void set_data_loc(int ret, void *dest, void *__dest, void
6363
* with max length and relative data location.
6464
*/
6565
static nokprobe_inline int
66-
kern_fetch_store_string_user(unsigned long addr, void *dest, void *base)
66+
fetch_store_string_user(unsigned long addr, void *dest, void *base)
6767
{
6868
const void __user *uaddr = (__force const void __user *)addr;
6969
int maxlen = get_loc_len(*(u32 *)dest);
@@ -86,15 +86,15 @@ kern_fetch_store_string_user(unsigned long addr, void *dest, void *base)
8686
* length and relative data location.
8787
*/
8888
static nokprobe_inline int
89-
kern_fetch_store_string(unsigned long addr, void *dest, void *base)
89+
fetch_store_string(unsigned long addr, void *dest, void *base)
9090
{
9191
int maxlen = get_loc_len(*(u32 *)dest);
9292
void *__dest;
9393
long ret;
9494

9595
#ifdef CONFIG_ARCH_HAS_NON_OVERLAPPING_ADDRESS_SPACE
9696
if ((unsigned long)addr < TASK_SIZE)
97-
return kern_fetch_store_string_user(addr, dest, base);
97+
return fetch_store_string_user(addr, dest, base);
9898
#endif
9999

100100
if (unlikely(!maxlen))
@@ -112,4 +112,22 @@ kern_fetch_store_string(unsigned long addr, void *dest, void *base)
112112
return ret;
113113
}
114114

115+
static nokprobe_inline int
116+
probe_mem_read_user(void *dest, void *src, size_t size)
117+
{
118+
const void __user *uaddr = (__force const void __user *)src;
119+
120+
return copy_from_user_nofault(dest, uaddr, size);
121+
}
122+
123+
static nokprobe_inline int
124+
probe_mem_read(void *dest, void *src, size_t size)
125+
{
126+
#ifdef CONFIG_ARCH_HAS_NON_OVERLAPPING_ADDRESS_SPACE
127+
if ((unsigned long)src < TASK_SIZE)
128+
return probe_mem_read_user(dest, src, size);
129+
#endif
130+
return copy_from_kernel_nofault(dest, src, size);
131+
}
132+
115133
#endif /* __TRACE_PROBE_KERNEL_H_ */

0 commit comments

Comments
 (0)