Re: [RFC][PATCH -mm 3/3] freezer: Fix problem with kthread_stop

2007-04-23 Thread Rafael J. Wysocki
On Monday, 23 April 2007 23:16, Gautham R Shenoy wrote:
> On Tue, Apr 24, 2007 at 12:46:37AM +0400, Oleg Nesterov wrote:
> > On 04/23, Rafael J. Wysocki wrote:
> > >
> > > On Monday, 23 April 2007 14:35, Gautham R Shenoy wrote:
> > > > > + if (!freezer_should_exempt(current)) {
> > > > task_lock(k);
> > > > > + /* We are freezable, so we must make sure that the 
> > > > > thread being
> > > > > +  * stopped is not frozen and will not be frozen until 
> > > > > it dies
> > > > > +  */
> > > > > + freezer_exempt(k);
> > > > > + if (frozen(k))
> > > > > + clear_frozen_flag(k);
> > > > task_unlock(k);
> > > > > + }
> > > 
> > > Yes, that's correct.  We need to take task_lock() to avoid the race with
> > > refrigerator().
> > 
> > Even if we use thaw_task() ?
> 
> I don't think so. As you correctly pointed out, thaw_task() is race free
> w.r.t the refrigerator(). 

Agreed.

Rafael
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [RFC][PATCH -mm 3/3] freezer: Fix problem with kthread_stop

2007-04-23 Thread Gautham R Shenoy
On Tue, Apr 24, 2007 at 12:46:37AM +0400, Oleg Nesterov wrote:
> On 04/23, Rafael J. Wysocki wrote:
> >
> > On Monday, 23 April 2007 14:35, Gautham R Shenoy wrote:
> > > > +   if (!freezer_should_exempt(current)) {
> > >   task_lock(k);
> > > > +   /* We are freezable, so we must make sure that the 
> > > > thread being
> > > > +* stopped is not frozen and will not be frozen until 
> > > > it dies
> > > > +*/
> > > > +   freezer_exempt(k);
> > > > +   if (frozen(k))
> > > > +   clear_frozen_flag(k);
> > >   task_unlock(k);
> > > > +   }
> > 
> > Yes, that's correct.  We need to take task_lock() to avoid the race with
> > refrigerator().
> 
> Even if we use thaw_task() ?

I don't think so. As you correctly pointed out, thaw_task() is race free
w.r.t the refrigerator(). 

> 
> Even if I am wrong, I think we should not use task_lock() for the freezing
> related code, except in freezer.[ch]
> 
> Note also that without CONFIG_FREEZER freezer_should_exempt() == 0, so we
> will do unneeded task_lock/task_unlock.
> 
> Oleg.
> 

Thanks and Regards
gautham.
-- 
Gautham R Shenoy
Linux Technology Center
IBM India.
"Freedom comes with a price tag of responsibility, which is still a bargain,
because Freedom is priceless!"
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [RFC][PATCH -mm 3/3] freezer: Fix problem with kthread_stop

2007-04-23 Thread Oleg Nesterov
On 04/23, Rafael J. Wysocki wrote:
>
> On Monday, 23 April 2007 14:35, Gautham R Shenoy wrote:
> > > + if (!freezer_should_exempt(current)) {
> > task_lock(k);
> > > + /* We are freezable, so we must make sure that the thread being
> > > +  * stopped is not frozen and will not be frozen until it dies
> > > +  */
> > > + freezer_exempt(k);
> > > + if (frozen(k))
> > > + clear_frozen_flag(k);
> > task_unlock(k);
> > > + }
> 
> Yes, that's correct.  We need to take task_lock() to avoid the race with
> refrigerator().

Even if we use thaw_task() ?

Even if I am wrong, I think we should not use task_lock() for the freezing
related code, except in freezer.[ch]

Note also that without CONFIG_FREEZER freezer_should_exempt() == 0, so we
will do unneeded task_lock/task_unlock.

Oleg.

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [RFC][PATCH -mm 3/3] freezer: Fix problem with kthread_stop

2007-04-23 Thread Rafael J. Wysocki
On Monday, 23 April 2007 21:03, Oleg Nesterov wrote:
> On 04/23, Gautham R Shenoy wrote:
> >
> > On Sun, Apr 22, 2007 at 09:40:59PM +0200, Rafael J. Wysocki wrote:
> > >  /*
> > > @@ -232,6 +233,14 @@ int kthread_stop(struct task_struct *k)
> > > 
> > >   /* Now set kthread_should_stop() to true, and wake it up. */
> > >   kthread_stop_info.k = k;
> > > + if (!freezer_should_exempt(current)) {
> > > + /* We are freezable, so we must make sure that the thread being
> > > +  * stopped is not frozen and will not be frozen until it dies
> > > +  */
> > > + freezer_exempt(k);
> > > + if (frozen(k))
> > > + clear_frozen_flag(k);
> > > + }
> > 
> > I'm trying hard to convince myself that this will work. May be I am
> > missing something here, but I find a potential race window (very small 
> > though) 
> > when k is entering the refrigerator.
> > 
> > [... snip ... ]
> > 
> > IMO, we need the to take the task_lock for k here. Something like
> > 
> > > + if (!freezer_should_exempt(current)) {
> > task_lock(k);
> > > + /* We are freezable, so we must make sure that the thread being
> > > +  * stopped is not frozen and will not be frozen until it dies
> > > +  */
> > > + freezer_exempt(k);
> > > + if (frozen(k))
> > > + clear_frozen_flag(k);
> > task_unlock(k);
> > > + }
> 
> Well, probably I missed something, but why can't we do
> 
>   if (!freezer_should_exempt(current)) {
>   freezer_exempt(k);
>   thaw_process(k);
>   }
> ?
> 
> thaw_process(k) is properly serialized with refrigerator(), and it checks
> frozen(k). We can make an extra wake_up, but this should not matter.

Yes, I think you're right.

> Rafael, please check the recent changes in kthread.c, kthread_stop() was
> reworked, we don't have kthread_stop_info any longer.

OK, I will, thanks.

Greetings,
Rafael
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [RFC][PATCH -mm 3/3] freezer: Fix problem with kthread_stop

2007-04-23 Thread Rafael J. Wysocki
Hi,

On Monday, 23 April 2007 12:40, Pavel Machek wrote:
> Hi!
> 
> > Fix the problem with kthread_stop() that causes the freezer to fail if a
> > freezable thread is attempting to stop a frozen one and that may cause the
> > freezer to fail if the thread being stopped is freezable and
> > try_to_freeze_tasks() is running concurrently with kthread_stop().
> 
> Parse error.

OK, will fix.

> > Index: linux-2.6.21-rc6-mm1/kernel/kthread.c
> > ===
> > --- linux-2.6.21-rc6-mm1.orig/kernel/kthread.c  2007-04-09 
> > 15:23:48.0 +0200
> > +++ linux-2.6.21-rc6-mm1/kernel/kthread.c   2007-04-22 19:05:29.0 
> > +0200
> > @@ -232,6 +233,14 @@ int kthread_stop(struct task_struct *k)
> >  
> > /* Now set kthread_should_stop() to true, and wake it up. */
> > kthread_stop_info.k = k;
> > +   if (!freezer_should_exempt(current)) {
> > +   /* We are freezable, so we must make sure that the thread being
> > +* stopped is not frozen and will not be frozen until it dies
> > +*/
> > +   freezer_exempt(k);
> > +   if (frozen(k))
> > +   clear_frozen_flag(k);
> > +   }
> > wake_up_process(k);
> > put_task_struct(k);
> >  
> 
> Do we need to take some locks to access other process' flags? Or do
> frozen_exempt() etc take enough locks, already?

After the previous patch we only use set_bit(), clear_bit() and test_bit() to
access freezer_falgs, so no special locking is needed to protect them.

Greetings,
Rafael
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [RFC][PATCH -mm 3/3] freezer: Fix problem with kthread_stop

2007-04-23 Thread Rafael J. Wysocki
On Monday, 23 April 2007 14:35, Gautham R Shenoy wrote:
> On Sun, Apr 22, 2007 at 09:40:59PM +0200, Rafael J. Wysocki wrote:
> > From: Rafael J. Wysocki <[EMAIL PROTECTED]>
> > 
> > Fix the problem with kthread_stop() that causes the freezer to fail if a
> > freezable thread is attempting to stop a frozen one and that may cause the
> > freezer to fail if the thread being stopped is freezable and
> > try_to_freeze_tasks() is running concurrently with kthread_stop().
> > 
> > Signed-off-by: Rafael J. Wysocki <[EMAIL PROTECTED]>
> > ---
> >  kernel/kthread.c |9 +
> >  1 file changed, 9 insertions(+)
> > 
> > Index: linux-2.6.21-rc6-mm1/kernel/kthread.c
> > ===
> > --- linux-2.6.21-rc6-mm1.orig/kernel/kthread.c  2007-04-09 
> > 15:23:48.0 +0200
> > +++ linux-2.6.21-rc6-mm1/kernel/kthread.c   2007-04-22 19:05:29.0 
> > +0200
> > @@ -13,6 +13,7 @@
> >  #include 
> >  #include 
> >  #include 
> > +#include 
> >  #include 
> > 
> >  /*
> > @@ -232,6 +233,14 @@ int kthread_stop(struct task_struct *k)
> > 
> > /* Now set kthread_should_stop() to true, and wake it up. */
> > kthread_stop_info.k = k;
> > +   if (!freezer_should_exempt(current)) {
> > +   /* We are freezable, so we must make sure that the thread being
> > +* stopped is not frozen and will not be frozen until it dies
> > +*/
> > +   freezer_exempt(k);
> > +   if (frozen(k))
> > +   clear_frozen_flag(k);
> > +   }
> 
> I'm trying hard to convince myself that this will work. May be I am
> missing something here, but I find a potential race window (very small 
> though) 
> when k is entering the refrigerator.
> 
> Here's how.
> 
> kthread_stop(k)   k->refrigerator()
> -
>   task_lock(k);
>   1) check_if_exempted();
>   /* not exempted. So 
>* we will freeze
>* ourself.
>*/
> 2) freezer_exempt(k);
> 
> 3) if(frozen(k))
> /* No, we're not yet frozen. So we
>  * don't clear_frozen_flag(k) here
>  */
>   4) frozen_process(k);
>  task_unlock(k);
>   
>   5) for(;;) {
>
> set_current_state(UNINTERRUPTIBLE);
> if(!frozen_process(k))
> /* k is frozen. We
>  * don't break :( 
>  */
>
>   schedule();
>   }
>   
> > wake_up_process(k);
> > put_task_struct(k);
> > 
> 
> Thus the freezer can still fail, no?
> IMO, we need the to take the task_lock for k here. Something like
> 
> > +   if (!freezer_should_exempt(current)) {
>   task_lock(k);
> > +   /* We are freezable, so we must make sure that the thread being
> > +* stopped is not frozen and will not be frozen until it dies
> > +*/
> > +   freezer_exempt(k);
> > +   if (frozen(k))
> > +   clear_frozen_flag(k);
>   task_unlock(k);
> > +   }

Yes, that's correct.  We need to take task_lock() to avoid the race with
refrigerator().

I'll fix the patch.

BTW, I think I should rediff the entire series against -mm with your patch from
http://lkml.org/lkml/2007/4/23/98 applied.

Greetings,
Rafael

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [RFC][PATCH -mm 3/3] freezer: Fix problem with kthread_stop

2007-04-23 Thread Oleg Nesterov
On 04/23, Gautham R Shenoy wrote:
>
> On Sun, Apr 22, 2007 at 09:40:59PM +0200, Rafael J. Wysocki wrote:
> >  /*
> > @@ -232,6 +233,14 @@ int kthread_stop(struct task_struct *k)
> > 
> > /* Now set kthread_should_stop() to true, and wake it up. */
> > kthread_stop_info.k = k;
> > +   if (!freezer_should_exempt(current)) {
> > +   /* We are freezable, so we must make sure that the thread being
> > +* stopped is not frozen and will not be frozen until it dies
> > +*/
> > +   freezer_exempt(k);
> > +   if (frozen(k))
> > +   clear_frozen_flag(k);
> > +   }
> 
> I'm trying hard to convince myself that this will work. May be I am
> missing something here, but I find a potential race window (very small 
> though) 
> when k is entering the refrigerator.
> 
> [... snip ... ]
> 
> IMO, we need the to take the task_lock for k here. Something like
> 
> > +   if (!freezer_should_exempt(current)) {
>   task_lock(k);
> > +   /* We are freezable, so we must make sure that the thread being
> > +* stopped is not frozen and will not be frozen until it dies
> > +*/
> > +   freezer_exempt(k);
> > +   if (frozen(k))
> > +   clear_frozen_flag(k);
>   task_unlock(k);
> > +   }

Well, probably I missed something, but why can't we do

if (!freezer_should_exempt(current)) {
freezer_exempt(k);
thaw_process(k);
}
?

thaw_process(k) is properly serialized with refrigerator(), and it checks
frozen(k). We can make an extra wake_up, but this should not matter.

Rafael, please check the recent changes in kthread.c, kthread_stop() was
reworked, we don't have kthread_stop_info any longer.

Oleg.

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [RFC][PATCH -mm 3/3] freezer: Fix problem with kthread_stop

2007-04-23 Thread Gautham R Shenoy
On Sun, Apr 22, 2007 at 09:40:59PM +0200, Rafael J. Wysocki wrote:
> From: Rafael J. Wysocki <[EMAIL PROTECTED]>
> 
> Fix the problem with kthread_stop() that causes the freezer to fail if a
> freezable thread is attempting to stop a frozen one and that may cause the
> freezer to fail if the thread being stopped is freezable and
> try_to_freeze_tasks() is running concurrently with kthread_stop().
> 
> Signed-off-by: Rafael J. Wysocki <[EMAIL PROTECTED]>
> ---
>  kernel/kthread.c |9 +
>  1 file changed, 9 insertions(+)
> 
> Index: linux-2.6.21-rc6-mm1/kernel/kthread.c
> ===
> --- linux-2.6.21-rc6-mm1.orig/kernel/kthread.c2007-04-09 
> 15:23:48.0 +0200
> +++ linux-2.6.21-rc6-mm1/kernel/kthread.c 2007-04-22 19:05:29.0 
> +0200
> @@ -13,6 +13,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  #include 
> 
>  /*
> @@ -232,6 +233,14 @@ int kthread_stop(struct task_struct *k)
> 
>   /* Now set kthread_should_stop() to true, and wake it up. */
>   kthread_stop_info.k = k;
> + if (!freezer_should_exempt(current)) {
> + /* We are freezable, so we must make sure that the thread being
> +  * stopped is not frozen and will not be frozen until it dies
> +  */
> + freezer_exempt(k);
> + if (frozen(k))
> + clear_frozen_flag(k);
> + }

I'm trying hard to convince myself that this will work. May be I am
missing something here, but I find a potential race window (very small though) 
when k is entering the refrigerator.

Here's how.

kthread_stop(k) k->refrigerator()
-
task_lock(k);
1) check_if_exempted();
/* not exempted. So 
 * we will freeze
 * ourself.
 */
2) freezer_exempt(k);

3) if(frozen(k))
/* No, we're not yet frozen. So we
 * don't clear_frozen_flag(k) here
 */
4) frozen_process(k);
   task_unlock(k);

5) for(;;) {
 
set_current_state(UNINTERRUPTIBLE);
  if(!frozen_process(k))
  /* k is frozen. We
   * don't break :( 
   */
 
schedule();
}

>   wake_up_process(k);
>   put_task_struct(k);
> 

Thus the freezer can still fail, no?
IMO, we need the to take the task_lock for k here. Something like

> + if (!freezer_should_exempt(current)) {
task_lock(k);
> + /* We are freezable, so we must make sure that the thread being
> +  * stopped is not frozen and will not be frozen until it dies
> +  */
> + freezer_exempt(k);
> + if (frozen(k))
> + clear_frozen_flag(k);
task_unlock(k);
> + }


Thanks and Regards
gautham.
-- 
Gautham R Shenoy
Linux Technology Center
IBM India.
"Freedom comes with a price tag of responsibility, which is still a bargain,
because Freedom is priceless!"
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [RFC][PATCH -mm 3/3] freezer: Fix problem with kthread_stop

2007-04-23 Thread Pavel Machek
Hi!

> Fix the problem with kthread_stop() that causes the freezer to fail if a
> freezable thread is attempting to stop a frozen one and that may cause the
> freezer to fail if the thread being stopped is freezable and
> try_to_freeze_tasks() is running concurrently with kthread_stop().

Parse error.

> Index: linux-2.6.21-rc6-mm1/kernel/kthread.c
> ===
> --- linux-2.6.21-rc6-mm1.orig/kernel/kthread.c2007-04-09 
> 15:23:48.0 +0200
> +++ linux-2.6.21-rc6-mm1/kernel/kthread.c 2007-04-22 19:05:29.0 
> +0200
> @@ -232,6 +233,14 @@ int kthread_stop(struct task_struct *k)
>  
>   /* Now set kthread_should_stop() to true, and wake it up. */
>   kthread_stop_info.k = k;
> + if (!freezer_should_exempt(current)) {
> + /* We are freezable, so we must make sure that the thread being
> +  * stopped is not frozen and will not be frozen until it dies
> +  */
> + freezer_exempt(k);
> + if (frozen(k))
> + clear_frozen_flag(k);
> + }
>   wake_up_process(k);
>   put_task_struct(k);
>  

Do we need to take some locks to access other process' flags? Or do
frozen_exempt() etc take enough locks, already?
Pavel
-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) 
http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [RFC][PATCH -mm 3/3] freezer: Fix problem with kthread_stop

2007-04-23 Thread Pavel Machek
Hi!

 Fix the problem with kthread_stop() that causes the freezer to fail if a
 freezable thread is attempting to stop a frozen one and that may cause the
 freezer to fail if the thread being stopped is freezable and
 try_to_freeze_tasks() is running concurrently with kthread_stop().

Parse error.

 Index: linux-2.6.21-rc6-mm1/kernel/kthread.c
 ===
 --- linux-2.6.21-rc6-mm1.orig/kernel/kthread.c2007-04-09 
 15:23:48.0 +0200
 +++ linux-2.6.21-rc6-mm1/kernel/kthread.c 2007-04-22 19:05:29.0 
 +0200
 @@ -232,6 +233,14 @@ int kthread_stop(struct task_struct *k)
  
   /* Now set kthread_should_stop() to true, and wake it up. */
   kthread_stop_info.k = k;
 + if (!freezer_should_exempt(current)) {
 + /* We are freezable, so we must make sure that the thread being
 +  * stopped is not frozen and will not be frozen until it dies
 +  */
 + freezer_exempt(k);
 + if (frozen(k))
 + clear_frozen_flag(k);
 + }
   wake_up_process(k);
   put_task_struct(k);
  

Do we need to take some locks to access other process' flags? Or do
frozen_exempt() etc take enough locks, already?
Pavel
-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) 
http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
-
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [RFC][PATCH -mm 3/3] freezer: Fix problem with kthread_stop

2007-04-23 Thread Gautham R Shenoy
On Sun, Apr 22, 2007 at 09:40:59PM +0200, Rafael J. Wysocki wrote:
 From: Rafael J. Wysocki [EMAIL PROTECTED]
 
 Fix the problem with kthread_stop() that causes the freezer to fail if a
 freezable thread is attempting to stop a frozen one and that may cause the
 freezer to fail if the thread being stopped is freezable and
 try_to_freeze_tasks() is running concurrently with kthread_stop().
 
 Signed-off-by: Rafael J. Wysocki [EMAIL PROTECTED]
 ---
  kernel/kthread.c |9 +
  1 file changed, 9 insertions(+)
 
 Index: linux-2.6.21-rc6-mm1/kernel/kthread.c
 ===
 --- linux-2.6.21-rc6-mm1.orig/kernel/kthread.c2007-04-09 
 15:23:48.0 +0200
 +++ linux-2.6.21-rc6-mm1/kernel/kthread.c 2007-04-22 19:05:29.0 
 +0200
 @@ -13,6 +13,7 @@
  #include linux/file.h
  #include linux/module.h
  #include linux/mutex.h
 +#include linux/freezer.h
  #include asm/semaphore.h
 
  /*
 @@ -232,6 +233,14 @@ int kthread_stop(struct task_struct *k)
 
   /* Now set kthread_should_stop() to true, and wake it up. */
   kthread_stop_info.k = k;
 + if (!freezer_should_exempt(current)) {
 + /* We are freezable, so we must make sure that the thread being
 +  * stopped is not frozen and will not be frozen until it dies
 +  */
 + freezer_exempt(k);
 + if (frozen(k))
 + clear_frozen_flag(k);
 + }

I'm trying hard to convince myself that this will work. May be I am
missing something here, but I find a potential race window (very small though) 
when k is entering the refrigerator.

Here's how.

kthread_stop(k) k-refrigerator()
-
task_lock(k);
1) check_if_exempted();
/* not exempted. So 
 * we will freeze
 * ourself.
 */
2) freezer_exempt(k);

3) if(frozen(k))
/* No, we're not yet frozen. So we
 * don't clear_frozen_flag(k) here
 */
4) frozen_process(k);
   task_unlock(k);

5) for(;;) {
 
set_current_state(UNINTERRUPTIBLE);
  if(!frozen_process(k))
  /* k is frozen. We
   * don't break :( 
   */
 
schedule();
}

   wake_up_process(k);
   put_task_struct(k);
 

Thus the freezer can still fail, no?
IMO, we need the to take the task_lock for k here. Something like

 + if (!freezer_should_exempt(current)) {
task_lock(k);
 + /* We are freezable, so we must make sure that the thread being
 +  * stopped is not frozen and will not be frozen until it dies
 +  */
 + freezer_exempt(k);
 + if (frozen(k))
 + clear_frozen_flag(k);
task_unlock(k);
 + }


Thanks and Regards
gautham.
-- 
Gautham R Shenoy
Linux Technology Center
IBM India.
Freedom comes with a price tag of responsibility, which is still a bargain,
because Freedom is priceless!
-
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [RFC][PATCH -mm 3/3] freezer: Fix problem with kthread_stop

2007-04-23 Thread Oleg Nesterov
On 04/23, Gautham R Shenoy wrote:

 On Sun, Apr 22, 2007 at 09:40:59PM +0200, Rafael J. Wysocki wrote:
   /*
  @@ -232,6 +233,14 @@ int kthread_stop(struct task_struct *k)
  
  /* Now set kthread_should_stop() to true, and wake it up. */
  kthread_stop_info.k = k;
  +   if (!freezer_should_exempt(current)) {
  +   /* We are freezable, so we must make sure that the thread being
  +* stopped is not frozen and will not be frozen until it dies
  +*/
  +   freezer_exempt(k);
  +   if (frozen(k))
  +   clear_frozen_flag(k);
  +   }
 
 I'm trying hard to convince myself that this will work. May be I am
 missing something here, but I find a potential race window (very small 
 though) 
 when k is entering the refrigerator.
 
 [... snip ... ]
 
 IMO, we need the to take the task_lock for k here. Something like
 
  +   if (!freezer_should_exempt(current)) {
   task_lock(k);
  +   /* We are freezable, so we must make sure that the thread being
  +* stopped is not frozen and will not be frozen until it dies
  +*/
  +   freezer_exempt(k);
  +   if (frozen(k))
  +   clear_frozen_flag(k);
   task_unlock(k);
  +   }

Well, probably I missed something, but why can't we do

if (!freezer_should_exempt(current)) {
freezer_exempt(k);
thaw_process(k);
}
?

thaw_process(k) is properly serialized with refrigerator(), and it checks
frozen(k). We can make an extra wake_up, but this should not matter.

Rafael, please check the recent changes in kthread.c, kthread_stop() was
reworked, we don't have kthread_stop_info any longer.

Oleg.

-
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [RFC][PATCH -mm 3/3] freezer: Fix problem with kthread_stop

2007-04-23 Thread Rafael J. Wysocki
Hi,

On Monday, 23 April 2007 12:40, Pavel Machek wrote:
 Hi!
 
  Fix the problem with kthread_stop() that causes the freezer to fail if a
  freezable thread is attempting to stop a frozen one and that may cause the
  freezer to fail if the thread being stopped is freezable and
  try_to_freeze_tasks() is running concurrently with kthread_stop().
 
 Parse error.

OK, will fix.

  Index: linux-2.6.21-rc6-mm1/kernel/kthread.c
  ===
  --- linux-2.6.21-rc6-mm1.orig/kernel/kthread.c  2007-04-09 
  15:23:48.0 +0200
  +++ linux-2.6.21-rc6-mm1/kernel/kthread.c   2007-04-22 19:05:29.0 
  +0200
  @@ -232,6 +233,14 @@ int kthread_stop(struct task_struct *k)
   
  /* Now set kthread_should_stop() to true, and wake it up. */
  kthread_stop_info.k = k;
  +   if (!freezer_should_exempt(current)) {
  +   /* We are freezable, so we must make sure that the thread being
  +* stopped is not frozen and will not be frozen until it dies
  +*/
  +   freezer_exempt(k);
  +   if (frozen(k))
  +   clear_frozen_flag(k);
  +   }
  wake_up_process(k);
  put_task_struct(k);
   
 
 Do we need to take some locks to access other process' flags? Or do
 frozen_exempt() etc take enough locks, already?

After the previous patch we only use set_bit(), clear_bit() and test_bit() to
access freezer_falgs, so no special locking is needed to protect them.

Greetings,
Rafael
-
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [RFC][PATCH -mm 3/3] freezer: Fix problem with kthread_stop

2007-04-23 Thread Rafael J. Wysocki
On Monday, 23 April 2007 14:35, Gautham R Shenoy wrote:
 On Sun, Apr 22, 2007 at 09:40:59PM +0200, Rafael J. Wysocki wrote:
  From: Rafael J. Wysocki [EMAIL PROTECTED]
  
  Fix the problem with kthread_stop() that causes the freezer to fail if a
  freezable thread is attempting to stop a frozen one and that may cause the
  freezer to fail if the thread being stopped is freezable and
  try_to_freeze_tasks() is running concurrently with kthread_stop().
  
  Signed-off-by: Rafael J. Wysocki [EMAIL PROTECTED]
  ---
   kernel/kthread.c |9 +
   1 file changed, 9 insertions(+)
  
  Index: linux-2.6.21-rc6-mm1/kernel/kthread.c
  ===
  --- linux-2.6.21-rc6-mm1.orig/kernel/kthread.c  2007-04-09 
  15:23:48.0 +0200
  +++ linux-2.6.21-rc6-mm1/kernel/kthread.c   2007-04-22 19:05:29.0 
  +0200
  @@ -13,6 +13,7 @@
   #include linux/file.h
   #include linux/module.h
   #include linux/mutex.h
  +#include linux/freezer.h
   #include asm/semaphore.h
  
   /*
  @@ -232,6 +233,14 @@ int kthread_stop(struct task_struct *k)
  
  /* Now set kthread_should_stop() to true, and wake it up. */
  kthread_stop_info.k = k;
  +   if (!freezer_should_exempt(current)) {
  +   /* We are freezable, so we must make sure that the thread being
  +* stopped is not frozen and will not be frozen until it dies
  +*/
  +   freezer_exempt(k);
  +   if (frozen(k))
  +   clear_frozen_flag(k);
  +   }
 
 I'm trying hard to convince myself that this will work. May be I am
 missing something here, but I find a potential race window (very small 
 though) 
 when k is entering the refrigerator.
 
 Here's how.
 
 kthread_stop(k)   k-refrigerator()
 -
   task_lock(k);
   1) check_if_exempted();
   /* not exempted. So 
* we will freeze
* ourself.
*/
 2) freezer_exempt(k);
 
 3) if(frozen(k))
 /* No, we're not yet frozen. So we
  * don't clear_frozen_flag(k) here
  */
   4) frozen_process(k);
  task_unlock(k);
   
   5) for(;;) {

 set_current_state(UNINTERRUPTIBLE);
 if(!frozen_process(k))
 /* k is frozen. We
  * don't break :( 
  */

   schedule();
   }
   
  wake_up_process(k);
  put_task_struct(k);
  
 
 Thus the freezer can still fail, no?
 IMO, we need the to take the task_lock for k here. Something like
 
  +   if (!freezer_should_exempt(current)) {
   task_lock(k);
  +   /* We are freezable, so we must make sure that the thread being
  +* stopped is not frozen and will not be frozen until it dies
  +*/
  +   freezer_exempt(k);
  +   if (frozen(k))
  +   clear_frozen_flag(k);
   task_unlock(k);
  +   }

Yes, that's correct.  We need to take task_lock() to avoid the race with
refrigerator().

I'll fix the patch.

BTW, I think I should rediff the entire series against -mm with your patch from
http://lkml.org/lkml/2007/4/23/98 applied.

Greetings,
Rafael

-
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [RFC][PATCH -mm 3/3] freezer: Fix problem with kthread_stop

2007-04-23 Thread Rafael J. Wysocki
On Monday, 23 April 2007 21:03, Oleg Nesterov wrote:
 On 04/23, Gautham R Shenoy wrote:
 
  On Sun, Apr 22, 2007 at 09:40:59PM +0200, Rafael J. Wysocki wrote:
/*
   @@ -232,6 +233,14 @@ int kthread_stop(struct task_struct *k)
   
 /* Now set kthread_should_stop() to true, and wake it up. */
 kthread_stop_info.k = k;
   + if (!freezer_should_exempt(current)) {
   + /* We are freezable, so we must make sure that the thread being
   +  * stopped is not frozen and will not be frozen until it dies
   +  */
   + freezer_exempt(k);
   + if (frozen(k))
   + clear_frozen_flag(k);
   + }
  
  I'm trying hard to convince myself that this will work. May be I am
  missing something here, but I find a potential race window (very small 
  though) 
  when k is entering the refrigerator.
  
  [... snip ... ]
  
  IMO, we need the to take the task_lock for k here. Something like
  
   + if (!freezer_should_exempt(current)) {
  task_lock(k);
   + /* We are freezable, so we must make sure that the thread being
   +  * stopped is not frozen and will not be frozen until it dies
   +  */
   + freezer_exempt(k);
   + if (frozen(k))
   + clear_frozen_flag(k);
  task_unlock(k);
   + }
 
 Well, probably I missed something, but why can't we do
 
   if (!freezer_should_exempt(current)) {
   freezer_exempt(k);
   thaw_process(k);
   }
 ?
 
 thaw_process(k) is properly serialized with refrigerator(), and it checks
 frozen(k). We can make an extra wake_up, but this should not matter.

Yes, I think you're right.

 Rafael, please check the recent changes in kthread.c, kthread_stop() was
 reworked, we don't have kthread_stop_info any longer.

OK, I will, thanks.

Greetings,
Rafael
-
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [RFC][PATCH -mm 3/3] freezer: Fix problem with kthread_stop

2007-04-23 Thread Oleg Nesterov
On 04/23, Rafael J. Wysocki wrote:

 On Monday, 23 April 2007 14:35, Gautham R Shenoy wrote:
   + if (!freezer_should_exempt(current)) {
  task_lock(k);
   + /* We are freezable, so we must make sure that the thread being
   +  * stopped is not frozen and will not be frozen until it dies
   +  */
   + freezer_exempt(k);
   + if (frozen(k))
   + clear_frozen_flag(k);
  task_unlock(k);
   + }
 
 Yes, that's correct.  We need to take task_lock() to avoid the race with
 refrigerator().

Even if we use thaw_task() ?

Even if I am wrong, I think we should not use task_lock() for the freezing
related code, except in freezer.[ch]

Note also that without CONFIG_FREEZER freezer_should_exempt() == 0, so we
will do unneeded task_lock/task_unlock.

Oleg.

-
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [RFC][PATCH -mm 3/3] freezer: Fix problem with kthread_stop

2007-04-23 Thread Gautham R Shenoy
On Tue, Apr 24, 2007 at 12:46:37AM +0400, Oleg Nesterov wrote:
 On 04/23, Rafael J. Wysocki wrote:
 
  On Monday, 23 April 2007 14:35, Gautham R Shenoy wrote:
+   if (!freezer_should_exempt(current)) {
 task_lock(k);
+   /* We are freezable, so we must make sure that the 
thread being
+* stopped is not frozen and will not be frozen until 
it dies
+*/
+   freezer_exempt(k);
+   if (frozen(k))
+   clear_frozen_flag(k);
 task_unlock(k);
+   }
  
  Yes, that's correct.  We need to take task_lock() to avoid the race with
  refrigerator().
 
 Even if we use thaw_task() ?

I don't think so. As you correctly pointed out, thaw_task() is race free
w.r.t the refrigerator(). 

 
 Even if I am wrong, I think we should not use task_lock() for the freezing
 related code, except in freezer.[ch]
 
 Note also that without CONFIG_FREEZER freezer_should_exempt() == 0, so we
 will do unneeded task_lock/task_unlock.
 
 Oleg.
 

Thanks and Regards
gautham.
-- 
Gautham R Shenoy
Linux Technology Center
IBM India.
Freedom comes with a price tag of responsibility, which is still a bargain,
because Freedom is priceless!
-
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [RFC][PATCH -mm 3/3] freezer: Fix problem with kthread_stop

2007-04-23 Thread Rafael J. Wysocki
On Monday, 23 April 2007 23:16, Gautham R Shenoy wrote:
 On Tue, Apr 24, 2007 at 12:46:37AM +0400, Oleg Nesterov wrote:
  On 04/23, Rafael J. Wysocki wrote:
  
   On Monday, 23 April 2007 14:35, Gautham R Shenoy wrote:
 + if (!freezer_should_exempt(current)) {
task_lock(k);
 + /* We are freezable, so we must make sure that the 
 thread being
 +  * stopped is not frozen and will not be frozen until 
 it dies
 +  */
 + freezer_exempt(k);
 + if (frozen(k))
 + clear_frozen_flag(k);
task_unlock(k);
 + }
   
   Yes, that's correct.  We need to take task_lock() to avoid the race with
   refrigerator().
  
  Even if we use thaw_task() ?
 
 I don't think so. As you correctly pointed out, thaw_task() is race free
 w.r.t the refrigerator(). 

Agreed.

Rafael
-
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[RFC][PATCH -mm 3/3] freezer: Fix problem with kthread_stop

2007-04-22 Thread Rafael J. Wysocki
From: Rafael J. Wysocki <[EMAIL PROTECTED]>

Fix the problem with kthread_stop() that causes the freezer to fail if a
freezable thread is attempting to stop a frozen one and that may cause the
freezer to fail if the thread being stopped is freezable and
try_to_freeze_tasks() is running concurrently with kthread_stop().

Signed-off-by: Rafael J. Wysocki <[EMAIL PROTECTED]>
---
 kernel/kthread.c |9 +
 1 file changed, 9 insertions(+)

Index: linux-2.6.21-rc6-mm1/kernel/kthread.c
===
--- linux-2.6.21-rc6-mm1.orig/kernel/kthread.c  2007-04-09 15:23:48.0 
+0200
+++ linux-2.6.21-rc6-mm1/kernel/kthread.c   2007-04-22 19:05:29.0 
+0200
@@ -13,6 +13,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 /*
@@ -232,6 +233,14 @@ int kthread_stop(struct task_struct *k)
 
/* Now set kthread_should_stop() to true, and wake it up. */
kthread_stop_info.k = k;
+   if (!freezer_should_exempt(current)) {
+   /* We are freezable, so we must make sure that the thread being
+* stopped is not frozen and will not be frozen until it dies
+*/
+   freezer_exempt(k);
+   if (frozen(k))
+   clear_frozen_flag(k);
+   }
wake_up_process(k);
put_task_struct(k);
 
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[RFC][PATCH -mm 3/3] freezer: Fix problem with kthread_stop

2007-04-22 Thread Rafael J. Wysocki
From: Rafael J. Wysocki [EMAIL PROTECTED]

Fix the problem with kthread_stop() that causes the freezer to fail if a
freezable thread is attempting to stop a frozen one and that may cause the
freezer to fail if the thread being stopped is freezable and
try_to_freeze_tasks() is running concurrently with kthread_stop().

Signed-off-by: Rafael J. Wysocki [EMAIL PROTECTED]
---
 kernel/kthread.c |9 +
 1 file changed, 9 insertions(+)

Index: linux-2.6.21-rc6-mm1/kernel/kthread.c
===
--- linux-2.6.21-rc6-mm1.orig/kernel/kthread.c  2007-04-09 15:23:48.0 
+0200
+++ linux-2.6.21-rc6-mm1/kernel/kthread.c   2007-04-22 19:05:29.0 
+0200
@@ -13,6 +13,7 @@
 #include linux/file.h
 #include linux/module.h
 #include linux/mutex.h
+#include linux/freezer.h
 #include asm/semaphore.h
 
 /*
@@ -232,6 +233,14 @@ int kthread_stop(struct task_struct *k)
 
/* Now set kthread_should_stop() to true, and wake it up. */
kthread_stop_info.k = k;
+   if (!freezer_should_exempt(current)) {
+   /* We are freezable, so we must make sure that the thread being
+* stopped is not frozen and will not be frozen until it dies
+*/
+   freezer_exempt(k);
+   if (frozen(k))
+   clear_frozen_flag(k);
+   }
wake_up_process(k);
put_task_struct(k);
 
-
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/