From: "zhangwei(Jovi)" <jovi.zhangwei@huawei.com>
To: Steven Rostedt <rostedt@goodmis.org>,
Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>,
Oleg Nesterov <oleg@redhat.com>,
Srikar Dronamraju <srikar@linux.vnet.ibm.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>,
Ingo Molnar <mingo@redhat.com>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: [PATCH 2/2] tracing/uprobes: disallow unregister trace_uprobe when trace_uprobe is in use
Date: Tue, 25 Jun 2013 16:16:13 +0800 [thread overview]
Message-ID: <51C951CD.50701@huawei.com> (raw)
We cannot unregister trace_uprobe when trace_uprobe is in use,
otherwise resource will leak.
Just return -EBUSY if user want to unregister a trace_uprobe
which in use.
Signed-off-by: zhangwei(Jovi) <jovi.zhangwei@huawei.com>
Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Srikar Dronamraju <srikar@linux.vnet.ibm.com>
---
kernel/trace/trace_uprobe.c | 51 ++++++++++++++++++++++++++++++++-----------
1 file changed, 38 insertions(+), 13 deletions(-)
diff --git a/kernel/trace/trace_uprobe.c b/kernel/trace/trace_uprobe.c
index d2da3ea..248757b 100644
--- a/kernel/trace/trace_uprobe.c
+++ b/kernel/trace/trace_uprobe.c
@@ -102,6 +102,11 @@ static inline bool is_ret_probe(struct trace_uprobe *tu)
return tu->consumer.ret_handler != NULL;
}
+static inline bool is_trace_uprobe_enabled(struct trace_uprobe *tu)
+{
+ return tu->flags & (TP_FLAG_TRACE | TP_FLAG_PROFILE);
+}
+
/*
* Allocate new trace_uprobe and initialize it (including uprobes).
*/
@@ -171,11 +176,17 @@ static struct trace_uprobe *find_probe_event(const char *event, const char *grou
}
/* Unregister a trace_uprobe and probe_event: call with locking uprobe_lock */
-static void unregister_trace_uprobe(struct trace_uprobe *tu)
+static int unregister_trace_uprobe(struct trace_uprobe *tu)
{
+ /* Enabled event can not be unregistered */
+ if (is_trace_uprobe_enabled(tu))
+ return -EBUSY;
+
list_del(&tu->list);
unregister_uprobe_event(tu);
free_trace_uprobe(tu);
+
+ return 0;
}
/* Register a trace_uprobe and probe_event */
@@ -188,9 +199,12 @@ static int register_trace_uprobe(struct trace_uprobe *tu)
/* register as an event */
old_tp = find_probe_event(tu->call.name, tu->call.class->system);
- if (old_tp)
+ if (old_tp) {
/* delete old event */
- unregister_trace_uprobe(old_tp);
+ ret = unregister_trace_uprobe(old_tp);
+ if (ret < 0)
+ goto end;
+ }
ret = register_uprobe_event(tu);
if (ret) {
@@ -276,9 +290,9 @@ static int create_trace_uprobe(int argc, char **argv)
return -ENOENT;
}
/* delete an event */
- unregister_trace_uprobe(tu);
+ ret = unregister_trace_uprobe(tu);
mutex_unlock(&uprobe_lock);
- return 0;
+ return ret;
}
if (argc < 2) {
@@ -413,16 +427,27 @@ fail_address_parse:
return ret;
}
-static void cleanup_all_probes(void)
+static int cleanup_all_probes(void)
{
struct trace_uprobe *tu;
+ int ret = 0;
mutex_lock(&uprobe_lock);
+
+ /* Ensure no probe is in use. */
+ list_for_each_entry(tu, &uprobe_list, list)
+ if (is_trace_uprobe_enabled(tu)) {
+ ret = -EBUSY;
+ goto end;
+ }
+
while (!list_empty(&uprobe_list)) {
tu = list_entry(uprobe_list.next, struct trace_uprobe, list);
unregister_trace_uprobe(tu);
}
+ end:
mutex_unlock(&uprobe_lock);
+ return ret;
}
/* Probes listing interfaces */
@@ -467,8 +492,13 @@ static const struct seq_operations probes_seq_op = {
static int probes_open(struct inode *inode, struct file *file)
{
- if ((file->f_mode & FMODE_WRITE) && (file->f_flags & O_TRUNC))
- cleanup_all_probes();
+ int ret;
+
+ if ((file->f_mode & FMODE_WRITE) && (file->f_flags & O_TRUNC)) {
+ ret = cleanup_all_probes();
+ if (ret < 0)
+ return ret;
+ }
return seq_open(file, &probes_seq_op);
}
@@ -622,11 +652,6 @@ partial:
return TRACE_TYPE_PARTIAL_LINE;
}
-static inline bool is_trace_uprobe_enabled(struct trace_uprobe *tu)
-{
- return tu->flags & (TP_FLAG_TRACE | TP_FLAG_PROFILE);
-}
-
typedef bool (*filter_func_t)(struct uprobe_consumer *self,
enum uprobe_filter_ctx ctx,
struct mm_struct *mm);
--
1.7.9.7
next reply other threads:[~2013-06-25 8:16 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-06-25 8:16 zhangwei(Jovi) [this message]
2013-06-25 17:23 ` [PATCH 2/2] tracing/uprobes: disallow unregister trace_uprobe when trace_uprobe is in use Oleg Nesterov
[not found] ` <20130626185205.GA27894@redhat.com>
[not found] ` <51CBEE3E.70103@hitachi.com>
[not found] ` <20130627161716.GA17889@redhat.com>
[not found] ` <51CCF8BA.4030601@hitachi.com>
[not found] ` <20130628180946.GA30838@redhat.com>
[not found] ` <51D16E1D.5040904@hitachi.com>
[not found] ` <20130702190037.GA6289@redhat.com>
2013-07-02 19:34 ` PATCH? trace_remove_event_call() should fail if call is active Oleg Nesterov
2013-07-02 21:04 ` Steven Rostedt
2013-07-02 21:35 ` Steven Rostedt
2013-07-02 21:38 ` Oleg Nesterov
2013-07-02 21:41 ` Oleg Nesterov
2013-07-02 22:23 ` Oleg Nesterov
2013-07-02 22:49 ` Steven Rostedt
2013-07-02 22:53 ` Steven Rostedt
2013-07-03 2:42 ` Masami Hiramatsu
2013-07-03 2:57 ` Steven Rostedt
2013-07-03 3:12 ` Masami Hiramatsu
2013-07-03 17:20 ` Oleg Nesterov
2013-07-03 17:54 ` Oleg Nesterov
2013-07-03 18:02 ` Steven Rostedt
2013-07-03 19:17 ` Oleg Nesterov
2013-07-03 20:34 ` Steven Rostedt
2013-07-03 20:36 ` Steven Rostedt
2013-07-03 23:11 ` Oleg Nesterov
2013-07-03 22:18 ` Oleg Nesterov
2013-07-04 0:19 ` Steven Rostedt
2013-07-03 21:02 ` Steven Rostedt
2013-07-04 4:25 ` Masami Hiramatsu
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=51C951CD.50701@huawei.com \
--to=jovi.zhangwei@huawei.com \
--cc=fweisbec@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=masami.hiramatsu.pt@hitachi.com \
--cc=mingo@redhat.com \
--cc=oleg@redhat.com \
--cc=rostedt@goodmis.org \
--cc=srikar@linux.vnet.ibm.com \
/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