public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Tejun Heo <tj@kernel.org>
To: Alan Stern <stern@rowland.harvard.edu>
Cc: Kernel development list <linux-kernel@vger.kernel.org>
Subject: Re: Warn people about flush_scheduled_work()
Date: Tue, 15 Dec 2009 07:38:31 +0900	[thread overview]
Message-ID: <4B26BE67.5060107@kernel.org> (raw)
In-Reply-To: <Pine.LNX.4.44L0.0912141619410.2690-100000@iolanthe.rowland.org>

Hello, Alan Stern.

On 12/15/2009 06:33 AM, Alan Stern wrote:
> You've spent some time working on the workqueue implementation, right?  
> I'd like to add comments or kerneldoc warning people about how 
> dangerous it can be to use flush_scheduled_work() and related 
> functions.  Something like this:
> 
> 	Think twice before calling this function!  It's very easy
> 	to get into trouble if you don't take great care.  Either
> 	of the following situations will lead to deadlock:
> 
> 		Your code is running in the context of a scheduled
> 		work routine.
>
> 		Your code or its caller holds a lock needed by
> 		one of the work items currently on the workqueue.
>
> 	Since you generally don't know who your caller is, what locks
> 	it holds, or what locks are needed by the items on the 
> 	workqueue, avoiding these situations is quite difficult.

I think both problems can be detected by lockdep, right?  So, they
aren't that difficult to detect.

> 	Consider using cancel_work_sync() or cancel_delayed_work_sync()
> 	instead.  In most situations they will accomplish what you 
> 	need.
> 
> Does this sound like a good idea?  Certainly flush_scheduled_work()  
> is used in places where it shouldn't be.

Yeah, recommending more work-specific constructs definitely would be
better.  It's bad that we can't recommend the use of flush_work() as
it doesn't do cross-cpu flushing.  Maybe that needs explanation too.

> If comments like this are added, where do you think would be a good 
> place to put them?

DocBook comment on top of each function, maybe?

Thanks.

-- 
tejun

  parent reply	other threads:[~2009-12-14 22:38 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-12-14 21:33 Warn people about flush_scheduled_work() Alan Stern
2009-12-14 21:42 ` Oliver Neukum
2009-12-14 22:02   ` Alan Stern
2009-12-14 22:12     ` Oliver Neukum
2009-12-14 23:04       ` Alan Stern
2009-12-14 22:38 ` Tejun Heo [this message]
2009-12-14 23:14   ` Alan Stern
2009-12-14 23:25     ` Tejun Heo
2009-12-16 15:52   ` [PATCH] Warn " Alan Stern
2009-12-21  8:26     ` Tejun Heo
2010-02-12  8:47       ` Tejun Heo

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=4B26BE67.5060107@kernel.org \
    --to=tj@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stern@rowland.harvard.edu \
    /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