[PATCH v2 1/4] VFS/xfs/ntfs: drop parent lock across d_alloc_parallel() in d_add_ci()

Christian Brauner brauner at kernel.org
Fri Nov 20 05:35:18 PST 2026


On Tue, Nov 17, 2026 at 10:54:58AM +1100, NeilBrown wrote:
> We don't need to keep the parent lock held when d_add_ci() is run - the
> VFS doesn't need it as dentry is exclusively held due to
> DCACHE_PAR_LOOKUP and the filesystem has finished its work.

I'm not sure that holds? Only d_alloc_parallel() honours
DCACHE_PAR_LOOKUP. lookup_one_qstr_excl() still uses d_alloc() and
relies on the exclusive lock to guarantee that there are no in-lookup
children at all. That stops being true here:

> +		if (lookup_flags & LOOKUP_SHARED)
> +			inode_unlock_shared(d_inode(dentry->d_parent));
> +		else
> +			inode_unlock(d_inode(dentry->d_parent));
> +		must_relock = true;
>  		found = d_alloc_parallel(dentry->d_parent, name);

So if "Foo" exists on an ascii-ci xfs:

P1: stat("FOO")                      P2: unlink("Foo")
lookup_slow()
-> xfs_vn_ci_lookup()
   -> d_add_ci(dentry, X, "Foo")
      -> inode_unlock_shared(dir)
      -> found = d_alloc_parallel()
                                     start_dirop()
                                     -> inode_lock_nested(dir)
                                     -> lookup_one_qstr_excl("Foo")
                                        -> d2 = d_alloc()
                                        -> xfs_vn_ci_lookup()
                                           -> d_splice_alias(X, d2)
                                     vfs_unlink()
                                     -> xfs_vn_unlink()
                                        -> d_invalidate(d2)
                                     inode_unlock(dir)
      -> d_splice_alias(X, found)

IOW, "Foo" ends up as a hashed positive dentry for an unlinked inode
that nothing revalidates.

open("Foo", O_CREAT) then opens the orphan instead of creating a new
file and O_EXCL fails with EEXIST. Do a rename() instead of the unlink()
and "Foo" keeps pointing to what is now "Bar". ntfs gets there the same
way.

Before this patch lookup_slow() held the lock shared across all of
that so start_dirop() couldn't get in between.

So afaict this needs "VFS: use d_alloc_parallel() in
lookup_one_qstr_excl()" from your RFC to go in first. Unless I'm
missing something obvious.



More information about the linux-um mailing list