linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* proc:Add a reference of module when proc_reg_file opened
@ 2012-02-26  6:34 majianpeng
  2012-02-26  7:50 ` Al Viro
  0 siblings, 1 reply; 2+ messages in thread
From: majianpeng @ 2012-02-26  6:34 UTC (permalink / raw)
  To: viro; +Cc: linux-fsdevel

>From 49b46362bf3221a259bfc73105ad041376b66878 Mon Sep 17 00:00:00 2001
From: majianpeng <majianpeng@gmail.com>
Date: Sun, 26 Feb 2012 22:19:51 +0800
Subject: [PATCH] proc:Add a reference of module when proc_reg_file opened.

If struct file_operations of a regular file in procfs defined in module
and defined .owner = THIS_MODULE,open this file must get a reference of
module.

Signed-off-by: majianpeng <majianpeng@gmail.com>
---
 fs/proc/inode.c |   13 +++++++++++--
 1 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/fs/proc/inode.c b/fs/proc/inode.c
index 84fd323..78dbb03 100644
--- a/fs/proc/inode.c
+++ b/fs/proc/inode.c
@@ -317,6 +317,7 @@ static int proc_reg_open(struct inode *inode, struct file *file)
 	int (*open)(struct inode *, struct file *);
 	int (*release)(struct inode *, struct file *);
 	struct pde_opener *pdeo;
+	const struct file_operations *fops;
 
 	/*
 	 * What for, you ask? Well, we can have open, rmmod, remove_proc_entry
@@ -339,7 +340,12 @@ static int proc_reg_open(struct inode *inode, struct file *file)
 		return -ENOENT;
 	}
 	pde->pde_users++;
-	open = pde->proc_fops->open;
+	/*
+	 *If proc_fops defined in module and used .owner = THIS_MODULE,so open must
+	 *get a reference of module.
+	 */
+	fops = fops_get(pde->proc_fops);
+	open = fops->open;
 	release = pde->proc_fops->release;
 	spin_unlock(&pde->pde_unload_lock);
 
@@ -354,8 +360,10 @@ static int proc_reg_open(struct inode *inode, struct file *file)
 		/* Strictly for "too late" ->release in proc_reg_release(). */
 		pdeo->release = release;
 		list_add(&pdeo->lh, &pde->pde_openers);
-	} else
+	} else	{
+		fops_put(pde->proc_fops);
 		kfree(pdeo);
+	}
 	__pde_users_dec(pde);
 	spin_unlock(&pde->pde_unload_lock);
 	return rv;
@@ -402,6 +410,7 @@ static int proc_reg_release(struct inode *inode, struct file *file)
 	}
 	pde->pde_users++;
 	release = pde->proc_fops->release;
+	fops_put(pde->proc_fops);
 	if (pdeo) {
 		list_del(&pdeo->lh);
 		kfree(pdeo);
-- 
1.7.5.4

 				
--------------
majianpeng
2012-02-26


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: proc:Add a reference of module when proc_reg_file opened
  2012-02-26  6:34 proc:Add a reference of module when proc_reg_file opened majianpeng
@ 2012-02-26  7:50 ` Al Viro
  0 siblings, 0 replies; 2+ messages in thread
From: Al Viro @ 2012-02-26  7:50 UTC (permalink / raw)
  To: majianpeng; +Cc: linux-fsdevel

On Sun, Feb 26, 2012 at 02:34:48PM +0800, majianpeng wrote:
> >From 49b46362bf3221a259bfc73105ad041376b66878 Mon Sep 17 00:00:00 2001
> From: majianpeng <majianpeng@gmail.com>
> Date: Sun, 26 Feb 2012 22:19:51 +0800
> Subject: [PATCH] proc:Add a reference of module when proc_reg_file opened.
> 
> If struct file_operations of a regular file in procfs defined in module
> and defined .owner = THIS_MODULE,open this file must get a reference of
> module.

No.  Read remove_proc_entry(), especially the part under ->pde_unload_lock.
The whole damn point of that stuff is that opened file on procfs does *not*
pin the module down; IO in progress does, but that's it.

You can't deadlock rmmod foobar </proc/crap/foobar; with your patch we'll
be back to a pile of deadlocks in there.

IOW, NAK.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2012-02-26  7:50 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-02-26  6:34 proc:Add a reference of module when proc_reg_file opened majianpeng
2012-02-26  7:50 ` Al Viro

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).