Skip to content

Commit 2f42f1e

Browse files
author
Al Viro
committed
Call retain_dentry() with refcount 0
Instead of bumping it from 0 to 1, calling retain_dentry(), then decrementing it back to 0 (with ->d_lock held all the way through), just leave refcount at 0 through all of that. It will have a visible effect for ->d_delete() - now it can be called with refcount 0 instead of 1 and it can no longer play silly buggers with dropping/regaining ->d_lock. Not that any in-tree instances tried to (it's pretty hard to get right). Any out-of-tree ones will have to adjust (assuming they need any changes). Note that we do not need to extend rcu-critical area here - we have verified that refcount is non-negative after having grabbed ->d_lock, so nobody will be able to free dentry until they get into __dentry_kill(), which won't happen until they manage to grab ->d_lock. Reviewed-by: Christian Brauner <brauner@kernel.org> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent b06c684 commit 2f42f1e

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

Documentation/filesystems/porting.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,3 +1070,11 @@ The list of children anchored in parent dentry got turned into hlist now.
10701070
Field names got changed (->d_children/->d_sib instead of ->d_subdirs/->d_child
10711071
for anchor/entries resp.), so any affected places will be immediately caught
10721072
by compiler.
1073+
1074+
---
1075+
1076+
**mandatory**
1077+
1078+
->d_delete() instances are now called for dentries with ->d_lock held
1079+
and refcount equal to 0. They are not permitted to drop/regain ->d_lock.
1080+
None of in-tree instances did anything of that sort. Make sure yours do not...

fs/dcache.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -888,15 +888,14 @@ void dput(struct dentry *dentry)
888888
}
889889

890890
/* Slow case: now with the dentry lock held */
891-
dentry->d_lockref.count = 1;
892891
rcu_read_unlock();
893892

894893
if (likely(retain_dentry(dentry))) {
895-
dentry->d_lockref.count--;
896894
spin_unlock(&dentry->d_lock);
897895
return;
898896
}
899897

898+
dentry->d_lockref.count = 1;
900899
dentry = dentry_kill(dentry);
901900
}
902901
}
@@ -921,13 +920,8 @@ void dput_to_list(struct dentry *dentry, struct list_head *list)
921920
return;
922921
}
923922
rcu_read_unlock();
924-
dentry->d_lockref.count = 1;
925-
if (!retain_dentry(dentry)) {
926-
--dentry->d_lockref.count;
923+
if (!retain_dentry(dentry))
927924
to_shrink_list(dentry, list);
928-
} else {
929-
--dentry->d_lockref.count;
930-
}
931925
spin_unlock(&dentry->d_lock);
932926
}
933927

0 commit comments

Comments
 (0)