public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Américo Wang" <xiyou.wangcong@gmail.com>
To: "Eric W. Biederman" <ebiederm@xmission.com>
Cc: "Greg Kroah-Hartman" <gregkh@suse.de>,
	"Américo Wang" <xiyou.wangcong@gmail.com>,
	"Tejun Heo <tj@kernel.org> Neil Brown" <neilb@suse.de>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 3/4] sysfs: Use one lockdep class per sysfs attribute.
Date: Mon, 15 Feb 2010 18:35:57 +0800	[thread overview]
Message-ID: <20100215103557.GJ12076@hack.private> (raw)
In-Reply-To: <m1hbpnwe7i.fsf_-_@fess.ebiederm.org>

On Thu, Feb 11, 2010 at 03:21:53PM -0800, Eric W. Biederman wrote:
>
>Acknowledge that the logical sysfs rwsem has one instance per
>sysfs attribute with different locking depencencies for different
>attributes.
>
>There is a sysfs idiom where writing to one sysfs file causes the
>addition or removal of other sysfs files.   Lumping all of the
>sysfs attributes together in one lock class causes lockdep to
>generate lots of false positives.
>
>This introduces the requirement that non-static sysfs attributes
>need to be initialized with sysfs_attr_init or sysfs_bin_attr_init.
>Strictly speaking this requirement only exists when lockdep is
>enabled, and when lockdep is enabled we get a bit fat warning
>if this requirement is not met.

Since there are fewer non-static attributes, this will not
waste much space.

>
>Signed-off-by: Eric W. Biederman <ebiederm@xmission.com>


Acked-by: WANG Cong <xiyou.wangcong@gmail.com>

>---
> fs/sysfs/sysfs.h      |    7 +++++--
> include/linux/sysfs.h |   18 ++++++++++++++++++
> 2 files changed, 23 insertions(+), 2 deletions(-)
>
>diff --git a/fs/sysfs/sysfs.h b/fs/sysfs/sysfs.h
>index 7db6884..37e0e08 100644
>--- a/fs/sysfs/sysfs.h
>+++ b/fs/sysfs/sysfs.h
>@@ -92,9 +92,12 @@ static inline unsigned int sysfs_type(struct sysfs_dirent *sd)
> #ifdef CONFIG_DEBUG_LOCK_ALLOC
> #define sysfs_dirent_init_lockdep(sd)				\
> do {								\
>-	static struct lock_class_key __key;			\
>+	struct attribute *attr = sd->s_attr.attr;		\
>+	struct lock_class_key *key = attr->key;			\
>+	if (!key)						\
>+		key = &attr->skey;				\
> 								\
>-	lockdep_init_map(&sd->dep_map, "s_active", &__key, 0);	\
>+	lockdep_init_map(&sd->dep_map, "s_active", key, 0);	\
> } while(0)
> #else
> #define sysfs_dirent_init_lockdep(sd) do {} while(0)
>diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
>index cfa8308..c3048de 100644
>--- a/include/linux/sysfs.h
>+++ b/include/linux/sysfs.h
>@@ -15,6 +15,7 @@
> #include <linux/compiler.h>
> #include <linux/errno.h>
> #include <linux/list.h>
>+#include <linux/lockdep.h>
> #include <asm/atomic.h>
> 
> struct kobject;
>@@ -29,8 +30,23 @@ struct attribute {
> 	const char		*name;
> 	struct module		*owner;
> 	mode_t			mode;
>+#ifdef CONFIG_DEBUG_LOCK_ALLOC
>+	struct lock_class_key	*key;
>+	struct lock_class_key	skey;
>+#endif
> };
> 
>+#ifdef CONFIG_DEBUG_LOCK_ALLOC
>+#define sysfs_attr_init(attr)				\
>+do {							\
>+	static struct lock_class_key __key;		\
>+							\
>+	(attr)->key = &__key;				\
>+} while(0)
>+#else
>+#define sysfs_attr_init(attr) do {} while(0)
>+#endif
>+
> struct attribute_group {
> 	const char		*name;
> 	mode_t			(*is_visible)(struct kobject *,
>@@ -74,6 +90,8 @@ struct bin_attribute {
> 		    struct vm_area_struct *vma);
> };
> 
>+#define sysfs_bin_attr_init(bin_attr) sysfs_attr_init(&bin_attr->attr)
>+
> struct sysfs_ops {
> 	ssize_t	(*show)(struct kobject *, struct attribute *,char *);
> 	ssize_t	(*store)(struct kobject *,struct attribute *,const char *, size_t);
>-- 
>1.6.5.2.143.g8cc62
>

-- 
Live like a child, think like the god.
 

  parent reply	other threads:[~2010-02-15 10:33 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                         ` Américo Wang [this message]
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
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=20100215103557.GJ12076@hack.private \
    --to=xiyou.wangcong@gmail.com \
    --cc=ebiederm@xmission.com \
    --cc=gregkh@suse.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=neilb@suse.de \
    /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