From: akpm@linux-foundation.org Subject: [patch for 2.6.35 1/1] vfs: don't hold s_umount over close_bdev_exclusive() call Date: Tue, 20 Jul 2010 15:18:07 -0700 Message-ID: <201007202218.o6KMI7Z3020942@imap1.linux-foundation.org> Mime-Version: 1.0 Content-Type: text/plain; charset=ANSI_X3.4-1968 Content-Transfer-Encoding: 8bit Cc: linux-fsdevel@vger.kernel.org, akpm@linux-foundation.org, tj@kernel.org, axboe@kernel.dk, docan@eden.rutgers.edu To: viro@zeniv.linux.org.uk Return-path: Received: from smtp1.linux-foundation.org ([140.211.169.13]:45208 "EHLO smtp1.linux-foundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753069Ab0GTWSl (ORCPT ); Tue, 20 Jul 2010 18:18:41 -0400 Sender: linux-fsdevel-owner@vger.kernel.org List-ID: From: Tejun Heo 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 Reported-by: Ciprian Docan Cc: Al Viro Acked-by: Jens Axboe Signed-off-by: Andrew Morton --- fs/super.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff -puN fs/super.c~vfs-dont-hold-s_umount-over-close_bdev_exclusive-call fs/super.c --- a/fs/super.c~vfs-dont-hold-s_umount-over-close_bdev_exclusive-call +++ a/fs/super.c @@ -773,7 +773,16 @@ int get_sb_bdev(struct file_system_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]; _