Skip to contentSkip to conversation

updates for tip core-v2

GIT PULL New Steven Rostedt 1 participant 3 messages Apr 1, 2009

Subsystems (3)
lore
Share & tools
lore

Steven Rostedt

author maintainer
#0 lore raw

Ingo,

I sent these patches before, but this time I rebased to your core-v2 branch.

Please pull the latest tip/tracing/core-v2 tree, which can be found at:

git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-2.6-trace.git
tip/tracing/core-v2

Steven Rostedt (2):
function-graph: allow unregistering twice
ring-buffer: do not remove reader page from list on ring buffer free

----

 kernel/trace/ftrace.c      |    4 ++++
 kernel/trace/ring_buffer.c |    1 -
 2 files changed, 4 insertions(+), 1 deletions(-)
author maintainer
#1 lore raw

PATCH 1/2 function-graph: allow unregistering twice

From: Steven Rostedt <[email protected]>

Impact: fix to permanent disabling of function graph tracer

There should be nothing to prevent a tracer from unregistering a function graph callback more than once. This can simplify error paths.

But currently, the counter does not account for mulitple unregistering of the function graph callback. If it happens, the function graph tracer will be permanently disabled.

---
 kernel/trace/ftrace.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)
kernel/trace/ftrace.c +4 -0
index 1752a63..f1ed080 100644
@@ -2719,6 +2719,9 @@ void unregister_ftrace_graph(void)
 {
 	mutex_lock(&ftrace_lock);
 
+	if (!unlikely(atomic_read(&ftrace_graph_active)))
+		goto out;
+
 	atomic_dec(&ftrace_graph_active);
 	unregister_trace_sched_switch(ftrace_graph_probe_sched_switch);
 	ftrace_graph_return = (trace_func_graph_ret_t)ftrace_stub;
@@ -2726,6 +2729,7 @@ void unregister_ftrace_graph(void)
 	ftrace_shutdown(FTRACE_STOP_FUNC_RET);
 	unregister_pm_notifier(&ftrace_suspend_notifier);
 
+ out:
 	mutex_unlock(&ftrace_lock);
 }
 
Signature · 3 lines
1.6.2.1

-- 
author maintainer
#2 lore raw

PATCH 2/2 ring-buffer: do not remove reader page from list on ring buffer free

In reply to Steven Rostedt

From: Steven Rostedt <[email protected]>

Impact: prevent possible memory leak

The reader page of the ring buffer is special. Although it points into the ring buffer, it is not part of the actual buffer. It is a page used by the reader to swap with a page in the ring buffer. Once the swap is made, the new reader page is again outside the buffer.

Even though the reader page points into the buffer, it is really pointing to residual data. Note, this data is used by the reader.

              reader page
                  |
                  v
       (prev)   +---+    (next)
     +----------|   |----------+
     |          +---+          |
     v                         v
   +---+        +---+        +---+
-->|   |------->|   |------->|   |--->
<--|   |<-------|   |<-------|   |<---
   +---+        +---+        +---+
     ^            ^            ^
      \           |            /
       ------- Buffer---------

If we perform a list_del_init() on the reader page we will actually remove the last page the reader swapped with and not the reader page itself. This will cause that page to not be freed, and thus is a memory leak.

Luckily, the only user of the ring buffer so far is ftrace. And ftrace will not free its ring buffer after it allocates it. There is no current possible memory leak. But once there are other users, or if ftrace dynamically creates and frees its ring buffer, then this would be a memory leak.

This patch fixes the leak for future cases.

---
 kernel/trace/ring_buffer.c |    1 -
 1 files changed, 0 insertions(+), 1 deletions(-)
kernel/trace/ring_buffer.c +0 -1
index edce2ff..960cbf4 100644
@@ -563,7 +563,6 @@ static void rb_free_cpu_buffer(struct ring_buffer_per_cpu *cpu_buffer)
 	struct list_head *head = &cpu_buffer->pages;
 	struct buffer_page *bpage, *tmp;
 
-	list_del_init(&cpu_buffer->reader_page->list);
 	free_buffer_page(cpu_buffer->reader_page);
 
 	list_for_each_entry_safe(bpage, tmp, head, list) {
Signature · 3 lines
1.6.2.1

--