<feed xmlns='http://www.w3.org/2005/Atom'>
<title>linux/kernel/trace/trace_kprobe.c, branch v3.12</title>
<subtitle>Mirror of https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/
</subtitle>
<id>https://git.shady.money/linux/atom?h=v3.12</id>
<link rel='self' href='https://git.shady.money/linux/atom?h=v3.12'/>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/'/>
<updated>2013-08-01T02:25:46Z</updated>
<entry>
<title>tracing/kprobes: Fail to unregister if probe event files are in use</title>
<updated>2013-08-01T02:25:46Z</updated>
<author>
<name>Steven Rostedt (Red Hat)</name>
<email>rostedt@goodmis.org</email>
</author>
<published>2013-07-04T03:33:50Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=40c32592668b727cbfcf7b1c0567f581bd62a5e4'/>
<id>urn:sha1:40c32592668b727cbfcf7b1c0567f581bd62a5e4</id>
<content type='text'>
When a probe is being removed, it cleans up the event files that correspond
to the probe. But there is a race between writing to one of these files
and deleting the probe. This is especially true for the "enable" file.

	CPU 0				CPU 1
	-----				-----

				  fd = open("enable",O_WRONLY);

  probes_open()
  release_all_trace_probes()
  unregister_trace_probe()
  if (trace_probe_is_enabled(tp))
	return -EBUSY

				   write(fd, "1", 1)
				   __ftrace_set_clr_event()
				   call-&gt;class-&gt;reg()
				    (kprobe_register)
				     enable_trace_probe(tp)

  __unregister_trace_probe(tp);
  list_del(&amp;tp-&gt;list)
  unregister_probe_event(tp) &lt;-- fails!
  free_trace_probe(tp)

				   write(fd, "0", 1)
				   __ftrace_set_clr_event()
				   call-&gt;class-&gt;unreg
				    (kprobe_register)
				    disable_trace_probe(tp) &lt;-- BOOM!

A test program was written that used two threads to simulate the
above scenario adding a nanosleep() interval to change the timings
and after several thousand runs, it was able to trigger this bug
and crash:

BUG: unable to handle kernel paging request at 00000005000000f9
IP: [&lt;ffffffff810dee70&gt;] probes_open+0x3b/0xa7
PGD 7808a067 PUD 0
Oops: 0000 [#1] PREEMPT SMP
Dumping ftrace buffer:
---------------------------------
Modules linked in: ipt_MASQUERADE sunrpc ip6t_REJECT nf_conntrack_ipv6
CPU: 1 PID: 2070 Comm: test-kprobe-rem Not tainted 3.11.0-rc3-test+ #47
Hardware name: To Be Filled By O.E.M. To Be Filled By O.E.M./To be filled by O.E.M., BIOS SDBLI944.86P 05/08/2007
task: ffff880077756440 ti: ffff880076e52000 task.ti: ffff880076e52000
RIP: 0010:[&lt;ffffffff810dee70&gt;]  [&lt;ffffffff810dee70&gt;] probes_open+0x3b/0xa7
RSP: 0018:ffff880076e53c38  EFLAGS: 00010203
RAX: 0000000500000001 RBX: ffff88007844f440 RCX: 0000000000000003
RDX: 0000000000000003 RSI: 0000000000000003 RDI: ffff880076e52000
RBP: ffff880076e53c58 R08: ffff880076e53bd8 R09: 0000000000000000
R10: ffff880077756440 R11: 0000000000000006 R12: ffffffff810dee35
R13: ffff880079250418 R14: 0000000000000000 R15: ffff88007844f450
FS:  00007f87a276f700(0000) GS:ffff88007d480000(0000) knlGS:0000000000000000
CS:  0010 DS: 0000 ES: 0000 CR0: 000000008005003b
CR2: 00000005000000f9 CR3: 0000000077262000 CR4: 00000000000007e0
Stack:
 ffff880076e53c58 ffffffff81219ea0 ffff88007844f440 ffffffff810dee35
 ffff880076e53ca8 ffffffff81130f78 ffff8800772986c0 ffff8800796f93a0
 ffffffff81d1b5d8 ffff880076e53e04 0000000000000000 ffff88007844f440
Call Trace:
 [&lt;ffffffff81219ea0&gt;] ? security_file_open+0x2c/0x30
 [&lt;ffffffff810dee35&gt;] ? unregister_trace_probe+0x4b/0x4b
 [&lt;ffffffff81130f78&gt;] do_dentry_open+0x162/0x226
 [&lt;ffffffff81131186&gt;] finish_open+0x46/0x54
 [&lt;ffffffff8113f30b&gt;] do_last+0x7f6/0x996
 [&lt;ffffffff8113cc6f&gt;] ? inode_permission+0x42/0x44
 [&lt;ffffffff8113f6dd&gt;] path_openat+0x232/0x496
 [&lt;ffffffff8113fc30&gt;] do_filp_open+0x3a/0x8a
 [&lt;ffffffff8114ab32&gt;] ? __alloc_fd+0x168/0x17a
 [&lt;ffffffff81131f4e&gt;] do_sys_open+0x70/0x102
 [&lt;ffffffff8108f06e&gt;] ? trace_hardirqs_on_caller+0x160/0x197
 [&lt;ffffffff81131ffe&gt;] SyS_open+0x1e/0x20
 [&lt;ffffffff81522742&gt;] system_call_fastpath+0x16/0x1b
Code: e5 41 54 53 48 89 f3 48 83 ec 10 48 23 56 78 48 39 c2 75 6c 31 f6 48 c7
RIP  [&lt;ffffffff810dee70&gt;] probes_open+0x3b/0xa7
 RSP &lt;ffff880076e53c38&gt;
CR2: 00000005000000f9
---[ end trace 35f17d68fc569897 ]---

The unregister_trace_probe() must be done first, and if it fails it must
fail the removal of the kprobe.

Several changes have already been made by Oleg Nesterov and Masami Hiramatsu
to allow moving the unregister_probe_event() before the removal of
the probe and exit the function if it fails. This prevents the tp
structure from being used after it is freed.

Link: http://lkml.kernel.org/r/20130704034038.819592356@goodmis.org

Acked-by: Masami Hiramatsu &lt;masami.hiramatsu.pt@hitachi.com&gt;
Signed-off-by: Steven Rostedt &lt;rostedt@goodmis.org&gt;
</content>
</entry>
<entry>
<title>tracing/kprobe: Wait for disabling all running kprobe handlers</title>
<updated>2013-07-19T01:31:29Z</updated>
<author>
<name>Masami Hiramatsu</name>
<email>masami.hiramatsu.pt@hitachi.com</email>
</author>
<published>2013-07-09T09:35:26Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=a232e270dcb55a70ad3241bc6fc160fd9b5c9e6c'/>
<id>urn:sha1:a232e270dcb55a70ad3241bc6fc160fd9b5c9e6c</id>
<content type='text'>
Wait for disabling all running kprobe handlers when a kprobe
event is disabled, since the caller, trace_remove_event_call()
supposes that a removing event is disabled completely by
disabling the event.
With this change, ftrace can ensure that there is no running
event handlers after disabling it.

Link: http://lkml.kernel.org/r/20130709093526.20138.93100.stgit@mhiramat-M0-7522

Signed-off-by: Masami Hiramatsu &lt;masami.hiramatsu.pt@hitachi.com&gt;
Signed-off-by: Steven Rostedt &lt;rostedt@goodmis.org&gt;
</content>
</entry>
<entry>
<title>tracing/perf: Move the PERF_MAX_TRACE_SIZE check into perf_trace_buf_prepare()</title>
<updated>2013-07-19T01:31:28Z</updated>
<author>
<name>Oleg Nesterov</name>
<email>oleg@redhat.com</email>
</author>
<published>2013-06-17T17:02:11Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=cd92bf61d6d70bd3eb33b46d600e3f3eb9c5778a'/>
<id>urn:sha1:cd92bf61d6d70bd3eb33b46d600e3f3eb9c5778a</id>
<content type='text'>
Every perf_trace_buf_prepare() caller does
WARN_ONCE(size &gt; PERF_MAX_TRACE_SIZE, message) and "message" is
almost the same.

Shift this WARN_ONCE() into perf_trace_buf_prepare(). This changes
the meaning of _ONCE, but I think this is fine.

	- 4947014 2932448 10104832  17984294  1126b26 vmlinux
	+ 4948422 2932448 10104832  17985702  11270a6 vmlinux

on my build.

Link: http://lkml.kernel.org/r/20130617170211.GA19813@redhat.com

Acked-by: Peter Zijlstra &lt;peterz@infradead.org&gt;
Signed-off-by: Oleg Nesterov &lt;oleg@redhat.com&gt;
Signed-off-by: Steven Rostedt &lt;rostedt@goodmis.org&gt;
</content>
</entry>
<entry>
<title>tracing/kprobes: Don't pass addr=ip to perf_trace_buf_submit()</title>
<updated>2013-07-02T00:34:28Z</updated>
<author>
<name>Oleg Nesterov</name>
<email>oleg@redhat.com</email>
</author>
<published>2013-06-20T17:38:11Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=cf6735a4b103b801753748531e3658cdc8cafa5e'/>
<id>urn:sha1:cf6735a4b103b801753748531e3658cdc8cafa5e</id>
<content type='text'>
kprobe_perf_func() and kretprobe_perf_func() pass addr=ip to
perf_trace_buf_submit() for no reason.

This sets perf_sample_data-&gt;addr for PERF_SAMPLE_ADDR, we already
have perf_sample_data-&gt;ip initialized if PERF_SAMPLE_IP.

Link: http://lkml.kernel.org/r/20130620173811.GA13161@redhat.com

Signed-off-by: Oleg Nesterov &lt;oleg@redhat.com&gt;
Signed-off-by: Steven Rostedt &lt;rostedt@goodmis.org&gt;
</content>
</entry>
<entry>
<title>tracing/kprobes: Turn trace_probe-&gt;files into list_head</title>
<updated>2013-07-02T00:34:27Z</updated>
<author>
<name>Oleg Nesterov</name>
<email>oleg@redhat.com</email>
</author>
<published>2013-06-20T17:38:14Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=b04d52e368e2cf526abb2bab61f304eaea126af2'/>
<id>urn:sha1:b04d52e368e2cf526abb2bab61f304eaea126af2</id>
<content type='text'>
I think that "ftrace_event_file *trace_probe[]" complicates the
code for no reason, turn it into list_head to simplify the code.
enable_trace_probe() no longer needs synchronize_sched().

This needs the extra sizeof(list_head) memory for every attached
ftrace_event_file, hopefully not a problem in this case.

Link: http://lkml.kernel.org/r/20130620173814.GA13165@redhat.com

Acked-by: Masami Hiramatsu &lt;masami.hiramatsu.pt@hitachi.com&gt;
Signed-off-by: Oleg Nesterov &lt;oleg@redhat.com&gt;
Signed-off-by: Steven Rostedt &lt;rostedt@goodmis.org&gt;
</content>
</entry>
<entry>
<title>tracing/kprobes: Kill probe_enable_lock</title>
<updated>2013-07-02T00:34:24Z</updated>
<author>
<name>Oleg Nesterov</name>
<email>oleg@redhat.com</email>
</author>
<published>2013-06-20T17:38:09Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=3fe3d6193e7cd7b4dd2bde10772f048bdefea4ee'/>
<id>urn:sha1:3fe3d6193e7cd7b4dd2bde10772f048bdefea4ee</id>
<content type='text'>
enable_trace_probe() and disable_trace_probe() should not worry about
serialization, the caller (perf_trace_init or __ftrace_set_clr_event)
holds event_mutex.

They are also called by kprobe_trace_self_tests_init(), but this __init
function can't race with itself or trace_events.c

And note that this code depended on event_mutex even before 41a7dd420c
which introduced probe_enable_lock. In fact it assumes that the caller
kprobe_register() can never race with itself. Otherwise, say, tp-&gt;flags
manipulations are racy.

Link: http://lkml.kernel.org/r/20130620173809.GA13158@redhat.com

Acked-by: Masami Hiramatsu &lt;masami.hiramatsu.pt@hitachi.com&gt;
Signed-off-by: Oleg Nesterov &lt;oleg@redhat.com&gt;
Signed-off-by: Steven Rostedt &lt;rostedt@goodmis.org&gt;
</content>
</entry>
<entry>
<title>tracing/kprobes: Avoid perf_trace_buf_*() if -&gt;perf_events is empty</title>
<updated>2013-07-02T00:34:23Z</updated>
<author>
<name>Oleg Nesterov</name>
<email>oleg@redhat.com</email>
</author>
<published>2013-06-20T17:38:06Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=288e984e622336bab8bc3dfdf2f190816362d9a1'/>
<id>urn:sha1:288e984e622336bab8bc3dfdf2f190816362d9a1</id>
<content type='text'>
perf_trace_buf_prepare() + perf_trace_buf_submit() make no sense
if this task/CPU has no active counters. Change kprobe_perf_func()
and kretprobe_perf_func() to check call-&gt;perf_events beforehand
and return if this list is empty.

For example, "perf record -e some_probe -p1". Only /sbin/init will
report, all other threads which hit the same probe will do
perf_trace_buf_prepare/perf_trace_buf_submit just to realize that
nobody wants perf_swevent_event().

Link: http://lkml.kernel.org/r/20130620173806.GA13151@redhat.com

Acked-by: Masami Hiramatsu &lt;masami.hiramatsu.pt@hitachi.com&gt;
Signed-off-by: Oleg Nesterov &lt;oleg@redhat.com&gt;
Signed-off-by: Steven Rostedt &lt;rostedt@goodmis.org&gt;
</content>
</entry>
<entry>
<title>tracing/kprobes: Remove unnecessary checking of trace_probe_is_enabled</title>
<updated>2013-06-20T03:32:08Z</updated>
<author>
<name>zhangwei(Jovi)</name>
<email>jovi.zhangwei@huawei.com</email>
</author>
<published>2013-06-14T02:10:38Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=195a84d91e92ee3fe571a2086a6db7e17bf5bc7c'/>
<id>urn:sha1:195a84d91e92ee3fe571a2086a6db7e17bf5bc7c</id>
<content type='text'>
Since tp-&gt;flags assignment was moved into function enable_trace_probe(),
there is no need to use trace_probe_is_enabled to check flags
in the same function.

Remove the unnecessary checking.

Link: http://lkml.kernel.org/r/51BA7B9E.3040807@huawei.com

Acked-by: Masami Hiramatsu &lt;masami.hiramatsu.pt@hitachi.com&gt;
Cc: Frederic Weisbecker &lt;fweisbec@gmail.com&gt;
Cc: Oleg Nesterov &lt;oleg@redhat.com&gt;
Cc: Srikar Dronamraju &lt;srikar@linux.vnet.ibm.com&gt;
Signed-off-by: zhangwei(Jovi) &lt;jovi.zhangwei@huawei.com&gt;
Signed-off-by: Steven Rostedt &lt;rostedt@goodmis.org&gt;
</content>
</entry>
<entry>
<title>tracing/kprobes: Make print_*probe_event static</title>
<updated>2013-05-15T17:50:24Z</updated>
<author>
<name>Masami Hiramatsu</name>
<email>masami.hiramatsu.pt@hitachi.com</email>
</author>
<published>2013-05-13T11:58:39Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=b62fdd97fcae17e483b005bafd13fadbd9840672'/>
<id>urn:sha1:b62fdd97fcae17e483b005bafd13fadbd9840672</id>
<content type='text'>
According to sparse warning, print_*probe_event static because
those functions are not directly called from outside.

Link: http://lkml.kernel.org/r/20130513115839.6545.83067.stgit@mhiramat-M0-7522

Cc: Srikar Dronamraju &lt;srikar@linux.vnet.ibm.com&gt;
Cc: Oleg Nesterov &lt;oleg@redhat.com&gt;
Cc: Tom Zanussi &lt;tom.zanussi@intel.com&gt;
Cc: Frederic Weisbecker &lt;fweisbec@gmail.com&gt;
Cc: Ingo Molnar &lt;mingo@redhat.com&gt;
Signed-off-by: Masami Hiramatsu &lt;masami.hiramatsu.pt@hitachi.com&gt;
Signed-off-by: Steven Rostedt &lt;rostedt@goodmis.org&gt;
</content>
</entry>
<entry>
<title>tracing/kprobes: Fix a sparse warning for incorrect type in assignment</title>
<updated>2013-05-15T17:50:23Z</updated>
<author>
<name>Masami Hiramatsu</name>
<email>masami.hiramatsu.pt@hitachi.com</email>
</author>
<published>2013-05-13T11:58:37Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=3d1fc7b0880c4db612a3d3211a808659e28af588'/>
<id>urn:sha1:3d1fc7b0880c4db612a3d3211a808659e28af588</id>
<content type='text'>
Fix a sparse warning about the rcu operated pointer is
defined without __rcu address space.

Link: http://lkml.kernel.org/r/20130513115837.6545.23322.stgit@mhiramat-M0-7522

Cc: Srikar Dronamraju &lt;srikar@linux.vnet.ibm.com&gt;
Cc: Oleg Nesterov &lt;oleg@redhat.com&gt;
Cc: Tom Zanussi &lt;tom.zanussi@intel.com&gt;
Cc: Frederic Weisbecker &lt;fweisbec@gmail.com&gt;
Cc: Ingo Molnar &lt;mingo@redhat.com&gt;
Signed-off-by: Masami Hiramatsu &lt;masami.hiramatsu.pt@hitachi.com&gt;
Signed-off-by: Steven Rostedt &lt;rostedt@goodmis.org&gt;
</content>
</entry>
</feed>
