summaryrefslogtreecommitdiff
path: root/kernel
diff options
context:
space:
mode:
authorCong Wang <cwang@twopensource.com>2014-09-02 15:27:20 -0700
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2014-10-05 14:52:22 -0700
commit77eeda2a01c46598857a5f128ed1e0158ec6e6c4 (patch)
tree8ffdeeac7b5c95d64a7160971034a87ff700ce68 /kernel
parentdef258584a2986b46659552cbd4b4b555be43042 (diff)
downloadlwn-77eeda2a01c46598857a5f128ed1e0158ec6e6c4.tar.gz
lwn-77eeda2a01c46598857a5f128ed1e0158ec6e6c4.zip
perf: Fix a race condition in perf_remove_from_context()
commit 3577af70a2ce4853d58e57d832e687d739281479 upstream. We saw a kernel soft lockup in perf_remove_from_context(), it looks like the `perf` process, when exiting, could not go out of the retry loop. Meanwhile, the target process was forking a child. So either the target process should execute the smp function call to deactive the event (if it was running) or it should do a context switch which deactives the event. It seems we optimize out a context switch in perf_event_context_sched_out(), and what's more important, we still test an obsolete task pointer when retrying, so no one actually would deactive that event in this situation. Fix it directly by reloading the task pointer in perf_remove_from_context(). This should cure the above soft lockup. Signed-off-by: Cong Wang <cwang@twopensource.com> Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com> Signed-off-by: Peter Zijlstra <peterz@infradead.org> Cc: Paul Mackerras <paulus@samba.org> Cc: Arnaldo Carvalho de Melo <acme@kernel.org> Cc: Linus Torvalds <torvalds@linux-foundation.org> Link: http://lkml.kernel.org/r/1409696840-843-1-git-send-email-xiyou.wangcong@gmail.com Signed-off-by: Ingo Molnar <mingo@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'kernel')
-rw-r--r--kernel/events/core.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/kernel/events/core.c b/kernel/events/core.c
index f774e9365a03..3a140ca37777 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -1516,6 +1516,11 @@ retry:
*/
if (ctx->is_active) {
raw_spin_unlock_irq(&ctx->lock);
+ /*
+ * Reload the task pointer, it might have been changed by
+ * a concurrent perf_event_context_sched_out().
+ */
+ task = ctx->task;
goto retry;
}
@@ -1957,6 +1962,11 @@ retry:
*/
if (ctx->is_active) {
raw_spin_unlock_irq(&ctx->lock);
+ /*
+ * Reload the task pointer, it might have been changed by
+ * a concurrent perf_event_context_sched_out().
+ */
+ task = ctx->task;
goto retry;
}