All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yong Zhang <yong.zhang0@gmail.com>
To: Andy Walls <awalls@md.metrocast.net>, Tejun Heo <tj@kernel.org>
Cc: Yong Zhang <yong.zhang0@gmail.com>,
	linux-kernel@vger.kernel.org, nicolas.mailhot@laposte.net,
	Jarod Wilson <jarod@redhat.com>, Ingo Molnar <mingo@redhat.com>,
	Mauro Carvalho Chehab <mchehab@redhat.com>,
	Hans Verkuil <hverkuil@xs4all.nl>,
	Andrew Morton <akpm@linux-foundation.org>
Subject: [V3 PATCH] kthread_work: Make lockdep happy
Date: Wed, 22 Dec 2010 11:23:05 +0800	[thread overview]
Message-ID: <20101222032305.GA30724@windriver.com> (raw)
In-Reply-To: <1292978393.2401.14.camel@morgan.silverblock.net>

From: Yong Zhang <yong.zhang0@gmail.com>
Subject: [V3 PATCH] kthread_work: Make lockdep happy

spinlock in kthread_worker and wait_queue_head in kthread_work
both should be lockdep sensible.
So change the interface to make it suiltable for CONFIG_LOCKDEP.

Reported-by: Nicolas <nicolas.mailhot@laposte.net>
Signed-off-by: Yong Zhang <yong.zhang0@gmail.com>
Signed-off-by: Andy Walls <awalls@md.metrocast.net>
Tested-by: Andy Walls <awalls@md.metrocast.net>
Cc: Tejun Heo <tj@kernel.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
---
Cahgnes form V2:
 *export __init_kthread_worker, fix module build issue.
 *explicitly name worker->lock, which will make debug more easy.
  idea from Andy Walls.

Changes from V1:
 *According to Tejun, kthread_worker could be defined on stack,
  So introduce DEFINE_KTHREAD_WORKER_ONSTACK.
 *Change wrong setting to kthread_work->task. Thanks Adny for
  pointing it.
 *including some minor issue.

 include/linux/kthread.h |   45 +++++++++++++++++++++++++++++++++++----------
 kernel/kthread.c        |   11 +++++++++++
 2 files changed, 46 insertions(+), 10 deletions(-)

diff --git a/include/linux/kthread.h b/include/linux/kthread.h
index 685ea65..fa48dfc 100644
--- a/include/linux/kthread.h
+++ b/include/linux/kthread.h
@@ -81,16 +81,41 @@ struct kthread_work {
 #define DEFINE_KTHREAD_WORK(work, fn)					\
 	struct kthread_work work = KTHREAD_WORK_INIT(work, fn)
 
-static inline void init_kthread_worker(struct kthread_worker *worker)
-{
-	*worker = (struct kthread_worker)KTHREAD_WORKER_INIT(*worker);
-}
-
-static inline void init_kthread_work(struct kthread_work *work,
-				     kthread_work_func_t fn)
-{
-	*work = (struct kthread_work)KTHREAD_WORK_INIT(*work, fn);
-}
+/*
+ * kthread_worker.lock and kthread_work.done need
+ * special work if they are defined on stack with
+ * lockdep enabled.
+ */
+#ifdef CONFIG_LOCKDEP
+# define KTHREAD_WORKER_INIT_ONSTACK(worker)				\
+	({ init_kthread_worker(&worker); worker; })
+# define DEFINE_KTHREAD_WORKER_ONSTACK(worker)				\
+	struct kthread_worker worker = KTHREAD_WORKER_INIT_ONSTACK(worker)
+# define KTHREAD_WORK_INIT_ONSTACK(work, fn)				\
+	({ init_kthread_work((&work), fn); work; })
+# define DEFINE_KTHREAD_WORK_ONSTACK(work, fn)				\
+	struct kthread_work work = KTHREAD_WORK_INIT_ONSTACK(work, fn)
+#else
+# define DEFINE_KTHREAD_WORKER_ONSTACK(worker) DEFINE_KTHREAD_WORKER(worker)
+# define DEFINE_KTHREAD_WORK_ONSTACK(work, fn) DEFINE_KTHREAD_WORK(work, fn)
+#endif
+
+extern void __init_kthread_worker(struct kthread_worker *worker,
+			const char *name, struct lock_class_key *key);
+
+#define init_kthread_worker(worker)					\
+	do {								\
+		static struct lock_class_key __key;			\
+		__init_kthread_worker((worker), "("#worker")->lock", &__key); \
+	} while (0)
+
+#define init_kthread_work(work, fn)					\
+	do {								\
+		memset((work), 0, sizeof(struct kthread_work));		\
+		INIT_LIST_HEAD(&(work)->node);				\
+		(work)->func = (fn);					\
+		init_waitqueue_head(&(work)->done);			\
+	} while (0)
 
 int kthread_worker_fn(void *worker_ptr);
 
diff --git a/kernel/kthread.c b/kernel/kthread.c
index 2dc3786..ca61bbd 100644
--- a/kernel/kthread.c
+++ b/kernel/kthread.c
@@ -265,6 +265,17 @@ int kthreadd(void *unused)
 	return 0;
 }
 
+void __init_kthread_worker(struct kthread_worker *worker,
+				const char *name,
+				struct lock_class_key *key)
+{
+	spin_lock_init(&worker->lock);
+	lockdep_set_class_and_name(&worker->lock, key, name);
+	INIT_LIST_HEAD(&worker->work_list);
+	worker->task = NULL;
+}
+EXPORT_SYMBOL_GPL(__init_kthread_worker);
+
 /**
  * kthread_worker_fn - kthread function to process kthread_worker
  * @worker_ptr: pointer to initialized kthread_worker
-- 
1.7.0.4


  parent reply	other threads:[~2010-12-22  3:23 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-12-19 12:49 [PATCH] kthread_worker: Initialize dynamically allocated spinlock properly for lockdep Andy Walls
2010-12-20  7:07 ` Yong Zhang
2010-12-20  9:28   ` Yong Zhang
2010-12-20 16:21     ` Tejun Heo
2010-12-21  1:54       ` Yong Zhang
2010-12-21  4:40       ` [V2 PATCH] kthread_work: Make lockdep happy Yong Zhang
2010-12-21 12:59         ` Tejun Heo
2010-12-21 13:25           ` Nicolas Mailhot
2010-12-21 16:07           ` Andy Walls
2010-12-22  0:39         ` Andy Walls
2010-12-22  3:12           ` Yong Zhang
2010-12-22  3:23           ` Yong Zhang [this message]
2010-12-22  9:33             ` [V3 " Tejun Heo
2010-12-20 17:16     ` [PATCH] kthread_worker: Initialize dynamically allocated spinlock properly for lockdep Andy Walls
2010-12-21  2:02       ` Yong Zhang

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=20101222032305.GA30724@windriver.com \
    --to=yong.zhang0@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=awalls@md.metrocast.net \
    --cc=hverkuil@xs4all.nl \
    --cc=jarod@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mchehab@redhat.com \
    --cc=mingo@redhat.com \
    --cc=nicolas.mailhot@laposte.net \
    --cc=tj@kernel.org \
    /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 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.