diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2018-03-23 18:34:18 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2018-03-23 18:34:18 -0400 |
commit | 99fec39e7725d091c94d1bb0242e40c8092994f6 (patch) | |
tree | 939bc96eb4de6a5d269b189f45b849d4aa0bc468 /tools | |
parent | 86d043d47c91cf40f19d3c0d9b21ec8ccee2826a (diff) | |
parent | dfa453bc90eca0febff33c8d292a656e53702158 (diff) |
Merge tag 'trace-v4.16-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace
Pull kprobe fixes from Steven Rostedt:
"The documentation for kprobe events says that symbol offets can take
both a + and - sign to get to befor and after the symbol address.
But in actuality, the code does not support the minus. This fixes that
issue, and adds a few more selftests to kprobe events"
* tag 'trace-v4.16-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace:
selftests: ftrace: Add a testcase for probepoint
selftests: ftrace: Add a testcase for string type with kprobe_event
selftests: ftrace: Add probe event argument syntax testcase
tracing: probeevent: Fix to support minus offset from symbol
Diffstat (limited to 'tools')
3 files changed, 186 insertions, 0 deletions
diff --git a/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args_string.tc b/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args_string.tc new file mode 100644 index 000000000000..5ba73035e1d9 --- /dev/null +++ b/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args_string.tc | |||
@@ -0,0 +1,46 @@ | |||
1 | #!/bin/sh | ||
2 | # SPDX-License-Identifier: GPL-2.0 | ||
3 | # description: Kprobe event string type argument | ||
4 | |||
5 | [ -f kprobe_events ] || exit_unsupported # this is configurable | ||
6 | |||
7 | echo 0 > events/enable | ||
8 | echo > kprobe_events | ||
9 | |||
10 | case `uname -m` in | ||
11 | x86_64) | ||
12 | ARG2=%si | ||
13 | OFFS=8 | ||
14 | ;; | ||
15 | i[3456]86) | ||
16 | ARG2=%cx | ||
17 | OFFS=4 | ||
18 | ;; | ||
19 | aarch64) | ||
20 | ARG2=%x1 | ||
21 | OFFS=8 | ||
22 | ;; | ||
23 | arm*) | ||
24 | ARG2=%r1 | ||
25 | OFFS=4 | ||
26 | ;; | ||
27 | *) | ||
28 | echo "Please implement other architecture here" | ||
29 | exit_untested | ||
30 | esac | ||
31 | |||
32 | : "Test get argument (1)" | ||
33 | echo "p:testprobe create_trace_kprobe arg1=+0(+0(${ARG2})):string" > kprobe_events | ||
34 | echo 1 > events/kprobes/testprobe/enable | ||
35 | ! echo test >> kprobe_events | ||
36 | tail -n 1 trace | grep -qe "testprobe.* arg1=\"test\"" | ||
37 | |||
38 | echo 0 > events/kprobes/testprobe/enable | ||
39 | : "Test get argument (2)" | ||
40 | echo "p:testprobe create_trace_kprobe arg1=+0(+0(${ARG2})):string arg2=+0(+${OFFS}(${ARG2})):string" > kprobe_events | ||
41 | echo 1 > events/kprobes/testprobe/enable | ||
42 | ! echo test1 test2 >> kprobe_events | ||
43 | tail -n 1 trace | grep -qe "testprobe.* arg1=\"test1\" arg2=\"test2\"" | ||
44 | |||
45 | echo 0 > events/enable | ||
46 | echo > kprobe_events | ||
diff --git a/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args_syntax.tc b/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args_syntax.tc new file mode 100644 index 000000000000..231bcd2c4eb5 --- /dev/null +++ b/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args_syntax.tc | |||
@@ -0,0 +1,97 @@ | |||
1 | #!/bin/sh | ||
2 | # SPDX-License-Identifier: GPL-2.0 | ||
3 | # description: Kprobe event argument syntax | ||
4 | |||
5 | [ -f kprobe_events ] || exit_unsupported # this is configurable | ||
6 | |||
7 | grep "x8/16/32/64" README > /dev/null || exit_unsupported # version issue | ||
8 | |||
9 | echo 0 > events/enable | ||
10 | echo > kprobe_events | ||
11 | |||
12 | PROBEFUNC="vfs_read" | ||
13 | GOODREG= | ||
14 | BADREG= | ||
15 | GOODSYM="_sdata" | ||
16 | if ! grep -qw ${GOODSYM} /proc/kallsyms ; then | ||
17 | GOODSYM=$PROBEFUNC | ||
18 | fi | ||
19 | BADSYM="deaqswdefr" | ||
20 | SYMADDR=0x`grep -w ${GOODSYM} /proc/kallsyms | cut -f 1 -d " "` | ||
21 | GOODTYPE="x16" | ||
22 | BADTYPE="y16" | ||
23 | |||
24 | case `uname -m` in | ||
25 | x86_64|i[3456]86) | ||
26 | GOODREG=%ax | ||
27 | BADREG=%ex | ||
28 | ;; | ||
29 | aarch64) | ||
30 | GOODREG=%x0 | ||
31 | BADREG=%ax | ||
32 | ;; | ||
33 | arm*) | ||
34 | GOODREG=%r0 | ||
35 | BADREG=%ax | ||
36 | ;; | ||
37 | esac | ||
38 | |||
39 | test_goodarg() # Good-args | ||
40 | { | ||
41 | while [ "$1" ]; do | ||
42 | echo "p ${PROBEFUNC} $1" > kprobe_events | ||
43 | shift 1 | ||
44 | done; | ||
45 | } | ||
46 | |||
47 | test_badarg() # Bad-args | ||
48 | { | ||
49 | while [ "$1" ]; do | ||
50 | ! echo "p ${PROBEFUNC} $1" > kprobe_events | ||
51 | shift 1 | ||
52 | done; | ||
53 | } | ||
54 | |||
55 | echo > kprobe_events | ||
56 | |||
57 | : "Register access" | ||
58 | test_goodarg ${GOODREG} | ||
59 | test_badarg ${BADREG} | ||
60 | |||
61 | : "Symbol access" | ||
62 | test_goodarg "@${GOODSYM}" "@${SYMADDR}" "@${GOODSYM}+10" "@${GOODSYM}-10" | ||
63 | test_badarg "@" "@${BADSYM}" "@${GOODSYM}*10" "@${GOODSYM}/10" \ | ||
64 | "@${GOODSYM}%10" "@${GOODSYM}&10" "@${GOODSYM}|10" | ||
65 | |||
66 | : "Stack access" | ||
67 | test_goodarg "\$stack" "\$stack0" "\$stack1" | ||
68 | test_badarg "\$stackp" "\$stack0+10" "\$stack1-10" | ||
69 | |||
70 | : "Retval access" | ||
71 | echo "r ${PROBEFUNC} \$retval" > kprobe_events | ||
72 | ! echo "p ${PROBEFUNC} \$retval" > kprobe_events | ||
73 | |||
74 | : "Comm access" | ||
75 | test_goodarg "\$comm" | ||
76 | |||
77 | : "Indirect memory access" | ||
78 | test_goodarg "+0(${GOODREG})" "-0(${GOODREG})" "+10(\$stack)" \ | ||
79 | "+0(\$stack1)" "+10(@${GOODSYM}-10)" "+0(+10(+20(\$stack)))" | ||
80 | test_badarg "+(${GOODREG})" "(${GOODREG}+10)" "-(${GOODREG})" "(${GOODREG})" \ | ||
81 | "+10(\$comm)" "+0(${GOODREG})+10" | ||
82 | |||
83 | : "Name assignment" | ||
84 | test_goodarg "varname=${GOODREG}" | ||
85 | test_badarg "varname=varname2=${GOODREG}" | ||
86 | |||
87 | : "Type syntax" | ||
88 | test_goodarg "${GOODREG}:${GOODTYPE}" | ||
89 | test_badarg "${GOODREG}::${GOODTYPE}" "${GOODREG}:${BADTYPE}" \ | ||
90 | "${GOODTYPE}:${GOODREG}" | ||
91 | |||
92 | : "Combination check" | ||
93 | |||
94 | test_goodarg "\$comm:string" "+0(\$stack):string" | ||
95 | test_badarg "\$comm:x64" "\$stack:string" "${GOODREG}:string" | ||
96 | |||
97 | echo > kprobe_events | ||
diff --git a/tools/testing/selftests/ftrace/test.d/kprobe/probepoint.tc b/tools/testing/selftests/ftrace/test.d/kprobe/probepoint.tc new file mode 100644 index 000000000000..4fda01a08da4 --- /dev/null +++ b/tools/testing/selftests/ftrace/test.d/kprobe/probepoint.tc | |||
@@ -0,0 +1,43 @@ | |||
1 | #!/bin/sh | ||
2 | # SPDX-License-Identifier: GPL-2.0 | ||
3 | # description: Kprobe events - probe points | ||
4 | |||
5 | [ -f kprobe_events ] || exit_unsupported # this is configurable | ||
6 | |||
7 | TARGET_FUNC=create_trace_kprobe | ||
8 | |||
9 | dec_addr() { # hexaddr | ||
10 | printf "%d" "0x"`echo $1 | tail -c 8` | ||
11 | } | ||
12 | |||
13 | set_offs() { # prev target next | ||
14 | A1=`dec_addr $1` | ||
15 | A2=`dec_addr $2` | ||
16 | A3=`dec_addr $3` | ||
17 | TARGET="0x$2" # an address | ||
18 | PREV=`expr $A1 - $A2` # offset to previous symbol | ||
19 | NEXT=+`expr $A3 - $A2` # offset to next symbol | ||
20 | OVERFLOW=+`printf "0x%x" ${PREV}` # overflow offset to previous symbol | ||
21 | } | ||
22 | |||
23 | # We have to decode symbol addresses to get correct offsets. | ||
24 | # If the offset is not an instruction boundary, it cause -EILSEQ. | ||
25 | set_offs `grep -A1 -B1 ${TARGET_FUNC} /proc/kallsyms | cut -f 1 -d " " | xargs` | ||
26 | |||
27 | UINT_TEST=no | ||
28 | # printf "%x" -1 returns (unsigned long)-1. | ||
29 | if [ `printf "%x" -1 | wc -c` != 9 ]; then | ||
30 | UINT_TEST=yes | ||
31 | fi | ||
32 | |||
33 | echo 0 > events/enable | ||
34 | echo > kprobe_events | ||
35 | echo "p:testprobe ${TARGET_FUNC}" > kprobe_events | ||
36 | echo "p:testprobe ${TARGET}" > kprobe_events | ||
37 | echo "p:testprobe ${TARGET_FUNC}${NEXT}" > kprobe_events | ||
38 | ! echo "p:testprobe ${TARGET_FUNC}${PREV}" > kprobe_events | ||
39 | if [ "${UINT_TEST}" = yes ]; then | ||
40 | ! echo "p:testprobe ${TARGET_FUNC}${OVERFLOW}" > kprobe_events | ||
41 | fi | ||
42 | echo > kprobe_events | ||
43 | clear_trace | ||