Commit 7539a3b3 authored by Rafael J. Wysocki's avatar Rafael J. Wysocki Committed by Ingo Molnar

sched: Make wakeup side and atomic variants of completion API irq safe

Alan Stern noticed that all the wakeup side (and atomic) variants of the
completion APIs should be irq safe, but the newly introduced
completion_done() and try_wait_for_completion() aren't. The use of the
irq unsafe variants in IRQ contexts can cause crashes/hangs.

Fix the problem by making them use spin_lock_irqsave() and
spin_lock_irqrestore().
Reported-by: default avatarAlan Stern <stern@rowland.harvard.edu>
Signed-off-by: default avatarRafael J. Wysocki <rjw@sisk.pl>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Zhang Rui <rui.zhang@intel.com>
Cc: pm list <linux-pm@lists.linux-foundation.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: David Chinner <david@fromorbit.com>
Cc: Lachlan McIlroy <lachlan@sgi.com>
LKML-Reference: <200912130007.30541.rjw@sisk.pl>
Signed-off-by: default avatarIngo Molnar <mingo@elte.hu>
parent f4054253
...@@ -5908,14 +5908,15 @@ EXPORT_SYMBOL(wait_for_completion_killable); ...@@ -5908,14 +5908,15 @@ EXPORT_SYMBOL(wait_for_completion_killable);
*/ */
bool try_wait_for_completion(struct completion *x) bool try_wait_for_completion(struct completion *x)
{ {
unsigned long flags;
int ret = 1; int ret = 1;
spin_lock_irq(&x->wait.lock); spin_lock_irqsave(&x->wait.lock, flags);
if (!x->done) if (!x->done)
ret = 0; ret = 0;
else else
x->done--; x->done--;
spin_unlock_irq(&x->wait.lock); spin_unlock_irqrestore(&x->wait.lock, flags);
return ret; return ret;
} }
EXPORT_SYMBOL(try_wait_for_completion); EXPORT_SYMBOL(try_wait_for_completion);
...@@ -5930,12 +5931,13 @@ EXPORT_SYMBOL(try_wait_for_completion); ...@@ -5930,12 +5931,13 @@ EXPORT_SYMBOL(try_wait_for_completion);
*/ */
bool completion_done(struct completion *x) bool completion_done(struct completion *x)
{ {
unsigned long flags;
int ret = 1; int ret = 1;
spin_lock_irq(&x->wait.lock); spin_lock_irqsave(&x->wait.lock, flags);
if (!x->done) if (!x->done)
ret = 0; ret = 0;
spin_unlock_irq(&x->wait.lock); spin_unlock_irqrestore(&x->wait.lock, flags);
return ret; return ret;
} }
EXPORT_SYMBOL(completion_done); EXPORT_SYMBOL(completion_done);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment