Skip to content

Commit

Permalink
worker_thread: fix racy try_to_freeze() usage
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Oleg Nesterov authored and Linus Torvalds committed May 9, 2007
1 parent b9aac8e commit 85f4186
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions kernel/workqueue.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 85f4186

Please sign in to comment.