From: Greg KH <greg@kroah.com>
To: linux-kernel@vger.kernel.org
Subject: Re: [PATCH] Driver Core patches for 2.6.6
Date: Fri, 14 May 2004 16:07:23 -0700 [thread overview]
Message-ID: <1084576043923@kroah.com> (raw)
In-Reply-To: <10845760433419@kroah.com>
ChangeSet 1.1587.5.27, 2004/05/11 16:43:50-07:00, maneesh@in.ibm.com
[PATCH] kobject/sysfs race fix
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 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 -Nru a/fs/sysfs/bin.c b/fs/sysfs/bin.c
--- a/fs/sysfs/bin.c Fri May 14 15:56:11 2004
+++ b/fs/sysfs/bin.c Fri May 14 15:56:11 2004
@@ -94,7 +94,7 @@
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;
diff -Nru a/fs/sysfs/file.c b/fs/sysfs/file.c
--- a/fs/sysfs/file.c Fri May 14 15:56:11 2004
+++ b/fs/sysfs/file.c Fri May 14 15:56:11 2004
@@ -238,7 +238,7 @@
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 -Nru a/fs/sysfs/sysfs.h b/fs/sysfs/sysfs.h
--- a/fs/sysfs/sysfs.h Fri May 14 15:56:11 2004
+++ b/fs/sysfs/sysfs.h Fri May 14 15:56:11 2004
@@ -11,3 +11,16 @@
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;
+}
next prev parent reply other threads:[~2004-05-14 23:08 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-05-14 23:06 [BK PATCH] Driver Core patches for 2.6.6 Greg KH
2004-05-14 23:07 ` [PATCH] " Greg KH
2004-05-14 23:07 ` Greg KH
2004-05-14 23:07 ` Greg KH
2004-05-14 23:07 ` Greg KH
2004-05-14 23:07 ` Greg KH
2004-05-14 23:07 ` Greg KH
2004-05-14 23:07 ` Greg KH
2004-05-14 23:07 ` Greg KH
2004-05-14 23:07 ` Greg KH
2004-05-14 23:07 ` Greg KH
2004-05-14 23:07 ` Greg KH
2004-05-14 23:07 ` Greg KH
2004-05-14 23:07 ` Greg KH
2004-05-14 23:07 ` Greg KH
2004-05-14 23:07 ` Greg KH
2004-05-14 23:07 ` Greg KH
2004-05-14 23:07 ` Greg KH [this message]
2004-05-14 23:07 ` Greg KH
2004-05-14 23:07 ` Greg KH
2004-05-14 23:24 ` zombies with AMD64 and 32 bit userspace with 2.6 David Lang
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=1084576043923@kroah.com \
--to=greg@kroah.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox