public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Jarek Poplawski <jarkao2@o2.pl>
To: linux-kernel@vger.kernel.org
Cc: Ingo Molnar <mingo@elte.hu>
Subject: [PATCH -mm] workqueue: debug possible lockups in flush_workqueue
Date: Thu, 19 Apr 2007 07:52:48 +0200	[thread overview]
Message-ID: <20070419055247.GA1782@ff.dom.local> (raw)

Hi,

Here is my patch proposal for detecting possible lockups,
when flush_workqueue caller holds a lock (e.g. rtnl_lock)
also used in work functions.

Regards,
Jarek P.

Signed-off-by: Jarek Poplawski <jarkao2@o2.pl>

---

diff -Nurp 2.6.21-rc6-mm1-/kernel/workqueue.c 2.6.21-rc6-mm1/kernel/workqueue.c
--- 2.6.21-rc6-mm1-/kernel/workqueue.c	2007-04-18 20:07:45.000000000 +0200
+++ 2.6.21-rc6-mm1/kernel/workqueue.c	2007-04-18 21:29:50.000000000 +0200
@@ -67,6 +67,12 @@ struct workqueue_struct {
 /* All the per-cpu workqueues on the system, for hotplug cpu to add/remove
    threads to each one as cpus come/go. */
 static DEFINE_MUTEX(workqueue_mutex);
+
+#ifdef CONFIG_PROVE_LOCKING
+/* Detect possible flush_workqueue() lockup with circular dependency check. */
+static struct lockdep_map flush_dep_map = { .name = "flush_dep_map" };
+#endif
+
 static LIST_HEAD(workqueues);
 
 static int singlethread_cpu __read_mostly;
@@ -247,8 +253,15 @@ static void run_workqueue(struct cpu_wor
 
 		BUG_ON(get_wq_data(work) != cwq);
 		work_clear_pending(work);
+#ifdef CONFIG_PROVE_LOCKING
+		/* lockdep dependency: flush_dep_map (read) before any lock: */
+		lock_acquire(&flush_dep_map, 0, 0, 1, 2, _THIS_IP_);
+#endif
 		f(work);
 
+#ifdef CONFIG_PROVE_LOCKING
+		lock_release(&flush_dep_map, 1, _THIS_IP_);
+#endif
 		if (unlikely(in_atomic() || lockdep_depth(current) > 0)) {
 			printk(KERN_ERR "BUG: workqueue leaked lock or atomic: "
 					"%s/0x%08x/%d\n",
@@ -389,6 +402,14 @@ void fastcall flush_workqueue(struct wor
 	int cpu;
 
 	might_sleep();
+#ifdef CONFIG_PROVE_LOCKING
+	/*
+	 * Add lockdep dependency: flush_dep_map (exclusive)
+	 * after any held mutex or rwsem.
+	 */
+	lock_acquire(&flush_dep_map, 0, 0, 0, 2, _THIS_IP_);
+	lock_release(&flush_dep_map, 1, _THIS_IP_);
+#endif
 	for_each_cpu_mask(cpu, *cpu_map)
 		flush_cpu_workqueue(per_cpu_ptr(wq->cpu_wq, cpu));
 }

             reply	other threads:[~2007-04-19  5:47 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-04-19  5:52 Jarek Poplawski [this message]
2007-04-19  6:14 ` [PATCH -mm] workqueue: debug possible lockups in flush_workqueue Ingo Molnar
2007-04-19  7:02   ` Jarek Poplawski

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=20070419055247.GA1782@ff.dom.local \
    --to=jarkao2@o2.pl \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    /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