aboutsummaryrefslogtreecommitdiffstats
path: root/fs/dcache.c
diff options
context:
space:
mode:
authorAl Viro <viro@zeniv.linux.org.uk>2014-06-12 00:29:13 -0400
committerAl Viro <viro@zeniv.linux.org.uk>2014-06-12 00:29:13 -0400
commitc2338f2dc7c1e9f6202f370c64ffd7f44f3d4b51 (patch)
tree54677cd1be2c934fea684a53e34f85d4c6f4981e /fs/dcache.c
parent9c1d5284c79fea050f115eadeec1dd1758e5c630 (diff)
lock_parent: don't step on stale ->d_parent of all-but-freed one
Dentry that had been through (or into) __dentry_kill() might be seen by shrink_dentry_list(); that's normal, it'll be taken off the shrink list and freed if __dentry_kill() has already finished. The problem is, its ->d_parent might be pointing to already freed dentry, so lock_parent() needs to be careful. We need to check that dentry hasn't already gone into __dentry_kill() *and* grab rcu_read_lock() before dropping ->d_lock - the latter makes sure that whatever we see in ->d_parent after dropping ->d_lock it won't be freed until we drop rcu_read_lock(). Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Diffstat (limited to 'fs/dcache.c')
-rw-r--r--fs/dcache.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/fs/dcache.c b/fs/dcache.c
index be2bea834bf4..e99c6f529ba8 100644
--- a/fs/dcache.c
+++ b/fs/dcache.c
@@ -532,10 +532,12 @@ static inline struct dentry *lock_parent(struct dentry *dentry)
532 struct dentry *parent = dentry->d_parent; 532 struct dentry *parent = dentry->d_parent;
533 if (IS_ROOT(dentry)) 533 if (IS_ROOT(dentry))
534 return NULL; 534 return NULL;
535 if (unlikely((int)dentry->d_lockref.count < 0))
536 return NULL;
535 if (likely(spin_trylock(&parent->d_lock))) 537 if (likely(spin_trylock(&parent->d_lock)))
536 return parent; 538 return parent;
537 spin_unlock(&dentry->d_lock);
538 rcu_read_lock(); 539 rcu_read_lock();
540 spin_unlock(&dentry->d_lock);
539again: 541again:
540 parent = ACCESS_ONCE(dentry->d_parent); 542 parent = ACCESS_ONCE(dentry->d_parent);
541 spin_lock(&parent->d_lock); 543 spin_lock(&parent->d_lock);