LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH] workqueue: detect uninitated work_struct and BUG() if true
@ 2015-03-09  4:43 Du, Changbin
  2015-03-09  6:22 ` Tejun Heo
  0 siblings, 1 reply; 3+ messages in thread
From: Du, Changbin @ 2015-03-09  4:43 UTC (permalink / raw)
  To: Tejun Heo; +Cc: linux-kernel

>From cdebb88ac0fb3f900ef28f28ccb4a12159c295db Mon Sep 17 00:00:00 2001
From: "Du, Changbin" <changbin.du@gmail.com>
Date: Mon, 9 Mar 2015 12:06:43 +0800
Subject: [PATCH] workqueue: detect uninitated work_struct and BUG() if true

Recently I encounter a driver issue that caused by missing initializing
the work_struct. Then the work never get executed and stay in workqueue
forever. This take me some time to locate the error. This issue can be
seen early if detect it when queuing a work.

Signed-off-by: Du, Changbin <changbin.du@intel.com>
---
 kernel/workqueue.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index f288493..5c1a5bc 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -1295,6 +1295,9 @@ static void __queue_work(int cpu, struct workqueue_struct *wq,
 	 */
 	WARN_ON_ONCE(!irqs_disabled());
 
+	if (!work->func)
+		BUG();
+
 	debug_work_activate(work);
 
 	/* if draining, only works from the same workqueue are allowed */
-- 
1.9.1


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

* Re: [PATCH] workqueue: detect uninitated work_struct and BUG() if true
  2015-03-09  4:43 [PATCH] workqueue: detect uninitated work_struct and BUG() if true Du, Changbin
@ 2015-03-09  6:22 ` Tejun Heo
  2015-03-10 13:20   ` Du, Changbin
  0 siblings, 1 reply; 3+ messages in thread
From: Tejun Heo @ 2015-03-09  6:22 UTC (permalink / raw)
  To: Du, Changbin; +Cc: linux-kernel

On Mon, Mar 09, 2015 at 04:43:11AM +0000, Du, Changbin wrote:
> From cdebb88ac0fb3f900ef28f28ccb4a12159c295db Mon Sep 17 00:00:00 2001
> From: "Du, Changbin" <changbin.du@gmail.com>
> Date: Mon, 9 Mar 2015 12:06:43 +0800
> Subject: [PATCH] workqueue: detect uninitated work_struct and BUG() if true
> 
> Recently I encounter a driver issue that caused by missing initializing
> the work_struct. Then the work never get executed and stay in workqueue
> forever. This take me some time to locate the error. This issue can be
> seen early if detect it when queuing a work.
> 
> Signed-off-by: Du, Changbin <changbin.du@intel.com>
> ---
>  kernel/workqueue.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/kernel/workqueue.c b/kernel/workqueue.c
> index f288493..5c1a5bc 100644
> --- a/kernel/workqueue.c
> +++ b/kernel/workqueue.c
> @@ -1295,6 +1295,9 @@ static void __queue_work(int cpu, struct workqueue_struct *wq,
>  	 */
>  	WARN_ON_ONCE(!irqs_disabled());
>  
> +	if (!work->func)
> +		BUG();
> +
>  	debug_work_activate(work);

Can't this be part of the debug_work mechanism?  I'm a bit wary of
adding essentially arbitrary checks.  I'd much prefer if it gets gated
by debug config somehow.

Thanks.

-- 
tejun

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

* RE: [PATCH] workqueue: detect uninitated work_struct and BUG() if true
  2015-03-09  6:22 ` Tejun Heo
@ 2015-03-10 13:20   ` Du, Changbin
  0 siblings, 0 replies; 3+ messages in thread
From: Du, Changbin @ 2015-03-10 13:20 UTC (permalink / raw)
  To: Tejun Heo; +Cc: linux-kernel

> -----Original Message-----
> From: Tejun Heo [mailto:htejun@gmail.com] On Behalf Of Tejun Heo
> Sent: Monday, March 9, 2015 2:23 PM
> To: Du, Changbin
> Cc: linux-kernel@vger.kernel.org
> Subject: Re: [PATCH] workqueue: detect uninitated work_struct and BUG() if
> true
> > @@ -1295,6 +1295,9 @@ static void __queue_work(int cpu, struct
> workqueue_struct *wq,
> >  	 */
> >  	WARN_ON_ONCE(!irqs_disabled());
> >
> > +	if (!work->func)
> > +		BUG();
> > +
> >  	debug_work_activate(work);
> 
> Can't this be part of the debug_work mechanism?  I'm a bit wary of adding
> essentially arbitrary checks.  I'd much prefer if it gets gated by debug config
> somehow.
> 
> Thanks.
> Tejun

Yes, I found there already have this checking and print a warning in work_fixup_activate.
So this patch can be droped. Thanks for point out.

static int work_fixup_activate(void *addr, enum debug_obj_state state)
{
	struct work_struct *work = addr;

	switch (state) {

	case ODEBUG_STATE_NOTAVAILABLE:
		/*
		 * This is not really a fixup. The work struct was
		 * statically initialized. We just make sure that it
		 * is tracked in the object tracker.
		 */
		if (test_bit(WORK_STRUCT_STATIC_BIT, work_data_bits(work))) {
			debug_object_init(work, &work_debug_descr);
			debug_object_activate(work, &work_debug_descr);
			return 0;
		}
		WARN_ON_ONCE(1);

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

end of thread, other threads:[~2015-03-10 13:20 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-09  4:43 [PATCH] workqueue: detect uninitated work_struct and BUG() if true Du, Changbin
2015-03-09  6:22 ` Tejun Heo
2015-03-10 13:20   ` Du, Changbin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).