All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] workqueue: fix possible race condition when rescuer VS pwq-release
@ 2014-03-27 16:20 Lai Jiangshan
  2014-03-28 12:07 ` [PATCH V2] " Lai Jiangshan
  0 siblings, 1 reply; 24+ messages in thread
From: Lai Jiangshan @ 2014-03-27 16:20 UTC (permalink / raw)
  To: linux-kernel; +Cc: Tejun Heo, Lai Jiangshan

There is a race condition between rescuer_thread() and
pwq_unbound_release_workfn().

The works of the @pwq may be processed by some other worker,
and @pwq is scheduled to release before the rescuer starts
to process. In this case pwq_unbound_release_workfn() will
corrupt wq->maydays, and rescuer_thead will access to corrupted
data.

Using get_pwq() when send_mayday() will keep @pwq's lifetime
and avoid the race condition.

Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
---
 kernel/workqueue.c |    7 +++++++
 1 files changed, 7 insertions(+), 0 deletions(-)

diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index 82ef9f3..7066519 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -1902,6 +1902,12 @@ static void send_mayday(struct work_struct *work)
 
 	/* mayday mayday mayday */
 	if (list_empty(&pwq->mayday_node)) {
+		/*
+		 * Keep the pwq and avoid the pwq to be scheduled to release
+		 * when someone else processes all the works before the rescuer
+		 * starts to process.
+		 */
+		get_pwq(pwq);
 		list_add_tail(&pwq->mayday_node, &wq->maydays);
 		wake_up_process(wq->rescuer->task);
 	}
@@ -2418,6 +2424,7 @@ repeat:
 		/* migrate to the target cpu if possible */
 		worker_maybe_bind_and_lock(pool);
 		rescuer->pool = pool;
+		put_pwq(pwq);
 
 		/*
 		 * Slurp in all works issued via this workqueue and
-- 
1.7.7.6


^ permalink raw reply related	[flat|nested] 24+ messages in thread

end of thread, other threads:[~2014-04-18 16:35 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-03-27 16:20 [PATCH] workqueue: fix possible race condition when rescuer VS pwq-release Lai Jiangshan
2014-03-28 12:07 ` [PATCH V2] " Lai Jiangshan
2014-03-31 14:40   ` Lai Jiangshan
2014-03-31 20:06     ` Tejun Heo
2014-04-14  7:02       ` Lai Jiangshan
2014-04-15 16:47   ` Tejun Heo
2014-04-16  1:25     ` Lai Jiangshan
2014-04-16 15:23       ` Tejun Heo
2014-04-16 16:21         ` Lai Jiangshan
2014-04-16 16:50           ` Tejun Heo
2014-04-16 22:35             ` Lai Jiangshan
2014-04-16 23:34             ` [PATCH 1/2] workqueue: rescuer_thread() processes all pwqs before exit Lai Jiangshan
2014-04-16 23:34               ` [PATCH 2/2] workqueue: fix possible race condition when rescuer VS pwq-release Lai Jiangshan
2014-04-17 15:27               ` [PATCH 1/2] workqueue: rescuer_thread() processes all pwqs before exit Tejun Heo
2014-04-17 16:04                 ` Lai Jiangshan
2014-04-17 16:08                   ` Tejun Heo
2014-04-17 16:21                     ` Lai Jiangshan
2014-04-17 16:27                       ` Tejun Heo
2014-04-18 13:25                         ` [PATCH 1/2 V4] " Lai Jiangshan
2014-04-18 13:25                           ` [PATCH 2/2 V4] workqueue: fix possible race condition when rescuer VS pwq-release Lai Jiangshan
2014-04-18 15:06                             ` [PATCH 2/2] workqueue: fix a possible race condition between rescuer and pwq-release Tejun Heo
2014-04-18 16:24                               ` Lai Jiangshan
2014-04-18 16:35                                 ` Tejun Heo
2014-04-18 15:06                           ` [PATCH 1/2] workqueue: make rescuer_thread() empty wq->maydays list before exiting Tejun Heo

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.