public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: linux-kernel@vger.kernel.org
Cc: Ingo Molnar <mingo@elte.hu>,
	Andrew Morton <akpm@linux-foundation.org>,
	Frederic Weisbecker <fweisbec@gmail.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Li Zefan <lizf@cn.fujitsu.com>,
	Mathieu Desnoyers <compudj@krystal.dyndns.org>
Subject: [PATCH 2/3] tracing/profile: add ref count for registering profile events
Date: Fri, 11 Sep 2009 09:54:54 -0400	[thread overview]
Message-ID: <20090911135626.421489476@goodmis.org> (raw)
In-Reply-To: 20090911135452.866274568@goodmis.org

[-- Attachment #1: 0002-tracing-profile-add-ref-count-for-registering-profil.patch --]
[-- Type: text/plain, Size: 2314 bytes --]

From: Steven Rostedt <srostedt@redhat.com>

Li Zefan discovered that doing the following:

 # insmod trace-events-sample.ko
 # perf record -f -a -e sample:foo_bar sleep 3 &
 # sleep 1
 # rmmod trace_events_sample
 # insmod trace-events-sample.ko

Would cause an OOPS. This was because the registering of the profiler
registers inside the module and does not unregister when unloaded.

This patch adds an increment of the module refcount when a profile
registers a tracepoint, to prevent a module from being unloaded
while being profiled.

Reported-by: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <4A9214E3.2070807@cn.fujitsu.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
---
 include/trace/ftrace.h |   22 ++++++++++++++++++++--
 1 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/include/trace/ftrace.h b/include/trace/ftrace.h
index 308bafd..59e09f9 100644
--- a/include/trace/ftrace.h
+++ b/include/trace/ftrace.h
@@ -400,6 +400,20 @@ static inline int ftrace_get_offsets_##call(				\
  *
  */
 
+#ifdef MODULE
+# define event_trace_up_ref()					\
+	do {							\
+		if (!try_module_get(THIS_MODULE)) {		\
+			atomic_dec(&event_call->profile_count);	\
+			return -ENOENT;				\
+		}						\
+	} while (0)
+# define event_trace_down_ref() module_put(THIS_MODULE)
+#else
+# define event_trace_up_ref() do { } while (0)
+# define event_trace_down_ref() do { } while (0)
+#endif
+
 #undef TRACE_EVENT
 #define TRACE_EVENT(call, proto, args, tstruct, assign, print)		\
 									\
@@ -409,16 +423,20 @@ static int ftrace_profile_enable_##call(struct ftrace_event_call *event_call) \
 {									\
 	int ret = 0;							\
 									\
-	if (!atomic_inc_return(&event_call->profile_count))		\
+	if (!atomic_inc_return(&event_call->profile_count)) {		\
+		event_trace_up_ref();					\
 		ret = register_trace_##call(ftrace_profile_##call);	\
+	}								\
 									\
 	return ret;							\
 }									\
 									\
 static void ftrace_profile_disable_##call(struct ftrace_event_call *event_call)\
 {									\
-	if (atomic_add_negative(-1, &event_call->profile_count))	\
+	if (atomic_add_negative(-1, &event_call->profile_count)) {	\
 		unregister_trace_##call(ftrace_profile_##call);		\
+		event_trace_down_ref();					\
+	}								\
 }
 
 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
-- 
1.6.3.3

-- 

  parent reply	other threads:[~2009-09-11 13:56 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-09-11 13:54 [PATCH 0/3] [GIT PULL] tracing: various updates Steven Rostedt
2009-09-11 13:54 ` [PATCH 1/3] x86/tracing: comment need for atomic nop Steven Rostedt
2009-09-11 13:54 ` Steven Rostedt [this message]
2009-09-11 14:04   ` [PATCH 2/3] tracing/profile: add ref count for registering profile events Peter Zijlstra
2009-09-11 14:09     ` Peter Zijlstra
2009-09-11 14:33       ` Steven Rostedt
2009-09-11 14:37         ` Peter Zijlstra
2009-09-11 14:52           ` Steven Rostedt
2009-09-12 14:14           ` Mathieu Desnoyers
2009-09-11 14:40       ` Steven Rostedt
2009-09-11 14:12     ` Steven Rostedt
2009-09-11 13:54 ` [PATCH 3/3] tracing: add latency format to function_graph tracer Steven Rostedt
2009-09-11 14:55   ` Frederic Weisbecker
2009-09-11 15:11     ` Steven Rostedt
2009-09-11 15:18       ` Frederic Weisbecker
2009-09-11 15:38         ` Török Edwin
2009-09-11 15:43           ` Frederic Weisbecker
2009-09-11 15:50           ` Steven Rostedt
2009-09-11 16:08             ` Török Edwin
2009-09-12 10:25               ` Matt Fleming

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=20090911135626.421489476@goodmis.org \
    --to=rostedt@goodmis.org \
    --cc=akpm@linux-foundation.org \
    --cc=compudj@krystal.dyndns.org \
    --cc=fweisbec@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lizf@cn.fujitsu.com \
    --cc=mingo@elte.hu \
    --cc=peterz@infradead.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