mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/2] [GIT PULL] updates for tip core-v2
@ 2009-04-01 14:19 Steven Rostedt
  2009-04-01 14:19 ` [PATCH 1/2] function-graph: allow unregistering twice Steven Rostedt
  2009-04-01 14:19 ` [PATCH 2/2] ring-buffer: do not remove reader page from list on ring buffer free Steven Rostedt
  0 siblings, 2 replies; 3+ messages in thread
From: Steven Rostedt @ 2009-04-01 14:19 UTC (permalink / raw)
  To: linux-kernel; +Cc: Ingo Molnar, Andrew Morton


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(-)
-- 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 1/2] function-graph: allow unregistering twice
  2009-04-01 14:19 [PATCH 0/2] [GIT PULL] updates for tip core-v2 Steven Rostedt
@ 2009-04-01 14:19 ` Steven Rostedt
  2009-04-01 14:19 ` [PATCH 2/2] ring-buffer: do not remove reader page from list on ring buffer free Steven Rostedt
  1 sibling, 0 replies; 3+ messages in thread
From: Steven Rostedt @ 2009-04-01 14:19 UTC (permalink / raw)
  To: linux-kernel; +Cc: Ingo Molnar, Andrew Morton, Steven Rostedt

[-- Attachment #1: 0001-function-graph-allow-unregistering-twice.patch --]
[-- Type: text/plain, Size: 1235 bytes --]

From: Steven Rostedt <srostedt@redhat.com>

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.

Signed-off-by: Steven Rostedt <srostedt@redhat.com>
---
 kernel/trace/ftrace.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
index 1752a63..f1ed080 100644
--- a/kernel/trace/ftrace.c
+++ b/kernel/trace/ftrace.c
@@ -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);
 }
 
-- 
1.6.2.1

-- 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 2/2] ring-buffer: do not remove reader page from list on ring buffer free
  2009-04-01 14:19 [PATCH 0/2] [GIT PULL] updates for tip core-v2 Steven Rostedt
  2009-04-01 14:19 ` [PATCH 1/2] function-graph: allow unregistering twice Steven Rostedt
@ 2009-04-01 14:19 ` Steven Rostedt
  1 sibling, 0 replies; 3+ messages in thread
From: Steven Rostedt @ 2009-04-01 14:19 UTC (permalink / raw)
  To: linux-kernel; +Cc: Ingo Molnar, Andrew Morton, Steven Rostedt

[-- Attachment #1: 0002-ring-buffer-do-not-remove-reader-page-from-list-on.patch --]
[-- Type: text/plain, Size: 2132 bytes --]

From: Steven Rostedt <srostedt@redhat.com>

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.

Signed-off-by: Steven Rostedt <srostedt@redhat.com>
---
 kernel/trace/ring_buffer.c |    1 -
 1 files changed, 0 insertions(+), 1 deletions(-)

diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
index edce2ff..960cbf4 100644
--- a/kernel/trace/ring_buffer.c
+++ b/kernel/trace/ring_buffer.c
@@ -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) {
-- 
1.6.2.1

-- 

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2009-04-01 14:21 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-04-01 14:19 [PATCH 0/2] [GIT PULL] updates for tip core-v2 Steven Rostedt
2009-04-01 14:19 ` [PATCH 1/2] function-graph: allow unregistering twice Steven Rostedt
2009-04-01 14:19 ` [PATCH 2/2] ring-buffer: do not remove reader page from list on ring buffer free Steven Rostedt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome