public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: Li Zefan <lizf@cn.fujitsu.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@elte.hu>,
	Frederic Weisbecker <fweisbec@gmail.com>,
	LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] tracing/profile: Fix profile_disable vs module_unload
Date: Thu, 27 Aug 2009 11:59:39 -0400	[thread overview]
Message-ID: <20090827155939.GA11070@Krystal> (raw)
In-Reply-To: <alpine.DEB.2.00.0908271125030.11745@gandalf.stny.rr.com>

* Steven Rostedt (rostedt@goodmis.org) wrote:
> 
> On Thu, 27 Aug 2009, Mathieu Desnoyers wrote:
> 
> > * Steven Rostedt (rostedt@goodmis.org) wrote:
> > > 
> > > On Thu, 27 Aug 2009, Mathieu Desnoyers wrote:
> > > 
> > > > Looks good. Just don't forget to eventually add the "synchronize" calls
> > > > between tracepoint unregistration and the removal of their module. There
> > > > is a race condition in the way you do it currently.
> > > 
> > > I'm trying to figure out the race here. What will disappear in the 
> > > tracepoint? Could you give a brief example of the issue.
> > 
> > Sure,
> > 
> > Let's say we have a tracepoint in module instrumented.c, and a probe in
> > module probe.c. The probe is registered by module probe.c init through
> > the tracepoint infrastructure to connect to the tracepoint in
> > instrumented.c. Unregistration is done in probe.c module exit.
> > 
> > As the instrumented code get executed (let's say periodically), it calls
> > the connected probe. Preemption is disabled around the call.
> > 
> > If you unload the probe.c module, the module exit will unregister the
> > probe, but the probe code can still be in use by another CPU. You have
> > to wait for quiescent state with the tracepoint synchronize (which is
> > just a wrapper over synchronize_sched() before you are allowed to
> > complete module unload. Otherwise, you will end up reclaiming module
> > memory that is still used by probe execution.
> > 
> > A test-case for this would be to create a probe with a delay in it, and
> > an instrumented module calling the instrumentation in a loop. On a SMP
> > system, running the instrumented code and probe load/unload in loops
> > should trigger this race.
> 
> Thanks for the explanation. So let me see if I get this correct.
> 
> For this race to occur, the probe (code that hooks to the tracepoint) must 
> be in module that does not contain the tracepoint. We don't even need more 
> than one module, this could occur even with a core tracepoint. If a module 
> registers it, if it unregisters before unloading, the tracepoint may be 
> hit before the unregister and executing while the module is unloading.
> 
> I don't think we need to worry about this with the case of TRACE_EVENT and 
> ftrace.h. The reason is that the trace point and probes are always in the 
> same location. The MACROS set up the probe code with the modules. Thus, to 
> remove the module, you must also remove the tracepoint itself along with 
> the probe. If you can be executing in the probe, then you must have hit 
> the trace point. If you hit the trace point, then you are executing code 
> inside the module you are removing, which is a bug in the module code 
> itself.
> 
> Using the ftrace.h MACROS limits the use of tracepoints and this race 
> does not exist. I feel we are safe not needing to have the 
> tracepoint_synchronize_unregister within the ftrace.h code.
> 

Looks right. If you can guarantee that the probe is only called from
tracepoints located within the same module as the probe, you should be
safe without tracepoint_synchronize_unregister. It's worth adding a
comment in ftrace.h explaining that though.

Mathieu

> -- Steve
> 

-- 
Mathieu Desnoyers
OpenPGP key fingerprint: 8CD5 52C3 8E3C 4140 715F  BA06 3F25 A8FE 3BAE 9A68

  reply	other threads:[~2009-08-27 16:04 UTC|newest]

Thread overview: 52+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-08-24  4:19 [PATCH] tracing/profile: Fix profile_disable vs module_unload Li Zefan
2009-08-24  6:01 ` Peter Zijlstra
2009-08-24  6:22   ` Li Zefan
2009-08-24  6:56     ` Peter Zijlstra
2009-08-24  9:24       ` Ingo Molnar
2009-08-24  9:27         ` Peter Zijlstra
2009-08-24 16:13           ` Steven Rostedt
2009-08-25  5:22           ` Li Zefan
2009-08-25  6:21             ` Peter Zijlstra
2009-08-25  6:33               ` Li Zefan
2009-08-25  6:40                 ` Peter Zijlstra
2009-08-25  9:05                   ` Ingo Molnar
2009-08-25  9:12                     ` Peter Zijlstra
2009-08-25 10:22                       ` Ingo Molnar
2009-08-25 10:32                         ` Peter Zijlstra
2009-08-25 10:39                           ` Ingo Molnar
2009-08-25 10:47                             ` Peter Zijlstra
2009-08-25 14:52                               ` Peter Zijlstra
2009-08-26  6:18                                 ` Li Zefan
2009-08-26  6:46                                   ` Peter Zijlstra
2009-08-26  6:52                                     ` Peter Zijlstra
2009-08-26  7:01                                     ` Peter Zijlstra
2009-08-26  7:10                                       ` Li Zefan
2009-08-26  7:26                                         ` Peter Zijlstra
2009-08-26  7:31                                           ` Li Zefan
2009-08-26  7:39                                             ` Peter Zijlstra
2009-08-26  7:44                                               ` Li Zefan
2009-08-26 14:37                                         ` Steven Rostedt
2009-08-26 16:46                                           ` Mathieu Desnoyers
2009-08-26 17:48                                             ` Steven Rostedt
2009-08-26 18:01                                               ` Mathieu Desnoyers
2009-08-26 18:17                                                 ` Mathieu Desnoyers
2009-08-26 19:48                                                   ` Steven Rostedt
2009-08-26 19:53                                                     ` Mathieu Desnoyers
2009-08-26 21:21                                                       ` Steven Rostedt
2009-08-26 22:29                                                         ` Mathieu Desnoyers
2009-08-27  1:53                                                     ` Li Zefan
2009-08-27  2:13                                                       ` Steven Rostedt
2009-08-27 14:39                                                         ` Mathieu Desnoyers
2009-08-27 14:56                                                           ` Steven Rostedt
2009-08-27 15:11                                                             ` Mathieu Desnoyers
2009-08-27 15:51                                                               ` Steven Rostedt
2009-08-27 15:59                                                                 ` Mathieu Desnoyers [this message]
2009-08-27 16:03                                                                   ` Steven Rostedt
2009-08-27  6:25                                                     ` Peter Zijlstra
2009-08-27 15:57                                                       ` Steven Rostedt
2009-08-27 16:04                                                         ` Peter Zijlstra
2009-08-27 16:18                                                           ` Steven Rostedt
2009-08-27  1:01                                                 ` Li Zefan
2009-08-26 19:14                                             ` Peter Zijlstra
2009-08-26 19:44                                               ` Mathieu Desnoyers
2009-09-13 15:02 ` [tip:tracing/core] tracing/profile: fix " tip-bot for Li Zefan

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=20090827155939.GA11070@Krystal \
    --to=mathieu.desnoyers@polymtl.ca \
    --cc=fweisbec@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lizf@cn.fujitsu.com \
    --cc=mingo@elte.hu \
    --cc=peterz@infradead.org \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox