sched/completion: Serialize completion_done() with complete()
authorOleg Nesterov <oleg@redhat.com>
Thu, 12 Feb 2015 19:59:13 +0000 (20:59 +0100)
committerIngo Molnar <mingo@kernel.org>
Wed, 18 Feb 2015 13:27:40 +0000 (14:27 +0100)
commitbc9560155f4063bbc9be71bd69d6726d41b47653
tree9d4be1d4a9526b0b0d9e74cfb335ad696195685f
parent06b1f8083d6ed379ec1207a96339f23e8f7abfcf
sched/completion: Serialize completion_done() with complete()

Commit de30ec47302c "Remove unnecessary ->wait.lock serialization when
reading completion state" was not correct, without lock/unlock the code
like stop_machine_from_inactive_cpu()

while (!completion_done())
cpu_relax();

can return before complete() finishes its spin_unlock() which writes to
this memory. And spin_unlock_wait().

While at it, change try_wait_for_completion() to use READ_ONCE().

Reported-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Reported-by: Davidlohr Bueso <dave@stgolabs.net>
Tested-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
[ Added a comment with the barrier. ]
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Nicholas Mc Guire <der.herr@hofr.at>
Cc: raghavendra.kt@linux.vnet.ibm.com
Cc: waiman.long@hp.com
Fixes: de30ec47302c ("sched/completion: Remove unnecessary ->wait.lock serialization when reading completion state")
Link: http://lkml.kernel.org/r/20150212195913.GA30430@redhat.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
kernel/sched/completion.c