Skip to content

Commit 0ddfb62

Browse files
author
Al Viro
committed
fix the softlockups in attach_recursive_mnt()
In case when we mounting something on top of a large stack of overmounts, all of them being peers of each other, we get quadratic time by the depth of overmount stack. Easily fixed by doing commit_tree() before reparenting the overmount; simplifies commit_tree() as well - it doesn't need to skip the already mounted stuff that had been reparented on top of the new mounts. Since we are holding mount_lock through both reparenting and call of commit_tree(), the order does not matter from the mount hash point of view. Reported-by: "Lai, Yi" <[email protected]> Tested-by: "Lai, Yi" <[email protected]> Reviewed-by: Christian Brauner <[email protected]> Fixes: 6632068 "copy_tree(): don't link the mounts via mnt_list" Signed-off-by: Al Viro <[email protected]>
1 parent 8742b2d commit 0ddfb62

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

fs/namespace.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1197,10 +1197,7 @@ static void commit_tree(struct mount *mnt)
11971197

11981198
if (!mnt_ns_attached(mnt)) {
11991199
for (struct mount *m = mnt; m; m = next_mnt(m, mnt))
1200-
if (unlikely(mnt_ns_attached(m)))
1201-
m = skip_mnt_tree(m);
1202-
else
1203-
mnt_add_to_ns(n, m);
1200+
mnt_add_to_ns(n, m);
12041201
n->nr_mounts += n->pending_mounts;
12051202
n->pending_mounts = 0;
12061203
}
@@ -2704,6 +2701,7 @@ static int attach_recursive_mnt(struct mount *source_mnt,
27042701
lock_mnt_tree(child);
27052702
q = __lookup_mnt(&child->mnt_parent->mnt,
27062703
child->mnt_mountpoint);
2704+
commit_tree(child);
27072705
if (q) {
27082706
struct mountpoint *mp = root.mp;
27092707
struct mount *r = child;
@@ -2713,7 +2711,6 @@ static int attach_recursive_mnt(struct mount *source_mnt,
27132711
mp = shorter;
27142712
mnt_change_mountpoint(r, mp, q);
27152713
}
2716-
commit_tree(child);
27172714
}
27182715
unpin_mountpoint(&root);
27192716
unlock_mount_hash();

0 commit comments

Comments
 (0)