Skip to contentSkip to conversation

tracing/kprobes: Simplify the logic of enable_trace_kprobe()

PATCH Superseded Steven Rostedt 3 participants 5 messages Jul 26, 2018 – Jul 27, 2018 Tracing

lore
Share & tools
lore

Steven Rostedt

author maintainer
#0 lore raw

PATCH 1/1 tracing/kprobes: Simplify the logic of enable_trace_kprobe()

[ Note this is applied on top of the other patch to quiet gcc ]

From: "Steven Rostedt (VMware)" <[email protected]>

The function enable_trace_kprobe() performs slightly differently if the file parameter is passed in as NULL on non-NULL. Instead of checking file twice, move the code between the two tests into a static inline helper function to make the code easier to follow.

---
 kernel/trace/trace_kprobe.c | 42 ++++++++++++++++++++++++------------------
 1 file changed, 24 insertions(+), 18 deletions(-)
kernel/trace/trace_kprobe.c +24 -18
index 6b71860f3998..1dec0855a59a 100644
@@ -393,6 +393,20 @@ static struct trace_kprobe *find_trace_kprobe(const char *event,
 	return NULL;
 }
 
+static inline int enable_probe(struct trace_kprobe *tk)
+{
+	int ret = 0;
+
+	if (trace_probe_is_registered(&tk->tp) && !trace_kprobe_has_gone(tk)) {
+		if (trace_kprobe_is_return(tk))
+			ret = enable_kretprobe(&tk->rp);
+		else
+			ret = enable_kprobe(&tk->rp.kp);
+	}
+
+	return ret;
+}
+
 /*
  * Enable trace_probe
  * if the file is NULL, enable "perf" handler, or enable "trace" handler.
@@ -400,7 +414,7 @@ static struct trace_kprobe *find_trace_kprobe(const char *event,
 static int
 enable_trace_kprobe(struct trace_kprobe *tk, struct trace_event_file *file)
 {
-	struct event_file_link *link = NULL;
+	struct event_file_link *link;
 	int ret = 0;
 
 	if (file) {
@@ -414,26 +428,18 @@ enable_trace_kprobe(struct trace_kprobe *tk, struct trace_event_file *file)
 		list_add_tail_rcu(&link->list, &tk->tp.files);
 
 		tk->tp.flags |= TP_FLAG_TRACE;
-	} else
-		tk->tp.flags |= TP_FLAG_PROFILE;
-
-	if (trace_probe_is_registered(&tk->tp) && !trace_kprobe_has_gone(tk)) {
-		if (trace_kprobe_is_return(tk))
-			ret = enable_kretprobe(&tk->rp);
-		else
-			ret = enable_kprobe(&tk->rp.kp);
-	}
-
-	if (ret) {
-		if (file) {
-			/* Notice the if is true on not WARN() */
-			if (!WARN_ON_ONCE(!link))
-				list_del_rcu(&link->list);
+		ret = enable_probe(tk);
+		if (ret) {
+			list_del_rcu(&link->list);
 			kfree(link);
 			tk->tp.flags &= ~TP_FLAG_TRACE;
-		} else {
-			tk->tp.flags &= ~TP_FLAG_PROFILE;
 		}
+
+	} else {
+		tk->tp.flags |= TP_FLAG_PROFILE;
+		ret = enable_probe(tk);
+		if (ret)
+			tk->tp.flags &= ~TP_FLAG_PROFILE;
 	}
  out:
 	return ret;
Signature · 1 line
2.13.6
Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 lines · Steven Rostedt

[ Note this is applied on top of the other patch to quiet gcc ]

From: "Steven Rostedt (VMware)" <[email protected]>

Quoted 8 lines

The function enable_trace_kprobe() performs slightly differently if the file parameter is passed in as NULL on non-NULL. Instead of checking file twice, move the code between the two tests into a static inline helper function to make the code easier to follow.

The enable_probe() name is a bit confusing, since it's not clear what the difference is between enable_probe() and enable_trace_kprobe() without looking at the code.

Maybe call it __enable_trace_kprobe()?

Otherwise it's a definite improvement.

Signature · 1 line
Josh
author maintainer
#2 lore raw
Quoted 11 lines · On Thu, 26 Jul 2018 11:43:52 -0500 Josh Poimboeuf <[email protected]> wrote:
Quoted 10 lines · Steven Rostedt

[ Note this is applied on top of the other patch to quiet gcc ]

From: "Steven Rostedt (VMware)" <[email protected]>

The function enable_trace_kprobe() performs slightly differently if the file parameter is passed in as NULL on non-NULL. Instead of checking file twice, move the code between the two tests into a static inline helper function to make the code easier to follow.

Quoted 7 lines
Quoted 3 lines

The enable_probe() name is a bit confusing, since it's not clear what the difference is between enable_probe() and enable_trace_kprobe() without looking at the code.

Yeah, I didn't like that name either.

Quoted 2 lines

Maybe call it __enable_trace_kprobe()?

Hmm, that may work.

Quoted 5 lines

Otherwise it's a definite improvement.

Thanks,

-- Steve

maintainer Acked-by
#3 lore raw
In reply to Josh Poimboeuf
Quoted 13 lines · On Thu, 26 Jul 2018 11:43:52 -0500 Josh Poimboeuf <[email protected]> wrote:
Quoted 12 lines · Steven Rostedt

[ Note this is applied on top of the other patch to quiet gcc ]

From: "Steven Rostedt (VMware)" <[email protected]>

The function enable_trace_kprobe() performs slightly differently if the file parameter is passed in as NULL on non-NULL. Instead of checking file twice, move the code between the two tests into a static inline helper function to make the code easier to follow.

Quoted 7 lines
Quoted 1 line

The enable_probe() name is a bit confusing, since it's not clear what the difference is between enable_probe() and enable_trace_kprobe() without looking at the code.

Maybe call it __enable_trace_kprobe()?

+1, I this this is better.

With that function name change,

Thanks!

Quoted 7 lines

Otherwise it's a definite improvement.

Signature · 1 line
Josh
Signature · 1 line
Masami Hiramatsu <[email protected]>
author maintainer
#4 lore raw

PATCH v2 1/1 tracing/kprobes: Simplify the logic of enable_trace_kprobe()

From: "Steven Rostedt (VMware)" <[email protected]>

The function enable_trace_kprobe() performs slightly differently if the file parameter is passed in as NULL on non-NULL. Instead of checking file twice, move the code between the two tests into a static inline helper function to make the code easier to follow.

---
 kernel/trace/trace_kprobe.c | 42 ++++++++++++++++++++++++------------------
 1 file changed, 24 insertions(+), 18 deletions(-)
kernel/trace/trace_kprobe.c +24 -18
index 6b71860f3998..0534eb8b7640 100644
@@ -393,6 +393,20 @@ static struct trace_kprobe *find_trace_kprobe(const char *event,
 	return NULL;
 }
 
+static inline int __enable_trace_kprobe(struct trace_kprobe *tk)
+{
+	int ret = 0;
+
+	if (trace_probe_is_registered(&tk->tp) && !trace_kprobe_has_gone(tk)) {
+		if (trace_kprobe_is_return(tk))
+			ret = enable_kretprobe(&tk->rp);
+		else
+			ret = enable_kprobe(&tk->rp.kp);
+	}
+
+	return ret;
+}
+
 /*
  * Enable trace_probe
  * if the file is NULL, enable "perf" handler, or enable "trace" handler.
@@ -400,7 +414,7 @@ static struct trace_kprobe *find_trace_kprobe(const char *event,
 static int
 enable_trace_kprobe(struct trace_kprobe *tk, struct trace_event_file *file)
 {
-	struct event_file_link *link = NULL;
+	struct event_file_link *link;
 	int ret = 0;
 
 	if (file) {
@@ -414,26 +428,18 @@ enable_trace_kprobe(struct trace_kprobe *tk, struct trace_event_file *file)
 		list_add_tail_rcu(&link->list, &tk->tp.files);
 
 		tk->tp.flags |= TP_FLAG_TRACE;
-	} else
-		tk->tp.flags |= TP_FLAG_PROFILE;
-
-	if (trace_probe_is_registered(&tk->tp) && !trace_kprobe_has_gone(tk)) {
-		if (trace_kprobe_is_return(tk))
-			ret = enable_kretprobe(&tk->rp);
-		else
-			ret = enable_kprobe(&tk->rp.kp);
-	}
-
-	if (ret) {
-		if (file) {
-			/* Notice the if is true on not WARN() */
-			if (!WARN_ON_ONCE(!link))
-				list_del_rcu(&link->list);
+		ret = __enable_trace_kprobe(tk);
+		if (ret) {
+			list_del_rcu(&link->list);
 			kfree(link);
 			tk->tp.flags &= ~TP_FLAG_TRACE;
-		} else {
-			tk->tp.flags &= ~TP_FLAG_PROFILE;
 		}
+
+	} else {
+		tk->tp.flags |= TP_FLAG_PROFILE;
+		ret = __enable_trace_kprobe(tk);
+		if (ret)
+			tk->tp.flags &= ~TP_FLAG_PROFILE;
 	}
  out:
 	return ret;
Signature · 1 line
2.13.6