worker_thread: fix racy try_to_freeze() usage
authorOleg Nesterov <oleg@tv-sign.ru>
Wed, 9 May 2007 09:34:20 +0000 (02:34 -0700)
committerLinus Torvalds <torvalds@woody.linux-foundation.org>
Wed, 9 May 2007 19:30:53 +0000 (12:30 -0700)
worker_thread() can miss freeze_process()->signal_wake_up() if it happens
between try_to_freeze() and prepare_to_wait().  We should check freezing()
before entering schedule().

This race was introduced by me in

[PATCH 1/1] workqueue: don't migrate pending works from the dead CPU

Looks like mm/vmscan.c:kswapd() has the same race.

Signed-off-by: Oleg Nesterov <oleg@tv-sign.ru>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
kernel/workqueue.c

index 87693b37d017add2a28af93db2213dfea2bc5d6e..63885abf1ba093e09af3b0dc981a789bd1bf1d46 100644 (file)
@@ -308,14 +308,14 @@ static int worker_thread(void *__cwq)
        do_sigaction(SIGCHLD, &sa, (struct k_sigaction *)0);
 
        for (;;) {
-               if (cwq->wq->freezeable)
-                       try_to_freeze();
-
                prepare_to_wait(&cwq->more_work, &wait, TASK_INTERRUPTIBLE);
-               if (!cwq->should_stop && list_empty(&cwq->worklist))
+               if (!freezing(current) && !cwq->should_stop
+                   && list_empty(&cwq->worklist))
                        schedule();
                finish_wait(&cwq->more_work, &wait);
 
+               try_to_freeze();
+
                if (cwq_should_stop(cwq))
                        break;