From: "Rafael J. Wysocki" <rjw@sisk.pl>
To: ego@in.ibm.com
Cc: Andrew Morton <akpm@linux-foundation.org>,
Oleg Nesterov <oleg@tv-sign.ru>,
linux-kernel@vger.kernel.org, mingo@elte.hu, vatsa@in.ibm.com,
paulmck@us.ibm.com, pavel@ucw.cz
Subject: Re: [RFC PATCH(experimental) 2/2] Fix freezer-kthread_stop race
Date: Fri, 20 Apr 2007 13:59:29 +0200 [thread overview]
Message-ID: <200704201359.30490.rjw@sisk.pl> (raw)
In-Reply-To: <20070420110520.GB11290@in.ibm.com>
On Friday, 20 April 2007 13:05, Gautham R Shenoy wrote:
> On Fri, Apr 20, 2007 at 10:54:36AM +0200, Rafael J. Wysocki wrote:
> >
> > Hmm, can't we do something like this instead:
> >
> > ---
> > kernel/kthread.c | 10 ++++++++++
> > 1 file changed, 10 insertions(+)
> >
> > Index: linux-2.6.21-rc7/kernel/kthread.c
> > ===================================================================
> > --- linux-2.6.21-rc7.orig/kernel/kthread.c
> > +++ linux-2.6.21-rc7/kernel/kthread.c
> > @@ -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,15 @@ int kthread_stop(struct task_struct *k)
> >
> > /* Now set kthread_should_stop() to true, and wake it up. */
> > kthread_stop_info.k = k;
> > + if (!(current->flags & PF_NOFREEZE)) {
> > + /* If we are freezable, the freezer will wait for us */
> > + task_lock(k);
> > + k->flags |= PF_NOFREEZE;
> > + if (frozen(k))
> > + k->flags &= ~PF_FROZEN;
> > +
> > + task_unlock(k);
> > + }
>
> Yes, we can do this for now since the tasks have only two freeze states,
> namely Freezeable and Non Freezeable.
> But with more events like cpu-hotplug and kprobes using the process
> freezer, the simple check
>
> if(!(current->flags & PF_NOFREEZE))
>
> may not suffice and something like
> if(!(current->flags & PFE_ALL & global_freeze_mask))
> /* global_freeze_mask is the mask of the events for which the system
> is freezing. */
>
> appears to be racy. Not that we cannot work it out ;-)
Actually, I thought about it for a while. The thread that is going to stop
another one may temporarily mark itself as freezable in all cases, which
will have no effect on it, since it's not going to cally try_to_freeze(), but
will make the freezer wait for it. Next, after returning from
wait_for_completion(), it should restore its old freezability status and that
should make the freezer finish.
> However, I was attempting to solve the generic problem where
> A waits on B and B is frozen. If A is freezeable (under one of the
> events) then the freezer will fail. So a solution would be for A to
> somehow inform B of the dependency and postpone it's freezing.
Well, I think it might be simpler to consider each case separately. This way
we may be able to avoid introducing the additional TIF_ flag.
> Since akpm mentioned that flush_workqueue() needs to go, I guess, I am
> ok with fixing only kthread_stop/kthread_should_stop for the moment.
> Unless I can spot any other valid case :)
Sure. :-)
BTW, if it turns out that we need to introduce yet another freezer-related
TIF_ flag, it may be acceptable (?) to move all of the freezer-related flags
into a separate member of task_struct (eg. freezer_flags) that can only be
manipulated under task_lock().
I mean, we already have four of them (PF_NOFREEZE, PF_FROZEN,
PF_FREEZER_SKIP, TIF_FREEZE), and you will need to introduce two more for
the freezer-based CPU hotplug, so if yet another one is needed, that will make
up almost a separate u8 field ...
Greetings,
Rafael
next prev parent reply other threads:[~2007-04-20 11:56 UTC|newest]
Thread overview: 60+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-04-19 12:01 [RFC 0/2] Fix Freezer related races Gautham R Shenoy
2007-04-19 12:02 ` [RFC PATCH 1/2] Fix PF_NOFREEZE and freezeable race Gautham R Shenoy
2007-04-19 21:39 ` Rafael J. Wysocki
2007-04-20 18:02 ` Oleg Nesterov
2007-04-23 10:26 ` Gautham R Shenoy
2007-04-23 17:49 ` Oleg Nesterov
[not found] ` <200704260044.03975.rjw@sisk.pl>
[not found] ` <20070425231638.GH15134@in.ibm.com>
[not found] ` <20070425163409.4f8476c4.akpm@linux-foundation.org>
[not found] ` <20070426060608.GA12892@in.ibm.com>
[not found] ` <20070425231232.302a83f0.akpm@linux-foundation.org>
2007-04-26 13:11 ` [PATCH -mm] Move frozen_process() to kernel/power/process.c Gautham R Shenoy
2007-04-26 12:36 ` Oleg Nesterov
2007-04-26 13:40 ` Gautham R Shenoy
2007-04-19 12:04 ` [RFC PATCH(experimental) 2/2] Fix freezer-kthread_stop race Gautham R Shenoy
2007-04-19 21:31 ` Andrew Morton
2007-04-20 8:54 ` Rafael J. Wysocki
2007-04-20 11:05 ` Gautham R Shenoy
2007-04-20 11:59 ` Rafael J. Wysocki [this message]
2007-04-20 12:26 ` Gautham R Shenoy
2007-04-20 12:50 ` Rafael J. Wysocki
2007-04-20 17:30 ` Andrew Morton
2007-04-20 18:31 ` Ingo Molnar
2007-04-20 21:13 ` Rafael J. Wysocki
2007-04-22 19:28 ` [RFC][PATCH -mm 0/3] Separate freezer flags Rafael J. Wysocki
2007-04-22 19:33 ` [RFC][PATCH -mm 1/3] Separate freezer from PM code Rafael J. Wysocki
2007-04-23 10:41 ` Pavel Machek
2007-04-22 19:39 ` [RFC][PATCH -mm 2/3] freezer: Introduce freezer_flags Rafael J. Wysocki
2007-04-22 21:14 ` Paul Jackson
2007-04-22 22:14 ` Rafael J. Wysocki
2007-04-22 22:31 ` Paul Jackson
2007-04-23 3:18 ` Satyam Sharma
2007-04-23 4:09 ` Satyam Sharma
2007-04-23 14:19 ` Gautham R Shenoy
2007-04-23 18:49 ` Rafael J. Wysocki
2007-04-23 19:06 ` Rafael J. Wysocki
2007-04-23 10:50 ` Pavel Machek
2007-04-23 13:17 ` Gautham R Shenoy
2007-04-23 19:57 ` Rafael J. Wysocki
2007-04-23 22:23 ` Oleg Nesterov
2007-04-23 22:40 ` Rafael J. Wysocki
2007-04-23 22:41 ` Gautham R Shenoy
2007-04-23 22:55 ` Rafael J. Wysocki
2007-04-23 22:55 ` Oleg Nesterov
2007-04-23 23:10 ` Rafael J. Wysocki
2007-04-23 23:19 ` Oleg Nesterov
2007-04-24 11:32 ` Rafael J. Wysocki
2007-04-22 19:40 ` [RFC][PATCH -mm 3/3] freezer: Fix problem with kthread_stop Rafael J. Wysocki
2007-04-23 10:40 ` Pavel Machek
2007-04-23 19:50 ` Rafael J. Wysocki
2007-04-23 12:35 ` Gautham R Shenoy
2007-04-23 19:03 ` Oleg Nesterov
2007-04-23 20:05 ` Rafael J. Wysocki
2007-04-23 19:55 ` Rafael J. Wysocki
2007-04-23 20:46 ` Oleg Nesterov
2007-04-23 21:16 ` Gautham R Shenoy
2007-04-23 21:30 ` Rafael J. Wysocki
2007-04-20 21:20 ` [RFC PATCH(experimental) 2/2] Fix freezer-kthread_stop race Oleg Nesterov
2007-04-20 21:45 ` Rafael J. Wysocki
2007-04-20 10:46 ` Gautham R Shenoy
2007-04-21 9:37 ` Pavel Machek
2007-04-20 21:12 ` Oleg Nesterov
2007-04-23 10:38 ` Gautham R Shenoy
2007-04-23 18:39 ` Oleg Nesterov
2007-04-23 20:34 ` Gautham R Shenoy
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=200704201359.30490.rjw@sisk.pl \
--to=rjw@sisk.pl \
--cc=akpm@linux-foundation.org \
--cc=ego@in.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=oleg@tv-sign.ru \
--cc=paulmck@us.ibm.com \
--cc=pavel@ucw.cz \
--cc=vatsa@in.ibm.com \
/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