From: Masami Hiramatsu <mhiramat@kernel.org>
To: Steven Rostedt <rostedt@goodmis.org>,
Jonathan Corbet <corbet@lwn.net>,
Shuah Khan <skhan@linuxfoundation.org>
Cc: mhiramat@kernel.org, linux-kernel@vger.kernel.org,
linux-doc@vger.kernel.org, Randy Dunlap <rdunlap@infradead.org>,
Ingo Molnar <mingo@kernel.org>,
linux-kselftest@vger.kernel.org
Subject: [PATCH v3 4/8] tracing/kprobes: Support perf-style return probe
Date: Thu, 10 Sep 2020 17:55:35 +0900 [thread overview]
Message-ID: <159972813535.428528.4437029657208468954.stgit@devnote2> (raw)
In-Reply-To: <159972809455.428528.4737752126800169128.stgit@devnote2>
Support perf-style return probe ("SYMBOL%return") for kprobe events.
This will allow boot-time tracing user to define a return probe event.
Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
---
Changes in v3:
- Update README so that user can notice the kernel supports this feature.
- Add a new error message.
---
kernel/trace/trace.c | 2 +-
kernel/trace/trace_kprobe.c | 18 +++++++++++++++++-
kernel/trace/trace_probe.h | 1 +
3 files changed, 19 insertions(+), 2 deletions(-)
diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index f40d850ebabc..2c8c8f7ddef7 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -5122,7 +5122,7 @@ static const char readme_msg[] =
"\t -:[<group>/]<event>\n"
#ifdef CONFIG_KPROBE_EVENTS
"\t place: [<module>:]<symbol>[+<offset>]|<memaddr>\n"
- "place (kretprobe): [<module>:]<symbol>[+<offset>]|<memaddr>\n"
+ "place (kretprobe): [<module>:]<symbol>[+<offset>]%return|<memaddr>\n"
#endif
#ifdef CONFIG_UPROBE_EVENTS
" place (uprobe): <path>:<offset>[(ref_ctr_offset)]\n"
diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c
index aefb6065b508..e33690a12255 100644
--- a/kernel/trace/trace_kprobe.c
+++ b/kernel/trace/trace_kprobe.c
@@ -717,6 +717,9 @@ static int trace_kprobe_create(int argc, const char *argv[])
* p[:[GRP/]EVENT] [MOD:]KSYM[+OFFS]|KADDR [FETCHARGS]
* - Add kretprobe:
* r[MAXACTIVE][:[GRP/]EVENT] [MOD:]KSYM[+0] [FETCHARGS]
+ * Or
+ * p:[GRP/]EVENT] [MOD:]KSYM[+0]%return [FETCHARGS]
+ *
* Fetch args:
* $retval : fetch return value
* $stack : fetch stack address
@@ -746,7 +749,6 @@ static int trace_kprobe_create(int argc, const char *argv[])
switch (argv[0][0]) {
case 'r':
is_return = true;
- flags |= TPARG_FL_RETURN;
break;
case 'p':
break;
@@ -804,12 +806,26 @@ static int trace_kprobe_create(int argc, const char *argv[])
symbol = kstrdup(argv[1], GFP_KERNEL);
if (!symbol)
return -ENOMEM;
+
+ tmp = strchr(symbol, '%');
+ if (tmp) {
+ if (!strcmp(tmp, "%return")) {
+ *tmp = '\0';
+ is_return = true;
+ } else {
+ trace_probe_log_err(tmp - symbol, BAD_ADDR_SUFFIX);
+ goto parse_error;
+ }
+ }
+
/* TODO: support .init module functions */
ret = traceprobe_split_symbol_offset(symbol, &offset);
if (ret || offset < 0 || offset > UINT_MAX) {
trace_probe_log_err(0, BAD_PROBE_ADDR);
goto parse_error;
}
+ if (is_return)
+ flags |= TPARG_FL_RETURN;
if (kprobe_on_func_entry(NULL, symbol, offset))
flags |= TPARG_FL_FENTRY;
if (offset && is_return && !(flags & TPARG_FL_FENTRY)) {
diff --git a/kernel/trace/trace_probe.h b/kernel/trace/trace_probe.h
index a22b62813f8c..04d00987da69 100644
--- a/kernel/trace/trace_probe.h
+++ b/kernel/trace/trace_probe.h
@@ -404,6 +404,7 @@ extern int traceprobe_define_arg_fields(struct trace_event_call *event_call,
C(MAXACT_TOO_BIG, "Maxactive is too big"), \
C(BAD_PROBE_ADDR, "Invalid probed address or symbol"), \
C(BAD_RETPROBE, "Retprobe address must be an function entry"), \
+ C(BAD_ADDR_SUFFIX, "Invalid probed address suffix"), \
C(NO_GROUP_NAME, "Group name is not specified"), \
C(GROUP_TOO_LONG, "Group name is too long"), \
C(BAD_GROUP_NAME, "Group name must follow the same rules as C identifiers"), \
next prev parent reply other threads:[~2020-09-10 8:57 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-10 8:54 [PATCH v3 0/8] tracing/boot: Add new options for tracing specific period Masami Hiramatsu
2020-09-10 8:55 ` [PATCH v3 1/8] kprobes: tracing/kprobes: Fix to kill kprobes on initmem after boot Masami Hiramatsu
2020-09-10 8:55 ` [PATCH v3 2/8] tracing/boot: Add per-instance tracing_on option support Masami Hiramatsu
2020-09-10 8:55 ` [PATCH v3 3/8] Documentation: tracing: Add tracing_on option to boot-time tracer Masami Hiramatsu
2020-09-10 13:26 ` Bird, Tim
2020-09-10 22:41 ` Masami Hiramatsu
2020-09-11 0:47 ` [PATCH v3.1 " Masami Hiramatsu
2020-09-10 8:55 ` Masami Hiramatsu [this message]
2020-09-10 8:55 ` [PATCH v3 5/8] tracing/uprobes: Support perf-style return probe Masami Hiramatsu
2020-09-10 8:55 ` [PATCH v3 6/8] Documentation: tracing: Add %return suffix description Masami Hiramatsu
2020-09-10 8:56 ` [PATCH v3 7/8] Documentation: tracing: boot: Add an example of tracing function-calls Masami Hiramatsu
2020-09-10 8:56 ` [PATCH v3 8/8] selftests/ftrace: Add %return suffix tests Masami Hiramatsu
2020-09-10 23:34 ` [PATCH v3 0/8] tracing/boot: Add new options for tracing specific period Steven Rostedt
2020-09-11 1:27 ` Masami Hiramatsu
2020-09-11 1:34 ` Shuah Khan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=159972813535.428528.4437029657208468954.stgit@devnote2 \
--to=mhiramat@kernel.org \
--cc=corbet@lwn.net \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=rdunlap@infradead.org \
--cc=rostedt@goodmis.org \
--cc=skhan@linuxfoundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).