Commit:     33e1c288da62a6a5aa9077a6b7bfa690b1b02cf4
Parent:     585a2858b970cb6e2e5ca4877eefd18b4dba8ed4
Author:     Rafael J. Wysocki <[EMAIL PROTECTED]>
AuthorDate: Wed May 23 13:57:24 2007 -0700
Committer:  Linus Torvalds <[EMAIL PROTECTED]>
CommitDate: Wed May 23 20:14:10 2007 -0700

    freezer: close potential race between refrigerator and thaw_tasks
    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 
    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 
    not frozen, we can be sure that all tasks are thawed and there are no 
    "freeze" requests after thaw_tasks() has run.
    Signed-off-by: Rafael J. Wysocki <[EMAIL PROTECTED]>
    Acked-by: Pavel Machek <[EMAIL PROTECTED]>
    Cc: Gautham R Shenoy <[EMAIL PROTECTED]>
    Cc: Oleg Nesterov <[EMAIL PROTECTED]>
    Cc: "Eric W. Biederman" <[EMAIL PROTECTED]>
    Signed-off-by: Andrew Morton <[EMAIL PROTECTED]>
    Signed-off-by: Linus Torvalds <[EMAIL PROTECTED]>
 include/linux/freezer.h |   10 ++++++++++
 kernel/power/process.c  |   12 +++++++++++-
 2 files changed, 21 insertions(+), 1 deletions(-)

diff --git a/include/linux/freezer.h b/include/linux/freezer.h
index 5e75e26..db5423e 100644
--- a/include/linux/freezer.h
+++ b/include/linux/freezer.h
@@ -37,14 +37,24 @@ static inline void do_not_freeze(struct task_struct *p)
  * Wake up a frozen process
+ *
+ * task_lock() is taken to prevent the race with refrigerator() which may
+ * occur if the freezing of tasks fails.  Namely, without the lock, if the
+ * freezing of tasks failed, thaw_tasks() might have run before a task in
+ * refrigerator() could call frozen_process(), in which case the task would be
+ * frozen and no one would thaw it.
 static inline int thaw_process(struct task_struct *p)
+       task_lock(p);
        if (frozen(p)) {
                p->flags &= ~PF_FROZEN;
+               task_unlock(p);
                return 1;
+       clear_tsk_thread_flag(p, TIF_FREEZE);
+       task_unlock(p);
        return 0;
diff --git a/kernel/power/process.c b/kernel/power/process.c
index 0884193..02e490e 100644
--- a/kernel/power/process.c
+++ b/kernel/power/process.c
@@ -37,10 +37,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);
        recalc_sigpending(); /* We sent fake signal, clean it up */
@@ -152,10 +160,12 @@ static unsigned int try_to_freeze_tasks(int 
                        if (is_user_space(p) == !freeze_user_space)
+                       task_lock(p);
                        if (freezeable(p) && !frozen(p))
                                printk(KERN_ERR " %s\n", p->comm);
+                       task_unlock(p);
                } while_each_thread(g, p);
To unsubscribe from this list: send the line "unsubscribe git-commits-head" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at

Reply via email to