public inbox for stable@vger.kernel.org
 help / color / mirror / Atom feed
From: David Sterba <dsterba@suse.com>
To: stable@vger.kernel.org
Subject: [PATCH 11/21] btrfs: fix lock dep warning move scratch super outside of chunk_mutex
Date: Fri,  3 Jun 2016 17:42:30 +0200	[thread overview]
Message-ID: <1464968550-6677-1-git-send-email-dsterba@suse.com> (raw)
In-Reply-To: <20160603154006.GP29147@suse.cz>

From: Anand Jain <anand.jain@oracle.com>

commit 48b3b9d401ec86899a52003b37331190a35a81a6 upstream.

Move scratch super outside of the chunk lock to avoid below
lockdep warning. The better place to scratch super is in
the function btrfs_rm_dev_replace_free_srcdev() just before
free_device, which is outside of the chunk lock as well.

To reproduce:
  (fresh boot)
  mkfs.btrfs -f -draid5 -mraid5 /dev/sdc /dev/sdd /dev/sde
  mount /dev/sdc /btrfs
  dd if=/dev/zero of=/btrfs/tf1 bs=4096 count=100
  (get devmgt from https://github.com/asj/devmgt.git)
  devmgt detach /dev/sde
  dd if=/dev/zero of=/btrfs/tf1 bs=4096 count=100
  sync
  btrfs replace start -Brf 3 /dev/sdf /btrfs <--
  devmgt attach host7

======================================================
[ INFO: possible circular locking dependency detected ]
4.6.0-rc2asj+ #1 Not tainted
---------------------------------------------------

btrfs/2174 is trying to acquire lock:
(sb_writers){.+.+.+}, at:
[<ffffffff812449b4>] __sb_start_write+0xb4/0xf0

but task is already holding lock:
(&fs_info->chunk_mutex){+.+.+.}, at:
[<ffffffffa05c5f55>] btrfs_dev_replace_finishing+0x145/0x980 [btrfs]

which lock already depends on the new lock.

Chain exists of:
sb_writers --> &fs_devs->device_list_mutex --> &fs_info->chunk_mutex
Possible unsafe locking scenario:
CPU0				CPU1
----				----
lock(&fs_info->chunk_mutex);
				lock(&fs_devs->device_list_mutex);
				lock(&fs_info->chunk_mutex);
lock(sb_writers);

*** DEADLOCK ***

-> #0 (sb_writers){.+.+.+}:
[<ffffffff810e6415>] __lock_acquire+0x1bc5/0x1ee0
[<ffffffff810e707e>] lock_acquire+0xbe/0x210
[<ffffffff810df49a>] percpu_down_read+0x4a/0xa0
[<ffffffff812449b4>] __sb_start_write+0xb4/0xf0
[<ffffffff81265534>] mnt_want_write+0x24/0x50
[<ffffffff812508a2>] path_openat+0x952/0x1190
[<ffffffff81252451>] do_filp_open+0x91/0x100
[<ffffffff8123f5cc>] file_open_name+0xfc/0x140
[<ffffffff8123f643>] filp_open+0x33/0x60
[<ffffffffa0572bb6>] update_dev_time+0x16/0x40 [btrfs]
[<ffffffffa057f60d>] btrfs_scratch_superblocks+0x5d/0xb0 [btrfs]
[<ffffffffa057f70e>] btrfs_rm_dev_replace_remove_srcdev+0xae/0xd0 [btrfs]
[<ffffffffa05c62c5>] btrfs_dev_replace_finishing+0x4b5/0x980 [btrfs]
[<ffffffffa05c6ae8>] btrfs_dev_replace_start+0x358/0x530 [btrfs]

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.com>
---
 fs/btrfs/volumes.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 839c2e9e89ae..542c04388ba5 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -1971,11 +1971,8 @@ void btrfs_rm_dev_replace_remove_srcdev(struct btrfs_fs_info *fs_info,
 	if (srcdev->missing)
 		fs_devices->missing_devices--;
 
-	if (srcdev->writeable) {
+	if (srcdev->writeable)
 		fs_devices->rw_devices--;
-		/* zero out the old super if it is writable */
-		btrfs_scratch_superblocks(srcdev->bdev, srcdev->name->str);
-	}
 
 	if (srcdev->bdev)
 		fs_devices->open_devices--;
@@ -1986,6 +1983,10 @@ void btrfs_rm_dev_replace_free_srcdev(struct btrfs_fs_info *fs_info,
 {
 	struct btrfs_fs_devices *fs_devices = srcdev->fs_devices;
 
+	if (srcdev->writeable) {
+		/* zero out the old super if it is writable */
+		btrfs_scratch_superblocks(srcdev->bdev, srcdev->name->str);
+	}
 	call_rcu(&srcdev->rcu, free_device);
 
 	/*
-- 
2.7.1


  parent reply	other threads:[~2016-06-03 15:43 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-03 15:40 Btrfs stable patches for 4.5.x David Sterba
2016-06-03 15:42 ` [PATCH 01/21] btrfs: bugfix: handle FS_IOC32_{GETFLAGS,SETFLAGS,GETVERSION} in btrfs_ioctl David Sterba
2016-06-03 15:42 ` [PATCH 02/21] Btrfs: do not create empty block group if we have allocated data David Sterba
2016-06-03 15:42 ` [PATCH 03/21] btrfs: allow balancing to dup with multi-device David Sterba
2016-06-03 15:42 ` [PATCH 04/21] btrfs: fix mixed block count of available space David Sterba
2016-06-03 15:42 ` [PATCH 05/21] btrfs: avoid overflowing f_bfree David Sterba
2016-06-03 15:42 ` [PATCH 06/21] btrfs: fix lock dep warning, move scratch dev out of device_list_mutex and uuid_mutex David Sterba
2016-06-03 15:42 ` [PATCH 07/21] btrfs: add read-only check to sysfs handler of features David Sterba
2016-06-03 15:42 ` [PATCH 08/21] btrfs: add check to sysfs handler of label David Sterba
2016-06-03 15:42 ` [PATCH 09/21] Btrfs: fix divide error upon chunk's stripe_len David Sterba
2016-06-03 15:42 ` [PATCH 10/21] Btrfs: remove BUG_ON()'s in btrfs_map_block David Sterba
2016-06-03 15:42 ` David Sterba [this message]
2016-06-03 15:42 ` [PATCH 12/21] btrfs: add write protection to SET_FEATURES ioctl David Sterba
2016-06-03 15:42 ` [PATCH 13/21] btrfs: fix int32 overflow in shrink_delalloc() David Sterba
2016-06-03 15:42 ` [PATCH 14/21] Btrfs: fix fspath error deallocation David Sterba
2016-06-03 15:42 ` [PATCH 15/21] btrfs: fix memory leak during RAID 5/6 device replacement David Sterba
2016-06-03 15:42 ` [PATCH 16/21] btrfs: pass the right error code to the btrfs_std_error David Sterba
2016-06-03 15:42 ` [PATCH 17/21] Btrfs: fix for incorrect directory entries after fsync log replay David Sterba
2016-06-03 15:42 ` [PATCH 18/21] Btrfs: fix empty symlink after creating symlink and fsync parent dir David Sterba
2016-06-03 15:42 ` [PATCH 19/21] Btrfs: fix unexpected return value of fiemap David Sterba
2016-06-03 15:42 ` [PATCH 20/21] btrfs: scrub: Set bbio to NULL before calling btrfs_map_block David Sterba
2016-06-03 15:42 ` [PATCH 21/21] btrfs: make state preallocation more speculative in __set_extent_bit David Sterba
2016-06-05 21:48 ` Btrfs stable patches for 4.5.x Greg KH

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1464968550-6677-1-git-send-email-dsterba@suse.com \
    --to=dsterba@suse.com \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox