All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jiri Olsa <jolsa@redhat.com>
To: mingo@elte.hu, rostedt@goodmis.org, andi@firstfloor.org,
	lwoodman@redhat.com, hch@infradead.org
Cc: linux-kernel@vger.kernel.org, Jiri Olsa <jolsa@redhat.com>
Subject: [PATCHv2 1/2] tracing - fix recursive user stack trace
Date: Thu, 11 Nov 2010 10:09:08 +0100	[thread overview]
Message-ID: <1289466549-7602-2-git-send-email-jolsa@redhat.com> (raw)
In-Reply-To: <20101110164413.GA5360@nowhere>

The user stack trace can fault when examining the trace. Which
would call the do_page_fault handler, which would trace again,
which would do the user stack trace, which would fault and call
do_page_fault again ...

Thus this is causing a recursive bug. We need to have a recursion
detector here.


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

diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index 82d9b81..1905a72 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -1284,6 +1284,8 @@ void trace_dump_stack(void)
 	__ftrace_trace_stack(global_trace.buffer, flags, 3, preempt_count());
 }
 
+static DEFINE_PER_CPU(int, user_stack_count);
+
 void
 ftrace_trace_userstack(struct ring_buffer *buffer, unsigned long flags, int pc)
 {
@@ -1302,6 +1304,16 @@ ftrace_trace_userstack(struct ring_buffer *buffer, unsigned long flags, int pc)
 	if (unlikely(in_nmi()))
 		return;
 
+	/*
+	 * Prevent recursion, since the user stack tracing may
+	 * trigger other kernel events.
+	 */
+	preempt_disable();
+	if (__get_cpu_var(user_stack_count))
+		goto out;
+
+	__get_cpu_var(user_stack_count)++;
+
 	event = trace_buffer_lock_reserve(buffer, TRACE_USER_STACK,
 					  sizeof(*entry), flags, pc);
 	if (!event)
@@ -1319,6 +1331,11 @@ ftrace_trace_userstack(struct ring_buffer *buffer, unsigned long flags, int pc)
 	save_stack_trace_user(&trace);
 	if (!filter_check_discard(call, entry, buffer, event))
 		ring_buffer_unlock_commit(buffer, event);
+
+	__get_cpu_var(user_stack_count)--;
+
+ out:
+	preempt_enable();
 }
 
 #ifdef UNUSED
-- 
1.7.1


  parent reply	other threads:[~2010-11-11  9:09 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-11-10 11:56 [PATCH 0/2] tracing,mm - add kernel pagefault tracepoint for x86 & x86_64 Jiri Olsa
2010-11-10 11:56 ` [PATCH 1/2] " Jiri Olsa
2010-11-10 13:29   ` Christoph Hellwig
2010-11-10 13:44     ` Jiri Olsa
2010-11-10 13:52       ` Ingo Molnar
2010-11-10 15:00         ` Frederic Weisbecker
2010-11-10 15:17           ` Jiri Olsa
2010-11-10 15:20             ` Christoph Hellwig
2010-11-10 16:28               ` Andi Kleen
2010-11-10 16:44             ` Frederic Weisbecker
2010-11-11  9:09               ` [PATCHv2 0/2] " Jiri Olsa
2010-11-11  9:09               ` Jiri Olsa [this message]
2010-11-11 10:34                 ` [PATCHv2 1/2] tracing - fix recursive user stack trace Andi Kleen
2010-11-11  9:09               ` [PATCHv2 2/2] tracing,mm - add kernel pagefault tracepoint for x86 & x86_64 Jiri Olsa
2010-11-11 12:51                 ` Christoph Hellwig
2010-11-11 13:15                   ` Jiri Olsa
2010-11-15 13:43                 ` Frederic Weisbecker
2010-11-15 14:06                   ` Andi Kleen
2010-11-15 14:54                     ` Frederic Weisbecker
2010-11-15 15:04                       ` Steven Rostedt
2010-11-15 14:19                   ` Steven Rostedt
2010-11-16  9:23                     ` Jiri Olsa
2010-11-16 13:13                       ` Steven Rostedt
2010-11-10 11:56 ` [PATCH 2/2] tracing - fix recursive user stack trace Jiri Olsa
2010-11-11  0:13   ` Li Zefan
2010-11-11 21:57     ` Steven Rostedt
2010-11-18 14:05   ` [tip:perf/core] tracing: Fix " tip-bot for Steven Rostedt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1289466549-7602-2-git-send-email-jolsa@redhat.com \
    --to=jolsa@redhat.com \
    --cc=andi@firstfloor.org \
    --cc=hch@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lwoodman@redhat.com \
    --cc=mingo@elte.hu \
    --cc=rostedt@goodmis.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.