lkml.org 
[lkml]   [2010]   [Jul]   [12]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
Subject[PATCH] workqueue: fix locking in retry path of maybe_create_worker()
maybe_create_worker() mismanaged locking when worker creation fails
and it has to retry. Fix locking and simplify lock manipulation.

Signed-off-by: Tejun Heo <tj@kernel.org>
Reported-by: Yong Zhang <yong.zhang@windriver.com>
---
Heh, that was stupid. Thanks a lot for spotting it. I simplified
things a bit there as there's no reason to repeatedly lock and unlock
there. Does this look good to you?

kernel/workqueue.c | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)

Index: work/kernel/workqueue.c
===================================================================
--- work.orig/kernel/workqueue.c
+++ work/kernel/workqueue.c
@@ -1442,14 +1442,14 @@ static bool maybe_create_worker(struct g
if (!need_to_create_worker(gcwq))
return false;
restart:
+ spin_unlock_irq(&gcwq->lock);
+
/* if we don't make progress in MAYDAY_INITIAL_TIMEOUT, call for help */
mod_timer(&gcwq->mayday_timer, jiffies + MAYDAY_INITIAL_TIMEOUT);

while (true) {
struct worker *worker;

- spin_unlock_irq(&gcwq->lock);
-
worker = create_worker(gcwq, true);
if (worker) {
del_timer_sync(&gcwq->mayday_timer);
@@ -1462,15 +1462,13 @@ restart:
if (!need_to_create_worker(gcwq))
break;

- spin_unlock_irq(&gcwq->lock);
__set_current_state(TASK_INTERRUPTIBLE);
schedule_timeout(CREATE_COOLDOWN);
- spin_lock_irq(&gcwq->lock);
+
if (!need_to_create_worker(gcwq))
break;
}

- spin_unlock_irq(&gcwq->lock);
del_timer_sync(&gcwq->mayday_timer);
spin_lock_irq(&gcwq->lock);
if (need_to_create_worker(gcwq))

\
 
 \ /
  Last update: 2010-07-12 10:57    [W:0.333 / U:2.976 seconds]
©2003-2017 Jasper Spaans. hosted at Digital OceanAdvertise on this site