Skip to content

Commit

Permalink
vfs: dcache: fix deadlock in tree traversal
Browse files Browse the repository at this point in the history
IBM reported a deadlock in select_parent().  This was found to be caused
by taking rename_lock when already locked when restarting the tree
traversal.

There are two cases when the traversal needs to be restarted:

 1) concurrent d_move(); this can only happen when not already locked,
    since taking rename_lock protects against concurrent d_move().

 2) racing with final d_put() on child just at the moment of ascending
    to parent; rename_lock doesn't protect against this rare race, so it
    can happen when already locked.

Because of case 2, we need to be able to handle restarting the traversal
when rename_lock is already held.  This patch fixes all three callers of
try_to_ascend().

IBM reported that the deadlock is gone with this patch.

[ I rewrote the patch to be smaller and just do the "goto again" if the
  lock was already held, but credit goes to Miklos for the real work.
   - Linus ]

Signed-off-by: Miklos Szeredi <[email protected]>
Cc: Al Viro <[email protected]>
Cc: [email protected]
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
szmi authored and torvalds committed Sep 30, 2012
1 parent 6a3e3db commit 8110e16
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions fs/dcache.c
Original file line number Diff line number Diff line change
Expand Up @@ -1134,6 +1134,8 @@ int have_submounts(struct dentry *parent)
return 1;

rename_retry:
if (locked)
goto again;
locked = 1;
write_seqlock(&rename_lock);
goto again;
Expand Down Expand Up @@ -1236,6 +1238,8 @@ static int select_parent(struct dentry *parent, struct list_head *dispose)
rename_retry:
if (found)
return found;
if (locked)
goto again;
locked = 1;
write_seqlock(&rename_lock);
goto again;
Expand Down Expand Up @@ -3035,6 +3039,8 @@ void d_genocide(struct dentry *root)
return;

rename_retry:
if (locked)
goto again;
locked = 1;
write_seqlock(&rename_lock);
goto again;
Expand Down

0 comments on commit 8110e16

Please sign in to comment.