Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[PATCH] PM: Fix freezing of stopped tasks

Currently, if a task is stopped (ie. it's in the TASK_STOPPED state), it
is considered by the freezer as unfreezeable. However, there may be a race
between the freezer and the delivery of the continuation signal to the task
resulting in the task running after we have finished freezing the other
tasks. This, in turn, may lead to undesirable effects up to and including
data corruption.

To prevent this from happening we first need to make the freezer consider
stopped tasks as freezeable. For this purpose we need to make freezeable()
stop returning 0 for these tasks and we need to force them to enter the
refrigerator. However, if there's no continuation signal in the meantime,
the stopped tasks should remain stopped after all processes have been
thawed, so we need to send an additional SIGSTOP to each of them before
waking it up.

Also, a stopped task that has just been woken up should first check if
there's a freezing request for it and go to the refrigerator if that's the
case.

Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
Acked-by: Pavel Machek <pavel@ucw.cz>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>

authored by

Rafael J. Wysocki and committed by
Linus Torvalds
3df494a3 6a2d7a95

+9 -7
+6 -6
kernel/power/process.c
··· 28 28 if ((p == current) || 29 29 (p->flags & PF_NOFREEZE) || 30 30 (p->exit_state == EXIT_ZOMBIE) || 31 - (p->exit_state == EXIT_DEAD) || 32 - (p->state == TASK_STOPPED)) 31 + (p->exit_state == EXIT_DEAD)) 33 32 return 0; 34 33 return 1; 35 34 } ··· 60 61 unsigned long flags; 61 62 62 63 if (!freezing(p)) { 64 + if (p->state == TASK_STOPPED) 65 + force_sig_specific(SIGSTOP, p); 66 + 63 67 freeze(p); 64 68 spin_lock_irqsave(&p->sighand->siglock, flags); 65 - signal_wake_up(p, 0); 69 + signal_wake_up(p, p->state == TASK_STOPPED); 66 70 spin_unlock_irqrestore(&p->sighand->siglock, flags); 67 71 } 68 72 } ··· 105 103 if (frozen(p)) 106 104 continue; 107 105 108 - if (p->state == TASK_TRACED && 109 - (frozen(p->parent) || 110 - p->parent->state == TASK_STOPPED)) { 106 + if (p->state == TASK_TRACED && frozen(p->parent)) { 111 107 cancel_freezing(p); 112 108 continue; 113 109 }
+3 -1
kernel/signal.c
··· 1705 1705 read_unlock(&tasklist_lock); 1706 1706 } 1707 1707 1708 - schedule(); 1708 + do { 1709 + schedule(); 1710 + } while (try_to_freeze()); 1709 1711 /* 1710 1712 * Now we don't run again until continued. 1711 1713 */