perf probe: Fix user attribute access in kprobes
authorSumanth Korikkar <sumanthk@linux.ibm.com>
Tue, 9 Jun 2020 08:10:18 +0000 (10:10 +0200)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Tue, 9 Jun 2020 15:40:04 +0000 (12:40 -0300)
commit9256c3031eb9beafa3957c61093104c3c75a6148
tree5e2b783d608e243319a86dbe09aebdb24ccf6428
parentc0c652fc705de75f4ba52e93053acc1ed3933e74
perf probe: Fix user attribute access in kprobes

Issue:

  # perf probe -a 'do_sched_setscheduler pid policy param->sched_priority@user'

did not work before.

Fix:

Make:

  # perf probe -a 'do_sched_setscheduler pid policy param->sched_priority@user'

output equivalent to ftrace:

  # echo 'p:probe/do_sched_setscheduler _text+517384 pid=%r2:s32 policy=%r3:s32 sched_priority=+u0(%r4):s32' > /sys/kernel/debug/tracing/kprobe_events

Other:

1. Right now, __match_glob() does not handle [u]<offset>. For now, use
  *u]<offset>.

2. @user attribute was introduced in commit 1e032f7cfa14 ("perf-probe:
   Add user memory access attribute support")

Test:
1. perf probe -a 'do_sched_setscheduler  pid policy
   param->sched_priority@user'

2 ./perf script
   sched 305669 [000] 1614458.838675: perf_bpf_probe:func: (2904e508)
   pid=261614 policy=2 sched_priority=1

3. cat /sys/kernel/debug/tracing/trace
   <...>-309956 [006] .... 1616098.093957: 0: prio: 1

Committer testing:

Before:

  # perf probe -a 'do_sched_setscheduler pid policy param->sched_priority@user'
  param(type:sched_param) has no member sched_priority@user.
    Error: Failed to add events.
  # pahole sched_param
  struct sched_param {
   int                        sched_priority;       /*     0     4 */

   /* size: 4, cachelines: 1, members: 1 */
   /* last cacheline: 4 bytes */
  };
  #

After:

  # perf probe -a 'do_sched_setscheduler pid policy param->sched_priority@user'
  Added new event:
    probe:do_sched_setscheduler (on do_sched_setscheduler with pid policy sched_priority=param->sched_priority)

  You can now use it in all perf tools, such as:

   perf record -e probe:do_sched_setscheduler -aR sleep 1

  # cat /sys/kernel/debug/tracing/kprobe_events
  p:probe/do_sched_setscheduler _text+1113792 pid=%di:s32 policy=%si:s32 sched_priority=+u0(%dx):s32
  #

Fixes: 1e032f7cfa14 ("perf-probe: Add user memory access attribute support")
Signed-off-by: Sumanth Korikkar <sumanthk@linux.ibm.com>
Reviewed-by: Thomas Richter <tmricht@linux.ibm.com>
Acked-by: Masami Hiramatsu <mhiramat@kernel.org>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
Cc: Ilya Leoshkevich <iii@linux.ibm.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Steven Rostedt (VMware) <rostedt@goodmis.org>
Cc: bpf@vger.kernel.org
LPU-Reference: 20200609081019.60234-2-sumanthk@linux.ibm.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/util/probe-event.c
tools/perf/util/probe-file.c