<feed xmlns='http://www.w3.org/2005/Atom'>
<title>kernel.git/kernel/trace/trace.c, branch linux-2.6.33.y</title>
<subtitle>Hosts the 0x221E linux distro kernel.
</subtitle>
<id>https://git.0xinfinity.dev/distro/kernel.git/atom?h=linux-2.6.33.y</id>
<link rel='self' href='https://git.0xinfinity.dev/distro/kernel.git/atom?h=linux-2.6.33.y'/>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/'/>
<updated>2011-11-07T21:47:24Z</updated>
<entry>
<title>tracing: Fix returning of duplicate data after EOF in trace_pipe_raw</title>
<updated>2011-11-07T21:47:24Z</updated>
<author>
<name>Steven Rostedt</name>
</author>
<published>2011-10-14T14:44:25Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=467b9b729d746c37c8597a37603b6de3c3ec53b0'/>
<id>urn:sha1:467b9b729d746c37c8597a37603b6de3c3ec53b0</id>
<content type='text'>
commit 436fc280261dcfce5af38f08b89287750dc91cd2 upstream.

The trace_pipe_raw handler holds a cached page from the time the file
is opened to the time it is closed. The cached page is used to handle
the case of the user space buffer being smaller than what was read from
the ring buffer. The left over buffer is held in the cache so that the
next read will continue where the data left off.

After EOF is returned (no more data in the buffer), the index of
the cached page is set to zero. If a user app reads the page again
after EOF, the check in the buffer will see that the cached page
is less than page size and will return the cached page again. This
will cause reading the trace_pipe_raw again after EOF to return
duplicate data, making the output look like the time went backwards
but instead data is just repeated.

The fix is to not reset the index right after all data is read
from the cache, but to reset it after all data is read and more
data exists in the ring buffer.

Reported-by: Jeremy Eder &lt;jeder@redhat.com&gt;
Signed-off-by: Steven Rostedt &lt;rostedt@goodmis.org&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@suse.de&gt;

</content>
</entry>
<entry>
<title>tracing: Fix panic when lseek() called on "trace" opened for writing</title>
<updated>2011-03-21T19:44:27Z</updated>
<author>
<name>Slava Pestov</name>
</author>
<published>2010-11-24T23:13:16Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=b5d59533fbb7c72bc1e87fa0a96d51d7a45e1c25'/>
<id>urn:sha1:b5d59533fbb7c72bc1e87fa0a96d51d7a45e1c25</id>
<content type='text'>
commit 364829b1263b44aa60383824e4c1289d83d78ca7 upstream.

The file_ops struct for the "trace" special file defined llseek as seq_lseek().
However, if the file was opened for writing only, seq_open() was not called,
and the seek would dereference a null pointer, file-&gt;private_data.

This patch introduces a new wrapper for seq_lseek() which checks if the file
descriptor is opened for reading first. If not, it does nothing.

Signed-off-by: Slava Pestov &lt;slavapestov@google.com&gt;
LKML-Reference: &lt;1290640396-24179-1-git-send-email-slavapestov@google.com&gt;
Signed-off-by: Steven Rostedt &lt;rostedt@goodmis.org&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@suse.de&gt;

</content>
</entry>
<entry>
<title>tracing: Consolidate protection of reader access to the ring buffer</title>
<updated>2010-07-05T18:16:10Z</updated>
<author>
<name>Lai Jiangshan</name>
</author>
<published>2010-01-06T12:08:50Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=d8a022afa2e1b3da28c8381b783ec1fd55480e18'/>
<id>urn:sha1:d8a022afa2e1b3da28c8381b783ec1fd55480e18</id>
<content type='text'>
commit 7e53bd42d14c75192b99674c40fcc359392da59d upstream.

At the beginning, access to the ring buffer was fully serialized
by trace_types_lock. Patch d7350c3f4569 gives more freedom to readers,
and patch b04cc6b1f6 adds code to protect trace_pipe and cpu#/trace_pipe.

But actually it is not enough, ring buffer readers are not always
read-only, they may consume data.

This patch makes accesses to trace, trace_pipe, trace_pipe_raw
cpu#/trace, cpu#/trace_pipe and cpu#/trace_pipe_raw serialized.
And removes tracing_reader_cpumask which is used to protect trace_pipe.

Details:

Ring buffer serializes readers, but it is low level protection.
The validity of the events (which returns by ring_buffer_peek() ..etc)
are not protected by ring buffer.

The content of events may become garbage if we allow another process to consume
these events concurrently:
  A) the page of the consumed events may become a normal page
     (not reader page) in ring buffer, and this page will be rewritten
     by the events producer.
  B) The page of the consumed events may become a page for splice_read,
     and this page will be returned to system.

This patch adds trace_access_lock() and trace_access_unlock() primitives.

These primitives allow multi process access to different cpu ring buffers
concurrently.

These primitives don't distinguish read-only and read-consume access.
Multi read-only access is also serialized.

And we don't use these primitives when we open files,
we only use them when we read files.

Signed-off-by: Lai Jiangshan &lt;laijs@cn.fujitsu.com&gt;
LKML-Reference: &lt;4B447D52.1050602@cn.fujitsu.com&gt;
Signed-off-by: Steven Rostedt &lt;rostedt@goodmis.org&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@suse.de&gt;

</content>
</entry>
<entry>
<title>tracing: Do not record user stack trace from NMI context</title>
<updated>2010-04-01T23:01:17Z</updated>
<author>
<name>Steven Rostedt</name>
</author>
<published>2010-03-13T01:03:30Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=a94b3267924327acf606ba22f4a5fb480e354da6'/>
<id>urn:sha1:a94b3267924327acf606ba22f4a5fb480e354da6</id>
<content type='text'>
commit b6345879ccbd9b92864fbd7eb8ac48acdb4d6b15 upstream.

A bug was found with Li Zefan's ftrace_stress_test that caused applications
to segfault during the test.

Placing a tracing_off() in the segfault code, and examining several
traces, I found that the following was always the case. The lock tracer
was enabled (lockdep being required) and userstack was enabled. Testing
this out, I just enabled the two, but that was not good enough. I needed
to run something else that could trigger it. Running a load like hackbench
did not work, but executing a new program would. The following would
trigger the segfault within seconds:

  # echo 1 &gt; /debug/tracing/options/userstacktrace
  # echo 1 &gt; /debug/tracing/events/lock/enable
  # while :; do ls &gt; /dev/null ; done

Enabling the function graph tracer and looking at what was happening
I finally noticed that all cashes happened just after an NMI.

 1)               |    copy_user_handle_tail() {
 1)               |      bad_area_nosemaphore() {
 1)               |        __bad_area_nosemaphore() {
 1)               |          no_context() {
 1)               |            fixup_exception() {
 1)   0.319 us    |              search_exception_tables();
 1)   0.873 us    |            }
[...]
 1)   0.314 us    |  __rcu_read_unlock();
 1)   0.325 us    |    native_apic_mem_write();
 1)   0.943 us    |  }
 1)   0.304 us    |  rcu_nmi_exit();
[...]
 1)   0.479 us    |  find_vma();
 1)               |  bad_area() {
 1)               |    __bad_area() {

After capturing several traces of failures, all of them happened
after an NMI. Curious about this, I added a trace_printk() to the NMI
handler to read the regs-&gt;ip to see where the NMI happened. In which I
found out it was here:

ffffffff8135b660 &lt;page_fault&gt;:
ffffffff8135b660:       48 83 ec 78             sub    $0x78,%rsp
ffffffff8135b664:       e8 97 01 00 00          callq  ffffffff8135b800 &lt;error_entry&gt;

What was happening is that the NMI would happen at the place that a page
fault occurred. It would call rcu_read_lock() which was traced by
the lock events, and the user_stack_trace would run. This would trigger
a page fault inside the NMI. I do not see where the CR2 register is
saved or restored in NMI handling. This means that it would corrupt
the page fault handling that the NMI interrupted.

The reason the while loop of ls helped trigger the bug, was that
each execution of ls would cause lots of pages to be faulted in, and
increase the chances of the race happening.

The simple solution is to not allow user stack traces in NMI context.
After this patch, I ran the above "ls" test for a couple of hours
without any issues. Without this patch, the bug would trigger in less
than a minute.

Reported-by: Li Zefan &lt;lizf@cn.fujitsu.com&gt;
Signed-off-by: Steven Rostedt &lt;rostedt@goodmis.org&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@suse.de&gt;

</content>
</entry>
<entry>
<title>tracing: Disable buffer switching when starting or stopping trace</title>
<updated>2010-04-01T23:01:17Z</updated>
<author>
<name>Steven Rostedt</name>
</author>
<published>2010-03-13T00:56:00Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=8c3492dc6b9ee58b025ffddc83431c5a5d466282'/>
<id>urn:sha1:8c3492dc6b9ee58b025ffddc83431c5a5d466282</id>
<content type='text'>
commit a2f8071428ed9a0f06865f417c962421c9a6b488 upstream.

When the trace iterator is read, tracing_start() and tracing_stop()
is called to stop tracing while the iterator is processing the trace
output.

These functions disable both the standard buffer and the max latency
buffer. But if the wakeup tracer is running, it can switch these
buffers between the two disables:

  buffer = global_trace.buffer;
  if (buffer)
      ring_buffer_record_disable(buffer);

      &lt;&lt;&lt;--------- swap happens here

  buffer = max_tr.buffer;
  if (buffer)
      ring_buffer_record_disable(buffer);

What happens is that we disabled the same buffer twice. On tracing_start()
we can enable the same buffer twice. All ring_buffer_record_disable()
must be matched with a ring_buffer_record_enable() or the buffer
can be disable permanently, or enable prematurely, and cause a bug
where a reset happens while a trace is commiting.

This patch protects these two by taking the ftrace_max_lock to prevent
a switch from occurring.

Found with Li Zefan's ftrace_stress_test.

Reported-by: Lai Jiangshan &lt;laijs@cn.fujitsu.com&gt;
Signed-off-by: Steven Rostedt &lt;rostedt@goodmis.org&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@suse.de&gt;

</content>
</entry>
<entry>
<title>tracing: Use same local variable when resetting the ring buffer</title>
<updated>2010-04-01T23:01:17Z</updated>
<author>
<name>Steven Rostedt</name>
</author>
<published>2010-03-13T00:48:41Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=70e27dedd11fdbb3a9dec79af59d8ba61a19365b'/>
<id>urn:sha1:70e27dedd11fdbb3a9dec79af59d8ba61a19365b</id>
<content type='text'>
commit 283740c619d211e34572cc93c8cdba92ccbdb9cc upstream.

In the ftrace code that resets the ring buffer it references the
buffer with a local variable, but then uses the tr-&gt;buffer as the
parameter to reset. If the wakeup tracer is running, which can
switch the tr-&gt;buffer with the max saved buffer, this can break
the requirement of disabling the buffer before the reset.

   buffer = tr-&gt;buffer;
   ring_buffer_record_disable(buffer);
   synchronize_sched();
   __tracing_reset(tr-&gt;buffer, cpu);

If the tr-&gt;buffer is swapped, then the reset is not happening to the
buffer that was disabled. This will cause the ring buffer to fail.

Found with Li Zefan's ftrace_stress_test.

Reported-by: Lai Jiangshan &lt;laijs@cn.fujitsu.com&gt;
Signed-off-by: Steven Rostedt &lt;rostedt@goodmis.org&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@suse.de&gt;

</content>
</entry>
<entry>
<title>tracing: Fix warning in s_next of trace file ops</title>
<updated>2010-04-01T23:01:16Z</updated>
<author>
<name>Lai Jiangshan</name>
</author>
<published>2010-03-02T09:54:50Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=fe030f50c598ffd9476da37d35a7dd7301487795'/>
<id>urn:sha1:fe030f50c598ffd9476da37d35a7dd7301487795</id>
<content type='text'>
commit ac91d85456372a90af5b85eb6620fd2efb1e431b upstream.

This warning in s_next() can be triggered by lseek():
 [&lt;c018b3f7&gt;] ? s_next+0x77/0x80
 [&lt;c013e3c1&gt;] warn_slowpath_common+0x81/0xa0
 [&lt;c018b3f7&gt;] ? s_next+0x77/0x80
 [&lt;c013e3fa&gt;] warn_slowpath_null+0x1a/0x20
 [&lt;c018b3f7&gt;] s_next+0x77/0x80
 [&lt;c01efa77&gt;] traverse+0x117/0x200
 [&lt;c01eff13&gt;] seq_lseek+0xa3/0x120
 [&lt;c01efe70&gt;] ? seq_lseek+0x0/0x120
 [&lt;c01d7081&gt;] vfs_llseek+0x41/0x50
 [&lt;c01d8116&gt;] sys_llseek+0x66/0xa0
 [&lt;c0102bd0&gt;] sysenter_do_call+0x12/0x26

The iterator "leftover" variable is zeroed in the opening of the trace
file. But lseek can call s_start() which will call s_next() without
reseting the "leftover" variable back to zero, which might trigger
the WARN_ON_ONCE(iter-&gt;leftover) that is in s_next().

Signed-off-by: Lai Jiangshan &lt;laijs@cn.fujitsu.com&gt;
LKML-Reference: &lt;4B8CE06A.9090207@cn.fujitsu.com&gt;
Signed-off-by: Steven Rostedt &lt;rostedt@goodmis.org&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@suse.de&gt;

</content>
</entry>
<entry>
<title>tracing: Prevent kernel oops with corrupted buffer</title>
<updated>2010-01-25T20:11:53Z</updated>
<author>
<name>Steven Rostedt</name>
</author>
<published>2010-01-25T20:11:53Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=74bf4076f2ed79b5510440b72a561823a8852ec0'/>
<id>urn:sha1:74bf4076f2ed79b5510440b72a561823a8852ec0</id>
<content type='text'>
If the contents of the ftrace ring buffer gets corrupted and the trace
file is read, it could create a kernel oops (usualy just killing the user
task thread). This is caused by the checking of the pid in the buffer.
If the pid is negative, it still references the cmdline cache array,
which could point to an invalid address.

The simple fix is to test for negative PIDs.

Signed-off-by: Steven Rostedt &lt;rostedt@goodmis.org&gt;
</content>
</entry>
<entry>
<title>Merge branch 'tracing-fixes-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip</title>
<updated>2009-12-31T19:52:01Z</updated>
<author>
<name>Linus Torvalds</name>
</author>
<published>2009-12-31T19:52:01Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=b21c07040304b8716e38a4a0e4ab60f386357e61'/>
<id>urn:sha1:b21c07040304b8716e38a4a0e4ab60f386357e61</id>
<content type='text'>
* 'tracing-fixes-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip:
  tracing: Fix sign fields in ftrace_define_fields_##call()
  tracing/syscalls: Fix typo in SYSCALL_DEFINE0
  tracing/kprobe: Show sign of fields in trace_kprobe format files
  ksym_tracer: Remove trace_stat
  ksym_tracer: Fix race when incrementing count
  ksym_tracer: Fix to allow writing newline to ksym_trace_filter
  ksym_tracer: Fix to make the tracer work
  tracing: Kconfig spelling fixes and cleanups
  tracing: Fix setting tracer specific options
  Documentation: Update ftrace-design.txt
  Documentation: Update tracepoint-analysis.txt
  Documentation: Update mmiotrace.txt
</content>
</entry>
<entry>
<title>tracing: Fix setting tracer specific options</title>
<updated>2009-12-22T03:35:16Z</updated>
<author>
<name>Steven Rostedt</name>
</author>
<published>2009-12-22T03:35:16Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=c757bea93bea4b77ebd181cc6dca60c15e3b1a2c'/>
<id>urn:sha1:c757bea93bea4b77ebd181cc6dca60c15e3b1a2c</id>
<content type='text'>
The function __set_tracer_option() takes as its last parameter a
"neg" value. If set it should negate the value of the option.

The trace_options_write() passed the value written to the file
which is what the new value needs to be set as. But since this
is not the negative, it never sets the value.

Reported-by: Peter Zijlstra &lt;peterz@infradead.org&gt;
Cc: Li Zefan &lt;lizf@cn.fujitsu.com&gt;
Signed-off-by: Steven Rostedt &lt;rostedt@goodmis.org&gt;
</content>
</entry>
</feed>
