Skip to content

Commit

Permalink
fix idiotic braino in d_alloc_parallel()
Browse files Browse the repository at this point in the history
Check for d_unhashed() while searching in in-lookup hash was absolutely
wrong.  Worse, it masked a deadlock on dget() done under bitlock that
nests inside ->d_lock.  Thanks to J. R. Okajima for spotting it.

Spotted-by: "J. R. Okajima" <[email protected]>
Wearing-brown-paperbag: Al Viro <[email protected]>
Signed-off-by: Al Viro <[email protected]>
  • Loading branch information
Al Viro committed Jun 20, 2016
1 parent ea01a18 commit e7d6ef9
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions fs/dcache.c
Original file line number Diff line number Diff line change
Expand Up @@ -2503,7 +2503,6 @@ struct dentry *d_alloc_parallel(struct dentry *parent,
rcu_read_unlock();
goto retry;
}
rcu_read_unlock();
/*
* No changes for the parent since the beginning of d_lookup().
* Since all removals from the chain happen with hlist_bl_lock(),
Expand All @@ -2516,8 +2515,6 @@ struct dentry *d_alloc_parallel(struct dentry *parent,
continue;
if (dentry->d_parent != parent)
continue;
if (d_unhashed(dentry))
continue;
if (parent->d_flags & DCACHE_OP_COMPARE) {
int tlen = dentry->d_name.len;
const char *tname = dentry->d_name.name;
Expand All @@ -2529,9 +2526,18 @@ struct dentry *d_alloc_parallel(struct dentry *parent,
if (dentry_cmp(dentry, str, len))
continue;
}
dget(dentry);
hlist_bl_unlock(b);
/* somebody is doing lookup for it right now; wait for it */
/* now we can try to grab a reference */
if (!lockref_get_not_dead(&dentry->d_lockref)) {
rcu_read_unlock();
goto retry;
}

rcu_read_unlock();
/*
* somebody is likely to be still doing lookup for it;
* wait for them to finish
*/
spin_lock(&dentry->d_lock);
d_wait_lookup(dentry);
/*
Expand Down Expand Up @@ -2562,6 +2568,7 @@ struct dentry *d_alloc_parallel(struct dentry *parent,
dput(new);
return dentry;
}
rcu_read_unlock();
/* we can't take ->d_lock here; it's OK, though. */
new->d_flags |= DCACHE_PAR_LOOKUP;
new->d_wait = wq;
Expand Down

0 comments on commit e7d6ef9

Please sign in to comment.