Skip to content

Commit

Permalink
vfs: don't hold s_umount over close_bdev_exclusive() call
Browse files Browse the repository at this point in the history
Fix an obscure AB-BA deadlock in get_sb_bdev().

When a superblock is mounted more than once get_sb_bdev() calls
close_bdev_exclusive() to drop the extra bdev reference while holding
s_umount.  However, sb->s_umount nests inside bd_mutex during
__invalidate_device() and close_bdev_exclusive() acquires bd_mutex during
blkdev_put(); thus creating an AB-BA deadlock.

This condition doesn't trigger frequently.  For this condition to be
visible to lockdep, the filesystem must occupy the whole device (as
__invalidate_device() only grabs bd_mutex for the whole device), the FS
must be mounted more than once and partition rescan should be issued while
the FS is still mounted.

Fix it by dropping s_umount over close_bdev_exclusive().

Signed-off-by: Tejun Heo <[email protected]>
Reported-by: Ciprian Docan <[email protected]>
Cc: Al Viro <[email protected]>
Acked-by: Jens Axboe <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Al Viro <[email protected]>
  • Loading branch information
htejun authored and Al Viro committed Aug 9, 2010
1 parent 719f2c8 commit 4f331f0
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions fs/super.c
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,16 @@ int get_sb_bdev(struct file_system_type *fs_type,
goto error_bdev;
}

/*
* s_umount nests inside bd_mutex during
* __invalidate_device(). close_bdev_exclusive()
* acquires bd_mutex and can't be called under
* s_umount. Drop s_umount temporarily. This is safe
* as we're holding an active reference.
*/
up_write(&s->s_umount);
close_bdev_exclusive(bdev, mode);
down_write(&s->s_umount);
} else {
char b[BDEVNAME_SIZE];

Expand Down

0 comments on commit 4f331f0

Please sign in to comment.