From: Greg KH <greg@kroah.com>
To: Maneesh Soni <maneesh@in.ibm.com>
Cc: Andrew Morton <akpm@osdl.org>,
Al Viro <viro@parcelfarce.linux.theplanet.co.uk>,
LKML <linux-kernel@vger.kernel.org>
Subject: Re: [linux-usb-devel] [PATCH] back out sysfs reference count change
Date: Thu, 15 Apr 2004 14:36:02 -0700 [thread overview]
Message-ID: <20040415213600.GD13578@kroah.com> (raw)
In-Reply-To: <20040414132015.GD5422@in.ibm.com>
On Wed, Apr 14, 2004 at 06:50:15PM +0530, Maneesh Soni wrote:
> On Tue, Apr 06, 2004 at 03:43:20PM +0530, Maneesh Soni wrote:
> [..]
> >
> > o The following patch fixes the race involved between unregistering a kobject
> > and simultaneously opeing a corresponding attribute file in sysfs.
> >
> > Ideally sysfs should take a ref. to the kobject as long as it has dentries
> > referring to the kobject, but because of current limitations in
> > module/kobject ref counting, sysfs's pinning of kobject leads to
> > hang/delays in rmmod of certain modules. The patch uses a new flag to mark
> > dentries as disconnected from a valid kobject in the process of unregistering
> > the kobject. The ->open in sysfs is failed if it finds a disconnected dentry.
> > Marking and checking for the flag is done under dentry->d_inode->i_sem.
> >
> [..]
>
>
> Hi Greg / Andrew,
>
> This problem can be solved without using the d_flags as I did previously.
> Viro suggested to just check for DCACHE_UNHASHED in check_perm() and this also
> solves the race. Please see the following patch instead of the previous one.
This patch looks sane, Andrew, can you let it sit in your -mm tree for a
while to see if anything breaks with it?
thanks,
greg k-h
----------------------------------------------------------------------------
o The following patch fixes the race involved between unregistering a kobject
and simultaneously opeing a corresponding attribute file in sysfs.
o Ideally sysfs should take a ref. to the kobject as long as it has dentries
referring to the kobjects, but because of current limitations in
module/kobject ref counting, sysfs's pinning of kobject leads to
hang/delays in rmmod of certain modules. The patch checks for unhashed
dentries in check_perm() while opening a sysfs file. If the dentry is
still hashed then it goes ahead and takes the ref to kobject. This done
under the per dentry lock. It does this in the inline routine
sysfs_get_kobject(dentry).
fs/sysfs/bin.c | 2 +-
fs/sysfs/file.c | 2 +-
fs/sysfs/sysfs.h | 13 +++++++++++++
3 files changed, 15 insertions(+), 2 deletions(-)
diff -puN fs/sysfs/sysfs.h~sysfs-d_fsdata-race-fix-2 fs/sysfs/sysfs.h
--- linux-2.6.5-mm5/fs/sysfs/sysfs.h~sysfs-d_fsdata-race-fix-2 2004-04-14 14:55:26.000000000 +0530
+++ linux-2.6.5-mm5-maneesh/fs/sysfs/sysfs.h 2004-04-14 15:29:51.000000000 +0530
@@ -11,3 +11,16 @@ extern void sysfs_hash_and_remove(struct
extern int sysfs_create_subdir(struct kobject *, const char *, struct dentry **);
extern void sysfs_remove_subdir(struct dentry *);
+
+
+static inline struct kobject * sysfs_get_kobject(struct dentry * dentry)
+{
+ struct kobject * kobj = NULL;
+
+ spin_lock(&dentry->d_lock);
+ if (!d_unhashed(dentry))
+ kobj = kobject_get(dentry->d_fsdata);
+ spin_unlock(&dentry->d_lock);
+
+ return kobj;
+}
diff -puN fs/sysfs/file.c~sysfs-d_fsdata-race-fix-2 fs/sysfs/file.c
--- linux-2.6.5-mm5/fs/sysfs/file.c~sysfs-d_fsdata-race-fix-2 2004-04-14 14:55:30.000000000 +0530
+++ linux-2.6.5-mm5-maneesh/fs/sysfs/file.c 2004-04-14 14:56:17.000000000 +0530
@@ -238,7 +238,7 @@ sysfs_write_file(struct file *file, cons
static int check_perm(struct inode * inode, struct file * file)
{
- struct kobject * kobj = kobject_get(file->f_dentry->d_parent->d_fsdata);
+ struct kobject * kobj = sysfs_get_kobject(file->f_dentry->d_parent);
struct attribute * attr = file->f_dentry->d_fsdata;
struct sysfs_buffer * buffer;
struct sysfs_ops * ops = NULL;
diff -puN fs/sysfs/bin.c~sysfs-d_fsdata-race-fix-2 fs/sysfs/bin.c
--- linux-2.6.5-mm5/fs/sysfs/bin.c~sysfs-d_fsdata-race-fix-2 2004-04-14 14:55:32.000000000 +0530
+++ linux-2.6.5-mm5-maneesh/fs/sysfs/bin.c 2004-04-14 14:56:17.000000000 +0530
@@ -94,7 +94,7 @@ static ssize_t write(struct file * file,
static int open(struct inode * inode, struct file * file)
{
- struct kobject * kobj = kobject_get(file->f_dentry->d_parent->d_fsdata);
+ struct kobject * kobj = sysfs_get_kobject(file->f_dentry->d_parent);
struct bin_attribute * attr = file->f_dentry->d_fsdata;
int error = -EINVAL;
next prev parent reply other threads:[~2004-04-15 21:54 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20040328063711.GA6387@kroah.com>
[not found] ` <Pine.LNX.4.44L0.0403281057100.17150-100000@netrider.rowland.org>
[not found] ` <20040328123857.55f04527.akpm@osdl.org>
[not found] ` <20040329210219.GA16735@kroah.com>
[not found] ` <20040329132551.23e12144.akpm@osdl.org>
2004-03-29 23:16 ` Unregistering interfaces Greg KH
2004-03-29 23:31 ` Andrew Morton
2004-03-30 0:01 ` Greg KH
2004-03-30 7:38 ` Maneesh Soni
2004-03-30 15:38 ` Alan Stern
2004-03-30 5:51 ` Maneesh Soni
2004-03-30 23:01 ` Greg KH
2004-03-30 23:16 ` Andrew Morton
2004-03-30 23:30 ` Greg KH
2004-03-30 23:57 ` Greg KH
2004-03-30 23:56 ` Alan Stern
2004-03-31 0:08 ` David Brownell
2004-03-31 0:34 ` Greg KH
2004-03-31 15:32 ` Alan Stern
2004-03-31 0:33 ` Greg KH
2004-03-31 15:54 ` Alan Stern
2004-04-01 7:24 ` Greg KH
2004-03-30 23:55 ` [PATCH] back out sysfs reference count change Greg KH
2004-03-31 2:11 ` [linux-usb-devel] " Benjamin Herrenschmidt
2004-03-31 2:19 ` Andrew Morton
2004-03-31 9:26 ` Maneesh Soni
2004-03-31 15:11 ` Alan Stern
2004-04-01 5:17 ` Maneesh Soni
2004-04-01 7:15 ` Greg KH
2004-04-01 14:56 ` Alan Stern
2004-04-02 4:38 ` Maneesh Soni
2004-04-02 21:41 ` Alan Stern
2004-04-06 10:13 ` Maneesh Soni
2004-04-06 17:03 ` Alan Stern
2004-04-14 13:20 ` Maneesh Soni
2004-04-15 21:36 ` Greg KH [this message]
2004-04-15 22:10 ` Andrew Morton
2004-04-16 8:42 ` Maneesh Soni
2004-03-31 22:18 ` Greg KH
2004-04-01 1:56 ` Benjamin Herrenschmidt
2004-04-01 3:48 ` Alan Stern
2004-04-01 6:55 ` Greg KH
2004-04-01 7:13 ` Benjamin Herrenschmidt
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=20040415213600.GD13578@kroah.com \
--to=greg@kroah.com \
--cc=akpm@osdl.org \
--cc=linux-kernel@vger.kernel.org \
--cc=maneesh@in.ibm.com \
--cc=viro@parcelfarce.linux.theplanet.co.uk \
/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