From: Andrew Morton <akpm@osdl.org>
To: Bjorn Helgaas <bjorn.helgaas@hp.com>, Ingo Molnar <mingo@elte.hu>,
linux-kernel@vger.kernel.org, Myron Stowe <myron.stowe@hp.com>,
Jens Axboe <axboe@kernel.dk>
Subject: Re: workqueue deadlock
Date: Thu, 7 Dec 2006 11:37:00 -0800 [thread overview]
Message-ID: <20061207113700.dc925068.akpm@osdl.org> (raw)
In-Reply-To: <20061207105148.20410b83.akpm@osdl.org>
On Thu, 7 Dec 2006 10:51:48 -0800
Andrew Morton <akpm@osdl.org> wrote:
> + if (!cpu_online(cpu)) /* oops, CPU got unplugged */
> + goto bail;
hm, actually we can pull the same trick with flush_scheduled_work().
Should fix quite a few things...
From: Andrew Morton <akpm@osdl.org>
We have a class of deadlocks where the flush_scheduled_work() caller can get
stuck waiting for a work to complete, where that work wants to take
workqueue_mutex for some reason.
Fix this by not holding workqueue_mutex when waiting for a workqueue to flush.
The patch assumes that the per-cpu workqueue won't get freed up while there's
a task waiting on cpu_workqueue_struct.work_done. If that can happen,
run_workqueue() would crash anyway.
Cc: Bjorn Helgaas <bjorn.helgaas@hp.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Srivatsa Vaddagiri <vatsa@in.ibm.com>
Cc: Gautham shenoy <ego@in.ibm.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
---
kernel/workqueue.c | 22 +++++++++++++++++++---
1 files changed, 19 insertions(+), 3 deletions(-)
diff -puN kernel/workqueue.c~workqueue-dont-hold-workqueue_mutex-in-flush_scheduled_work kernel/workqueue.c
--- a/kernel/workqueue.c~workqueue-dont-hold-workqueue_mutex-in-flush_scheduled_work
+++ a/kernel/workqueue.c
@@ -325,14 +325,22 @@ static int worker_thread(void *__cwq)
return 0;
}
-static void flush_cpu_workqueue(struct cpu_workqueue_struct *cwq)
+/*
+ * If cpu == -1 it's a single-threaded workqueue and the caller does not hold
+ * workqueue_mutex
+ */
+static void flush_cpu_workqueue(struct cpu_workqueue_struct *cwq, int cpu)
{
if (cwq->thread == current) {
/*
* Probably keventd trying to flush its own queue. So simply run
* it by hand rather than deadlocking.
*/
+ if (cpu != -1)
+ mutex_unlock(&workqueue_mutex);
run_workqueue(cwq);
+ if (cpu != -1)
+ mutex_lock(&workqueue_mutex);
} else {
DEFINE_WAIT(wait);
long sequence_needed;
@@ -344,7 +352,14 @@ static void flush_cpu_workqueue(struct c
prepare_to_wait(&cwq->work_done, &wait,
TASK_UNINTERRUPTIBLE);
spin_unlock_irq(&cwq->lock);
+ if (cpu != -1)
+ mutex_unlock(&workqueue_mutex);
schedule();
+ if (cpu != -1) {
+ mutex_lock(&workqueue_mutex);
+ if (!cpu_online(cpu))
+ return; /* oops, CPU unplugged */
+ }
spin_lock_irq(&cwq->lock);
}
finish_wait(&cwq->work_done, &wait);
@@ -373,13 +388,14 @@ void fastcall flush_workqueue(struct wor
if (is_single_threaded(wq)) {
/* Always use first cpu's area. */
- flush_cpu_workqueue(per_cpu_ptr(wq->cpu_wq, singlethread_cpu));
+ flush_cpu_workqueue(per_cpu_ptr(wq->cpu_wq, singlethread_cpu),
+ -1);
} else {
int cpu;
mutex_lock(&workqueue_mutex);
for_each_online_cpu(cpu)
- flush_cpu_workqueue(per_cpu_ptr(wq->cpu_wq, cpu));
+ flush_cpu_workqueue(per_cpu_ptr(wq->cpu_wq, cpu), cpu);
mutex_unlock(&workqueue_mutex);
}
}
_
next prev parent reply other threads:[~2006-12-07 19:37 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-12-07 0:26 Bjorn Helgaas
2006-12-07 6:17 ` Srivatsa Vaddagiri
2006-12-07 6:45 ` Srivatsa Vaddagiri
2006-12-07 18:51 ` Andrew Morton
2006-12-07 19:37 ` Andrew Morton [this message]
2006-12-08 2:53 ` Srivatsa Vaddagiri
2006-12-08 4:54 ` Andrew Morton
2006-12-08 7:58 ` Srivatsa Vaddagiri
2006-12-09 10:26 ` Ingo Molnar
2006-12-09 19:47 ` Andrew Morton
2006-12-10 8:26 ` Ingo Molnar
2006-12-10 8:43 ` Andrew Morton
2006-12-10 11:49 ` Ingo Molnar
2006-12-10 12:16 ` Andrew Morton
2006-12-10 12:19 ` Ingo Molnar
2006-12-10 12:34 ` Andrew Morton
2006-12-11 6:09 ` Ingo Molnar
2006-12-10 14:18 ` Rafael J. Wysocki
2006-12-11 6:52 ` Dipankar Sarma
2006-12-11 16:34 ` Rafael J. Wysocki
2006-12-11 5:45 ` Srivatsa Vaddagiri
2006-12-11 6:03 ` Andrew Morton
2006-12-11 4:58 ` Srivatsa Vaddagiri
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20061207113700.dc925068.akpm@osdl.org \
--to=akpm@osdl.org \
--cc=axboe@kernel.dk \
--cc=bjorn.helgaas@hp.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=myron.stowe@hp.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®