Commit d2212d27 authored by Miklos Szeredi's avatar Miklos Szeredi Committed by Greg Kroah-Hartman

vfs: dcache: fix deadlock in tree traversal

commit 8110e16d upstream.

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: default avatarMiklos Szeredi <mszeredi@suse.cz>
Cc: Al Viro <viro@ZenIV.linux.org.uk>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent b9a7985a
...@@ -1101,6 +1101,8 @@ int have_submounts(struct dentry *parent) ...@@ -1101,6 +1101,8 @@ int have_submounts(struct dentry *parent)
return 1; return 1;
rename_retry: rename_retry:
if (locked)
goto again;
locked = 1; locked = 1;
write_seqlock(&rename_lock); write_seqlock(&rename_lock);
goto again; goto again;
...@@ -1203,6 +1205,8 @@ static int select_parent(struct dentry * parent) ...@@ -1203,6 +1205,8 @@ static int select_parent(struct dentry * parent)
rename_retry: rename_retry:
if (found) if (found)
return found; return found;
if (locked)
goto again;
locked = 1; locked = 1;
write_seqlock(&rename_lock); write_seqlock(&rename_lock);
goto again; goto again;
...@@ -2990,6 +2994,8 @@ void d_genocide(struct dentry *root) ...@@ -2990,6 +2994,8 @@ void d_genocide(struct dentry *root)
return; return;
rename_retry: rename_retry:
if (locked)
goto again;
locked = 1; locked = 1;
write_seqlock(&rename_lock); write_seqlock(&rename_lock);
goto again; goto again;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment