aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/sched.c
diff options
context:
space:
mode:
authorRafael J. Wysocki <rjw@sisk.pl>2009-12-12 18:07:30 -0500
committerIngo Molnar <mingo@elte.hu>2009-12-13 02:12:46 -0500
commit7539a3b3d1f892dd97eaf094134d7de55c13befe (patch)
treef49c29135265e452208c5a2e404590f2e0becbc8 /kernel/sched.c
parentf40542532e96dda5506eb76badea322f2ae4731c (diff)
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: Alan Stern <stern@rowland.harvard.edu> Signed-off-by: Rafael 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: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'kernel/sched.c')
-rw-r--r--kernel/sched.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/kernel/sched.c b/kernel/sched.c
index ff39cadf621e..8b3532f262d7 100644
--- a/kernel/sched.c
+++ b/kernel/sched.c
@@ -5908,14 +5908,15 @@ EXPORT_SYMBOL(wait_for_completion_killable);
5908 */ 5908 */
5909bool try_wait_for_completion(struct completion *x) 5909bool try_wait_for_completion(struct completion *x)
5910{ 5910{
5911 unsigned long flags;
5911 int ret = 1; 5912 int ret = 1;
5912 5913
5913 spin_lock_irq(&x->wait.lock); 5914 spin_lock_irqsave(&x->wait.lock, flags);
5914 if (!x->done) 5915 if (!x->done)
5915 ret = 0; 5916 ret = 0;
5916 else 5917 else
5917 x->done--; 5918 x->done--;
5918 spin_unlock_irq(&x->wait.lock); 5919 spin_unlock_irqrestore(&x->wait.lock, flags);
5919 return ret; 5920 return ret;
5920} 5921}
5921EXPORT_SYMBOL(try_wait_for_completion); 5922EXPORT_SYMBOL(try_wait_for_completion);
@@ -5930,12 +5931,13 @@ EXPORT_SYMBOL(try_wait_for_completion);
5930 */ 5931 */
5931bool completion_done(struct completion *x) 5932bool completion_done(struct completion *x)
5932{ 5933{
5934 unsigned long flags;
5933 int ret = 1; 5935 int ret = 1;
5934 5936
5935 spin_lock_irq(&x->wait.lock); 5937 spin_lock_irqsave(&x->wait.lock, flags);
5936 if (!x->done) 5938 if (!x->done)
5937 ret = 0; 5939 ret = 0;
5938 spin_unlock_irq(&x->wait.lock); 5940 spin_unlock_irqrestore(&x->wait.lock, flags);
5939 return ret; 5941 return ret;
5940} 5942}
5941EXPORT_SYMBOL(completion_done); 5943EXPORT_SYMBOL(completion_done);