Skip to contentSkip to conversation

tracing: A few more last minute updates for 4.13

PATCH New Steven Rostedt 1 participant 5 messages Jul 10, 2017

Subsystems (2)
lore
Share & tools
lore

Steven Rostedt

author maintainer
#0 lore raw

cover tracing: A few more last minute updates for 4.13

git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace.git
for-next

Head SHA1: 8cb0bc9e3f863f3e77522d02443a75c0e45a6ed0

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
author maintainer
#1 lore raw

PATCH 1/4 trace/kprobes: Sanitize derived event names

From: "Naveen N. Rao" <[email protected]>

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 argument

After 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
index c129fca6ec99..44fd819aa33d 100644
@@ -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.10.2
author maintainer
#2 lore raw

PATCH 2/4 selftests/ftrace: Update multiple kprobes test for powerpc

In reply to Steven Rostedt

From: "Naveen N. Rao" <[email protected]>

KPROBES_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
index f4d1ff785d67..2a1cb9908746 100644
@@ -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.10.2
author maintainer
#3 lore raw

PATCH 3/4 selftests/ftrace: Add a test to probe module functions

In reply to Steven Rostedt

From: "Naveen N. Rao" <[email protected]>

Add 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
new file mode 100644
index 000000000000..6d634e4b7680
@@ -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.10.2
author maintainer
#4 lore raw

PATCH 4/4 selftests/ftrace: Add a testcase for kprobe event naming

In reply to Steven Rostedt

From: 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
new file mode 100644
index 000000000000..b9302cc82c12
@@ -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.10.2