|
@@ -1946,6 +1946,25 @@ try_to_wake_up(struct task_struct *p, unsigned int state, int wake_flags)
|
|
|
goto stat;
|
|
|
|
|
|
#ifdef CONFIG_SMP
|
|
|
+ /*
|
|
|
+ * Ensure we load p->on_cpu _after_ p->on_rq, otherwise it would be
|
|
|
+ * possible to, falsely, observe p->on_cpu == 0.
|
|
|
+ *
|
|
|
+ * One must be running (->on_cpu == 1) in order to remove oneself
|
|
|
+ * from the runqueue.
|
|
|
+ *
|
|
|
+ * [S] ->on_cpu = 1; [L] ->on_rq
|
|
|
+ * UNLOCK rq->lock
|
|
|
+ * RMB
|
|
|
+ * LOCK rq->lock
|
|
|
+ * [S] ->on_rq = 0; [L] ->on_cpu
|
|
|
+ *
|
|
|
+ * Pairs with the full barrier implied in the UNLOCK+LOCK on rq->lock
|
|
|
+ * from the consecutive calls to schedule(); the first switching to our
|
|
|
+ * task, the second putting it to sleep.
|
|
|
+ */
|
|
|
+ smp_rmb();
|
|
|
+
|
|
|
/*
|
|
|
* If the owning (remote) cpu is still in the middle of schedule() with
|
|
|
* this task as prev, wait until its done referencing the task.
|