__dentry_kill(): get consistent rules for victim's refcount
authorAl Viro <viro@zeniv.linux.org.uk>
Sun, 29 Oct 2023 22:38:27 +0000 (18:38 -0400)
committerAl Viro <viro@zeniv.linux.org.uk>
Sat, 25 Nov 2023 07:33:42 +0000 (02:33 -0500)
Currently we call it with refcount equal to 1 when called from
dentry_kill(); all other callers have it equal to 0.

Make it always be called with zero refcount; on this step we
just decrement it before the calls in dentry_kill().  That is
safe, since all places that care about the value of refcount
either do that under ->d_lock or hold a reference to dentry
in question.  Either is sufficient to prevent observing a
dentry immediately prior to __dentry_kill() getting called
from dentry_kill().

Reviewed-by: Christian Brauner <brauner@kernel.org>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
fs/dcache.c

index 2e74f3f2ce2ee03752b314ae4514f4f1a44649e6..b527db8e5901e29d4f119abfe9c7d1872064e6f0 100644 (file)
@@ -729,6 +729,7 @@ static struct dentry *dentry_kill(struct dentry *dentry)
                        goto slow_positive;
                }
        }
+       dentry->d_lockref.count--;
        __dentry_kill(dentry);
        return parent;
 
@@ -741,6 +742,7 @@ got_locks:
        if (unlikely(dentry->d_lockref.count != 1)) {
                dentry->d_lockref.count--;
        } else if (likely(!retain_dentry(dentry))) {
+               dentry->d_lockref.count--;
                __dentry_kill(dentry);
                return parent;
        } else {