aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeter Zijlstra <peterz@infradead.org>2014-05-21 11:32:19 -0400
committerIngo Molnar <mingo@kernel.org>2014-06-06 01:54:02 -0400
commite041e328c4b41e1db79bfe5ba9992c2ed771ad19 (patch)
tree88f8689160ae586c728e6ef665cc4c580c116ba9
parent22c91aa23547a4363fd2a9ffddde95c899ac8aa0 (diff)
perf: Fix perf_event_comm() vs. exec() assumption
perf_event_comm() assumes that set_task_comm() is only called on exec(), and in particular that its only called on current. Neither are true, as Dave reported a WARN triggered by set_task_comm() being called on !current. Separate the exec() hook from the comm hook. Reported-by: Dave Jones <davej@redhat.com> Signed-off-by: Peter Zijlstra <peterz@infradead.org> Cc: Alexander Viro <viro@zeniv.linux.org.uk> Cc: Arnaldo Carvalho de Melo <acme@kernel.org> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: linux-fsdevel@vger.kernel.org Cc: linux-kernel@vger.kernel.org Link: http://lkml.kernel.org/r/20140521153219.GH5226@laptop.programming.kicks-ass.net [ Build fix. ] Signed-off-by: Ingo Molnar <mingo@kernel.org>
-rw-r--r--fs/exec.c1
-rw-r--r--include/linux/perf_event.h4
-rw-r--r--kernel/events/core.c28
3 files changed, 20 insertions, 13 deletions
diff --git a/fs/exec.c b/fs/exec.c
index 238b7aa26f68..a038a41a3677 100644
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -1110,6 +1110,7 @@ void setup_new_exec(struct linux_binprm * bprm)
1110 else 1110 else
1111 set_dumpable(current->mm, suid_dumpable); 1111 set_dumpable(current->mm, suid_dumpable);
1112 1112
1113 perf_event_exec();
1113 set_task_comm(current, kbasename(bprm->filename)); 1114 set_task_comm(current, kbasename(bprm->filename));
1114 1115
1115 /* Set the new mm task size. We have to do that late because it may 1116 /* Set the new mm task size. We have to do that late because it may
diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
index 3ef6ea12806a..9b5cd1992a88 100644
--- a/include/linux/perf_event.h
+++ b/include/linux/perf_event.h
@@ -695,6 +695,7 @@ extern struct perf_guest_info_callbacks *perf_guest_cbs;
695extern int perf_register_guest_info_callbacks(struct perf_guest_info_callbacks *callbacks); 695extern int perf_register_guest_info_callbacks(struct perf_guest_info_callbacks *callbacks);
696extern int perf_unregister_guest_info_callbacks(struct perf_guest_info_callbacks *callbacks); 696extern int perf_unregister_guest_info_callbacks(struct perf_guest_info_callbacks *callbacks);
697 697
698extern void perf_event_exec(void);
698extern void perf_event_comm(struct task_struct *tsk); 699extern void perf_event_comm(struct task_struct *tsk);
699extern void perf_event_fork(struct task_struct *tsk); 700extern void perf_event_fork(struct task_struct *tsk);
700 701
@@ -772,7 +773,7 @@ extern void perf_event_enable(struct perf_event *event);
772extern void perf_event_disable(struct perf_event *event); 773extern void perf_event_disable(struct perf_event *event);
773extern int __perf_event_disable(void *info); 774extern int __perf_event_disable(void *info);
774extern void perf_event_task_tick(void); 775extern void perf_event_task_tick(void);
775#else 776#else /* !CONFIG_PERF_EVENTS: */
776static inline void 777static inline void
777perf_event_task_sched_in(struct task_struct *prev, 778perf_event_task_sched_in(struct task_struct *prev,
778 struct task_struct *task) { } 779 struct task_struct *task) { }
@@ -802,6 +803,7 @@ static inline int perf_unregister_guest_info_callbacks
802(struct perf_guest_info_callbacks *callbacks) { return 0; } 803(struct perf_guest_info_callbacks *callbacks) { return 0; }
803 804
804static inline void perf_event_mmap(struct vm_area_struct *vma) { } 805static inline void perf_event_mmap(struct vm_area_struct *vma) { }
806static inline void perf_event_exec(void) { }
805static inline void perf_event_comm(struct task_struct *tsk) { } 807static inline void perf_event_comm(struct task_struct *tsk) { }
806static inline void perf_event_fork(struct task_struct *tsk) { } 808static inline void perf_event_fork(struct task_struct *tsk) { }
807static inline void perf_event_init(void) { } 809static inline void perf_event_init(void) { }
diff --git a/kernel/events/core.c b/kernel/events/core.c
index 440eefc67397..647698f91988 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -2970,6 +2970,22 @@ out:
2970 local_irq_restore(flags); 2970 local_irq_restore(flags);
2971} 2971}
2972 2972
2973void perf_event_exec(void)
2974{
2975 struct perf_event_context *ctx;
2976 int ctxn;
2977
2978 rcu_read_lock();
2979 for_each_task_context_nr(ctxn) {
2980 ctx = current->perf_event_ctxp[ctxn];
2981 if (!ctx)
2982 continue;
2983
2984 perf_event_enable_on_exec(ctx);
2985 }
2986 rcu_read_unlock();
2987}
2988
2973/* 2989/*
2974 * Cross CPU call to read the hardware event 2990 * Cross CPU call to read the hardware event
2975 */ 2991 */
@@ -5057,18 +5073,6 @@ static void perf_event_comm_event(struct perf_comm_event *comm_event)
5057void perf_event_comm(struct task_struct *task) 5073void perf_event_comm(struct task_struct *task)
5058{ 5074{
5059 struct perf_comm_event comm_event; 5075 struct perf_comm_event comm_event;
5060 struct perf_event_context *ctx;
5061 int ctxn;
5062
5063 rcu_read_lock();
5064 for_each_task_context_nr(ctxn) {
5065 ctx = task->perf_event_ctxp[ctxn];
5066 if (!ctx)
5067 continue;
5068
5069 perf_event_enable_on_exec(ctx);
5070 }
5071 rcu_read_unlock();
5072 5076
5073 if (!atomic_read(&nr_comm_events)) 5077 if (!atomic_read(&nr_comm_events))
5074 return; 5078 return;