Skip to contentSkip to conversation

unregister_trace_probe needs to be called under mutex

Bugfix Srikar Dronamraju 4 participants 7 messages Jun 30, 2010 – Aug 5, 2010 Tracing

lore
Share & tools
lore
#0 lore raw

Comment in unregister_trace_probe() says probe_lock will be held when it gets called. However there is a case where it might called without the probe_lock being held. Also since we are traversing the probe_list and deleting an element from the probe_list, probe_lock should be held.

This was first pointed in uprobes traceevent review by Frederic Weisbecker here. (http://lkml.org/lkml/2010/5/12/106)

This patch is needed for both 2.6.35-rc3 and 2.6.35-rc3-tip

---

kernel/trace/trace_kprobe.c +3 -0
index 4f11a56..67670cd 100644
@@ -269,14 +269,17 @@ static int create_trace_probe(int argc, char **argv)
 			pr_info("Delete command needs an event name.\n");
 			return -EINVAL;
 		}
+		mutex_lock(&probe_lock);
 		tp = find_probe_event(event, group);
 		if (!tp) {
+			mutex_unlock(&probe_lock);
 			pr_info("Event %s/%s doesn't exist.\n", group, event);
 			return -ENOENT;
 		}
 		/* delete an event */
 		unregister_trace_probe(tp);
 		free_trace_probe(tp);
+		mutex_unlock(&probe_lock);
 		return 0;
 	}
 
#1 lore raw
Quoted 25 lines · Srikar Dronamraju

Comment in unregister_trace_probe() says probe_lock will be held when it gets called. However there is a case where it might called without the probe_lock being held. Also since we are traversing the probe_list and deleting an element from the probe_list, probe_lock should be held.

This was first pointed in uprobes traceevent review by Frederic Weisbecker here. (http://lkml.org/lkml/2010/5/12/106)

This patch is needed for both 2.6.35-rc3 and 2.6.35-rc3-tip

---

kernel/trace/trace_kprobe.c +1 -0
index 4f11a56..67670cd 100644
@@ -269,14 +269,17 @@ static int create_trace_probe(int argc, char **argv)
 			pr_info("Delete command needs an event name.\n");
 			return -EINVAL;
 		}
+		mutex_lock(&probe_lock);
 		tp = find_probe_event(event, group);
 		if (!tp) {

kernel/trace/trace_kprobe.c static int create_trace_probe(int argc, char **argv) · line 284

Quoted 10 lines
kernel/trace/trace_kprobe.c +2 -0
+			mutex_unlock(&probe_lock);
 			pr_info("Event %s/%s doesn't exist.\n", group, event);
 			return -ENOENT;
 		}
 		/* delete an event */
 		unregister_trace_probe(tp);
 		free_trace_probe(tp);
+		mutex_unlock(&probe_lock);
 		return 0;
 	}

Shouldn't all that go through steven's ->reg() interface?

#2 lore raw
Quoted 15 lines
Quoted 15 lines
kernel/trace/trace_kprobe.c +2 -0
index 4f11a56..67670cd 100644
@@ -269,14 +269,17 @@ static int create_trace_probe(int argc, char **argv)
 			pr_info("Delete command needs an event name.\n");
 			return -EINVAL;
 		}
+		mutex_lock(&probe_lock);
 		tp = find_probe_event(event, group);
 		if (!tp) {
+			mutex_unlock(&probe_lock);
 			pr_info("Event %s/%s doesn't exist.\n", group, event);
 			return -ENOENT;
 		}
Quoted 8 lines

kernel/trace/trace_kprobe.c static int create_trace_probe(int argc, char **argv) · line 284

Quoted 6 lines
kernel/trace/trace_kprobe.c +1 -0
 		/* delete an event */
 		unregister_trace_probe(tp);
 		free_trace_probe(tp);
+		mutex_unlock(&probe_lock);
 		return 0;
 	}

Shouldn't all that go through steven's ->reg() interface?

Currently the ->reg() interface does a enable/disable of the probe_events. Infact the reg callback gets set in register_trace_probe() function which inturn gets called from the create_trace_probe().

Do we have plans to move probe_events creation to ->reg() interface?

--
Regards
Srikar

maintainer Acked-by
#3 lore raw
In reply to Peter Zijlstra
Quoted 11 lines · Peter Zijlstra
Quoted 10 lines · Srikar Dronamraju

Comment in unregister_trace_probe() says probe_lock will be held when it gets called. However there is a case where it might called without the probe_lock being held. Also since we are traversing the probe_list and deleting an element from the probe_list, probe_lock should be held.

This was first pointed in uprobes traceevent review by Frederic Weisbecker here. (http://lkml.org/lkml/2010/5/12/106)

This patch is needed for both 2.6.35-rc3 and 2.6.35-rc3-tip

Quoted 19 lines
Quoted 19 lines

---

kernel/trace/trace_kprobe.c +2 -0
index 4f11a56..67670cd 100644
@@ -269,14 +269,17 @@ static int create_trace_probe(int argc, char **argv)
 			pr_info("Delete command needs an event name.\n");
 			return -EINVAL;
 		}
+		mutex_lock(&probe_lock);
 		tp = find_probe_event(event, group);
 		if (!tp) {
+			mutex_unlock(&probe_lock);
 			pr_info("Event %s/%s doesn't exist.\n", group, event);
 			return -ENOENT;
 		}
Quoted 8 lines

kernel/trace/trace_kprobe.c static int create_trace_probe(int argc, char **argv) · line 284

Quoted 6 lines
kernel/trace/trace_kprobe.c +1 -0
 		/* delete an event */
 		unregister_trace_probe(tp);
 		free_trace_probe(tp);
+		mutex_unlock(&probe_lock);
 		return 0;
 	}

Shouldn't all that go through steven's ->reg() interface?

Nah, this is specific to the kprobe code. Has really nothing to do with the ->reg() interface.

-- Steve

#4 lore raw
In reply to Srikar Dronamraju
Quoted 6 lines · Srikar Dronamraju

Comment in unregister_trace_probe() says probe_lock will be held when it gets called. However there is a case where it might called without the probe_lock being held. Also since we are traversing the probe_list and deleting an element from the probe_list, probe_lock should be held.

Quoted 6 lines

This was first pointed in uprobes traceevent review by Frederic Weisbecker here. (http://lkml.org/lkml/2010/5/12/106)

This patch is needed for both 2.6.35-rc3 and 2.6.35-rc3-tip

Ah, right! That's definately needed.

Thank you!

Quoted 24 lines

---

kernel/trace/trace_kprobe.c +3 -0
index 4f11a56..67670cd 100644
@@ -269,14 +269,17 @@ static int create_trace_probe(int argc, char **argv)
 			pr_info("Delete command needs an event name.\n");
 			return -EINVAL;
 		}
+		mutex_lock(&probe_lock);
 		tp = find_probe_event(event, group);
 		if (!tp) {
+			mutex_unlock(&probe_lock);
 			pr_info("Event %s/%s doesn't exist.\n", group, event);
 			return -ENOENT;
 		}
 		/* delete an event */
 		unregister_trace_probe(tp);
 		free_trace_probe(tp);
+		mutex_unlock(&probe_lock);
 		return 0;
 	}
 
#5 lore raw

Ingo,

Any particular reason to not pick this patch?

Steven Rostedt and Masami Hiramatsu agree that this patch needs to be pushed in.

--
Thanks and Regards
Srikar

Quoted 46 lines
Quoted 6 lines · Srikar Dronamraju

Comment in unregister_trace_probe() says probe_lock will be held when it gets called. However there is a case where it might called without the probe_lock being held. Also since we are traversing the probe_list and deleting an element from the probe_list, probe_lock should be held.

Quoted 6 lines

This was first pointed in uprobes traceevent review by Frederic Weisbecker here. (http://lkml.org/lkml/2010/5/12/106)

This patch is needed for both 2.6.35-rc3 and 2.6.35-rc3-tip

Ah, right! That's definately needed.

Thank you!

Quoted 24 lines

---

kernel/trace/trace_kprobe.c +3 -0
index 4f11a56..67670cd 100644
@@ -269,14 +269,17 @@ static int create_trace_probe(int argc, char **argv)
 			pr_info("Delete command needs an event name.\n");
 			return -EINVAL;
 		}
+		mutex_lock(&probe_lock);
 		tp = find_probe_event(event, group);
 		if (!tp) {
+			mutex_unlock(&probe_lock);
 			pr_info("Event %s/%s doesn't exist.\n", group, event);
 			return -ENOENT;
 		}
 		/* delete an event */
 		unregister_trace_probe(tp);
 		free_trace_probe(tp);
+		mutex_unlock(&probe_lock);
 		return 0;
 	}
 
#6 lore raw

[tip:perf/core] tracing/kprobes: unregister_trace_probe needs to be called under mutex

In reply to Srikar Dronamraju
Commit-ID:  9da79ab83ee33ddc1fdd0858fd3d70925a1bde99
Gitweb:     http://git.kernel.org/tip/9da79ab83ee33ddc1fdd0858fd3d70925a1bde99
Author:     Srikar Dronamraju <[email protected]>
AuthorDate: Wed, 30 Jun 2010 14:15:48 +0530
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Wed, 4 Aug 2010 12:41:23 -0300

tracing/kprobes: unregister_trace_probe needs to be called under mutex

Comment in unregister_trace_probe() says probe_lock will be held when it gets called. However there is a case where it might called without the probe_lock being held. Also since we are traversing the probe_list and deleting an element from the probe_list, probe_lock should be held.

This was first pointed in uprobes traceevent review by Frederic Weisbecker here. (http://lkml.org/lkml/2010/5/12/106)

LKML-Reference: <[email protected]>

---
 kernel/trace/trace_kprobe.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
kernel/trace/trace_kprobe.c +3 -0
index 1b79d1c..8b27c98 100644
@@ -925,14 +925,17 @@ static int create_trace_probe(int argc, char **argv)
 			pr_info("Delete command needs an event name.\n");
 			return -EINVAL;
 		}
+		mutex_lock(&probe_lock);
 		tp = find_probe_event(event, group);
 		if (!tp) {
+			mutex_unlock(&probe_lock);
 			pr_info("Event %s/%s doesn't exist.\n", group, event);
 			return -ENOENT;
 		}
 		/* delete an event */
 		unregister_trace_probe(tp);
 		free_trace_probe(tp);
+		mutex_unlock(&probe_lock);
 		return 0;
 	}