mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] d_drop should use per dentry lock
@ 2005-01-28 15:58 Jan Blunck
  0 siblings, 0 replies; only message in thread
From: Jan Blunck @ 2005-01-28 15:58 UTC (permalink / raw)
  To: Linux-Kernel Mailing List
  Cc: Andrew Morton, Alexander Viro, raven, Martin Schwidefsky

[-- Attachment #1: Type: text/plain, Size: 192 bytes --]

d_drop() must use the dentry->d_lock spinlock. In some cases __d_drop() 
was used without holding the dentry->d_lock spinlock, too. This could 
end in a race with __d_lookup().

Regards,
Jan


[-- Attachment #2: d_drop-locking.diff --]
[-- Type: text/x-patch, Size: 3993 bytes --]

Signed-off-by: Jan Blunck <j.blunck@tu-harburg.de>

 fs/autofs4/root.c      |    2 ++
 fs/dcache.c            |    3 +++
 fs/namei.c             |   14 +++++---------
 fs/proc/base.c         |    6 +++++-
 fs/sysfs/inode.c       |    6 +++++-
 include/linux/dcache.h |    2 ++
 6 files changed, 22 insertions(+), 11 deletions(-)

Index: testing-um/include/linux/dcache.h
===================================================================
--- testing-um.orig/include/linux/dcache.h	2005-01-28 15:06:27.000000000 +0100
+++ testing-um/include/linux/dcache.h	2005-01-28 15:58:15.000000000 +0100
@@ -186,7 +186,9 @@
 static inline void d_drop(struct dentry *dentry)
 {
 	spin_lock(&dcache_lock);
+	spin_lock(&dentry->d_lock);
  	__d_drop(dentry);
+	spin_unlock(&dentry->d_lock);
 	spin_unlock(&dcache_lock);
 }
 
Index: testing-um/fs/namei.c
===================================================================
--- testing-um.orig/fs/namei.c	2005-01-28 15:58:15.000000000 +0100
+++ testing-um/fs/namei.c	2005-01-28 15:58:15.000000000 +0100
@@ -1684,17 +1684,13 @@
 void dentry_unhash(struct dentry *dentry)
 {
 	dget(dentry);
-	spin_lock(&dcache_lock);
-	switch (atomic_read(&dentry->d_count)) {
-	default:
-		spin_unlock(&dcache_lock);
+	if (atomic_read(&dentry->d_count))
 		shrink_dcache_parent(dentry);
-		spin_lock(&dcache_lock);
-		if (atomic_read(&dentry->d_count) != 2)
-			break;
-	case 2:
+	spin_lock(&dcache_lock);
+	spin_lock(&dentry->d_lock);
+	if (atomic_read(&dentry->d_count) == 2)
 		__d_drop(dentry);
-	}
+	spin_unlock(&dentry->d_lock);
 	spin_unlock(&dcache_lock);
 }
 
Index: testing-um/fs/sysfs/inode.c
===================================================================
--- testing-um.orig/fs/sysfs/inode.c	2005-01-28 15:06:24.000000000 +0100
+++ testing-um/fs/sysfs/inode.c	2005-01-28 15:58:15.000000000 +0100
@@ -129,13 +129,17 @@
 
 	if (dentry) {
 		spin_lock(&dcache_lock);
+		spin_lock(&dentry->d_lock);
 		if (!(d_unhashed(dentry) && dentry->d_inode)) {
 			dget_locked(dentry);
 			__d_drop(dentry);
+			spin_unlock(&dentry->d_lock);
 			spin_unlock(&dcache_lock);
 			simple_unlink(parent->d_inode, dentry);
-		} else
+		} else {
+			spin_unlock(&dentry->d_lock);
 			spin_unlock(&dcache_lock);
+		}
 	}
 }
 
Index: testing-um/fs/dcache.c
===================================================================
--- testing-um.orig/fs/dcache.c	2005-01-28 15:53:19.000000000 +0100
+++ testing-um/fs/dcache.c	2005-01-28 16:52:49.609883016 +0100
@@ -340,13 +340,16 @@
 	tmp = head;
 	while ((tmp = tmp->next) != head) {
 		struct dentry *dentry = list_entry(tmp, struct dentry, d_alias);
+		spin_lock(&dentry->d_lock);
 		if (!atomic_read(&dentry->d_count)) {
 			__dget_locked(dentry);
 			__d_drop(dentry);
+			spin_unlock(&dentry->d_lock);
 			spin_unlock(&dcache_lock);
 			dput(dentry);
 			goto restart;
 		}
+		spin_unlock(&dentry->d_lock);
 	}
 	spin_unlock(&dcache_lock);
 }
Index: testing-um/fs/autofs4/root.c
===================================================================
--- testing-um.orig/fs/autofs4/root.c	2005-01-28 15:53:22.000000000 +0100
+++ testing-um/fs/autofs4/root.c	2005-01-28 16:04:35.000000000 +0100
@@ -605,7 +605,9 @@
 		spin_unlock(&dcache_lock);
 		return -ENOTEMPTY;
 	}
+	spin_lock(&dentry->d_lock);
 	__d_drop(dentry);
+	spin_unlock(&dentry->d_lock);
 	spin_unlock(&dcache_lock);
 
 	dput(ino->dentry);
Index: testing-um/fs/proc/base.c
===================================================================
--- testing-um.orig/fs/proc/base.c	2005-01-28 15:53:38.000000000 +0100
+++ testing-um/fs/proc/base.c	2005-01-28 16:29:14.000000000 +0100
@@ -1468,11 +1468,15 @@
 	if (proc_dentry != NULL) {
 
 		spin_lock(&dcache_lock);
+		spin_lock(&proc_dentry->d_lock);
 		if (!d_unhashed(proc_dentry)) {
 			dget_locked(proc_dentry);
 			__d_drop(proc_dentry);
-		} else
+			spin_unlock(&proc_dentry->d_lock);
+		} else {
+			spin_unlock(&proc_dentry->d_lock);
 			proc_dentry = NULL;
+		}
 		spin_unlock(&dcache_lock);
 	}
 	return proc_dentry;

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2005-01-28 15:59 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-01-28 15:58 [PATCH] d_drop should use per dentry lock Jan Blunck

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome