Skip to content

Commit 9abca36

Browse files
author
Nick Piggin
committed
fs: increase d_name lock coverage
Cover d_name with d_lock in more cases, where there may be concurrent modification to it. Signed-off-by: Nick Piggin <npiggin@kernel.dk>
1 parent b23fb0a commit 9abca36

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

‎fs/dcache.c‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1350,6 +1350,11 @@ static struct dentry *__d_instantiate_unique(struct dentry *entry,
13501350
list_for_each_entry(alias, &inode->i_dentry, d_alias) {
13511351
struct qstr *qstr = &alias->d_name;
13521352

1353+
/*
1354+
* Don't need alias->d_lock here, because aliases with
1355+
* d_parent == entry->d_parent are not subject to name or
1356+
* parent changes, because the parent inode i_mutex is held.
1357+
*/
13531358
if (qstr->hash != hash)
13541359
continue;
13551360
if (alias->d_parent != entry->d_parent)
@@ -2313,7 +2318,9 @@ static int prepend_path(const struct path *path, struct path *root,
23132318
}
23142319
parent = dentry->d_parent;
23152320
prefetch(parent);
2321+
spin_lock(&dentry->d_lock);
23162322
error = prepend_name(buffer, buflen, &dentry->d_name);
2323+
spin_unlock(&dentry->d_lock);
23172324
if (!error)
23182325
error = prepend(buffer, buflen, "/", 1);
23192326
if (error)
@@ -2515,10 +2522,13 @@ static char *__dentry_path(struct dentry *dentry, char *buf, int buflen)
25152522

25162523
while (!IS_ROOT(dentry)) {
25172524
struct dentry *parent = dentry->d_parent;
2525+
int error;
25182526

25192527
prefetch(parent);
2520-
if ((prepend_name(&end, &buflen, &dentry->d_name) != 0) ||
2521-
(prepend(&end, &buflen, "/", 1) != 0))
2528+
spin_lock(&dentry->d_lock);
2529+
error = prepend_name(&end, &buflen, &dentry->d_name);
2530+
spin_unlock(&dentry->d_lock);
2531+
if (error != 0 || prepend(&end, &buflen, "/", 1) != 0)
25222532
goto Elong;
25232533

25242534
retval = end;

0 commit comments

Comments
 (0)