A fix and a few new tests for kprobe tracer
v3 cover A fix and a few new tests for kprobe tracer
v2:
https://www.mail-archive.com/[email protected]/msg1434048.html
Changes since v2:
- Update tests to include additional scenarios and better error checking.
Thanks,
Naveen
Masami Hiramatsu (1):
selftests/ftrace: Add a testcase for kprobe event naming
Naveen N. Rao (3):
trace/kprobes: Sanitize derived event names selftests/ftrace: Update multiple kprobes test for powerpc selftests/ftrace: Add a test to probe module functions
kernel/trace/trace_kprobe.c | 9 ++++++ .../ftrace/test.d/kprobe/kprobe_eventname.tc | 36 ++++++++++++++++++++++ .../ftrace/test.d/kprobe/kprobe_module.tc | 28 +++++++++++++++++ .../ftrace/test.d/kprobe/multiple_kprobes.tc | 4 +-- 4 files changed, 75 insertions(+), 2 deletions(-) create mode 100644 tools/testing/selftests/ftrace/test.d/kprobe/kprobe_eventname.tc create mode 100644 tools/testing/selftests/ftrace/test.d/kprobe/kprobe_module.tc
Signature · 1 line
2.13.2
PATCH v3 1/4 trace/kprobes: Sanitize derived event names
When we derive event names, convert some expected symbols (such as ':' used to specify module:name and '.' present in some symbols) into underscores so that the event name is not rejected.
Before this patch:
# echo 'p kobject_example:foo_store' > kprobe_events
trace_kprobe: Failed to allocate trace_probe.(-22)
-sh: write error: Invalid argumentAfter this patch:
# echo 'p kobject_example:foo_store' > kprobe_events
# cat kprobe_events
p:kprobes/p_kobject_example_foo_store_0 kobject_example:foo_store--- kernel/trace/trace_kprobe.c | 9 +++++++++ 1 file changed, 9 insertions(+)
kernel/trace/trace_kprobe.c +9 -0
@@ -598,6 +598,14 @@ static struct notifier_block trace_kprobe_module_nb = { .priority = 1 /* Invoked after kprobe module callback */ }; +/* Convert certain expected symbols into '_' when generating event names */ +static inline void sanitize_event_name (char *name) +{ +while (*name++ !='\0' ) +if (*name ==':' || *name =='.' ) + *name ='_' ; +} +static int create_trace_kprobe (int argc,char **argv) {/*
@@ -740,6 +748,7 @@ static int create_trace_kprobe(int argc, char **argv)else snprintf (buf,MAX_EVENT_NAME_LEN ,"%c_0x%p" , is_return ?'r' :'p' , addr); +sanitize_event_name (buf); event = buf; } tk = alloc_trace_kprobe(group, event, addr, symbol, offset, maxactive,
Signature · 1 line
2.13.2
PATCH v3 2/4 selftests/ftrace: Update multiple kprobes test for powerpc
In reply to Naveen N. RaoKPROBES_ON_FTRACE is only available on powerpc64le. Update comment to clarify this.
Also, we should use an offset of 8 to ensure that the probe does not fall on ftrace location. The current offset of 4 will fall before the function local entry point and won't fire, while an offset of 12 or 16 will fall on ftrace location. Offset 8 is currently guaranteed to not be the ftrace location.
--- tools/testing/selftests/ftrace/test.d/kprobe/multiple_kprobes.tc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tools/testing/selftests/ftrace/test.d/kprobe/multiple_kprobes.tc +2 -2
@@ -2,10 +2,10 @@ # description: Register/unregister many kprobe events # ftrace fentry skip size depends on the machine architecture. -# Currently HAVE_KPROBES_ON_FTRACE defined on x86 and powerpc +# Currently HAVE_KPROBES_ON_FTRACE defined on x86 and powerpc64le case `uname -m` in x86_64|i[3456]86) OFFS=5;; - ppc*) OFFS=4;; + ppc64le) OFFS=8;; *) OFFS=0;; esac
Signature · 1 line
2.13.2
PATCH v3 3/4 selftests/ftrace: Add a test to probe module functions
In reply to Naveen N. RaoAdd a kprobes test to ensure that we are able to add a probe on a module function using 'p <mod>:<func>' format, with/without having to specify a probe name.
--- .../ftrace/test.d/kprobe/kprobe_module.tc | 28 ++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 tools/testing/selftests/ftrace/test.d/kprobe/kprobe_module.tc
tools/testing/selftests/ftrace/test.d/kprobe/kprobe_module.tc new file +28 -0
@@ -0,0 +1,28 @@ +#!/bin/sh +# description: Kprobe dynamic event - probing module + +[ -f kprobe_events ] || exit_unsupported # this is configurable + +disable_events +echo > kprobe_events + +:;: "Add an event on a module function without specifying event name" ;: + +MOD=`lsmod | head -n 2 | tail -n 1 | cut -f1 -d" "` +FUNC=`grep -m 1 ".* t .*\\[$MOD\\]" /proc/kallsyms | xargs | cut -f3 -d" "` +[ "x" != "x$MOD" -a "y" != "y$FUNC" ] || exit_unresolved +echo "p $MOD:$FUNC" > kprobe_events +PROBE_NAME=`echo $MOD:$FUNC | tr ".:" "_"` +test -d events/kprobes/p_${PROBE_NAME}_0 || exit_failure + +:;: "Add an event on a module function with new event name" ;: + +echo "p:event1 $MOD:$FUNC" > kprobe_events +test -d events/kprobes/event1 || exit_failure + +:;: "Add an event on a module function with new event and group name" ;: + +echo "p:kprobes1/event1 $MOD:$FUNC" > kprobe_events +test -d events/kprobes1/event1 || exit_failure + +echo > kprobe_events
Signature · 1 line
2.13.2
PATCH v3 4/4 selftests/ftrace: Add a testcase for kprobe event naming
In reply to Naveen N. RaoFrom: Masami Hiramatsu <[email protected]>
Add a testcase for kprobe event naming. This testcase checks whether the kprobe events can automatically ganerate its event name on normal function and dot-suffixed function. Also it checks whether the kprobe events can correctly define new event with given event name and group name.
[Updated tests to use vfs_read and symbols with '.isra.', added check for kprobe_events and a command to clear it on exit, various additional checks and tests]
--- .../ftrace/test.d/kprobe/kprobe_eventname.tc | 36 ++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 tools/testing/selftests/ftrace/test.d/kprobe/kprobe_eventname.tc
tools/testing/selftests/ftrace/test.d/kprobe/kprobe_eventname.tc new file +36 -0
@@ -0,0 +1,36 @@ +#!/bin/sh +# description: Kprobe event auto/manual naming + +[ -f kprobe_events ] || exit_unsupported # this is configurable + +disable_events +echo > kprobe_events + +:;: "Add an event on function without name" ;: + +FUNC=`grep " [tT] .*vfs_read$" /proc/kallsyms | tail -n 1 | cut -f 3 -d " "` +[ "x" != "x$FUNC" ] || exit_unresolved +echo "p $FUNC" > kprobe_events +PROBE_NAME=`echo $FUNC | tr ".:" "_"` +test -d events/kprobes/p_${PROBE_NAME}_0 || exit_failure + +:;: "Add an event on function with new name" ;: + +echo "p:event1 $FUNC" > kprobe_events +test -d events/kprobes/event1 || exit_failure + +:;: "Add an event on function with new name and group" ;: + +echo "p:kprobes2/event2 $FUNC" > kprobe_events +test -d events/kprobes2/event2 || exit_failure + +:;: "Add an event on dot function without name" ;: + +FUNC=`grep -m 10 " [tT] .*\.isra\..*$" /proc/kallsyms | tail -n 1 | cut -f 3 -d " "` +[ "x" != "x$FUNC" ] || exit_unresolved +echo "p $FUNC" > kprobe_events +EVENT=`grep $FUNC kprobe_events | cut -f 1 -d " " | cut -f 2 -d:` +[ "x" != "x$EVENT" ] || exit_failure +test -d events/$EVENT || exit_failure + +echo > kprobe_events
Signature · 1 line
2.13.2
Steven Rostedt
maintainerQuoted 7 lines · On Sat, 8 Jul 2017 00:27:29 +0530 "Naveen N. Rao"…
v2:
https://www.mail-archive.com/[email protected]/msg1434048.htmlChanges since v2:
- Update tests to include additional scenarios and better error checking.
I pulled these into my branch and started testing them now.
-- Steve
Quoted 20 lines
Thanks,
NaveenMasami Hiramatsu (1):
selftests/ftrace: Add a testcase for kprobe event namingNaveen N. Rao (3):
trace/kprobes: Sanitize derived event names selftests/ftrace: Update multiple kprobes test for powerpc selftests/ftrace: Add a test to probe module functionskernel/trace/trace_kprobe.c | 9 ++++++ .../ftrace/test.d/kprobe/kprobe_eventname.tc | 36 ++++++++++++++++++++++ .../ftrace/test.d/kprobe/kprobe_module.tc | 28 +++++++++++++++++ .../ftrace/test.d/kprobe/multiple_kprobes.tc | 4 +-- 4 files changed, 75 insertions(+), 2 deletions(-) create mode 100644 tools/testing/selftests/ftrace/test.d/kprobe/kprobe_eventname.tc create mode 100644 tools/testing/selftests/ftrace/test.d/kprobe/kprobe_module.tc
Quoted 6 lines · Steven Rostedt
Quoted 3 lines · On Sat, 8 Jul 2017 00:27:29 +0530 "Naveen N. Rao"…
v2:
https://www.mail-archive.com/[email protected]/msg1434048.html
Quoted 8 lines
Quoted 4 lines
Changes since v2:
- Update tests to include additional scenarios and better error checking.I pulled these into my branch and started testing them now.
-- Steve
Hi Steve,
Here is my ack for selftests in this series.
thanks,
-- Shuah
Quoted 24 lines
Quoted 21 lines
Thanks,
NaveenMasami Hiramatsu (1):
selftests/ftrace: Add a testcase for kprobe event namingNaveen N. Rao (3):
trace/kprobes: Sanitize derived event names selftests/ftrace: Update multiple kprobes test for powerpc selftests/ftrace: Add a test to probe module functionskernel/trace/trace_kprobe.c | 9 ++++++ .../ftrace/test.d/kprobe/kprobe_eventname.tc | 36 ++++++++++++++++++++++ .../ftrace/test.d/kprobe/kprobe_module.tc | 28 +++++++++++++++++ .../ftrace/test.d/kprobe/multiple_kprobes.tc | 4 +-- 4 files changed, 75 insertions(+), 2 deletions(-) create mode 100644 tools/testing/selftests/ftrace/test.d/kprobe/kprobe_eventname.tc create mode 100644 tools/testing/selftests/ftrace/test.d/kprobe/kprobe_module.tc
Steven Rostedt
maintainerQuoted 14 lines · On Mon, 24 Jul 2017 09:58:04 -0600 Shuah Khan <[email protected]> wrote:
Quoted 13 lines · Steven Rostedt
Quoted 7 lines · On Sat, 8 Jul 2017 00:27:29 +0530 "Naveen N. Rao"…
v2:
https://www.mail-archive.com/[email protected]/msg1434048.htmlChanges since v2:
- Update tests to include additional scenarios and better error checking.I pulled these into my branch and started testing them now.
Quoted 8 lines
Quoted 1 line
-- Steve
Hi Steve,
Here is my ack for selftests in this series.
Acked-by Shuah Khan <[email protected]>
Thanks! Sorry I already pushed it to Linus. :-/
-- Steve