public inbox for linux-pm@vger.kernel.org
 help / color / mirror / Atom feed
From: "tip-bot for Rafael J. Wysocki" <rjw@sisk.pl>
To: linux-tip-commits@vger.kernel.org
Cc: tglx@linutronix.de, a.p.zijlstra@chello.nl, mingo@elte.hu,
	david@fromorbit.com, linux-kernel@vger.kernel.org,
	mingo@redhat.com, hpa@zytor.com, lachlan@sgi.com,
	linux-pm@lists.linux-foundation.org,
	torvalds@linux-foundation.org
Subject: [tip:sched/urgent] sched: Make wakeup side and atomic variants of completion API irq safe
Date: Sun, 13 Dec 2009 07:36:42 GMT	[thread overview]
Message-ID: <tip-7539a3b3d1f892dd97eaf094134d7de55c13befe@git.kernel.org> (raw)
In-Reply-To: <200912130007.30541.rjw@sisk.pl>

Commit-ID:  7539a3b3d1f892dd97eaf094134d7de55c13befe
Gitweb:     http://git.kernel.org/tip/7539a3b3d1f892dd97eaf094134d7de55c13befe
Author:     Rafael J. Wysocki <rjw@sisk.pl>
AuthorDate: Sun, 13 Dec 2009 00:07:30 +0100
Committer:  Ingo Molnar <mingo@elte.hu>
CommitDate: Sun, 13 Dec 2009 08:12:46 +0100

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>
---
 kernel/sched.c |   10 ++++++----
 1 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/kernel/sched.c b/kernel/sched.c
index ff39cad..8b3532f 100644
--- a/kernel/sched.c
+++ b/kernel/sched.c
@@ -5908,14 +5908,15 @@ EXPORT_SYMBOL(wait_for_completion_killable);
  */
 bool try_wait_for_completion(struct completion *x)
 {
+	unsigned long flags;
 	int ret = 1;
 
-	spin_lock_irq(&x->wait.lock);
+	spin_lock_irqsave(&x->wait.lock, flags);
 	if (!x->done)
 		ret = 0;
 	else
 		x->done--;
-	spin_unlock_irq(&x->wait.lock);
+	spin_unlock_irqrestore(&x->wait.lock, flags);
 	return ret;
 }
 EXPORT_SYMBOL(try_wait_for_completion);
@@ -5930,12 +5931,13 @@ EXPORT_SYMBOL(try_wait_for_completion);
  */
 bool completion_done(struct completion *x)
 {
+	unsigned long flags;
 	int ret = 1;
 
-	spin_lock_irq(&x->wait.lock);
+	spin_lock_irqsave(&x->wait.lock, flags);
 	if (!x->done)
 		ret = 0;
-	spin_unlock_irq(&x->wait.lock);
+	spin_unlock_irqrestore(&x->wait.lock, flags);
 	return ret;
 }
 EXPORT_SYMBOL(completion_done);

      reply	other threads:[~2009-12-13  7:36 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <Pine.LNX.4.44L0.0912081633540.3046-100000@iolanthe.rowland.org>
2009-12-08 21:48 ` spinlock in completion_done() (was: Re: Async resume patch (was: Re: [GIT PULL] PM updates for 2.6.33)) Rafael J. Wysocki
2009-12-08 22:18 ` Async resume patch (was: Re: [GIT PULL] PM updates for 2.6.33) Linus Torvalds
     [not found] ` <200912082248.14138.rjw@sisk.pl>
2009-12-09  9:29   ` spinlock in completion_done() (was: Re: Async resume patch (was: Re: [GIT PULL] PM updates for 2.6.33)) Ingo Molnar
     [not found]   ` <20091209092922.GC28428@elte.hu>
2009-12-09 22:37     ` Rafael J. Wysocki
     [not found]     ` <200912092337.52492.rjw@sisk.pl>
2009-12-10  7:59       ` Ingo Molnar
     [not found]       ` <20091210075947.GD25549@elte.hu>
2009-12-11  4:10         ` Dave Chinner
     [not found]         ` <20091211041041.GJ30608@discord.disaster>
2009-12-11  7:54           ` Ingo Molnar
2009-12-12 23:07         ` [PATCH] sched: Make wakeup side variants of completion API irq safe (was: Re: spinlock in completion_done()) Rafael J. Wysocki
2009-12-13  7:36           ` tip-bot for Rafael J. Wysocki [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=tip-7539a3b3d1f892dd97eaf094134d7de55c13befe@git.kernel.org \
    --to=rjw@sisk.pl \
    --cc=a.p.zijlstra@chello.nl \
    --cc=david@fromorbit.com \
    --cc=hpa@zytor.com \
    --cc=lachlan@sgi.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@lists.linux-foundation.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=mingo@redhat.com \
    --cc=rui.zhang@intel.com \
    --cc=stern@rowland.harvard.edu \
    --cc=tglx@linutronix.de \
    --cc=torvalds@linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox