public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: "Eric W. Biederman" <ebiederm@xmission.com>
Cc: "Neil Brown" <neilb@suse.de>, "Tejun Heo" <tj@kernel.org>,
	"Greg Kroah-Hartman" <gregkh@suse.de>,
	linux-kernel@vger.kernel.org,
	"Américo Wang" <xiyou.wangcong@gmail.com>
Subject: Re: [PATCH] sysfs: differentiate  between locking links and non-links
Date: Wed, 10 Feb 2010 09:55:51 -0800	[thread overview]
Message-ID: <201002100955.52493.dmitry.torokhov@gmail.com> (raw)
In-Reply-To: <m1636556xr.fsf@fess.ebiederm.org>

On Wednesday 10 February 2010 09:36:32 am Eric W. Biederman wrote:
> Neil Brown <neilb@suse.de> writes:
> > Hi,
> >  I've just spent a while sorting out some lockdep complaints triggered
> >  by the recent addition of the "s_active" lockdep annotation in sysfs
> >   (commit 846f99749ab68bbc7f75c74fec305de675b1a1bf)
> >
> >  Some of them are genuine and I have submitted a fix for those.
> >  Some are, I think, debatable and I get to that is a minute.  I've
> >  submitted a fix for them anyway.
> >  But some are to my mind clearly bogus and I'm hoping that can be
> >  fixed by the change below (or similar).
> >  The 'bogus' ones are triggered by writing to a sysfs attribute file
> >  for which the handler tries to delete a symlink from sysfs.
> >  This appears to be a recursion on s_active as s_active is held while
> >  the handler runs and is again needed to effect the delete.  However
> >  as the thing being deleted is a symlink, it is very clearly a
> >  different object to the thing triggering the delete, so there is no
> >  real loop.
> >
> >  The following patch splits the lockdep context in two - one for
> >  symlink and one for everything else.  This removes the apparent loop.
> >  (An example report can be seen in
> >      http://bugzilla.kernel.org/show_bug.cgi?id=15142).
> >
> >  The "debatable" dependency loops happen when writing to one attribute
> >  causes a different attribute to be deleted.  In my (md) case this can
> >  actually cause a deadlock as both the attributes take the same lock
> >  while the handler is running.  This is because deleting the attribute
> >  will block until the all accesses of that attribute have completed (I
> >  think).
> 
> You are correct.  Not until the file handles are closed but until all
> users of the underyling methods are complete.
> 
> >  However it should be possible to delete a name from sysfs while there
> >  are still accesses pending (it works for normal files!!).  So if
> >  sysfs could be changed to simply unlink the file and leave deletion to
> >  happen when the refcount become zero it would certainly make my life
> >  a lot easier, and allow the removal of some ugly code from md.c.
> >  I don't know sysfs well enough to suggest a patch though.
> 
> Thanks for this.
> 
> Separating out symlinks and treating them differently because they can not
> cause problems is definitely worth doing.  We never take an active
>  reference in the symlink code so we can never block waiting for symlinks
>  to be deleted.
> 
> 
> We block when deleting files in sysfs (and proc and sysctl).  If we
> did not block we could follow pointers into modules that are being
> deleted, or those methods that are running could access data
> structures that we want to tear down (perhaps there is a lock we want
> to kfree).  Blocking in sysfs is to simplify the life of the callers.
> Unfortunately for a handful of callers it complicates things.

Exactly. Before Tejun changed sysfs to provide guarantee that no
show/store methods are still running, nor new references to the
corresponding kobject will be acquired through sysfs after
sysfs_remove_file() returns, you had to jump through million of
hoops at subsystem level to work with lifetime rules and work around
the fact that kobjects could outlive your module.

I was glad to see bunch of ugly code in serio, gameport and input go
and I do not want it coming back ;)

> 
> If you want to compare this to regular files think of what sysfs is
> doing as a combined remove and revoke.  The remove is easy.  Revoke
> is just plane difficult.
> 
> Eric

-- 
Dmitry

  reply	other threads:[~2010-02-10 17:56 UTC|newest]

Thread overview: 52+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-02-10  1:09 [PATCH] sysfs: differentiate between locking links and non-links Neil Brown
2010-02-10  1:21 ` David Rientjes
2010-02-10  1:56   ` Américo Wang
2010-02-10  3:05     ` David Rientjes
2010-02-10  3:14       ` Américo Wang
2010-02-10  3:19         ` David Rientjes
2010-02-10  3:33           ` Américo Wang
2010-02-10  2:08 ` Américo Wang
2010-02-10  2:19   ` Tejun Heo
2010-02-10  3:12     ` Américo Wang
2010-02-10  8:03     ` Eric W. Biederman
2010-02-10 10:39       ` Tejun Heo
2010-02-10 18:25         ` Eric W. Biederman
2010-02-10 23:05           ` Greg KH
2010-02-11  1:31             ` Eric W. Biederman
2010-02-11  2:10               ` Tejun Heo
2010-02-11 18:08                 ` Eric W. Biederman
2010-02-12  0:59                   ` Tejun Heo
2010-02-12  1:20                     ` Eric W. Biederman
2010-02-12  1:20                     ` Eric W. Biederman
2010-02-12  2:16                       ` Tejun Heo
2010-02-11 23:13                 ` [PATCH 0/4] Better sysfs lockdep Eric W. Biederman
2010-02-11 23:14                   ` [PATCH 1/4] sysfs: Remove sysfs_get/put_active_two Eric W. Biederman
2010-02-11 23:20                     ` [PATCH 2/4] sysfs: Only take active references on attributes Eric W. Biederman
2010-02-11 23:21                       ` [PATCH 3/4] sysfs: Use one lockdep class per sysfs attribute Eric W. Biederman
2010-02-11 23:23                         ` [PATCH 4/4] sysfs: Use sysfs_attr_init and sysfs_bin_attr_init on dynamic attributes Eric W. Biederman
2010-02-11 23:42                           ` Greg KH
2010-02-12 12:47                             ` [PATCH] sysfs: Document sysfs_attr_init and sysfs_bin_attr_init Eric W. Biederman
2010-02-12 21:41                               ` [PATCH] sysfs: Use sysfs_attr_init and sysfs_bin_attr_init on module dynamic attributes Eric W. Biederman
2010-02-15 10:38                           ` [PATCH 4/4] sysfs: Use sysfs_attr_init and sysfs_bin_attr_init on " Américo Wang
2010-02-15 12:53                             ` Eric W. Biederman
2010-02-15 10:35                         ` [PATCH 3/4] sysfs: Use one lockdep class per sysfs attribute Américo Wang
2010-02-15  7:27                       ` [PATCH 2/4] sysfs: Only take active references on attributes Américo Wang
2010-02-15  8:15                         ` Américo Wang
2010-02-15  8:31                           ` Américo Wang
2010-02-15 10:11                           ` Eric W. Biederman
2010-02-15  7:03                     ` [PATCH 1/4] sysfs: Remove sysfs_get/put_active_two Américo Wang
2010-02-11 23:18                   ` Eric W. Biederman
2010-02-11 23:17                 ` [PATCH 0/4] Better sysfs lockdep Eric W. Biederman
2010-02-11 23:43                   ` Greg KH
2010-02-10 23:54           ` [PATCH] sysfs: differentiate between locking links and non-links Tejun Heo
2010-02-11  0:38             ` Eric W. Biederman
2010-02-10 17:36 ` Eric W. Biederman
2010-02-10 17:55   ` Dmitry Torokhov [this message]
2010-02-10 23:06 ` Greg KH
2010-02-11 21:42   ` Eric W. Biederman
2010-02-11 22:32     ` Greg KH
2010-02-11 22:47       ` Eric W. Biederman
2010-02-17 22:38         ` Greg KH
2010-02-18  0:39           ` Neil Brown
2010-02-18  1:01             ` Eric W. Biederman
2010-02-18  1:12               ` 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=201002100955.52493.dmitry.torokhov@gmail.com \
    --to=dmitry.torokhov@gmail.com \
    --cc=ebiederm@xmission.com \
    --cc=gregkh@suse.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=neilb@suse.de \
    --cc=tj@kernel.org \
    --cc=xiyou.wangcong@gmail.com \
    /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