perf: Fix a race condition in perf_remove_from_context()
[firefly-linux-kernel-4.4.55.git] / kernel / events / core.c
index 459b94c9472140e1ea2160f070594887d2de60f2..6bf387a603998e2786ff70b3abbe5b0b24a7bfa2 100644 (file)
@@ -1398,6 +1398,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;
        }
 
@@ -1829,6 +1834,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;
        }