Skip to content

Commit 4725cd8

Browse files
mhiramatrostedt
authored andcommitted
tracing/kprobes: Support perf-style return probe
Support perf-style return probe ("SYMBOL%return") for kprobe events. This will allow boot-time tracing user to define a return probe event. Link: https://lkml.kernel.org/r/159972813535.428528.4437029657208468954.stgit@devnote2 Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org> Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
1 parent c51ba51 commit 4725cd8

3 files changed

Lines changed: 19 additions & 2 deletions

File tree

‎kernel/trace/trace.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5122,7 +5122,7 @@ static const char readme_msg[] =
51225122
"\t -:[<group>/]<event>\n"
51235123
#ifdef CONFIG_KPROBE_EVENTS
51245124
"\t place: [<module>:]<symbol>[+<offset>]|<memaddr>\n"
5125-
"place (kretprobe): [<module>:]<symbol>[+<offset>]|<memaddr>\n"
5125+
"place (kretprobe): [<module>:]<symbol>[+<offset>]%return|<memaddr>\n"
51265126
#endif
51275127
#ifdef CONFIG_UPROBE_EVENTS
51285128
" place (uprobe): <path>:<offset>[(ref_ctr_offset)]\n"

‎kernel/trace/trace_kprobe.c‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -718,6 +718,9 @@ static int trace_kprobe_create(int argc, const char *argv[])
718718
* p[:[GRP/]EVENT] [MOD:]KSYM[+OFFS]|KADDR [FETCHARGS]
719719
* - Add kretprobe:
720720
* r[MAXACTIVE][:[GRP/]EVENT] [MOD:]KSYM[+0] [FETCHARGS]
721+
* Or
722+
* p:[GRP/]EVENT] [MOD:]KSYM[+0]%return [FETCHARGS]
723+
*
721724
* Fetch args:
722725
* $retval : fetch return value
723726
* $stack : fetch stack address
@@ -747,7 +750,6 @@ static int trace_kprobe_create(int argc, const char *argv[])
747750
switch (argv[0][0]) {
748751
case 'r':
749752
is_return = true;
750-
flags |= TPARG_FL_RETURN;
751753
break;
752754
case 'p':
753755
break;
@@ -805,12 +807,26 @@ static int trace_kprobe_create(int argc, const char *argv[])
805807
symbol = kstrdup(argv[1], GFP_KERNEL);
806808
if (!symbol)
807809
return -ENOMEM;
810+
811+
tmp = strchr(symbol, '%');
812+
if (tmp) {
813+
if (!strcmp(tmp, "%return")) {
814+
*tmp = '\0';
815+
is_return = true;
816+
} else {
817+
trace_probe_log_err(tmp - symbol, BAD_ADDR_SUFFIX);
818+
goto parse_error;
819+
}
820+
}
821+
808822
/* TODO: support .init module functions */
809823
ret = traceprobe_split_symbol_offset(symbol, &offset);
810824
if (ret || offset < 0 || offset > UINT_MAX) {
811825
trace_probe_log_err(0, BAD_PROBE_ADDR);
812826
goto parse_error;
813827
}
828+
if (is_return)
829+
flags |= TPARG_FL_RETURN;
814830
if (kprobe_on_func_entry(NULL, symbol, offset))
815831
flags |= TPARG_FL_FENTRY;
816832
if (offset && is_return && !(flags & TPARG_FL_FENTRY)) {

‎kernel/trace/trace_probe.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,7 @@ extern int traceprobe_define_arg_fields(struct trace_event_call *event_call,
404404
C(MAXACT_TOO_BIG, "Maxactive is too big"), \
405405
C(BAD_PROBE_ADDR, "Invalid probed address or symbol"), \
406406
C(BAD_RETPROBE, "Retprobe address must be an function entry"), \
407+
C(BAD_ADDR_SUFFIX, "Invalid probed address suffix"), \
407408
C(NO_GROUP_NAME, "Group name is not specified"), \
408409
C(GROUP_TOO_LONG, "Group name is too long"), \
409410
C(BAD_GROUP_NAME, "Group name must follow the same rules as C identifiers"), \

0 commit comments

Comments
 (0)