mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: Eric Dumazet <eric.dumazet@gmail.com>
Cc: linux-kernel@vger.kernel.org, Ingo Molnar <mingo@elte.hu>,
	Andrew Morton <akpm@linux-foundation.org>,
	Frederic Weisbecker <fweisbec@gmail.com>,
	Jiri Olsa <jolsa@redhat.com>
Subject: Re: [PATCH 3/3] tracing: Fix recursive user stack trace
Date: Fri, 12 Nov 2010 10:45:11 -0500	[thread overview]
Message-ID: <1289576711.12418.401.camel@gandalf.stny.rr.com> (raw)
In-Reply-To: <1289575271.3185.256.camel@edumazet-laptop>

On Fri, 2010-11-12 at 16:21 +0100, Eric Dumazet wrote:
> Le vendredi 12 novembre 2010 à 10:10 -0500, Steven Rostedt a écrit :
> > pièce jointe document texte brut
> > (0003-tracing-Fix-recursive-user-stack-trace.patch)
> > From: Steven Rostedt <srostedt@redhat.com>
> > 
> > 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.
> > 
> > [ Resubmitted by Jiri Olsa ]
> > Signed-off-by: Jiri Olsa <jolsa@redhat.com>
> > LKML-Reference: <1289390172-9730-3-git-send-email-jolsa@redhat.com>
> > Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
> > ---
> >  kernel/trace/trace.c |   19 +++++++++++++++++++
> >  1 files changed, 19 insertions(+), 0 deletions(-)
> > 
> > diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
> > index 82d9b81..0215e87 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,18 @@ 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;
> > +
> 
> 	if (__this_cpu_read(user_stack_count))
> 		goto out;
> 
> > +	__get_cpu_var(user_stack_count)++;
> 
> 	__this_cpu_inc(user_stack_count);

Thanks, I'll update and resubmit.

-- Steve

> 
> > +
> > +
> > +
> >  	event = trace_buffer_lock_reserve(buffer, TRACE_USER_STACK,
> >  					  sizeof(*entry), flags, pc);
> >  	if (!event)
> > @@ -1319,6 +1333,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)--;
> 	__this_cpu_dec(user_stack_count);
> 
> > +
> > + out:
> > +	preempt_enable();
> >  }
> >  
> >  #ifdef UNUSED
> 



      reply	other threads:[~2010-11-12 15:45 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-11-12 15:10 [PATCH 0/3] [GIT PULL][2.6.37] tracing: fixes v2 Steven Rostedt
2010-11-12 15:10 ` [PATCH 1/3] tracing: Fix module use of trace_bprintk() Steven Rostedt
2010-11-12 15:10 ` [PATCH 2/3] tracing: Force arch_local_irq_* notrace for paravirt Steven Rostedt
2010-11-12 15:10 ` [PATCH 3/3] tracing: Fix recursive user stack trace Steven Rostedt
2010-11-12 15:21   ` Eric Dumazet
2010-11-12 15:45     ` Steven Rostedt [this message]

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=1289576711.12418.401.camel@gandalf.stny.rr.com \
    --to=rostedt@goodmis.org \
    --cc=akpm@linux-foundation.org \
    --cc=eric.dumazet@gmail.com \
    --cc=fweisbec@gmail.com \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®