public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH pm-for-3.2 1/2] freezer: reimplement wait_event_freezekillable using freezer_do_not_count/freezer_count()
@ 2011-11-03 23:07 Tejun Heo
  2011-11-03 23:09 ` [PATCH pm-for-3.2 2/2] freezer: revert 27920651fe "PM / Freezer: Make fake_signal_wake_up() wake TASK_KILLABLE tasks too" Tejun Heo
  2011-11-04  0:13 ` [PATCH pm-for-3.2 1/2] freezer: reimplement wait_event_freezekillable using freezer_do_not_count/freezer_count() Rafael J. Wysocki
  0 siblings, 2 replies; 8+ messages in thread
From: Tejun Heo @ 2011-11-03 23:07 UTC (permalink / raw)
  To: Rafael J. Wysocki; +Cc: linux-pm, linux-kernel, Oleg Nesterov, Jeff Layton

From: Oleg Nesterov <oleg@redhat.com>

Commit 27920651fe "PM / Freezer: Make fake_signal_wake_up() wake
TASK_KILLABLE tasks too" updated fake_signal_wake_up() used by freezer
to wake up KILLABLE tasks.  Sending unsolicited wakeups to tasks in
killable sleep is dangerous as there are code paths which depend on
tasks not waking up spuriously from KILLABLE sleep.

For example. sys_read() or page can sleep in TASK_KILLABLE assuming
that wait/down/whatever _killable can only fail if we can not return
to the usermode.  TASK_TRACED is another obvious example.

The offending commit was to resolve freezer hang during system PM
operations caused by KILLABLE sleeps in network filesystems.
wait_event_freezekillable(), which depends on the spurious KILLABLE
wakeup, was added by f06ac72e92 "cifs, freezer: add
wait_event_freezekillable and have cifs use it" to be used to
implement killable & freezable sleeps in network filesystems.

To prepare for reverting of 27920651fe, this patch reimplements
wait_event_freezekillable() using freezer_do_not_count/freezer_count()
so that it doesn't depend on the spurious KILLABLE wakeup.  This isn't
very nice but should do for now.

tj: Refreshed patch to apply to linus/master and updated commit
    description on Rafael's request.

Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Signed-off-by: Tejun Heo <tj@kernel.org>
Cc: Jeff Layton <jlayton@redhat.com>
LKML-Reference: <20111102175327.GA4446@redhat.com>
---
 include/linux/freezer.h |   11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)

Index: work/include/linux/freezer.h
===================================================================
--- work.orig/include/linux/freezer.h
+++ work/include/linux/freezer.h
@@ -143,14 +143,9 @@ static inline void set_freezable_with_si
 #define wait_event_freezekillable(wq, condition)			\
 ({									\
 	int __retval;							\
-	do {								\
-		__retval = wait_event_killable(wq,			\
-				(condition) || freezing(current));	\
-		if (__retval && !freezing(current))			\
-			break;						\
-		else if (!(condition))					\
-			__retval = -ERESTARTSYS;			\
-	} while (try_to_freeze());					\
+	freezer_do_not_count();						\
+	__retval = wait_event_killable(wq, (condition));		\
+	freezer_count();						\
 	__retval;							\
 })
 

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH pm-for-3.2 2/2] freezer: revert 27920651fe "PM / Freezer: Make fake_signal_wake_up() wake TASK_KILLABLE tasks too"
  2011-11-03 23:07 [PATCH pm-for-3.2 1/2] freezer: reimplement wait_event_freezekillable using freezer_do_not_count/freezer_count() Tejun Heo
@ 2011-11-03 23:09 ` Tejun Heo
  2011-11-04  0:13   ` Rafael J. Wysocki
  2011-11-04  0:13 ` [PATCH pm-for-3.2 1/2] freezer: reimplement wait_event_freezekillable using freezer_do_not_count/freezer_count() Rafael J. Wysocki
  1 sibling, 1 reply; 8+ messages in thread
From: Tejun Heo @ 2011-11-03 23:09 UTC (permalink / raw)
  To: Rafael J. Wysocki; +Cc: linux-pm, linux-kernel, Oleg Nesterov, Jeff Layton

Commit 27920651fe "PM / Freezer: Make fake_signal_wake_up() wake
TASK_KILLABLE tasks too" updated fake_signal_wake_up() used by freezer
to wake up KILLABLE tasks.  Sending unsolicited wakeups to tasks in
killable sleep is dangerous as there are code paths which depend on
tasks not waking up spuriously from KILLABLE sleep.

For example. sys_read() or page can sleep in TASK_KILLABLE assuming
that wait/down/whatever _killable can only fail if we can not return
to the usermode.  TASK_TRACED is another obvious example.

The previous patch updated wait_event_freezekillable() such that it
doesn't depend on the spurious wakeup.  This patch reverts the
offending commit.

Note that the spurious KILLABLE wakeup had other implicit effects in
KILLABLE sleeps in nfs and cifs and those will need further updates to
regain freezekillable behavior.

Signed-off-by: Tejun Heo <tj@kernel.org>
Cc: Jeff Layton <jlayton@redhat.com>
LKML-Reference: <20111031221743.GA18855@google.com>
---
This will cause conflict with the pending linux-next patches but the
resolution should be trivial.  Simply changing @resume from 0 to 1 is
enough.

Thanks.

 kernel/freezer.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Index: work/kernel/freezer.c
===================================================================
--- work.orig/kernel/freezer.c
+++ work/kernel/freezer.c
@@ -67,7 +67,7 @@ static void fake_signal_wake_up(struct t
 	unsigned long flags;
 
 	spin_lock_irqsave(&p->sighand->siglock, flags);
-	signal_wake_up(p, 1);
+	signal_wake_up(p, 0);
 	spin_unlock_irqrestore(&p->sighand->siglock, flags);
 }
 

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH pm-for-3.2 1/2] freezer: reimplement wait_event_freezekillable using freezer_do_not_count/freezer_count()
  2011-11-03 23:07 [PATCH pm-for-3.2 1/2] freezer: reimplement wait_event_freezekillable using freezer_do_not_count/freezer_count() Tejun Heo
  2011-11-03 23:09 ` [PATCH pm-for-3.2 2/2] freezer: revert 27920651fe "PM / Freezer: Make fake_signal_wake_up() wake TASK_KILLABLE tasks too" Tejun Heo
@ 2011-11-04  0:13 ` Rafael J. Wysocki
  1 sibling, 0 replies; 8+ messages in thread
From: Rafael J. Wysocki @ 2011-11-04  0:13 UTC (permalink / raw)
  To: Tejun Heo; +Cc: linux-pm, linux-kernel, Oleg Nesterov, Jeff Layton

On Friday, November 04, 2011, Tejun Heo wrote:
> From: Oleg Nesterov <oleg@redhat.com>
> 
> Commit 27920651fe "PM / Freezer: Make fake_signal_wake_up() wake
> TASK_KILLABLE tasks too" updated fake_signal_wake_up() used by freezer
> to wake up KILLABLE tasks.  Sending unsolicited wakeups to tasks in
> killable sleep is dangerous as there are code paths which depend on
> tasks not waking up spuriously from KILLABLE sleep.
> 
> For example. sys_read() or page can sleep in TASK_KILLABLE assuming
> that wait/down/whatever _killable can only fail if we can not return
> to the usermode.  TASK_TRACED is another obvious example.
> 
> The offending commit was to resolve freezer hang during system PM
> operations caused by KILLABLE sleeps in network filesystems.
> wait_event_freezekillable(), which depends on the spurious KILLABLE
> wakeup, was added by f06ac72e92 "cifs, freezer: add
> wait_event_freezekillable and have cifs use it" to be used to
> implement killable & freezable sleeps in network filesystems.
> 
> To prepare for reverting of 27920651fe, this patch reimplements
> wait_event_freezekillable() using freezer_do_not_count/freezer_count()
> so that it doesn't depend on the spurious KILLABLE wakeup.  This isn't
> very nice but should do for now.
> 
> tj: Refreshed patch to apply to linus/master and updated commit
>     description on Rafael's request.
> 
> Signed-off-by: Oleg Nesterov <oleg@redhat.com>
> Signed-off-by: Tejun Heo <tj@kernel.org>
> Cc: Jeff Layton <jlayton@redhat.com>
> LKML-Reference: <20111102175327.GA4446@redhat.com>

Applied to linux-pm/linux-next.

Thanks,
Rafael


> ---
>  include/linux/freezer.h |   11 +++--------
>  1 file changed, 3 insertions(+), 8 deletions(-)
> 
> Index: work/include/linux/freezer.h
> ===================================================================
> --- work.orig/include/linux/freezer.h
> +++ work/include/linux/freezer.h
> @@ -143,14 +143,9 @@ static inline void set_freezable_with_si
>  #define wait_event_freezekillable(wq, condition)			\
>  ({									\
>  	int __retval;							\
> -	do {								\
> -		__retval = wait_event_killable(wq,			\
> -				(condition) || freezing(current));	\
> -		if (__retval && !freezing(current))			\
> -			break;						\
> -		else if (!(condition))					\
> -			__retval = -ERESTARTSYS;			\
> -	} while (try_to_freeze());					\
> +	freezer_do_not_count();						\
> +	__retval = wait_event_killable(wq, (condition));		\
> +	freezer_count();						\
>  	__retval;							\
>  })
>  
> 
> 


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH pm-for-3.2 2/2] freezer: revert 27920651fe "PM / Freezer: Make fake_signal_wake_up() wake TASK_KILLABLE tasks too"
  2011-11-03 23:09 ` [PATCH pm-for-3.2 2/2] freezer: revert 27920651fe "PM / Freezer: Make fake_signal_wake_up() wake TASK_KILLABLE tasks too" Tejun Heo
@ 2011-11-04  0:13   ` Rafael J. Wysocki
  2011-11-04  0:17     ` Tejun Heo
  0 siblings, 1 reply; 8+ messages in thread
From: Rafael J. Wysocki @ 2011-11-04  0:13 UTC (permalink / raw)
  To: Tejun Heo; +Cc: linux-pm, linux-kernel, Oleg Nesterov, Jeff Layton

On Friday, November 04, 2011, Tejun Heo wrote:
> Commit 27920651fe "PM / Freezer: Make fake_signal_wake_up() wake
> TASK_KILLABLE tasks too" updated fake_signal_wake_up() used by freezer
> to wake up KILLABLE tasks.  Sending unsolicited wakeups to tasks in
> killable sleep is dangerous as there are code paths which depend on
> tasks not waking up spuriously from KILLABLE sleep.
> 
> For example. sys_read() or page can sleep in TASK_KILLABLE assuming
> that wait/down/whatever _killable can only fail if we can not return
> to the usermode.  TASK_TRACED is another obvious example.
> 
> The previous patch updated wait_event_freezekillable() such that it
> doesn't depend on the spurious wakeup.  This patch reverts the
> offending commit.
> 
> Note that the spurious KILLABLE wakeup had other implicit effects in
> KILLABLE sleeps in nfs and cifs and those will need further updates to
> regain freezekillable behavior.
> 
> Signed-off-by: Tejun Heo <tj@kernel.org>
> Cc: Jeff Layton <jlayton@redhat.com>
> LKML-Reference: <20111031221743.GA18855@google.com>

Applied to linux-pm/linux-next.

Thanks,
Rafael


> ---
> This will cause conflict with the pending linux-next patches but the
> resolution should be trivial.  Simply changing @resume from 0 to 1 is
> enough.
> 
> Thanks.
> 
>  kernel/freezer.c |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> Index: work/kernel/freezer.c
> ===================================================================
> --- work.orig/kernel/freezer.c
> +++ work/kernel/freezer.c
> @@ -67,7 +67,7 @@ static void fake_signal_wake_up(struct t
>  	unsigned long flags;
>  
>  	spin_lock_irqsave(&p->sighand->siglock, flags);
> -	signal_wake_up(p, 1);
> +	signal_wake_up(p, 0);
>  	spin_unlock_irqrestore(&p->sighand->siglock, flags);
>  }
>  
> 
> 


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH pm-for-3.2 2/2] freezer: revert 27920651fe "PM / Freezer: Make fake_signal_wake_up() wake TASK_KILLABLE tasks too"
  2011-11-04  0:13   ` Rafael J. Wysocki
@ 2011-11-04  0:17     ` Tejun Heo
  2011-11-04  0:24       ` Rafael J. Wysocki
  0 siblings, 1 reply; 8+ messages in thread
From: Tejun Heo @ 2011-11-04  0:17 UTC (permalink / raw)
  To: Rafael J. Wysocki; +Cc: linux-pm, linux-kernel, Oleg Nesterov, Jeff Layton

Hello, Rafael.

On Fri, Nov 04, 2011 at 01:13:21AM +0100, Rafael J. Wysocki wrote:
> On Friday, November 04, 2011, Tejun Heo wrote:
> > Commit 27920651fe "PM / Freezer: Make fake_signal_wake_up() wake
> > TASK_KILLABLE tasks too" updated fake_signal_wake_up() used by freezer
> > to wake up KILLABLE tasks.  Sending unsolicited wakeups to tasks in
> > killable sleep is dangerous as there are code paths which depend on
> > tasks not waking up spuriously from KILLABLE sleep.
> > 
> > For example. sys_read() or page can sleep in TASK_KILLABLE assuming
> > that wait/down/whatever _killable can only fail if we can not return
> > to the usermode.  TASK_TRACED is another obvious example.
> > 
> > The previous patch updated wait_event_freezekillable() such that it
> > doesn't depend on the spurious wakeup.  This patch reverts the
> > offending commit.
> > 
> > Note that the spurious KILLABLE wakeup had other implicit effects in
> > KILLABLE sleeps in nfs and cifs and those will need further updates to
> > regain freezekillable behavior.
> > 
> > Signed-off-by: Tejun Heo <tj@kernel.org>
> > Cc: Jeff Layton <jlayton@redhat.com>
> > LKML-Reference: <20111031221743.GA18855@google.com>
> 
> Applied to linux-pm/linux-next.

Just to be sure, as the commit which changed fake_signal_wake_up() to
use KILLABLE wakeup is already mainline, these two will have to be
pushed as fixes after some time in this devel cycle.

Thanks.

-- 
tejun

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH pm-for-3.2 2/2] freezer: revert 27920651fe "PM / Freezer: Make fake_signal_wake_up() wake TASK_KILLABLE tasks too"
  2011-11-04  0:17     ` Tejun Heo
@ 2011-11-04  0:24       ` Rafael J. Wysocki
  2011-11-04  0:27         ` Tejun Heo
  0 siblings, 1 reply; 8+ messages in thread
From: Rafael J. Wysocki @ 2011-11-04  0:24 UTC (permalink / raw)
  To: Tejun Heo; +Cc: linux-pm, linux-kernel, Oleg Nesterov, Jeff Layton

On Friday, November 04, 2011, Tejun Heo wrote:
> Hello, Rafael.
> 
> On Fri, Nov 04, 2011 at 01:13:21AM +0100, Rafael J. Wysocki wrote:
> > On Friday, November 04, 2011, Tejun Heo wrote:
> > > Commit 27920651fe "PM / Freezer: Make fake_signal_wake_up() wake
> > > TASK_KILLABLE tasks too" updated fake_signal_wake_up() used by freezer
> > > to wake up KILLABLE tasks.  Sending unsolicited wakeups to tasks in
> > > killable sleep is dangerous as there are code paths which depend on
> > > tasks not waking up spuriously from KILLABLE sleep.
> > > 
> > > For example. sys_read() or page can sleep in TASK_KILLABLE assuming
> > > that wait/down/whatever _killable can only fail if we can not return
> > > to the usermode.  TASK_TRACED is another obvious example.
> > > 
> > > The previous patch updated wait_event_freezekillable() such that it
> > > doesn't depend on the spurious wakeup.  This patch reverts the
> > > offending commit.
> > > 
> > > Note that the spurious KILLABLE wakeup had other implicit effects in
> > > KILLABLE sleeps in nfs and cifs and those will need further updates to
> > > regain freezekillable behavior.
> > > 
> > > Signed-off-by: Tejun Heo <tj@kernel.org>
> > > Cc: Jeff Layton <jlayton@redhat.com>
> > > LKML-Reference: <20111031221743.GA18855@google.com>
> > 
> > Applied to linux-pm/linux-next.
> 
> Just to be sure, as the commit which changed fake_signal_wake_up() to
> use KILLABLE wakeup is already mainline, these two will have to be
> pushed as fixes after some time in this devel cycle.

Yes, they are 3.2 material and I'm going to push them in the next few days
along with a number of other PM-related fixes/cleanups.  Is that OK?

Rafael

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH pm-for-3.2 2/2] freezer: revert 27920651fe "PM / Freezer: Make fake_signal_wake_up() wake TASK_KILLABLE tasks too"
  2011-11-04  0:24       ` Rafael J. Wysocki
@ 2011-11-04  0:27         ` Tejun Heo
  2011-11-04  0:42           ` Rafael J. Wysocki
  0 siblings, 1 reply; 8+ messages in thread
From: Tejun Heo @ 2011-11-04  0:27 UTC (permalink / raw)
  To: Rafael J. Wysocki; +Cc: linux-pm, linux-kernel, Oleg Nesterov, Jeff Layton

On Fri, Nov 04, 2011 at 01:24:33AM +0100, Rafael J. Wysocki wrote:
> > Just to be sure, as the commit which changed fake_signal_wake_up() to
> > use KILLABLE wakeup is already mainline, these two will have to be
> > pushed as fixes after some time in this devel cycle.
> 
> Yes, they are 3.2 material and I'm going to push them in the next few days
> along with a number of other PM-related fixes/cleanups.  Is that OK?

Yeap, definitely.  Just got a bit worried that it was going into
linux-next.  Thanks. :)

-- 
tejun

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH pm-for-3.2 2/2] freezer: revert 27920651fe "PM / Freezer: Make fake_signal_wake_up() wake TASK_KILLABLE tasks too"
  2011-11-04  0:27         ` Tejun Heo
@ 2011-11-04  0:42           ` Rafael J. Wysocki
  0 siblings, 0 replies; 8+ messages in thread
From: Rafael J. Wysocki @ 2011-11-04  0:42 UTC (permalink / raw)
  To: Tejun Heo; +Cc: linux-pm, linux-kernel, Oleg Nesterov, Jeff Layton

On Friday, November 04, 2011, Tejun Heo wrote:
> On Fri, Nov 04, 2011 at 01:24:33AM +0100, Rafael J. Wysocki wrote:
> > > Just to be sure, as the commit which changed fake_signal_wake_up() to
> > > use KILLABLE wakeup is already mainline, these two will have to be
> > > pushed as fixes after some time in this devel cycle.
> > 
> > Yes, they are 3.2 material and I'm going to push them in the next few days
> > along with a number of other PM-related fixes/cleanups.  Is that OK?
> 
> Yeap, definitely.  Just got a bit worried that it was going into
> linux-next.  Thanks. :)

As long as the merge window is open linux-next contains material for the
current development cycle.

Thanks,
Rafael

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2011-11-04  0:40 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-11-03 23:07 [PATCH pm-for-3.2 1/2] freezer: reimplement wait_event_freezekillable using freezer_do_not_count/freezer_count() Tejun Heo
2011-11-03 23:09 ` [PATCH pm-for-3.2 2/2] freezer: revert 27920651fe "PM / Freezer: Make fake_signal_wake_up() wake TASK_KILLABLE tasks too" Tejun Heo
2011-11-04  0:13   ` Rafael J. Wysocki
2011-11-04  0:17     ` Tejun Heo
2011-11-04  0:24       ` Rafael J. Wysocki
2011-11-04  0:27         ` Tejun Heo
2011-11-04  0:42           ` Rafael J. Wysocki
2011-11-04  0:13 ` [PATCH pm-for-3.2 1/2] freezer: reimplement wait_event_freezekillable using freezer_do_not_count/freezer_count() Rafael J. Wysocki

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox