Re: [PATCH v2 4/6] fs/dcache: Avoid the try_lock loops in dentry_kill()
From: Al Viro
Date: Thu Feb 22 2018 - 21:22:50 EST
On Fri, Feb 23, 2018 at 12:50:23AM +0100, John Ogness wrote:
> static struct dentry *dentry_kill(struct dentry *dentry)
> __releases(dentry->d_lock)
> {
> - struct inode *inode = dentry->d_inode;
> - struct dentry *parent = NULL;
> + int saved_count = dentry->d_lockref.count;
Umm... How can that be not 1? After all, fast_dput() should
never return false without ->d_lock being held *and* ->d_count being
equal to 1.
> + /*
> + * d_inode might have changed if d_lock was temporarily
> + * dropped. If it changed it is necessary to start over
> + * because a wrong inode (or no inode) lock is held.
> + */
If it might have changed, we are fucked.
> +out_ref_changed:
> + /*
> + * The refcount was incremented while dentry->d_lock was dropped.
> + * Just decrement the refcount, unlock, and tell the caller to
> + * stop the directory walk.
> + */
> + if (!WARN_ON(dentry->d_lockref.count < 1))
> + dentry->d_lockref.count--;
> +
> spin_unlock(&dentry->d_lock);
> - return dentry; /* try again with same dentry */
> +
> + return NULL;
No. This is completely wrong. If somebody else has found the sucker
while we dropped the lock and even got around to playing with refcount,
they might have done more than that.
In particular, they might have *dropped* their reference, after e.g.
picking it as our inode's alias and rehashed the fucker. Making
our decision not to retain it no longer valid. And your code will
not notice that.