Skip to content

tracing/uprobes: Add support for more fetch methods (v6)

Namhyung Kim lkml 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest13 patches 59 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/13tracing/uprobes: Fix documentation of uprobe registration syntaxDocumentation/trace/uprobetracer.txt kernel/trace/trace_uprobe.c+6 -60 replies
2/13tracing/probes: Fix basic print type functionskernel/trace/trace_probe.c+11 -60 replies
3/13tracing/kprobes: Move fetch functions to trace_kprobe.ckernel/trace/trace_kprobe.c kernel/trace/trace_probe.c kernel/trace/trace_probe.h+335 -2650 replies
4/13tracing/kprobes: Add fetch{,_size} member into deref fetch methodkernel/trace/trace_probe.c+20 -20 replies
5/13tracing/kprobes: Staticize stack and memory fetch functionskernel/trace/trace_kprobe.c kernel/trace/trace_probe.h+4 -120 replies
6/13tracing/kprobes: Factor out struct trace_probekernel/trace/trace_kprobe.c kernel/trace/trace_probe.h+213 -2030 replies
7/13tracing/uprobes: Convert to struct trace_probekernel/trace/trace_uprobe.c+75 -760 replies
8/13tracing/kprobes: Move common functions to trace_probe.hkernel/trace/trace_kprobe.c kernel/trace/trace_probe.h+48 -480 replies
9/13tracing/kprobes: Integrate duplicate set_print_fmt()kernel/trace/trace_kprobe.c kernel/trace/trace_probe.c kernel/trace/trace_probe.h +1 more+66 -1160 replies
10/13tracing/uprobes: Fetch args before reserving a ring bufferkernel/trace/trace_uprobe.c+82 -1611 replies
11/13tracing/kprobes: Add priv argument to fetch functionskernel/trace/trace_kprobe.c kernel/trace/trace_probe.c kernel/trace/trace_probe.h +1 more+44 -392 replies
12/13tracing/uprobes: Add more fetch functionskernel/trace/trace_probe.c kernel/trace/trace_probe.h kernel/trace/trace_uprobe.c+192 -67 replies
13/13tracing/uprobes: Add support for full argument access methodsDocumentation/trace/uprobetracer.txt kernel/trace/trace_probe.c+48 -130 replies

Reviews trailers per patch

All 13 patches have a Reviewed-by or Acked-by.

PatchMasami HiramatsuHyeoncheol Lee
1/13R-b
2/13A-b
3/13A-b
4/13A-b
5/13A-b
6/13A-b
7/13R-b
8/13A-b
9/13A-b
10/13R-b
11/13A-b
12/13R-b Original-patch-by
13/13A-b Original-patch-by

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v1 thread

Cover letter [PATCHSET 00/13] tracing/uprobes: Add support for more fetch methods (v6)

Hello,

This patchset implements memory (address), stack[N], deference, bitfield and retval (it needs uretprobe tho) fetch methods for uprobes. It's based on the previous work [1] done by Hyeoncheol Lee.

Now kprobes and uprobes have their own fetch_type_tables and, in turn, memory and stack access methods. Other fetch methods are shared.

For the dereference method, I added a new argument to fetch functions. It's because for uprobes it needs to know whether the given address is a file offset or a virtual address in an user process. For instance, in case of fetching from a memory directly (like @offset) it should convert the address (offset) to a virtual address of the process, but if it's a dereferencing, the given address already has the virtual address.

To determine this in a fetch function, I passed a pointer to trace_uprobe for direct fetch, and passed NULL for dereference.

The patch 1-2 are bug fixes and can be applied independently.

Please look at patch 10 that uses per-cpu buffer for accessing user memory as suggested by Steven. While I tried hard not to mess things up there might be a chance I did something horrible. It'd be great if you guys take a look and give comments.

* v6 changes:
- add more Ack's from Masami
- fix ref count of uprobe_cpu_buffer (thanks to Jovi)

* v5 changes:
- use user_stack_pointer() instead of GET_USP()
- fix a bug in 'stack' fetch method of uprobes

* v4 changes:
- add Ack's from Masami
- rearrange patches to make it easy for simple fixes to be applied
- update documentation
- use per-cpu buffer for storing args (thanks to Steve!)

[1] https://lkml.org/lkml/2012/11/14/84

A simple example:

  # cat foo.c
  int glob = -1;
  char str[] = "hello uprobe.";
  struct foo {
    unsigned int unused: 2;
    unsigned int foo: 20;
    unsigned int bar: 10;
  } foo = {
    .foo = 5,
  };

  int main(int argc, char *argv[])
  {
    long local = 0x1234;
    return 127;

}

  # gcc -o foo -g foo.c
  # objdump -d foo | grep -A9 -F '<main>'
  00000000004004b0 <main>:
    4004b0:	55                   	push   %rbp
    4004b1:	48 89 e5             	mov    %rsp,%rbp
    4004b4:	89 7d ec             	mov    %edi,-0x14(%rbp)
    4004b7:	48 89 75 e0          	mov    %rsi,-0x20(%rbp)
    4004bb:	48 c7 45 f8 34 12 00 	movq   $0x1234,-0x8(%rbp)
    4004c2:	00 
    4004c3:	b8 7f 00 00 00       	mov    $0x7f,%eax
    4004c8:	5d                   	pop    %rbp
    4004c9:	c3                   	retq   
  # nm foo | grep -e glob$ -e str -e foo
  00000000006008bc D foo
  00000000006008a8 D glob
  00000000006008ac D str
  # perf probe -x /home/namhyung/tmp/foo -a 'foo=main+0x13 glob=@0x8a8:s32 \
Quoted 1 line

str=@0x8ac:string bit=@0x8bc:b10@2/32 argc=%di local=-0x8(%bp)'

Added new event:

    probe_foo:foo      (on 0x4c3 with glob=@0x8a8:s32 str=@0x8ac:string 
                                 bit=@0x8bc:b10@2/32 argc=%di local=-0x8(%bp))

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

perf record -e probe_foo:foo -aR sleep 1

  # perf record -e probe_foo:foo ./foo
  [ perf record: Woken up 1 times to write data ]
  [ perf record: Captured and wrote 0.001 MB perf.data (~33 samples) ]
  # perf script | grep -v ^#
               foo  2008 [002  2199.867154: probe_foo:foo (4004c3)
                   glob=-1 str="hello uprobe." bit=5 argc=1 local=1234

This patchset is based on the current for-next branch of the Steven Rostedt's linux-trace tree. I also put this on my 'uprobe/fetch-v6' branch in my tree:

git://git.kernel.org/pub/scm/linux/kernel/git/namhyung/linux-perf.git

Any comments are welcome, thanks.
Namhyung

Cc Masami Hiramatsu <[email protected]>
Cc Srikar Dronamraju <[email protected]>
Cc Oleg Nesterov <[email protected]>
Cc zhangwei(Jovi) <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Hemant Kumar <[email protected]>

Hyeoncheol Lee (2):
tracing/kprobes: Move fetch functions to trace_kprobe.c tracing/kprobes: Add fetch{,_size} member into deref fetch method

Namhyung Kim (11):
tracing/uprobes: Fix documentation of uprobe registration syntax tracing/probes: Fix basic print type functions tracing/kprobes: Staticize stack and memory fetch functions tracing/kprobes: Factor out struct trace_probe tracing/uprobes: Convert to struct trace_probe tracing/kprobes: Move common functions to trace_probe.h tracing/kprobes: Integrate duplicate set_print_fmt() tracing/uprobes: Fetch args before reserving a ring buffer tracing/kprobes: Add priv argument to fetch functions tracing/uprobes: Add more fetch functions tracing/uprobes: Add support for full argument access methods

 Documentation/trace/uprobetracer.txt |  35 +-
 kernel/trace/trace_kprobe.c          | 642 +++++++++++++++++++----------------
 kernel/trace/trace_probe.c           | 453 +++++++++---------------
 kernel/trace/trace_probe.h           | 202 ++++++++++-
 kernel/trace/trace_uprobe.c          | 458 +++++++++++++++++--------
 5 files changed, 1063 insertions(+), 727 deletions(-)
Signature · 1 line
1.7.11.7