LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: "Rafael J. Wysocki" <rjw@sisk.pl>
To: LKML <linux-kernel@vger.kernel.org>
Cc: paulmck@linux.vnet.ibm.com, ego@in.ibm.com, akpm@osdl.org,
mingo@elte.hu, vatsa@in.ibm.com, dipankar@in.ibm.com,
venkatesh.pallipadi@intel.com, Pavel Machek <pavel@ucw.cz>,
"Aneesh Kumar" <aneesh.kumar@gmail.com>
Subject: [RFC][PATCH 3/7] Freezer: Close theoretical race between refrigerator and thaw_tasks
Date: Fri, 23 Feb 2007 11:21:20 +0100 [thread overview]
Message-ID: <200702231121.21970.rjw@sisk.pl> (raw)
In-Reply-To: <200702231116.23607.rjw@sisk.pl>
From: Rafael J. Wysocki <rjw@sisk.pl>
If the freezing of tasks fails and a task is preempted in refrigerator() before
calling frozen_process(), then thaw_tasks() may run before this task is frozen.
In that case the task will freeze and no one will thaw it.
To fix this race we can call freezing(current) in refrigerator() along with
frozen_process(current) under the task_lock() which also should be taken in
the error path of try_to_freeze_tasks() as well as in thaw_process(). Moreover,
if thaw_process() additionally clears TIF_FREEZE for tasks that are not frozen,
we can be sure that all tasks are thawed and there are no pending "freeze"
requests after thaw_tasks() has run.
Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
---
include/linux/freezer.h | 4 ++++
kernel/power/process.c | 12 +++++++++++-
2 files changed, 15 insertions(+), 1 deletion(-)
Index: linux-2.6.20-mm2/include/linux/freezer.h
===================================================================
--- linux-2.6.20-mm2.orig/include/linux/freezer.h
+++ linux-2.6.20-mm2/include/linux/freezer.h
@@ -40,11 +40,15 @@ static inline void do_not_freeze(struct
*/
static inline int thaw_process(struct task_struct *p)
{
+ task_lock(p);
if (frozen(p)) {
p->flags &= ~PF_FROZEN;
+ task_unlock(p);
wake_up_process(p);
return 1;
}
+ clear_tsk_thread_flag(p, TIF_FREEZE);
+ task_unlock(p);
return 0;
}
Index: linux-2.6.20-mm2/kernel/power/process.c
===================================================================
--- linux-2.6.20-mm2.orig/kernel/power/process.c
+++ linux-2.6.20-mm2/kernel/power/process.c
@@ -39,10 +39,18 @@ void refrigerator(void)
/* Hmm, should we be allowed to suspend when there are realtime
processes around? */
long save;
+
+ task_lock(current);
+ if (freezing(current)) {
+ frozen_process(current);
+ task_unlock(current);
+ } else {
+ task_unlock(current);
+ return;
+ }
save = current->state;
pr_debug("%s entered refrigerator\n", current->comm);
- frozen_process(current);
spin_lock_irq(¤t->sighand->siglock);
recalc_sigpending(); /* We sent fake signal, clean it up */
spin_unlock_irq(¤t->sighand->siglock);
@@ -159,10 +167,12 @@ static unsigned int try_to_freeze_tasks(
if (is_user_space(p) == !freeze_user_space)
continue;
+ task_lock(p);
if (freezeable(p) && !frozen(p))
printk(KERN_ERR " %s\n", p->comm);
cancel_freezing(p);
+ task_unlock(p);
} while_each_thread(g, p);
read_unlock(&tasklist_lock);
}
next prev parent reply other threads:[~2007-02-23 11:54 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-02-23 10:16 [RFC][PATCH 0/7] Freezer: Hardening and preparation for CPU hotplug changes Rafael J. Wysocki
2007-02-23 10:18 ` [RFC][PATCH 1/7] Freezer: Read PF_BORROWED_MM in a nonracy way Rafael J. Wysocki
2007-02-25 10:43 ` Pavel Machek
2007-02-23 10:19 ` [RFC][PATCH 2/7] Freezer: Fix memory ordering in refrigerator Rafael J. Wysocki
2007-02-23 10:21 ` Rafael J. Wysocki [this message]
2007-02-25 10:44 ` [RFC][PATCH 3/7] Freezer: Close theoretical race between refrigerator and thaw_tasks Pavel Machek
2007-02-23 10:22 ` [RFC][PATCH 4/7] Freezer: Fix vfork problem Rafael J. Wysocki
2007-02-25 10:46 ` Pavel Machek
2007-02-25 10:45 ` Rafael J. Wysocki
2007-02-25 12:59 ` Rafael J. Wysocki
2007-02-25 14:33 ` Aneesh Kumar
2007-02-25 15:05 ` Rafael J. Wysocki
2007-02-25 15:28 ` Aneesh Kumar
2007-02-25 15:40 ` Aneesh Kumar
2007-02-25 19:17 ` Rafael J. Wysocki
2007-02-25 20:31 ` Oleg Nesterov
2007-02-25 20:33 ` Rafael J. Wysocki
2007-02-25 13:01 ` Aneesh Kumar
2007-02-25 13:43 ` Rafael J. Wysocki
2007-02-23 10:23 ` [RFC][PATCH 5/7] Freezer: Remove PF_NOFREEZE from rcutorture thread Rafael J. Wysocki
2007-02-25 10:44 ` Pavel Machek
2007-02-23 10:25 ` [RFC][PATCH 6/7] Freezer: Remove PF_NOFREEZE from bluetooth threads Rafael J. Wysocki
2007-02-25 10:44 ` Pavel Machek
2007-02-25 23:53 ` Marcel Holtmann
2007-02-23 10:26 ` [RFC][PATCH 7/7] Freezer: Add try_to_freeze calls to all kernel threads Rafael J. Wysocki
2007-02-25 10:45 ` Pavel Machek
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=200702231121.21970.rjw@sisk.pl \
--to=rjw@sisk.pl \
--cc=akpm@osdl.org \
--cc=aneesh.kumar@gmail.com \
--cc=dipankar@in.ibm.com \
--cc=ego@in.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=paulmck@linux.vnet.ibm.com \
--cc=pavel@ucw.cz \
--cc=vatsa@in.ibm.com \
--cc=venkatesh.pallipadi@intel.com \
--subject='Re: [RFC][PATCH 3/7] Freezer: Close theoretical race between refrigerator and thaw_tasks' \
/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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).