<feed xmlns='http://www.w3.org/2005/Atom'>
<title>linux-stable.git/fs, branch v4.5.5</title>
<subtitle>Linux kernel stable tree</subtitle>
<link rel='alternate' type='text/html' href='https://git.tavy.me/linux-stable.git/'/>
<entry>
<title>btrfs: Reset IO error counters before start of device replacing</title>
<updated>2016-05-19T01:35:18+00:00</updated>
<author>
<name>Yauhen Kharuzhy</name>
<email>yauhen.kharuzhy@zavadatar.com</email>
</author>
<published>2016-03-29T21:17:48+00:00</published>
<link rel='alternate' type='text/html' href='https://git.tavy.me/linux-stable.git/commit/?id=9abb19bd9efe6999877edc10ffef3d34f261c767'/>
<id>9abb19bd9efe6999877edc10ffef3d34f261c767</id>
<content type='text'>
commit 7ccefb98ce3e5c4493cd213cd03714b7149cf0cb upstream.

If device replace entry was found on disk at mounting and its num_write_errors
stats counter has non-NULL value, then replace operation will never be
finished and -EIO error will be reported by btrfs_scrub_dev() because
this counter is never reset.

 # mount -o degraded /media/a4fb5c0a-21c5-4fe7-8d0e-fdd87d5f71ee/
 # btrfs replace status /media/a4fb5c0a-21c5-4fe7-8d0e-fdd87d5f71ee/
 Started on 25.Mar 07:28:00, canceled on 25.Mar 07:28:01 at 0.0%, 40 write errs, 0 uncorr. read errs
 # btrfs replace start -B 4 /dev/sdg /media/a4fb5c0a-21c5-4fe7-8d0e-fdd87d5f71ee/
 ERROR: ioctl(DEV_REPLACE_START) failed on "/media/a4fb5c0a-21c5-4fe7-8d0e-fdd87d5f71ee/": Input/output error, no error

Reset num_write_errors and num_uncorrectable_read_errors counters in the
dev_replace structure before start of replacing.

Signed-off-by: Yauhen Kharuzhy &lt;yauhen.kharuzhy@zavadatar.com&gt;
Reviewed-by: David Sterba &lt;dsterba@suse.com&gt;
Signed-off-by: David Sterba &lt;dsterba@suse.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;

</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
commit 7ccefb98ce3e5c4493cd213cd03714b7149cf0cb upstream.

If device replace entry was found on disk at mounting and its num_write_errors
stats counter has non-NULL value, then replace operation will never be
finished and -EIO error will be reported by btrfs_scrub_dev() because
this counter is never reset.

 # mount -o degraded /media/a4fb5c0a-21c5-4fe7-8d0e-fdd87d5f71ee/
 # btrfs replace status /media/a4fb5c0a-21c5-4fe7-8d0e-fdd87d5f71ee/
 Started on 25.Mar 07:28:00, canceled on 25.Mar 07:28:01 at 0.0%, 40 write errs, 0 uncorr. read errs
 # btrfs replace start -B 4 /dev/sdg /media/a4fb5c0a-21c5-4fe7-8d0e-fdd87d5f71ee/
 ERROR: ioctl(DEV_REPLACE_START) failed on "/media/a4fb5c0a-21c5-4fe7-8d0e-fdd87d5f71ee/": Input/output error, no error

Reset num_write_errors and num_uncorrectable_read_errors counters in the
dev_replace structure before start of replacing.

Signed-off-by: Yauhen Kharuzhy &lt;yauhen.kharuzhy@zavadatar.com&gt;
Reviewed-by: David Sterba &lt;dsterba@suse.com&gt;
Signed-off-by: David Sterba &lt;dsterba@suse.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;

</pre>
</div>
</content>
</entry>
<entry>
<title>Btrfs: don't use src fd for printk</title>
<updated>2016-05-19T01:35:18+00:00</updated>
<author>
<name>Josef Bacik</name>
<email>jbacik@fb.com</email>
</author>
<published>2016-03-25T14:02:41+00:00</published>
<link rel='alternate' type='text/html' href='https://git.tavy.me/linux-stable.git/commit/?id=f188c432c9db3be8a705f6825c5a9d9f837ed215'/>
<id>f188c432c9db3be8a705f6825c5a9d9f837ed215</id>
<content type='text'>
commit c79b4713304f812d3d6c95826fc3e5fc2c0b0c14 upstream.

The fd we pass in may not be on a btrfs file system, so don't try to do
BTRFS_I() on it.  Thanks,

Signed-off-by: Josef Bacik &lt;jbacik@fb.com&gt;
Reviewed-by: David Sterba &lt;dsterba@suse.com&gt;
Signed-off-by: David Sterba &lt;dsterba@suse.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;

</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
commit c79b4713304f812d3d6c95826fc3e5fc2c0b0c14 upstream.

The fd we pass in may not be on a btrfs file system, so don't try to do
BTRFS_I() on it.  Thanks,

Signed-off-by: Josef Bacik &lt;jbacik@fb.com&gt;
Reviewed-by: David Sterba &lt;dsterba@suse.com&gt;
Signed-off-by: David Sterba &lt;dsterba@suse.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;

</pre>
</div>
</content>
</entry>
<entry>
<title>btrfs: fallback to vmalloc in btrfs_compare_tree</title>
<updated>2016-05-19T01:35:17+00:00</updated>
<author>
<name>David Sterba</name>
<email>dsterba@suse.com</email>
</author>
<published>2016-03-30T14:01:12+00:00</published>
<link rel='alternate' type='text/html' href='https://git.tavy.me/linux-stable.git/commit/?id=440323f92e3542110978dcbca890aad8b3798c34'/>
<id>440323f92e3542110978dcbca890aad8b3798c34</id>
<content type='text'>
commit 8f282f71eaee7ac979cdbe525f76daa0722798a8 upstream.

The allocation of node could fail if the memory is too fragmented for a
given node size, practically observed with 64k.

http://article.gmane.org/gmane.comp.file-systems.btrfs/54689

Reported-and-tested-by: Jean-Denis Girard &lt;jd.girard@sysnux.pf&gt;
Signed-off-by: David Sterba &lt;dsterba@suse.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;

</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
commit 8f282f71eaee7ac979cdbe525f76daa0722798a8 upstream.

The allocation of node could fail if the memory is too fragmented for a
given node size, practically observed with 64k.

http://article.gmane.org/gmane.comp.file-systems.btrfs/54689

Reported-and-tested-by: Jean-Denis Girard &lt;jd.girard@sysnux.pf&gt;
Signed-off-by: David Sterba &lt;dsterba@suse.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;

</pre>
</div>
</content>
</entry>
<entry>
<title>btrfs: handle non-fatal errors in btrfs_qgroup_inherit()</title>
<updated>2016-05-19T01:35:17+00:00</updated>
<author>
<name>Mark Fasheh</name>
<email>mfasheh@suse.de</email>
</author>
<published>2016-03-31T00:57:48+00:00</published>
<link rel='alternate' type='text/html' href='https://git.tavy.me/linux-stable.git/commit/?id=52ec554945bb69c7bd9790ce11338566b25ba293'/>
<id>52ec554945bb69c7bd9790ce11338566b25ba293</id>
<content type='text'>
commit 918c2ee103cf9956f1c61d3f848dbb49fd2d104a upstream.

create_pending_snapshot() will go readonly on _any_ error return from
btrfs_qgroup_inherit(). If qgroups are enabled, a user can crash their fs by
just making a snapshot and asking it to inherit from an invalid qgroup. For
example:

$ btrfs sub snap -i 1/10 /btrfs/ /btrfs/foo

Will cause a transaction abort.

Fix this by only throwing errors in btrfs_qgroup_inherit() when we know
going readonly is acceptable.

The following xfstests test case reproduces this bug:

  seq=`basename $0`
  seqres=$RESULT_DIR/$seq
  echo "QA output created by $seq"

  here=`pwd`
  tmp=/tmp/$$
  status=1	# failure is the default!
  trap "_cleanup; exit \$status" 0 1 2 3 15

  _cleanup()
  {
  	cd /
  	rm -f $tmp.*
  }

  # get standard environment, filters and checks
  . ./common/rc
  . ./common/filter

  # remove previous $seqres.full before test
  rm -f $seqres.full

  # real QA test starts here
  _supported_fs btrfs
  _supported_os Linux
  _require_scratch

  rm -f $seqres.full

  _scratch_mkfs
  _scratch_mount
  _run_btrfs_util_prog quota enable $SCRATCH_MNT
  # The qgroup '1/10' does not exist and should be silently ignored
  _run_btrfs_util_prog subvolume snapshot -i 1/10 $SCRATCH_MNT $SCRATCH_MNT/snap1

  _scratch_unmount

  echo "Silence is golden"

  status=0
  exit

Signed-off-by: Mark Fasheh &lt;mfasheh@suse.de&gt;
Reviewed-by: Qu Wenruo &lt;quwenruo@cn.fujitsu.com&gt;
Signed-off-by: David Sterba &lt;dsterba@suse.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;

</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
commit 918c2ee103cf9956f1c61d3f848dbb49fd2d104a upstream.

create_pending_snapshot() will go readonly on _any_ error return from
btrfs_qgroup_inherit(). If qgroups are enabled, a user can crash their fs by
just making a snapshot and asking it to inherit from an invalid qgroup. For
example:

$ btrfs sub snap -i 1/10 /btrfs/ /btrfs/foo

Will cause a transaction abort.

Fix this by only throwing errors in btrfs_qgroup_inherit() when we know
going readonly is acceptable.

The following xfstests test case reproduces this bug:

  seq=`basename $0`
  seqres=$RESULT_DIR/$seq
  echo "QA output created by $seq"

  here=`pwd`
  tmp=/tmp/$$
  status=1	# failure is the default!
  trap "_cleanup; exit \$status" 0 1 2 3 15

  _cleanup()
  {
  	cd /
  	rm -f $tmp.*
  }

  # get standard environment, filters and checks
  . ./common/rc
  . ./common/filter

  # remove previous $seqres.full before test
  rm -f $seqres.full

  # real QA test starts here
  _supported_fs btrfs
  _supported_os Linux
  _require_scratch

  rm -f $seqres.full

  _scratch_mkfs
  _scratch_mount
  _run_btrfs_util_prog quota enable $SCRATCH_MNT
  # The qgroup '1/10' does not exist and should be silently ignored
  _run_btrfs_util_prog subvolume snapshot -i 1/10 $SCRATCH_MNT $SCRATCH_MNT/snap1

  _scratch_unmount

  echo "Silence is golden"

  status=0
  exit

Signed-off-by: Mark Fasheh &lt;mfasheh@suse.de&gt;
Reviewed-by: Qu Wenruo &lt;quwenruo@cn.fujitsu.com&gt;
Signed-off-by: David Sterba &lt;dsterba@suse.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;

</pre>
</div>
</content>
</entry>
<entry>
<title>Btrfs: fix invalid reference in replace_path</title>
<updated>2016-05-19T01:35:17+00:00</updated>
<author>
<name>Liu Bo</name>
<email>bo.li.liu@oracle.com</email>
</author>
<published>2016-03-21T21:59:53+00:00</published>
<link rel='alternate' type='text/html' href='https://git.tavy.me/linux-stable.git/commit/?id=24469ab4f3b7dd6fef36787bad42b2f75053556e'/>
<id>24469ab4f3b7dd6fef36787bad42b2f75053556e</id>
<content type='text'>
commit 264813acb1c756aebc337b16b832604a0c9aadaf upstream.

Dan Carpenter's static checker has found this error, it's introduced by
commit 64c043de466d
("Btrfs: fix up read_tree_block to return proper error")

It's really supposed to 'break' the loop on error like others.

Cc: Dan Carpenter &lt;dan.carpenter@oracle.com&gt;
Reported-by: Dan Carpenter &lt;dan.carpenter@oracle.com&gt;
Signed-off-by: Liu Bo &lt;bo.li.liu@oracle.com&gt;
Reviewed-by: David Sterba &lt;dsterba@suse.com&gt;
Signed-off-by: David Sterba &lt;dsterba@suse.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;

</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
commit 264813acb1c756aebc337b16b832604a0c9aadaf upstream.

Dan Carpenter's static checker has found this error, it's introduced by
commit 64c043de466d
("Btrfs: fix up read_tree_block to return proper error")

It's really supposed to 'break' the loop on error like others.

Cc: Dan Carpenter &lt;dan.carpenter@oracle.com&gt;
Reported-by: Dan Carpenter &lt;dan.carpenter@oracle.com&gt;
Signed-off-by: Liu Bo &lt;bo.li.liu@oracle.com&gt;
Reviewed-by: David Sterba &lt;dsterba@suse.com&gt;
Signed-off-by: David Sterba &lt;dsterba@suse.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;

</pre>
</div>
</content>
</entry>
<entry>
<title>btrfs: do not write corrupted metadata blocks to disk</title>
<updated>2016-05-19T01:35:17+00:00</updated>
<author>
<name>Alex Lyakas</name>
<email>alex.bolshoy@gmail.com</email>
</author>
<published>2016-03-10T11:10:15+00:00</published>
<link rel='alternate' type='text/html' href='https://git.tavy.me/linux-stable.git/commit/?id=b96513cce7b82c66f6d1ff87261d65d7cda08861'/>
<id>b96513cce7b82c66f6d1ff87261d65d7cda08861</id>
<content type='text'>
commit 0f805531daa2ebfb5706422dc2ead1cff9e53e65 upstream.

csum_dirty_buffer was issuing a warning in case the extent buffer
did not look alright, but was still returning success.
Let's return error in this case, and also add an additional sanity
check on the extent buffer header.
The caller up the chain may BUG_ON on this, for example flush_epd_write_bio will,
but it is better than to have a silent metadata corruption on disk.

Signed-off-by: Alex Lyakas &lt;alex@zadarastorage.com&gt;
Reviewed-by: Filipe Manana &lt;fdmanana@suse.com&gt;
Signed-off-by: David Sterba &lt;dsterba@suse.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;

</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
commit 0f805531daa2ebfb5706422dc2ead1cff9e53e65 upstream.

csum_dirty_buffer was issuing a warning in case the extent buffer
did not look alright, but was still returning success.
Let's return error in this case, and also add an additional sanity
check on the extent buffer header.
The caller up the chain may BUG_ON on this, for example flush_epd_write_bio will,
but it is better than to have a silent metadata corruption on disk.

Signed-off-by: Alex Lyakas &lt;alex@zadarastorage.com&gt;
Reviewed-by: Filipe Manana &lt;fdmanana@suse.com&gt;
Signed-off-by: David Sterba &lt;dsterba@suse.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;

</pre>
</div>
</content>
</entry>
<entry>
<title>btrfs: csum_tree_block: return proper errno value</title>
<updated>2016-05-19T01:35:17+00:00</updated>
<author>
<name>Alex Lyakas</name>
<email>alex.bolshoy@gmail.com</email>
</author>
<published>2016-03-10T11:09:46+00:00</published>
<link rel='alternate' type='text/html' href='https://git.tavy.me/linux-stable.git/commit/?id=342da5cefddbf818e1cb59537e021cdad9744e93'/>
<id>342da5cefddbf818e1cb59537e021cdad9744e93</id>
<content type='text'>
commit 8bd98f0e6bf792e8fa7c3fed709321ad42ba8d2e upstream.

Signed-off-by: Alex Lyakas &lt;alex@zadarastorage.com&gt;
Reviewed-by: Filipe Manana &lt;fdmanana@suse.com&gt;
Signed-off-by: David Sterba &lt;dsterba@suse.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;

</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
commit 8bd98f0e6bf792e8fa7c3fed709321ad42ba8d2e upstream.

Signed-off-by: Alex Lyakas &lt;alex@zadarastorage.com&gt;
Reviewed-by: Filipe Manana &lt;fdmanana@suse.com&gt;
Signed-off-by: David Sterba &lt;dsterba@suse.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;

</pre>
</div>
</content>
</entry>
<entry>
<title>Btrfs: do not collect ordered extents when logging that inode exists</title>
<updated>2016-05-19T01:35:16+00:00</updated>
<author>
<name>Filipe Manana</name>
<email>fdmanana@suse.com</email>
</author>
<published>2016-02-25T23:19:38+00:00</published>
<link rel='alternate' type='text/html' href='https://git.tavy.me/linux-stable.git/commit/?id=13b7e683b67b36a7dc3a5bc98e3718028b3c5dfd'/>
<id>13b7e683b67b36a7dc3a5bc98e3718028b3c5dfd</id>
<content type='text'>
commit 5e33a2bd7ca7fa687fb0965869196eea6815d1f3 upstream.

When logging that an inode exists, for example as part of a directory
fsync operation, we were collecting any ordered extents for the inode but
we ended up doing nothing with them except tagging them as processed, by
setting the flag BTRFS_ORDERED_LOGGED on them, which prevented a
subsequent fsync of that inode (using the LOG_INODE_ALL mode) from
collecting and processing them. This created a time window where a second
fsync against the inode, using the fast path, ended up not logging the
checksums for the new extents but it logged the extents since they were
part of the list of modified extents. This happened because the ordered
extents were not collected and checksums were not yet added to the csum
tree - the ordered extents have not gone through btrfs_finish_ordered_io()
yet (which is where we add them to the csum tree by calling
inode.c:add_pending_csums()).

So fix this by not collecting an inode's ordered extents if we are logging
it with the LOG_INODE_EXISTS mode.

Signed-off-by: Filipe Manana &lt;fdmanana@suse.com&gt;
Signed-off-by: Chris Mason &lt;clm@fb.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;

</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
commit 5e33a2bd7ca7fa687fb0965869196eea6815d1f3 upstream.

When logging that an inode exists, for example as part of a directory
fsync operation, we were collecting any ordered extents for the inode but
we ended up doing nothing with them except tagging them as processed, by
setting the flag BTRFS_ORDERED_LOGGED on them, which prevented a
subsequent fsync of that inode (using the LOG_INODE_ALL mode) from
collecting and processing them. This created a time window where a second
fsync against the inode, using the fast path, ended up not logging the
checksums for the new extents but it logged the extents since they were
part of the list of modified extents. This happened because the ordered
extents were not collected and checksums were not yet added to the csum
tree - the ordered extents have not gone through btrfs_finish_ordered_io()
yet (which is where we add them to the csum tree by calling
inode.c:add_pending_csums()).

So fix this by not collecting an inode's ordered extents if we are logging
it with the LOG_INODE_EXISTS mode.

Signed-off-by: Filipe Manana &lt;fdmanana@suse.com&gt;
Signed-off-by: Chris Mason &lt;clm@fb.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;

</pre>
</div>
</content>
</entry>
<entry>
<title>Btrfs: fix race when checking if we can skip fsync'ing an inode</title>
<updated>2016-05-19T01:35:16+00:00</updated>
<author>
<name>Filipe Manana</name>
<email>fdmanana@suse.com</email>
</author>
<published>2016-02-24T07:35:05+00:00</published>
<link rel='alternate' type='text/html' href='https://git.tavy.me/linux-stable.git/commit/?id=ce91def62e14b955a3831af9123c60fefb68d421'/>
<id>ce91def62e14b955a3831af9123c60fefb68d421</id>
<content type='text'>
commit affc0ff902d539ebe9bba405d330410314f46e9f upstream.

If we're about to do a fast fsync for an inode and btrfs_inode_in_log()
returns false, it's possible that we had an ordered extent in progress
(btrfs_finish_ordered_io() not run yet) when we noticed that the inode's
last_trans field was not greater than the id of the last committed
transaction, but shortly after, before we checked if there were any
ongoing ordered extents, the ordered extent had just completed and
removed itself from the inode's ordered tree, in which case we end up not
logging the inode, losing some data if a power failure or crash happens
after the fsync handler returns and before the transaction is committed.

Fix this by checking first if there are any ongoing ordered extents
before comparing the inode's last_trans with the id of the last committed
transaction - when it completes, an ordered extent always updates the
inode's last_trans before it removes itself from the inode's ordered
tree (at btrfs_finish_ordered_io()).

Signed-off-by: Filipe Manana &lt;fdmanana@suse.com&gt;
Signed-off-by: Chris Mason &lt;clm@fb.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;

</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
commit affc0ff902d539ebe9bba405d330410314f46e9f upstream.

If we're about to do a fast fsync for an inode and btrfs_inode_in_log()
returns false, it's possible that we had an ordered extent in progress
(btrfs_finish_ordered_io() not run yet) when we noticed that the inode's
last_trans field was not greater than the id of the last committed
transaction, but shortly after, before we checked if there were any
ongoing ordered extents, the ordered extent had just completed and
removed itself from the inode's ordered tree, in which case we end up not
logging the inode, losing some data if a power failure or crash happens
after the fsync handler returns and before the transaction is committed.

Fix this by checking first if there are any ongoing ordered extents
before comparing the inode's last_trans with the id of the last committed
transaction - when it completes, an ordered extent always updates the
inode's last_trans before it removes itself from the inode's ordered
tree (at btrfs_finish_ordered_io()).

Signed-off-by: Filipe Manana &lt;fdmanana@suse.com&gt;
Signed-off-by: Chris Mason &lt;clm@fb.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;

</pre>
</div>
</content>
</entry>
<entry>
<title>Btrfs: fix deadlock between direct IO reads and buffered writes</title>
<updated>2016-05-19T01:35:16+00:00</updated>
<author>
<name>Filipe Manana</name>
<email>fdmanana@suse.com</email>
</author>
<published>2016-02-18T14:28:55+00:00</published>
<link rel='alternate' type='text/html' href='https://git.tavy.me/linux-stable.git/commit/?id=8eb64c913af6f50933b6a332123d7bb8688b7244'/>
<id>8eb64c913af6f50933b6a332123d7bb8688b7244</id>
<content type='text'>
commit ade770294df29e08f913e5d733a756893128f45e upstream.

While running a test with a mix of buffered IO and direct IO against
the same files I hit a deadlock reported by the following trace:

[11642.140352] INFO: task kworker/u32:3:15282 blocked for more than 120 seconds.
[11642.142452]       Not tainted 4.4.0-rc6-btrfs-next-21+ #1
[11642.143982] "echo 0 &gt; /proc/sys/kernel/hung_task_timeout_secs" disables this message.
[11642.146332] kworker/u32:3   D ffff880230ef7988 [11642.147737] systemd-journald[571]: Sent WATCHDOG=1 notification.
[11642.149771]     0 15282      2 0x00000000
[11642.151205] Workqueue: btrfs-flush_delalloc btrfs_flush_delalloc_helper [btrfs]
[11642.154074]  ffff880230ef7988 0000000000000246 0000000000014ec0 ffff88023ec94ec0
[11642.156722]  ffff880233fe8f80 ffff880230ef8000 ffff88023ec94ec0 7fffffffffffffff
[11642.159205]  0000000000000002 ffffffff8147b7f9 ffff880230ef79a0 ffffffff8147b541
[11642.161403] Call Trace:
[11642.162129]  [&lt;ffffffff8147b7f9&gt;] ? bit_wait+0x2f/0x2f
[11642.163396]  [&lt;ffffffff8147b541&gt;] schedule+0x82/0x9a
[11642.164871]  [&lt;ffffffff8147e7fe&gt;] schedule_timeout+0x43/0x109
[11642.167020]  [&lt;ffffffff8147b7f9&gt;] ? bit_wait+0x2f/0x2f
[11642.167931]  [&lt;ffffffff8108afd1&gt;] ? trace_hardirqs_on_caller+0x17b/0x197
[11642.182320]  [&lt;ffffffff8108affa&gt;] ? trace_hardirqs_on+0xd/0xf
[11642.183762]  [&lt;ffffffff810b079b&gt;] ? timekeeping_get_ns+0xe/0x33
[11642.185308]  [&lt;ffffffff810b0f61&gt;] ? ktime_get+0x41/0x52
[11642.186782]  [&lt;ffffffff8147ac08&gt;] io_schedule_timeout+0xa0/0x102
[11642.188217]  [&lt;ffffffff8147ac08&gt;] ? io_schedule_timeout+0xa0/0x102
[11642.189626]  [&lt;ffffffff8147b814&gt;] bit_wait_io+0x1b/0x39
[11642.190803]  [&lt;ffffffff8147bb21&gt;] __wait_on_bit_lock+0x4c/0x90
[11642.192158]  [&lt;ffffffff8111829f&gt;] __lock_page+0x66/0x68
[11642.193379]  [&lt;ffffffff81082f29&gt;] ? autoremove_wake_function+0x3a/0x3a
[11642.194831]  [&lt;ffffffffa0450ddd&gt;] lock_page+0x31/0x34 [btrfs]
[11642.197068]  [&lt;ffffffffa0454e3b&gt;] extent_write_cache_pages.isra.19.constprop.35+0x1af/0x2f4 [btrfs]
[11642.199188]  [&lt;ffffffffa0455373&gt;] extent_writepages+0x4b/0x5c [btrfs]
[11642.200723]  [&lt;ffffffffa043c913&gt;] ? btrfs_writepage_start_hook+0xce/0xce [btrfs]
[11642.202465]  [&lt;ffffffffa043aa82&gt;] btrfs_writepages+0x28/0x2a [btrfs]
[11642.203836]  [&lt;ffffffff811236bc&gt;] do_writepages+0x23/0x2c
[11642.205624]  [&lt;ffffffff811198c9&gt;] __filemap_fdatawrite_range+0x5a/0x61
[11642.207057]  [&lt;ffffffff81119946&gt;] filemap_fdatawrite_range+0x13/0x15
[11642.208529]  [&lt;ffffffffa044f87e&gt;] btrfs_start_ordered_extent+0xd0/0x1a1 [btrfs]
[11642.210375]  [&lt;ffffffffa0462613&gt;] ? btrfs_scrubparity_helper+0x140/0x33a [btrfs]
[11642.212132]  [&lt;ffffffffa044f974&gt;] btrfs_run_ordered_extent_work+0x25/0x34 [btrfs]
[11642.213837]  [&lt;ffffffffa046262f&gt;] btrfs_scrubparity_helper+0x15c/0x33a [btrfs]
[11642.215457]  [&lt;ffffffffa046293b&gt;] btrfs_flush_delalloc_helper+0xe/0x10 [btrfs]
[11642.217095]  [&lt;ffffffff8106483e&gt;] process_one_work+0x256/0x48b
[11642.218324]  [&lt;ffffffff81064f20&gt;] worker_thread+0x1f5/0x2a7
[11642.219466]  [&lt;ffffffff81064d2b&gt;] ? rescuer_thread+0x289/0x289
[11642.220801]  [&lt;ffffffff8106a500&gt;] kthread+0xd4/0xdc
[11642.222032]  [&lt;ffffffff8106a42c&gt;] ? kthread_parkme+0x24/0x24
[11642.223190]  [&lt;ffffffff8147fdef&gt;] ret_from_fork+0x3f/0x70
[11642.224394]  [&lt;ffffffff8106a42c&gt;] ? kthread_parkme+0x24/0x24
[11642.226295] 2 locks held by kworker/u32:3/15282:
[11642.227273]  #0:  ("%s-%s""btrfs", name){++++.+}, at: [&lt;ffffffff8106474d&gt;] process_one_work+0x165/0x48b
[11642.229412]  #1:  ((&amp;work-&gt;normal_work)){+.+.+.}, at: [&lt;ffffffff8106474d&gt;] process_one_work+0x165/0x48b
[11642.231414] INFO: task kworker/u32:8:15289 blocked for more than 120 seconds.
[11642.232872]       Not tainted 4.4.0-rc6-btrfs-next-21+ #1
[11642.234109] "echo 0 &gt; /proc/sys/kernel/hung_task_timeout_secs" disables this message.
[11642.235776] kworker/u32:8   D ffff88020de5f848     0 15289      2 0x00000000
[11642.237412] Workqueue: writeback wb_workfn (flush-btrfs-481)
[11642.238670]  ffff88020de5f848 0000000000000246 0000000000014ec0 ffff88023ed54ec0
[11642.240475]  ffff88021b1ece40 ffff88020de60000 ffff88023ed54ec0 7fffffffffffffff
[11642.242154]  0000000000000002 ffffffff8147b7f9 ffff88020de5f860 ffffffff8147b541
[11642.243715] Call Trace:
[11642.244390]  [&lt;ffffffff8147b7f9&gt;] ? bit_wait+0x2f/0x2f
[11642.245432]  [&lt;ffffffff8147b541&gt;] schedule+0x82/0x9a
[11642.246392]  [&lt;ffffffff8147e7fe&gt;] schedule_timeout+0x43/0x109
[11642.247479]  [&lt;ffffffff8147b7f9&gt;] ? bit_wait+0x2f/0x2f
[11642.248551]  [&lt;ffffffff8108afd1&gt;] ? trace_hardirqs_on_caller+0x17b/0x197
[11642.249968]  [&lt;ffffffff8108affa&gt;] ? trace_hardirqs_on+0xd/0xf
[11642.251043]  [&lt;ffffffff810b079b&gt;] ? timekeeping_get_ns+0xe/0x33
[11642.252202]  [&lt;ffffffff810b0f61&gt;] ? ktime_get+0x41/0x52
[11642.253210]  [&lt;ffffffff8147ac08&gt;] io_schedule_timeout+0xa0/0x102
[11642.254307]  [&lt;ffffffff8147ac08&gt;] ? io_schedule_timeout+0xa0/0x102
[11642.256118]  [&lt;ffffffff8147b814&gt;] bit_wait_io+0x1b/0x39
[11642.257131]  [&lt;ffffffff8147bb21&gt;] __wait_on_bit_lock+0x4c/0x90
[11642.258200]  [&lt;ffffffff8111829f&gt;] __lock_page+0x66/0x68
[11642.259168]  [&lt;ffffffff81082f29&gt;] ? autoremove_wake_function+0x3a/0x3a
[11642.260516]  [&lt;ffffffffa0450ddd&gt;] lock_page+0x31/0x34 [btrfs]
[11642.261841]  [&lt;ffffffffa0454e3b&gt;] extent_write_cache_pages.isra.19.constprop.35+0x1af/0x2f4 [btrfs]
[11642.263531]  [&lt;ffffffffa0455373&gt;] extent_writepages+0x4b/0x5c [btrfs]
[11642.264747]  [&lt;ffffffffa043c913&gt;] ? btrfs_writepage_start_hook+0xce/0xce [btrfs]
[11642.266148]  [&lt;ffffffffa043aa82&gt;] btrfs_writepages+0x28/0x2a [btrfs]
[11642.267264]  [&lt;ffffffff811236bc&gt;] do_writepages+0x23/0x2c
[11642.268280]  [&lt;ffffffff81192a2b&gt;] __writeback_single_inode+0xda/0x5ba
[11642.269407]  [&lt;ffffffff811939f0&gt;] writeback_sb_inodes+0x27b/0x43d
[11642.270476]  [&lt;ffffffff81193c28&gt;] __writeback_inodes_wb+0x76/0xae
[11642.271547]  [&lt;ffffffff81193ea6&gt;] wb_writeback+0x19e/0x41c
[11642.272588]  [&lt;ffffffff81194821&gt;] wb_workfn+0x201/0x341
[11642.273523]  [&lt;ffffffff81194821&gt;] ? wb_workfn+0x201/0x341
[11642.274479]  [&lt;ffffffff8106483e&gt;] process_one_work+0x256/0x48b
[11642.275497]  [&lt;ffffffff81064f20&gt;] worker_thread+0x1f5/0x2a7
[11642.276518]  [&lt;ffffffff81064d2b&gt;] ? rescuer_thread+0x289/0x289
[11642.277520]  [&lt;ffffffff81064d2b&gt;] ? rescuer_thread+0x289/0x289
[11642.278517]  [&lt;ffffffff8106a500&gt;] kthread+0xd4/0xdc
[11642.279371]  [&lt;ffffffff8106a42c&gt;] ? kthread_parkme+0x24/0x24
[11642.280468]  [&lt;ffffffff8147fdef&gt;] ret_from_fork+0x3f/0x70
[11642.281607]  [&lt;ffffffff8106a42c&gt;] ? kthread_parkme+0x24/0x24
[11642.282604] 3 locks held by kworker/u32:8/15289:
[11642.283423]  #0:  ("writeback"){++++.+}, at: [&lt;ffffffff8106474d&gt;] process_one_work+0x165/0x48b
[11642.285629]  #1:  ((&amp;(&amp;wb-&gt;dwork)-&gt;work)){+.+.+.}, at: [&lt;ffffffff8106474d&gt;] process_one_work+0x165/0x48b
[11642.287538]  #2:  (&amp;type-&gt;s_umount_key#37){+++++.}, at: [&lt;ffffffff81171217&gt;] trylock_super+0x1b/0x4b
[11642.289423] INFO: task fdm-stress:26848 blocked for more than 120 seconds.
[11642.290547]       Not tainted 4.4.0-rc6-btrfs-next-21+ #1
[11642.291453] "echo 0 &gt; /proc/sys/kernel/hung_task_timeout_secs" disables this message.
[11642.292864] fdm-stress      D ffff88022c107c20     0 26848  26591 0x00000000
[11642.294118]  ffff88022c107c20 000000038108affa 0000000000014ec0 ffff88023ed54ec0
[11642.295602]  ffff88013ab1ca40 ffff88022c108000 ffff8800b2fc19d0 00000000000e0fff
[11642.297098]  ffff8800b2fc19b0 ffff88022c107c88 ffff88022c107c38 ffffffff8147b541
[11642.298433] Call Trace:
[11642.298896]  [&lt;ffffffff8147b541&gt;] schedule+0x82/0x9a
[11642.299738]  [&lt;ffffffffa045225d&gt;] lock_extent_bits+0xfe/0x1a3 [btrfs]
[11642.300833]  [&lt;ffffffff81082eef&gt;] ? add_wait_queue_exclusive+0x44/0x44
[11642.301943]  [&lt;ffffffffa0447516&gt;] lock_and_cleanup_extent_if_need+0x68/0x18e [btrfs]
[11642.303270]  [&lt;ffffffffa04485ba&gt;] __btrfs_buffered_write+0x238/0x4c1 [btrfs]
[11642.304552]  [&lt;ffffffffa044b50a&gt;] ? btrfs_file_write_iter+0x17c/0x408 [btrfs]
[11642.305782]  [&lt;ffffffffa044b682&gt;] btrfs_file_write_iter+0x2f4/0x408 [btrfs]
[11642.306878]  [&lt;ffffffff8116e298&gt;] __vfs_write+0x7c/0xa5
[11642.307729]  [&lt;ffffffff8116e7d1&gt;] vfs_write+0x9d/0xe8
[11642.308602]  [&lt;ffffffff8116efbb&gt;] SyS_write+0x50/0x7e
[11642.309410]  [&lt;ffffffff8147fa97&gt;] entry_SYSCALL_64_fastpath+0x12/0x6b
[11642.310403] 3 locks held by fdm-stress/26848:
[11642.311108]  #0:  (&amp;f-&gt;f_pos_lock){+.+.+.}, at: [&lt;ffffffff811877e8&gt;] __fdget_pos+0x3a/0x40
[11642.312578]  #1:  (sb_writers#11){.+.+.+}, at: [&lt;ffffffff811706ee&gt;] __sb_start_write+0x5f/0xb0
[11642.314170]  #2:  (&amp;sb-&gt;s_type-&gt;i_mutex_key#15){+.+.+.}, at: [&lt;ffffffffa044b401&gt;] btrfs_file_write_iter+0x73/0x408 [btrfs]
[11642.316796] INFO: task fdm-stress:26849 blocked for more than 120 seconds.
[11642.317842]       Not tainted 4.4.0-rc6-btrfs-next-21+ #1
[11642.318691] "echo 0 &gt; /proc/sys/kernel/hung_task_timeout_secs" disables this message.
[11642.319959] fdm-stress      D ffff8801964ffa68     0 26849  26591 0x00000000
[11642.321312]  ffff8801964ffa68 00ff8801e9975f80 0000000000014ec0 ffff88023ed94ec0
[11642.322555]  ffff8800b00b4840 ffff880196500000 ffff8801e9975f20 0000000000000002
[11642.323715]  ffff8801e9975f18 ffff8800b00b4840 ffff8801964ffa80 ffffffff8147b541
[11642.325096] Call Trace:
[11642.325532]  [&lt;ffffffff8147b541&gt;] schedule+0x82/0x9a
[11642.326303]  [&lt;ffffffff8147e7fe&gt;] schedule_timeout+0x43/0x109
[11642.327180]  [&lt;ffffffff8108ae40&gt;] ? mark_held_locks+0x5e/0x74
[11642.328114]  [&lt;ffffffff8147f30e&gt;] ? _raw_spin_unlock_irq+0x2c/0x4a
[11642.329051]  [&lt;ffffffff8108afd1&gt;] ? trace_hardirqs_on_caller+0x17b/0x197
[11642.330053]  [&lt;ffffffff8147bceb&gt;] __wait_for_common+0x109/0x147
[11642.330952]  [&lt;ffffffff8147bceb&gt;] ? __wait_for_common+0x109/0x147
[11642.331869]  [&lt;ffffffff8147e7bb&gt;] ? usleep_range+0x4a/0x4a
[11642.332925]  [&lt;ffffffff81074075&gt;] ? wake_up_q+0x47/0x47
[11642.333736]  [&lt;ffffffff8147bd4d&gt;] wait_for_completion+0x24/0x26
[11642.334672]  [&lt;ffffffffa044f5ce&gt;] btrfs_wait_ordered_extents+0x1c8/0x217 [btrfs]
[11642.335858]  [&lt;ffffffffa0465b5a&gt;] btrfs_mksubvol+0x224/0x45d [btrfs]
[11642.336854]  [&lt;ffffffff81082eef&gt;] ? add_wait_queue_exclusive+0x44/0x44
[11642.337820]  [&lt;ffffffffa0465edb&gt;] btrfs_ioctl_snap_create_transid+0x148/0x17a [btrfs]
[11642.339026]  [&lt;ffffffffa046603b&gt;] btrfs_ioctl_snap_create_v2+0xc7/0x110 [btrfs]
[11642.340214]  [&lt;ffffffffa0468582&gt;] btrfs_ioctl+0x590/0x27bd [btrfs]
[11642.341123]  [&lt;ffffffff8147dc00&gt;] ? mutex_unlock+0xe/0x10
[11642.341934]  [&lt;ffffffffa00fa6e9&gt;] ? ext4_file_write_iter+0x2a3/0x36f [ext4]
[11642.342936]  [&lt;ffffffff8108895d&gt;] ? __lock_is_held+0x3c/0x57
[11642.343772]  [&lt;ffffffff81186a1d&gt;] ? rcu_read_unlock+0x3e/0x5d
[11642.344673]  [&lt;ffffffff8117dc95&gt;] do_vfs_ioctl+0x458/0x4dc
[11642.346024]  [&lt;ffffffff81186bbe&gt;] ? __fget_light+0x62/0x71
[11642.346873]  [&lt;ffffffff8117dd70&gt;] SyS_ioctl+0x57/0x79
[11642.347720]  [&lt;ffffffff8147fa97&gt;] entry_SYSCALL_64_fastpath+0x12/0x6b
[11642.350222] 4 locks held by fdm-stress/26849:
[11642.350898]  #0:  (sb_writers#11){.+.+.+}, at: [&lt;ffffffff811706ee&gt;] __sb_start_write+0x5f/0xb0
[11642.352375]  #1:  (&amp;type-&gt;i_mutex_dir_key#4/1){+.+.+.}, at: [&lt;ffffffffa0465981&gt;] btrfs_mksubvol+0x4b/0x45d [btrfs]
[11642.354072]  #2:  (&amp;fs_info-&gt;subvol_sem){++++..}, at: [&lt;ffffffffa0465a2a&gt;] btrfs_mksubvol+0xf4/0x45d [btrfs]
[11642.355647]  #3:  (&amp;root-&gt;ordered_extent_mutex){+.+...}, at: [&lt;ffffffffa044f456&gt;] btrfs_wait_ordered_extents+0x50/0x217 [btrfs]
[11642.357516] INFO: task fdm-stress:26850 blocked for more than 120 seconds.
[11642.358508]       Not tainted 4.4.0-rc6-btrfs-next-21+ #1
[11642.359376] "echo 0 &gt; /proc/sys/kernel/hung_task_timeout_secs" disables this message.
[11642.368625] fdm-stress      D ffff88021f167688     0 26850  26591 0x00000000
[11642.369716]  ffff88021f167688 0000000000000001 0000000000014ec0 ffff88023edd4ec0
[11642.370950]  ffff880128a98680 ffff88021f168000 ffff88023edd4ec0 7fffffffffffffff
[11642.372210]  0000000000000002 ffffffff8147b7f9 ffff88021f1676a0 ffffffff8147b541
[11642.373430] Call Trace:
[11642.373853]  [&lt;ffffffff8147b7f9&gt;] ? bit_wait+0x2f/0x2f
[11642.374623]  [&lt;ffffffff8147b541&gt;] schedule+0x82/0x9a
[11642.375948]  [&lt;ffffffff8147e7fe&gt;] schedule_timeout+0x43/0x109
[11642.376862]  [&lt;ffffffff8147b7f9&gt;] ? bit_wait+0x2f/0x2f
[11642.377637]  [&lt;ffffffff8108afd1&gt;] ? trace_hardirqs_on_caller+0x17b/0x197
[11642.378610]  [&lt;ffffffff8108affa&gt;] ? trace_hardirqs_on+0xd/0xf
[11642.379457]  [&lt;ffffffff810b079b&gt;] ? timekeeping_get_ns+0xe/0x33
[11642.380366]  [&lt;ffffffff810b0f61&gt;] ? ktime_get+0x41/0x52
[11642.381353]  [&lt;ffffffff8147ac08&gt;] io_schedule_timeout+0xa0/0x102
[11642.382255]  [&lt;ffffffff8147ac08&gt;] ? io_schedule_timeout+0xa0/0x102
[11642.383162]  [&lt;ffffffff8147b814&gt;] bit_wait_io+0x1b/0x39
[11642.383945]  [&lt;ffffffff8147bb21&gt;] __wait_on_bit_lock+0x4c/0x90
[11642.384875]  [&lt;ffffffff8111829f&gt;] __lock_page+0x66/0x68
[11642.385749]  [&lt;ffffffff81082f29&gt;] ? autoremove_wake_function+0x3a/0x3a
[11642.386721]  [&lt;ffffffffa0450ddd&gt;] lock_page+0x31/0x34 [btrfs]
[11642.387596]  [&lt;ffffffffa0454e3b&gt;] extent_write_cache_pages.isra.19.constprop.35+0x1af/0x2f4 [btrfs]
[11642.389030]  [&lt;ffffffffa0455373&gt;] extent_writepages+0x4b/0x5c [btrfs]
[11642.389973]  [&lt;ffffffff810a25ad&gt;] ? rcu_read_lock_sched_held+0x61/0x69
[11642.390939]  [&lt;ffffffffa043c913&gt;] ? btrfs_writepage_start_hook+0xce/0xce [btrfs]
[11642.392271]  [&lt;ffffffffa0451c32&gt;] ? __clear_extent_bit+0x26e/0x2c0 [btrfs]
[11642.393305]  [&lt;ffffffffa043aa82&gt;] btrfs_writepages+0x28/0x2a [btrfs]
[11642.394239]  [&lt;ffffffff811236bc&gt;] do_writepages+0x23/0x2c
[11642.395045]  [&lt;ffffffff811198c9&gt;] __filemap_fdatawrite_range+0x5a/0x61
[11642.395991]  [&lt;ffffffff81119946&gt;] filemap_fdatawrite_range+0x13/0x15
[11642.397144]  [&lt;ffffffffa044f87e&gt;] btrfs_start_ordered_extent+0xd0/0x1a1 [btrfs]
[11642.398392]  [&lt;ffffffffa0452094&gt;] ? clear_extent_bit+0x17/0x19 [btrfs]
[11642.399363]  [&lt;ffffffffa0445945&gt;] btrfs_get_blocks_direct+0x12b/0x61c [btrfs]
[11642.400445]  [&lt;ffffffff8119f7a1&gt;] ? dio_bio_add_page+0x3d/0x54
[11642.401309]  [&lt;ffffffff8119fa93&gt;] ? submit_page_section+0x7b/0x111
[11642.402213]  [&lt;ffffffff811a0258&gt;] do_blockdev_direct_IO+0x685/0xc24
[11642.403139]  [&lt;ffffffffa044581a&gt;] ? btrfs_page_exists_in_range+0x1a1/0x1a1 [btrfs]
[11642.404360]  [&lt;ffffffffa043d267&gt;] ? btrfs_get_extent_fiemap+0x1c0/0x1c0 [btrfs]
[11642.406187]  [&lt;ffffffff811a0828&gt;] __blockdev_direct_IO+0x31/0x33
[11642.407070]  [&lt;ffffffff811a0828&gt;] ? __blockdev_direct_IO+0x31/0x33
[11642.407990]  [&lt;ffffffffa043d267&gt;] ? btrfs_get_extent_fiemap+0x1c0/0x1c0 [btrfs]
[11642.409192]  [&lt;ffffffffa043b4ca&gt;] btrfs_direct_IO+0x1c7/0x27e [btrfs]
[11642.410146]  [&lt;ffffffffa043d267&gt;] ? btrfs_get_extent_fiemap+0x1c0/0x1c0 [btrfs]
[11642.411291]  [&lt;ffffffff81119a2c&gt;] generic_file_read_iter+0x89/0x4e1
[11642.412263]  [&lt;ffffffff8108ac05&gt;] ? mark_lock+0x24/0x201
[11642.413057]  [&lt;ffffffff8116e1f8&gt;] __vfs_read+0x79/0x9d
[11642.413897]  [&lt;ffffffff8116e6f1&gt;] vfs_read+0x8f/0xd2
[11642.414708]  [&lt;ffffffff8116ef3d&gt;] SyS_read+0x50/0x7e
[11642.415573]  [&lt;ffffffff8147fa97&gt;] entry_SYSCALL_64_fastpath+0x12/0x6b
[11642.416572] 1 lock held by fdm-stress/26850:
[11642.417345]  #0:  (&amp;f-&gt;f_pos_lock){+.+.+.}, at: [&lt;ffffffff811877e8&gt;] __fdget_pos+0x3a/0x40
[11642.418703] INFO: task fdm-stress:26851 blocked for more than 120 seconds.
[11642.419698]       Not tainted 4.4.0-rc6-btrfs-next-21+ #1
[11642.420612] "echo 0 &gt; /proc/sys/kernel/hung_task_timeout_secs" disables this message.
[11642.421807] fdm-stress      D ffff880196483d28     0 26851  26591 0x00000000
[11642.422878]  ffff880196483d28 00ff8801c8f60740 0000000000014ec0 ffff88023ed94ec0
[11642.424149]  ffff8801c8f60740 ffff880196484000 0000000000000246 ffff8801c8f60740
[11642.425374]  ffff8801bb711840 ffff8801bb711878 ffff880196483d40 ffffffff8147b541
[11642.426591] Call Trace:
[11642.427013]  [&lt;ffffffff8147b541&gt;] schedule+0x82/0x9a
[11642.427856]  [&lt;ffffffff8147b6d5&gt;] schedule_preempt_disabled+0x18/0x24
[11642.428852]  [&lt;ffffffff8147c23a&gt;] mutex_lock_nested+0x1d7/0x3b4
[11642.429743]  [&lt;ffffffffa044f456&gt;] ? btrfs_wait_ordered_extents+0x50/0x217 [btrfs]
[11642.430911]  [&lt;ffffffffa044f456&gt;] btrfs_wait_ordered_extents+0x50/0x217 [btrfs]
[11642.432102]  [&lt;ffffffffa044f674&gt;] ? btrfs_wait_ordered_roots+0x57/0x191 [btrfs]
[11642.433259]  [&lt;ffffffffa044f456&gt;] ? btrfs_wait_ordered_extents+0x50/0x217 [btrfs]
[11642.434431]  [&lt;ffffffffa044f6ea&gt;] btrfs_wait_ordered_roots+0xcd/0x191 [btrfs]
[11642.436079]  [&lt;ffffffffa0410cab&gt;] btrfs_sync_fs+0xe0/0x1ad [btrfs]
[11642.437009]  [&lt;ffffffff81197900&gt;] ? SyS_tee+0x23c/0x23c
[11642.437860]  [&lt;ffffffff81197920&gt;] sync_fs_one_sb+0x20/0x22
[11642.438723]  [&lt;ffffffff81171435&gt;] iterate_supers+0x75/0xc2
[11642.439597]  [&lt;ffffffff81197d00&gt;] sys_sync+0x52/0x80
[11642.440454]  [&lt;ffffffff8147fa97&gt;] entry_SYSCALL_64_fastpath+0x12/0x6b
[11642.441533] 3 locks held by fdm-stress/26851:
[11642.442370]  #0:  (&amp;type-&gt;s_umount_key#37){+++++.}, at: [&lt;ffffffff8117141f&gt;] iterate_supers+0x5f/0xc2
[11642.444043]  #1:  (&amp;fs_info-&gt;ordered_operations_mutex){+.+...}, at: [&lt;ffffffffa044f661&gt;] btrfs_wait_ordered_roots+0x44/0x191 [btrfs]
[11642.446010]  #2:  (&amp;root-&gt;ordered_extent_mutex){+.+...}, at: [&lt;ffffffffa044f456&gt;] btrfs_wait_ordered_extents+0x50/0x217 [btrfs]

This happened because under specific timings the path for direct IO reads
can deadlock with concurrent buffered writes. The diagram below shows how
this happens for an example file that has the following layout:

     [  extent A  ]  [  extent B  ]  [ ....
     0K              4K              8K

     CPU 1                                               CPU 2                             CPU 3

DIO read against range
 [0K, 8K[ starts

btrfs_direct_IO()
  --&gt; calls btrfs_get_blocks_direct()
      which finds the extent map for the
      extent A and leaves the range
      [0K, 4K[ locked in the inode's
      io tree

                                                   buffered write against
                                                   range [4K, 8K[ starts

                                                   __btrfs_buffered_write()
                                                     --&gt; dirties page at 4K

                                                                                     a user space
                                                                                     task calls sync
                                                                                     for e.g or
                                                                                     writepages() is
                                                                                     invoked by mm

                                                                                     writepages()
                                                                                       run_delalloc_range()
                                                                                         cow_file_range()
                                                                                           --&gt; ordered extent X
                                                                                               for the buffered
                                                                                               write is created
                                                                                               and
                                                                                               writeback starts

  --&gt; calls btrfs_get_blocks_direct()
      again, without submitting first
      a bio for reading extent A, and
      finds the extent map for extent B

  --&gt; calls lock_extent_direct()

      --&gt; locks range [4K, 8K[
      --&gt; finds ordered extent X
          covering range [4K, 8K[
      --&gt; unlocks range [4K, 8K[

                                                  buffered write against
                                                  range [0K, 8K[ starts

                                                  __btrfs_buffered_write()
                                                    prepare_pages()
                                                      --&gt; locks pages with
                                                          offsets 0 and 4K
                                                    lock_and_cleanup_extent_if_need()
                                                      --&gt; blocks attempting to
                                                          lock range [0K, 8K[ in
                                                          the inode's io tree,
                                                          because the range [0, 4K[
                                                          is already locked by the
                                                          direct IO task at CPU 1

      --&gt; calls
          btrfs_start_ordered_extent(oe X)

          btrfs_start_ordered_extent(oe X)

            --&gt; At this point writeback for ordered
                extent X has not finished yet

            filemap_fdatawrite_range()
              btrfs_writepages()
                extent_writepages()
                  extent_write_cache_pages()
                    --&gt; finds page with offset 0
                        with the writeback tag
                        (and not dirty)
                    --&gt; tries to lock it
                         --&gt; deadlock, task at CPU 2
                             has the page locked and
                             is blocked on the io range
                             [0, 4K[ that was locked
                             earlier by this task

So fix this by falling back to a buffered read in the direct IO read path
when an ordered extent for a buffered write is found.

Signed-off-by: Filipe Manana &lt;fdmanana@suse.com&gt;
Reviewed-by: Liu Bo &lt;bo.li.liu@oracle.com&gt;
Signed-off-by: Chris Mason &lt;clm@fb.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;

</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
commit ade770294df29e08f913e5d733a756893128f45e upstream.

While running a test with a mix of buffered IO and direct IO against
the same files I hit a deadlock reported by the following trace:

[11642.140352] INFO: task kworker/u32:3:15282 blocked for more than 120 seconds.
[11642.142452]       Not tainted 4.4.0-rc6-btrfs-next-21+ #1
[11642.143982] "echo 0 &gt; /proc/sys/kernel/hung_task_timeout_secs" disables this message.
[11642.146332] kworker/u32:3   D ffff880230ef7988 [11642.147737] systemd-journald[571]: Sent WATCHDOG=1 notification.
[11642.149771]     0 15282      2 0x00000000
[11642.151205] Workqueue: btrfs-flush_delalloc btrfs_flush_delalloc_helper [btrfs]
[11642.154074]  ffff880230ef7988 0000000000000246 0000000000014ec0 ffff88023ec94ec0
[11642.156722]  ffff880233fe8f80 ffff880230ef8000 ffff88023ec94ec0 7fffffffffffffff
[11642.159205]  0000000000000002 ffffffff8147b7f9 ffff880230ef79a0 ffffffff8147b541
[11642.161403] Call Trace:
[11642.162129]  [&lt;ffffffff8147b7f9&gt;] ? bit_wait+0x2f/0x2f
[11642.163396]  [&lt;ffffffff8147b541&gt;] schedule+0x82/0x9a
[11642.164871]  [&lt;ffffffff8147e7fe&gt;] schedule_timeout+0x43/0x109
[11642.167020]  [&lt;ffffffff8147b7f9&gt;] ? bit_wait+0x2f/0x2f
[11642.167931]  [&lt;ffffffff8108afd1&gt;] ? trace_hardirqs_on_caller+0x17b/0x197
[11642.182320]  [&lt;ffffffff8108affa&gt;] ? trace_hardirqs_on+0xd/0xf
[11642.183762]  [&lt;ffffffff810b079b&gt;] ? timekeeping_get_ns+0xe/0x33
[11642.185308]  [&lt;ffffffff810b0f61&gt;] ? ktime_get+0x41/0x52
[11642.186782]  [&lt;ffffffff8147ac08&gt;] io_schedule_timeout+0xa0/0x102
[11642.188217]  [&lt;ffffffff8147ac08&gt;] ? io_schedule_timeout+0xa0/0x102
[11642.189626]  [&lt;ffffffff8147b814&gt;] bit_wait_io+0x1b/0x39
[11642.190803]  [&lt;ffffffff8147bb21&gt;] __wait_on_bit_lock+0x4c/0x90
[11642.192158]  [&lt;ffffffff8111829f&gt;] __lock_page+0x66/0x68
[11642.193379]  [&lt;ffffffff81082f29&gt;] ? autoremove_wake_function+0x3a/0x3a
[11642.194831]  [&lt;ffffffffa0450ddd&gt;] lock_page+0x31/0x34 [btrfs]
[11642.197068]  [&lt;ffffffffa0454e3b&gt;] extent_write_cache_pages.isra.19.constprop.35+0x1af/0x2f4 [btrfs]
[11642.199188]  [&lt;ffffffffa0455373&gt;] extent_writepages+0x4b/0x5c [btrfs]
[11642.200723]  [&lt;ffffffffa043c913&gt;] ? btrfs_writepage_start_hook+0xce/0xce [btrfs]
[11642.202465]  [&lt;ffffffffa043aa82&gt;] btrfs_writepages+0x28/0x2a [btrfs]
[11642.203836]  [&lt;ffffffff811236bc&gt;] do_writepages+0x23/0x2c
[11642.205624]  [&lt;ffffffff811198c9&gt;] __filemap_fdatawrite_range+0x5a/0x61
[11642.207057]  [&lt;ffffffff81119946&gt;] filemap_fdatawrite_range+0x13/0x15
[11642.208529]  [&lt;ffffffffa044f87e&gt;] btrfs_start_ordered_extent+0xd0/0x1a1 [btrfs]
[11642.210375]  [&lt;ffffffffa0462613&gt;] ? btrfs_scrubparity_helper+0x140/0x33a [btrfs]
[11642.212132]  [&lt;ffffffffa044f974&gt;] btrfs_run_ordered_extent_work+0x25/0x34 [btrfs]
[11642.213837]  [&lt;ffffffffa046262f&gt;] btrfs_scrubparity_helper+0x15c/0x33a [btrfs]
[11642.215457]  [&lt;ffffffffa046293b&gt;] btrfs_flush_delalloc_helper+0xe/0x10 [btrfs]
[11642.217095]  [&lt;ffffffff8106483e&gt;] process_one_work+0x256/0x48b
[11642.218324]  [&lt;ffffffff81064f20&gt;] worker_thread+0x1f5/0x2a7
[11642.219466]  [&lt;ffffffff81064d2b&gt;] ? rescuer_thread+0x289/0x289
[11642.220801]  [&lt;ffffffff8106a500&gt;] kthread+0xd4/0xdc
[11642.222032]  [&lt;ffffffff8106a42c&gt;] ? kthread_parkme+0x24/0x24
[11642.223190]  [&lt;ffffffff8147fdef&gt;] ret_from_fork+0x3f/0x70
[11642.224394]  [&lt;ffffffff8106a42c&gt;] ? kthread_parkme+0x24/0x24
[11642.226295] 2 locks held by kworker/u32:3/15282:
[11642.227273]  #0:  ("%s-%s""btrfs", name){++++.+}, at: [&lt;ffffffff8106474d&gt;] process_one_work+0x165/0x48b
[11642.229412]  #1:  ((&amp;work-&gt;normal_work)){+.+.+.}, at: [&lt;ffffffff8106474d&gt;] process_one_work+0x165/0x48b
[11642.231414] INFO: task kworker/u32:8:15289 blocked for more than 120 seconds.
[11642.232872]       Not tainted 4.4.0-rc6-btrfs-next-21+ #1
[11642.234109] "echo 0 &gt; /proc/sys/kernel/hung_task_timeout_secs" disables this message.
[11642.235776] kworker/u32:8   D ffff88020de5f848     0 15289      2 0x00000000
[11642.237412] Workqueue: writeback wb_workfn (flush-btrfs-481)
[11642.238670]  ffff88020de5f848 0000000000000246 0000000000014ec0 ffff88023ed54ec0
[11642.240475]  ffff88021b1ece40 ffff88020de60000 ffff88023ed54ec0 7fffffffffffffff
[11642.242154]  0000000000000002 ffffffff8147b7f9 ffff88020de5f860 ffffffff8147b541
[11642.243715] Call Trace:
[11642.244390]  [&lt;ffffffff8147b7f9&gt;] ? bit_wait+0x2f/0x2f
[11642.245432]  [&lt;ffffffff8147b541&gt;] schedule+0x82/0x9a
[11642.246392]  [&lt;ffffffff8147e7fe&gt;] schedule_timeout+0x43/0x109
[11642.247479]  [&lt;ffffffff8147b7f9&gt;] ? bit_wait+0x2f/0x2f
[11642.248551]  [&lt;ffffffff8108afd1&gt;] ? trace_hardirqs_on_caller+0x17b/0x197
[11642.249968]  [&lt;ffffffff8108affa&gt;] ? trace_hardirqs_on+0xd/0xf
[11642.251043]  [&lt;ffffffff810b079b&gt;] ? timekeeping_get_ns+0xe/0x33
[11642.252202]  [&lt;ffffffff810b0f61&gt;] ? ktime_get+0x41/0x52
[11642.253210]  [&lt;ffffffff8147ac08&gt;] io_schedule_timeout+0xa0/0x102
[11642.254307]  [&lt;ffffffff8147ac08&gt;] ? io_schedule_timeout+0xa0/0x102
[11642.256118]  [&lt;ffffffff8147b814&gt;] bit_wait_io+0x1b/0x39
[11642.257131]  [&lt;ffffffff8147bb21&gt;] __wait_on_bit_lock+0x4c/0x90
[11642.258200]  [&lt;ffffffff8111829f&gt;] __lock_page+0x66/0x68
[11642.259168]  [&lt;ffffffff81082f29&gt;] ? autoremove_wake_function+0x3a/0x3a
[11642.260516]  [&lt;ffffffffa0450ddd&gt;] lock_page+0x31/0x34 [btrfs]
[11642.261841]  [&lt;ffffffffa0454e3b&gt;] extent_write_cache_pages.isra.19.constprop.35+0x1af/0x2f4 [btrfs]
[11642.263531]  [&lt;ffffffffa0455373&gt;] extent_writepages+0x4b/0x5c [btrfs]
[11642.264747]  [&lt;ffffffffa043c913&gt;] ? btrfs_writepage_start_hook+0xce/0xce [btrfs]
[11642.266148]  [&lt;ffffffffa043aa82&gt;] btrfs_writepages+0x28/0x2a [btrfs]
[11642.267264]  [&lt;ffffffff811236bc&gt;] do_writepages+0x23/0x2c
[11642.268280]  [&lt;ffffffff81192a2b&gt;] __writeback_single_inode+0xda/0x5ba
[11642.269407]  [&lt;ffffffff811939f0&gt;] writeback_sb_inodes+0x27b/0x43d
[11642.270476]  [&lt;ffffffff81193c28&gt;] __writeback_inodes_wb+0x76/0xae
[11642.271547]  [&lt;ffffffff81193ea6&gt;] wb_writeback+0x19e/0x41c
[11642.272588]  [&lt;ffffffff81194821&gt;] wb_workfn+0x201/0x341
[11642.273523]  [&lt;ffffffff81194821&gt;] ? wb_workfn+0x201/0x341
[11642.274479]  [&lt;ffffffff8106483e&gt;] process_one_work+0x256/0x48b
[11642.275497]  [&lt;ffffffff81064f20&gt;] worker_thread+0x1f5/0x2a7
[11642.276518]  [&lt;ffffffff81064d2b&gt;] ? rescuer_thread+0x289/0x289
[11642.277520]  [&lt;ffffffff81064d2b&gt;] ? rescuer_thread+0x289/0x289
[11642.278517]  [&lt;ffffffff8106a500&gt;] kthread+0xd4/0xdc
[11642.279371]  [&lt;ffffffff8106a42c&gt;] ? kthread_parkme+0x24/0x24
[11642.280468]  [&lt;ffffffff8147fdef&gt;] ret_from_fork+0x3f/0x70
[11642.281607]  [&lt;ffffffff8106a42c&gt;] ? kthread_parkme+0x24/0x24
[11642.282604] 3 locks held by kworker/u32:8/15289:
[11642.283423]  #0:  ("writeback"){++++.+}, at: [&lt;ffffffff8106474d&gt;] process_one_work+0x165/0x48b
[11642.285629]  #1:  ((&amp;(&amp;wb-&gt;dwork)-&gt;work)){+.+.+.}, at: [&lt;ffffffff8106474d&gt;] process_one_work+0x165/0x48b
[11642.287538]  #2:  (&amp;type-&gt;s_umount_key#37){+++++.}, at: [&lt;ffffffff81171217&gt;] trylock_super+0x1b/0x4b
[11642.289423] INFO: task fdm-stress:26848 blocked for more than 120 seconds.
[11642.290547]       Not tainted 4.4.0-rc6-btrfs-next-21+ #1
[11642.291453] "echo 0 &gt; /proc/sys/kernel/hung_task_timeout_secs" disables this message.
[11642.292864] fdm-stress      D ffff88022c107c20     0 26848  26591 0x00000000
[11642.294118]  ffff88022c107c20 000000038108affa 0000000000014ec0 ffff88023ed54ec0
[11642.295602]  ffff88013ab1ca40 ffff88022c108000 ffff8800b2fc19d0 00000000000e0fff
[11642.297098]  ffff8800b2fc19b0 ffff88022c107c88 ffff88022c107c38 ffffffff8147b541
[11642.298433] Call Trace:
[11642.298896]  [&lt;ffffffff8147b541&gt;] schedule+0x82/0x9a
[11642.299738]  [&lt;ffffffffa045225d&gt;] lock_extent_bits+0xfe/0x1a3 [btrfs]
[11642.300833]  [&lt;ffffffff81082eef&gt;] ? add_wait_queue_exclusive+0x44/0x44
[11642.301943]  [&lt;ffffffffa0447516&gt;] lock_and_cleanup_extent_if_need+0x68/0x18e [btrfs]
[11642.303270]  [&lt;ffffffffa04485ba&gt;] __btrfs_buffered_write+0x238/0x4c1 [btrfs]
[11642.304552]  [&lt;ffffffffa044b50a&gt;] ? btrfs_file_write_iter+0x17c/0x408 [btrfs]
[11642.305782]  [&lt;ffffffffa044b682&gt;] btrfs_file_write_iter+0x2f4/0x408 [btrfs]
[11642.306878]  [&lt;ffffffff8116e298&gt;] __vfs_write+0x7c/0xa5
[11642.307729]  [&lt;ffffffff8116e7d1&gt;] vfs_write+0x9d/0xe8
[11642.308602]  [&lt;ffffffff8116efbb&gt;] SyS_write+0x50/0x7e
[11642.309410]  [&lt;ffffffff8147fa97&gt;] entry_SYSCALL_64_fastpath+0x12/0x6b
[11642.310403] 3 locks held by fdm-stress/26848:
[11642.311108]  #0:  (&amp;f-&gt;f_pos_lock){+.+.+.}, at: [&lt;ffffffff811877e8&gt;] __fdget_pos+0x3a/0x40
[11642.312578]  #1:  (sb_writers#11){.+.+.+}, at: [&lt;ffffffff811706ee&gt;] __sb_start_write+0x5f/0xb0
[11642.314170]  #2:  (&amp;sb-&gt;s_type-&gt;i_mutex_key#15){+.+.+.}, at: [&lt;ffffffffa044b401&gt;] btrfs_file_write_iter+0x73/0x408 [btrfs]
[11642.316796] INFO: task fdm-stress:26849 blocked for more than 120 seconds.
[11642.317842]       Not tainted 4.4.0-rc6-btrfs-next-21+ #1
[11642.318691] "echo 0 &gt; /proc/sys/kernel/hung_task_timeout_secs" disables this message.
[11642.319959] fdm-stress      D ffff8801964ffa68     0 26849  26591 0x00000000
[11642.321312]  ffff8801964ffa68 00ff8801e9975f80 0000000000014ec0 ffff88023ed94ec0
[11642.322555]  ffff8800b00b4840 ffff880196500000 ffff8801e9975f20 0000000000000002
[11642.323715]  ffff8801e9975f18 ffff8800b00b4840 ffff8801964ffa80 ffffffff8147b541
[11642.325096] Call Trace:
[11642.325532]  [&lt;ffffffff8147b541&gt;] schedule+0x82/0x9a
[11642.326303]  [&lt;ffffffff8147e7fe&gt;] schedule_timeout+0x43/0x109
[11642.327180]  [&lt;ffffffff8108ae40&gt;] ? mark_held_locks+0x5e/0x74
[11642.328114]  [&lt;ffffffff8147f30e&gt;] ? _raw_spin_unlock_irq+0x2c/0x4a
[11642.329051]  [&lt;ffffffff8108afd1&gt;] ? trace_hardirqs_on_caller+0x17b/0x197
[11642.330053]  [&lt;ffffffff8147bceb&gt;] __wait_for_common+0x109/0x147
[11642.330952]  [&lt;ffffffff8147bceb&gt;] ? __wait_for_common+0x109/0x147
[11642.331869]  [&lt;ffffffff8147e7bb&gt;] ? usleep_range+0x4a/0x4a
[11642.332925]  [&lt;ffffffff81074075&gt;] ? wake_up_q+0x47/0x47
[11642.333736]  [&lt;ffffffff8147bd4d&gt;] wait_for_completion+0x24/0x26
[11642.334672]  [&lt;ffffffffa044f5ce&gt;] btrfs_wait_ordered_extents+0x1c8/0x217 [btrfs]
[11642.335858]  [&lt;ffffffffa0465b5a&gt;] btrfs_mksubvol+0x224/0x45d [btrfs]
[11642.336854]  [&lt;ffffffff81082eef&gt;] ? add_wait_queue_exclusive+0x44/0x44
[11642.337820]  [&lt;ffffffffa0465edb&gt;] btrfs_ioctl_snap_create_transid+0x148/0x17a [btrfs]
[11642.339026]  [&lt;ffffffffa046603b&gt;] btrfs_ioctl_snap_create_v2+0xc7/0x110 [btrfs]
[11642.340214]  [&lt;ffffffffa0468582&gt;] btrfs_ioctl+0x590/0x27bd [btrfs]
[11642.341123]  [&lt;ffffffff8147dc00&gt;] ? mutex_unlock+0xe/0x10
[11642.341934]  [&lt;ffffffffa00fa6e9&gt;] ? ext4_file_write_iter+0x2a3/0x36f [ext4]
[11642.342936]  [&lt;ffffffff8108895d&gt;] ? __lock_is_held+0x3c/0x57
[11642.343772]  [&lt;ffffffff81186a1d&gt;] ? rcu_read_unlock+0x3e/0x5d
[11642.344673]  [&lt;ffffffff8117dc95&gt;] do_vfs_ioctl+0x458/0x4dc
[11642.346024]  [&lt;ffffffff81186bbe&gt;] ? __fget_light+0x62/0x71
[11642.346873]  [&lt;ffffffff8117dd70&gt;] SyS_ioctl+0x57/0x79
[11642.347720]  [&lt;ffffffff8147fa97&gt;] entry_SYSCALL_64_fastpath+0x12/0x6b
[11642.350222] 4 locks held by fdm-stress/26849:
[11642.350898]  #0:  (sb_writers#11){.+.+.+}, at: [&lt;ffffffff811706ee&gt;] __sb_start_write+0x5f/0xb0
[11642.352375]  #1:  (&amp;type-&gt;i_mutex_dir_key#4/1){+.+.+.}, at: [&lt;ffffffffa0465981&gt;] btrfs_mksubvol+0x4b/0x45d [btrfs]
[11642.354072]  #2:  (&amp;fs_info-&gt;subvol_sem){++++..}, at: [&lt;ffffffffa0465a2a&gt;] btrfs_mksubvol+0xf4/0x45d [btrfs]
[11642.355647]  #3:  (&amp;root-&gt;ordered_extent_mutex){+.+...}, at: [&lt;ffffffffa044f456&gt;] btrfs_wait_ordered_extents+0x50/0x217 [btrfs]
[11642.357516] INFO: task fdm-stress:26850 blocked for more than 120 seconds.
[11642.358508]       Not tainted 4.4.0-rc6-btrfs-next-21+ #1
[11642.359376] "echo 0 &gt; /proc/sys/kernel/hung_task_timeout_secs" disables this message.
[11642.368625] fdm-stress      D ffff88021f167688     0 26850  26591 0x00000000
[11642.369716]  ffff88021f167688 0000000000000001 0000000000014ec0 ffff88023edd4ec0
[11642.370950]  ffff880128a98680 ffff88021f168000 ffff88023edd4ec0 7fffffffffffffff
[11642.372210]  0000000000000002 ffffffff8147b7f9 ffff88021f1676a0 ffffffff8147b541
[11642.373430] Call Trace:
[11642.373853]  [&lt;ffffffff8147b7f9&gt;] ? bit_wait+0x2f/0x2f
[11642.374623]  [&lt;ffffffff8147b541&gt;] schedule+0x82/0x9a
[11642.375948]  [&lt;ffffffff8147e7fe&gt;] schedule_timeout+0x43/0x109
[11642.376862]  [&lt;ffffffff8147b7f9&gt;] ? bit_wait+0x2f/0x2f
[11642.377637]  [&lt;ffffffff8108afd1&gt;] ? trace_hardirqs_on_caller+0x17b/0x197
[11642.378610]  [&lt;ffffffff8108affa&gt;] ? trace_hardirqs_on+0xd/0xf
[11642.379457]  [&lt;ffffffff810b079b&gt;] ? timekeeping_get_ns+0xe/0x33
[11642.380366]  [&lt;ffffffff810b0f61&gt;] ? ktime_get+0x41/0x52
[11642.381353]  [&lt;ffffffff8147ac08&gt;] io_schedule_timeout+0xa0/0x102
[11642.382255]  [&lt;ffffffff8147ac08&gt;] ? io_schedule_timeout+0xa0/0x102
[11642.383162]  [&lt;ffffffff8147b814&gt;] bit_wait_io+0x1b/0x39
[11642.383945]  [&lt;ffffffff8147bb21&gt;] __wait_on_bit_lock+0x4c/0x90
[11642.384875]  [&lt;ffffffff8111829f&gt;] __lock_page+0x66/0x68
[11642.385749]  [&lt;ffffffff81082f29&gt;] ? autoremove_wake_function+0x3a/0x3a
[11642.386721]  [&lt;ffffffffa0450ddd&gt;] lock_page+0x31/0x34 [btrfs]
[11642.387596]  [&lt;ffffffffa0454e3b&gt;] extent_write_cache_pages.isra.19.constprop.35+0x1af/0x2f4 [btrfs]
[11642.389030]  [&lt;ffffffffa0455373&gt;] extent_writepages+0x4b/0x5c [btrfs]
[11642.389973]  [&lt;ffffffff810a25ad&gt;] ? rcu_read_lock_sched_held+0x61/0x69
[11642.390939]  [&lt;ffffffffa043c913&gt;] ? btrfs_writepage_start_hook+0xce/0xce [btrfs]
[11642.392271]  [&lt;ffffffffa0451c32&gt;] ? __clear_extent_bit+0x26e/0x2c0 [btrfs]
[11642.393305]  [&lt;ffffffffa043aa82&gt;] btrfs_writepages+0x28/0x2a [btrfs]
[11642.394239]  [&lt;ffffffff811236bc&gt;] do_writepages+0x23/0x2c
[11642.395045]  [&lt;ffffffff811198c9&gt;] __filemap_fdatawrite_range+0x5a/0x61
[11642.395991]  [&lt;ffffffff81119946&gt;] filemap_fdatawrite_range+0x13/0x15
[11642.397144]  [&lt;ffffffffa044f87e&gt;] btrfs_start_ordered_extent+0xd0/0x1a1 [btrfs]
[11642.398392]  [&lt;ffffffffa0452094&gt;] ? clear_extent_bit+0x17/0x19 [btrfs]
[11642.399363]  [&lt;ffffffffa0445945&gt;] btrfs_get_blocks_direct+0x12b/0x61c [btrfs]
[11642.400445]  [&lt;ffffffff8119f7a1&gt;] ? dio_bio_add_page+0x3d/0x54
[11642.401309]  [&lt;ffffffff8119fa93&gt;] ? submit_page_section+0x7b/0x111
[11642.402213]  [&lt;ffffffff811a0258&gt;] do_blockdev_direct_IO+0x685/0xc24
[11642.403139]  [&lt;ffffffffa044581a&gt;] ? btrfs_page_exists_in_range+0x1a1/0x1a1 [btrfs]
[11642.404360]  [&lt;ffffffffa043d267&gt;] ? btrfs_get_extent_fiemap+0x1c0/0x1c0 [btrfs]
[11642.406187]  [&lt;ffffffff811a0828&gt;] __blockdev_direct_IO+0x31/0x33
[11642.407070]  [&lt;ffffffff811a0828&gt;] ? __blockdev_direct_IO+0x31/0x33
[11642.407990]  [&lt;ffffffffa043d267&gt;] ? btrfs_get_extent_fiemap+0x1c0/0x1c0 [btrfs]
[11642.409192]  [&lt;ffffffffa043b4ca&gt;] btrfs_direct_IO+0x1c7/0x27e [btrfs]
[11642.410146]  [&lt;ffffffffa043d267&gt;] ? btrfs_get_extent_fiemap+0x1c0/0x1c0 [btrfs]
[11642.411291]  [&lt;ffffffff81119a2c&gt;] generic_file_read_iter+0x89/0x4e1
[11642.412263]  [&lt;ffffffff8108ac05&gt;] ? mark_lock+0x24/0x201
[11642.413057]  [&lt;ffffffff8116e1f8&gt;] __vfs_read+0x79/0x9d
[11642.413897]  [&lt;ffffffff8116e6f1&gt;] vfs_read+0x8f/0xd2
[11642.414708]  [&lt;ffffffff8116ef3d&gt;] SyS_read+0x50/0x7e
[11642.415573]  [&lt;ffffffff8147fa97&gt;] entry_SYSCALL_64_fastpath+0x12/0x6b
[11642.416572] 1 lock held by fdm-stress/26850:
[11642.417345]  #0:  (&amp;f-&gt;f_pos_lock){+.+.+.}, at: [&lt;ffffffff811877e8&gt;] __fdget_pos+0x3a/0x40
[11642.418703] INFO: task fdm-stress:26851 blocked for more than 120 seconds.
[11642.419698]       Not tainted 4.4.0-rc6-btrfs-next-21+ #1
[11642.420612] "echo 0 &gt; /proc/sys/kernel/hung_task_timeout_secs" disables this message.
[11642.421807] fdm-stress      D ffff880196483d28     0 26851  26591 0x00000000
[11642.422878]  ffff880196483d28 00ff8801c8f60740 0000000000014ec0 ffff88023ed94ec0
[11642.424149]  ffff8801c8f60740 ffff880196484000 0000000000000246 ffff8801c8f60740
[11642.425374]  ffff8801bb711840 ffff8801bb711878 ffff880196483d40 ffffffff8147b541
[11642.426591] Call Trace:
[11642.427013]  [&lt;ffffffff8147b541&gt;] schedule+0x82/0x9a
[11642.427856]  [&lt;ffffffff8147b6d5&gt;] schedule_preempt_disabled+0x18/0x24
[11642.428852]  [&lt;ffffffff8147c23a&gt;] mutex_lock_nested+0x1d7/0x3b4
[11642.429743]  [&lt;ffffffffa044f456&gt;] ? btrfs_wait_ordered_extents+0x50/0x217 [btrfs]
[11642.430911]  [&lt;ffffffffa044f456&gt;] btrfs_wait_ordered_extents+0x50/0x217 [btrfs]
[11642.432102]  [&lt;ffffffffa044f674&gt;] ? btrfs_wait_ordered_roots+0x57/0x191 [btrfs]
[11642.433259]  [&lt;ffffffffa044f456&gt;] ? btrfs_wait_ordered_extents+0x50/0x217 [btrfs]
[11642.434431]  [&lt;ffffffffa044f6ea&gt;] btrfs_wait_ordered_roots+0xcd/0x191 [btrfs]
[11642.436079]  [&lt;ffffffffa0410cab&gt;] btrfs_sync_fs+0xe0/0x1ad [btrfs]
[11642.437009]  [&lt;ffffffff81197900&gt;] ? SyS_tee+0x23c/0x23c
[11642.437860]  [&lt;ffffffff81197920&gt;] sync_fs_one_sb+0x20/0x22
[11642.438723]  [&lt;ffffffff81171435&gt;] iterate_supers+0x75/0xc2
[11642.439597]  [&lt;ffffffff81197d00&gt;] sys_sync+0x52/0x80
[11642.440454]  [&lt;ffffffff8147fa97&gt;] entry_SYSCALL_64_fastpath+0x12/0x6b
[11642.441533] 3 locks held by fdm-stress/26851:
[11642.442370]  #0:  (&amp;type-&gt;s_umount_key#37){+++++.}, at: [&lt;ffffffff8117141f&gt;] iterate_supers+0x5f/0xc2
[11642.444043]  #1:  (&amp;fs_info-&gt;ordered_operations_mutex){+.+...}, at: [&lt;ffffffffa044f661&gt;] btrfs_wait_ordered_roots+0x44/0x191 [btrfs]
[11642.446010]  #2:  (&amp;root-&gt;ordered_extent_mutex){+.+...}, at: [&lt;ffffffffa044f456&gt;] btrfs_wait_ordered_extents+0x50/0x217 [btrfs]

This happened because under specific timings the path for direct IO reads
can deadlock with concurrent buffered writes. The diagram below shows how
this happens for an example file that has the following layout:

     [  extent A  ]  [  extent B  ]  [ ....
     0K              4K              8K

     CPU 1                                               CPU 2                             CPU 3

DIO read against range
 [0K, 8K[ starts

btrfs_direct_IO()
  --&gt; calls btrfs_get_blocks_direct()
      which finds the extent map for the
      extent A and leaves the range
      [0K, 4K[ locked in the inode's
      io tree

                                                   buffered write against
                                                   range [4K, 8K[ starts

                                                   __btrfs_buffered_write()
                                                     --&gt; dirties page at 4K

                                                                                     a user space
                                                                                     task calls sync
                                                                                     for e.g or
                                                                                     writepages() is
                                                                                     invoked by mm

                                                                                     writepages()
                                                                                       run_delalloc_range()
                                                                                         cow_file_range()
                                                                                           --&gt; ordered extent X
                                                                                               for the buffered
                                                                                               write is created
                                                                                               and
                                                                                               writeback starts

  --&gt; calls btrfs_get_blocks_direct()
      again, without submitting first
      a bio for reading extent A, and
      finds the extent map for extent B

  --&gt; calls lock_extent_direct()

      --&gt; locks range [4K, 8K[
      --&gt; finds ordered extent X
          covering range [4K, 8K[
      --&gt; unlocks range [4K, 8K[

                                                  buffered write against
                                                  range [0K, 8K[ starts

                                                  __btrfs_buffered_write()
                                                    prepare_pages()
                                                      --&gt; locks pages with
                                                          offsets 0 and 4K
                                                    lock_and_cleanup_extent_if_need()
                                                      --&gt; blocks attempting to
                                                          lock range [0K, 8K[ in
                                                          the inode's io tree,
                                                          because the range [0, 4K[
                                                          is already locked by the
                                                          direct IO task at CPU 1

      --&gt; calls
          btrfs_start_ordered_extent(oe X)

          btrfs_start_ordered_extent(oe X)

            --&gt; At this point writeback for ordered
                extent X has not finished yet

            filemap_fdatawrite_range()
              btrfs_writepages()
                extent_writepages()
                  extent_write_cache_pages()
                    --&gt; finds page with offset 0
                        with the writeback tag
                        (and not dirty)
                    --&gt; tries to lock it
                         --&gt; deadlock, task at CPU 2
                             has the page locked and
                             is blocked on the io range
                             [0, 4K[ that was locked
                             earlier by this task

So fix this by falling back to a buffered read in the direct IO read path
when an ordered extent for a buffered write is found.

Signed-off-by: Filipe Manana &lt;fdmanana@suse.com&gt;
Reviewed-by: Liu Bo &lt;bo.li.liu@oracle.com&gt;
Signed-off-by: Chris Mason &lt;clm@fb.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;

</pre>
</div>
</content>
</entry>
</feed>
