|
@@ -274,7 +274,7 @@ bool try_wait_for_completion(struct completion *x)
|
|
* first without taking the lock so we can
|
|
* first without taking the lock so we can
|
|
* return early in the blocking case.
|
|
* return early in the blocking case.
|
|
*/
|
|
*/
|
|
- if (!ACCESS_ONCE(x->done))
|
|
|
|
|
|
+ if (!READ_ONCE(x->done))
|
|
return 0;
|
|
return 0;
|
|
|
|
|
|
spin_lock_irqsave(&x->wait.lock, flags);
|
|
spin_lock_irqsave(&x->wait.lock, flags);
|
|
@@ -297,6 +297,21 @@ EXPORT_SYMBOL(try_wait_for_completion);
|
|
*/
|
|
*/
|
|
bool completion_done(struct completion *x)
|
|
bool completion_done(struct completion *x)
|
|
{
|
|
{
|
|
- return !!ACCESS_ONCE(x->done);
|
|
|
|
|
|
+ if (!READ_ONCE(x->done))
|
|
|
|
+ return false;
|
|
|
|
+
|
|
|
|
+ /*
|
|
|
|
+ * If ->done, we need to wait for complete() to release ->wait.lock
|
|
|
|
+ * otherwise we can end up freeing the completion before complete()
|
|
|
|
+ * is done referencing it.
|
|
|
|
+ *
|
|
|
|
+ * The RMB pairs with complete()'s RELEASE of ->wait.lock and orders
|
|
|
|
+ * the loads of ->done and ->wait.lock such that we cannot observe
|
|
|
|
+ * the lock before complete() acquires it while observing the ->done
|
|
|
|
+ * after it's acquired the lock.
|
|
|
|
+ */
|
|
|
|
+ smp_rmb();
|
|
|
|
+ spin_unlock_wait(&x->wait.lock);
|
|
|
|
+ return true;
|
|
}
|
|
}
|
|
EXPORT_SYMBOL(completion_done);
|
|
EXPORT_SYMBOL(completion_done);
|