All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: Greg Kroah-Hartman <gregkh@suse.de>
Cc: linux-kernel@vger.kernel.org, achiang@hp.com, gregkh@suse.de,
	Lai Jiangshan <laijs@cn.fujitsu.com>
Subject: Re: [PATCH 01/10] sysfs: don't use global workqueue in sysfs_schedule_callback()
Date: Wed, 22 Apr 2009 13:14:02 -0700	[thread overview]
Message-ID: <20090422131402.b35a76bc.akpm@linux-foundation.org> (raw)
In-Reply-To: <1239995074-4065-1-git-send-email-gregkh@suse.de>

On Fri, 17 Apr 2009 12:04:25 -0700
Greg Kroah-Hartman <gregkh@suse.de> wrote:

> From: Alex Chiang <achiang@hp.com>
> 
> A sysfs attribute using sysfs_schedule_callback() to commit suicide
> may end up calling device_unregister(), which will eventually call
> a driver's ->remove function.
> 
> Drivers may call flush_scheduled_work() in their shutdown routines,
> in which case lockdep will complain with something like the following:
> 
>   =============================================
>   [ INFO: possible recursive locking detected ]
>   2.6.29-rc8-kk #1
>   ---------------------------------------------
>   events/4/56 is trying to acquire lock:
>   (events){--..}, at: [<ffffffff80257fc0>] flush_workqueue+0x0/0xa0
> 
>   but task is already holding lock:
>   (events){--..}, at: [<ffffffff80257648>] run_workqueue+0x108/0x230
> 
>   other info that might help us debug this:
>   3 locks held by events/4/56:
>   #0:  (events){--..}, at: [<ffffffff80257648>] run_workqueue+0x108/0x230
>   #1:  (&ss->work){--..}, at: [<ffffffff80257648>] run_workqueue+0x108/0x230
>   #2:  (pci_remove_rescan_mutex){--..}, at: [<ffffffff803c10d1>] remove_callback+0x21/0x40
> 
>   stack backtrace:
>   Pid: 56, comm: events/4 Not tainted 2.6.29-rc8-kk #1
>   Call Trace:
>   [<ffffffff8026dfcd>] validate_chain+0xb7d/0x1260
>   [<ffffffff8026eade>] __lock_acquire+0x42e/0xa40
>   [<ffffffff8026f148>] lock_acquire+0x58/0x80
>   [<ffffffff80257fc0>] ? flush_workqueue+0x0/0xa0
>   [<ffffffff8025800d>] flush_workqueue+0x4d/0xa0
>   [<ffffffff80257fc0>] ? flush_workqueue+0x0/0xa0
>   [<ffffffff80258070>] flush_scheduled_work+0x10/0x20
>   [<ffffffffa0144065>] e1000_remove+0x55/0xfe [e1000e]
>   [<ffffffff8033ee30>] ? sysfs_schedule_callback_work+0x0/0x50
>   [<ffffffff803bfeb2>] pci_device_remove+0x32/0x70
>   [<ffffffff80441da9>] __device_release_driver+0x59/0x90
>   [<ffffffff80441edb>] device_release_driver+0x2b/0x40
>   [<ffffffff804419d6>] bus_remove_device+0xa6/0x120
>   [<ffffffff8043e46b>] device_del+0x12b/0x190
>   [<ffffffff8043e4f6>] device_unregister+0x26/0x70
>   [<ffffffff803ba969>] pci_stop_dev+0x49/0x60
>   [<ffffffff803baab0>] pci_remove_bus_device+0x40/0xc0
>   [<ffffffff803c10d9>] remove_callback+0x29/0x40
>   [<ffffffff8033ee4f>] sysfs_schedule_callback_work+0x1f/0x50
>   [<ffffffff8025769a>] run_workqueue+0x15a/0x230
>   [<ffffffff80257648>] ? run_workqueue+0x108/0x230
>   [<ffffffff8025846f>] worker_thread+0x9f/0x100
>   [<ffffffff8025bce0>] ? autoremove_wake_function+0x0/0x40
>   [<ffffffff802583d0>] ? worker_thread+0x0/0x100
>   [<ffffffff8025b89d>] kthread+0x4d/0x80
>   [<ffffffff8020d4ba>] child_rip+0xa/0x20
>   [<ffffffff8020cebc>] ? restore_args+0x0/0x30
>   [<ffffffff8025b850>] ? kthread+0x0/0x80
>   [<ffffffff8020d4b0>] ? child_rip+0x0/0x20
> 
> Although we know that the device_unregister path will never acquire
> a lock that a driver might try to acquire in its ->remove, in general
> we should never attempt to flush a workqueue from within the same
> workqueue, and lockdep rightly complains.
> 
> So as long as sysfs attributes cannot commit suicide directly and we
> are stuck with this callback mechanism, put the sysfs callbacks on
> their own workqueue instead of the global one.
> 
> This has the side benefit that if a suicidal sysfs attribute kicks
> off a long chain of ->remove callbacks, we no longer induce a long
> delay on the global queue.

I still don't know why I merged 

: commit 2355b70fd59cb5be7de2052a9edeee7afb7ff099
: Author: Lai Jiangshan <laijs@cn.fujitsu.com>
: Date:   Thu Apr 2 16:58:24 2009 -0700
:
:    workqueue: avoid recursion in run_workqueue()

there was nothing wrong with permitting limited recursion into
run_workqueue().  It never deadlocked and the three-deep-recursion
warning never triggered.

> +	if (sysfs_workqueue == NULL) {
> +		sysfs_workqueue = create_workqueue("sysfsd");
> +		if (sysfs_workqueue == NULL) {
> +			module_put(owner);
> +			return -ENOMEM;
> +		}
> +	}

This will create a kernel thread per CPU.  Surely
create_singlethread_workqueue() will suffice?


  reply	other threads:[~2009-04-22 20:17 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-04-17 19:01 [GIT PATCH] driver core patches for 2.6.31-rc2 Greg KH
2009-04-17 19:04 ` [PATCH 01/10] sysfs: don't use global workqueue in sysfs_schedule_callback() Greg Kroah-Hartman
2009-04-22 20:14   ` Andrew Morton [this message]
2009-04-28  5:15     ` Alex Chiang
2009-04-17 19:04 ` [PATCH 02/10] driver core: fix driver_match_device Greg Kroah-Hartman
2009-04-17 19:04 ` [PATCH 03/10] driver core: allow non-root users to listen to uevents Greg Kroah-Hartman
2009-04-17 19:04 ` [PATCH 04/10] sysfs: sysfs poll keep the poll rule of regular file Greg Kroah-Hartman
2009-04-17 19:04 ` [PATCH 05/10] proc: mounts_poll() make consistent to mdstat_poll Greg Kroah-Hartman
2009-04-17 19:04 ` [PATCH 06/10] Driver Core: early platform driver Greg Kroah-Hartman
2009-04-17 19:04 ` [PATCH 07/10] dynamic debug: resurrect old pr_debug() semantics as pr_devel() Greg Kroah-Hartman
2009-04-17 19:04 ` [PATCH 08/10] driver core: prevent device_for_each_child from oopsing Greg Kroah-Hartman
2009-04-17 19:04 ` [PATCH 09/10] Driver core: remove pr_fmt() from dynamic_dev_dbg() printk Greg Kroah-Hartman
2009-04-17 19:04 ` [PATCH 10/10] UIO: fix specific device driver missing statement for depmod Greg Kroah-Hartman
2009-04-18  3:57 ` [GIT PATCH] driver core patches for 2.6.31-rc2 KOSAKI Motohiro
2009-04-18 16:50   ` Greg KH

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=20090422131402.b35a76bc.akpm@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=achiang@hp.com \
    --cc=gregkh@suse.de \
    --cc=laijs@cn.fujitsu.com \
    --cc=linux-kernel@vger.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.