summaryrefslogtreecommitdiff
path: root/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args_syntax.tc
blob: 474ca1a9a088528e2f15b5a642fcd775a518e5d2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/bin/sh
# SPDX-License-Identifier: GPL-2.0
# description: Kprobe event argument syntax
# requires: kprobe_events "x8/16/32/64":README

PROBEFUNC="vfs_read"
GOODREG=
BADREG=
GOODSYM="_sdata"
if ! grep -qw ${GOODSYM} /proc/kallsyms ; then
  GOODSYM=$PROBEFUNC
fi
BADSYM="deaqswdefr"
SYMADDR=0x`grep -w ${GOODSYM} /proc/kallsyms | cut -f 1 -d " "`
GOODTYPE="x16"
BADTYPE="y16"

case `uname -m` in
x86_64|i[3456]86)
  GOODREG=%ax
  BADREG=%ex
;;
aarch64)
  GOODREG=%x0
  BADREG=%ax
;;
arm*)
  GOODREG=%r0
  BADREG=%ax
;;
ppc*)
  GOODREG=%r3
  BADREG=%msr
;;
*)
  echo "Please implement other architecture here"
  exit_untested
esac

test_goodarg() # Good-args
{
  while [ "$1" ]; do
    echo "p ${PROBEFUNC} $1" > kprobe_events
    shift 1
  done;
}

test_badarg() # Bad-args
{
  while [ "$1" ]; do
    ! echo "p ${PROBEFUNC} $1" > kprobe_events
    shift 1
  done;
}

echo > kprobe_events

: "Register access"
test_goodarg ${GOODREG}
test_badarg ${BADREG}

: "Symbol access"
test_goodarg "@${GOODSYM}" "@${SYMADDR}" "@${GOODSYM}+10" "@${GOODSYM}-10"
test_badarg "@" "@${BADSYM}" "@${GOODSYM}*10" "@${GOODSYM}/10" \
	    "@${GOODSYM}%10" "@${GOODSYM}&10" "@${GOODSYM}|10"

: "Stack access"
test_goodarg "\$stack" "\$stack0" "\$stack1"
test_badarg "\$stackp" "\$stack0+10" "\$stack1-10"

: "Retval access"
echo "r ${PROBEFUNC} \$retval" > kprobe_events
! echo "p ${PROBEFUNC} \$retval" > kprobe_events

# $comm was introduced in 4.8, older kernels reject it.
if grep -A1 "fetcharg:" README | grep -q '\$comm' ; then
: "Comm access"
test_goodarg "\$comm"
fi

: "Indirect memory access"
test_goodarg "+0(${GOODREG})" "-0(${GOODREG})" "+10(\$stack)" \
	"+0(\$stack1)" "+10(@${GOODSYM}-10)" "+0(+10(+20(\$stack)))"
test_badarg "+(${GOODREG})" "(${GOODREG}+10)" "-(${GOODREG})" "(${GOODREG})" \
	"+10(\$comm)" "+0(${GOODREG})+10"

: "Name assignment"
test_goodarg "varname=${GOODREG}"
test_badarg "varname=varname2=${GOODREG}"

: "Type syntax"
test_goodarg "${GOODREG}:${GOODTYPE}"
test_badarg "${GOODREG}::${GOODTYPE}" "${GOODREG}:${BADTYPE}" \
	"${GOODTYPE}:${GOODREG}"

: "Combination check"

test_goodarg "\$comm:string" "+0(\$stack):string"
test_badarg "\$comm:x64" "\$stack:string" "${GOODREG}:string"