public inbox for linux-pm@vger.kernel.org
 help / color / mirror / Atom feed
From: "Rafael J. Wysocki" <rjw@sisk.pl>
To: Ingo Molnar <mingo@elte.hu>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>,
	David Chinner <david@fromorbit.com>,
	LKML <linux-kernel@vger.kernel.org>,
	ACPI Devel Maling List <linux-acpi@vger.kernel.org>,
	Lachlan McIlroy <lachlan@sgi.com>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	pm list <linux-pm@lists.linux-foundation.org>
Subject: [PATCH] sched: Make wakeup side variants of completion API irq safe (was: Re: spinlock in completion_done())
Date: Sun, 13 Dec 2009 00:07:30 +0100	[thread overview]
Message-ID: <200912130007.30541.rjw@sisk.pl> (raw)
In-Reply-To: <20091210075947.GD25549@elte.hu>

On Thursday 10 December 2009, Ingo Molnar wrote:
> 
> * Rafael J. Wysocki <rjw@sisk.pl> wrote:
> 
> > On Wednesday 09 December 2009, Ingo Molnar wrote:
> > > 
> > > * Rafael J. Wysocki <rjw@sisk.pl> wrote:
> > > 
> > > > On Tuesday 08 December 2009, Alan Stern wrote:
> > > > > On Tue, 8 Dec 2009, Rafael J. Wysocki wrote:
> > > > > 
> > > > > > BTW, is there a good reason why completion_done() doesn't use spin_lock_irqsave
> > > > > > and spin_unlock_irqrestore?  complete() and complete_all() use them, so why not
> > > > > > here?
> > > > > 
> > > > > And likewise in try_wait_for_completion().  It looks like a bug.  Maybe 
> > > > > these routines were not intended to be called with interrupts disabled, 
> > > > > but that requirement doesn't seem to be documented.  And it isn't a 
> > > > > natural requirement anyway.
> > > > 
> > > > OK, let's ask Ingo about that.
> > > > 
> > > > Ingo, is there any particular reason why completion_done() and
> > > > try_wait_for_completion() don't use spin_lock_irqsave() and
> > > > spin_unlock_irqrestore()?
> > > 
> > > that's a bug that should be fixed - all the wakeup side (and atomic) 
> > > variants of completetion API should be irq safe.
> > > 
> > > It appears that these new completion APIs were added via the XFS tree 
> > > about a year ago:
> > > 
> > >   39d2f1a: [XFS] extend completions to provide XFS object flush requirements
> > > 
> > > Please Cc: scheduler folks to all scheduler patches.
> > 
> > If you haven't fixed it locally yet, would you mind me posting a fix?
> 
> I wouldnt mind it at all.

Is appended.

Thanks,
Rafael

---
From: Rafael J. Wysocki <rjw@sisk.pl>
Subject: sched: Make wakeup side variants of completion API irq safe

All the wakeup side variants of the completion API shoild be irq
safe, but completion_done() and try_wait_for_completion() aren't.
Fix the problem by making them use spin_lock_irqsave() and
spin_lock_irqrestore().

Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
---
 kernel/sched.c |   10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

Index: linux-2.6/kernel/sched.c
===================================================================
--- linux-2.6.orig/kernel/sched.c
+++ linux-2.6/kernel/sched.c
@@ -5931,14 +5931,15 @@ EXPORT_SYMBOL(wait_for_completion_killab
  */
 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);
@@ -5953,12 +5954,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);

  parent reply	other threads:[~2009-12-12 23:07 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         ` Rafael J. Wysocki [this message]
2009-12-13  7:36           ` [tip:sched/urgent] sched: Make wakeup side and atomic variants of completion API irq safe tip-bot for Rafael J. Wysocki

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=200912130007.30541.rjw@sisk.pl \
    --to=rjw@sisk.pl \
    --cc=a.p.zijlstra@chello.nl \
    --cc=david@fromorbit.com \
    --cc=lachlan@sgi.com \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@lists.linux-foundation.org \
    --cc=mingo@elte.hu \
    --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